mirror of
https://github.com/1dot13/source.git
synced 2026-07-29 13:52:17 +02:00
Added functions for utf8 <> wstring conversion.
Added message when AI breaks deadlock because cannot complete action. git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@9262 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
@@ -4,6 +4,9 @@
|
||||
#include "text.h"
|
||||
#include "Fileman.h"
|
||||
#include "GameSettings.h"
|
||||
// sevenfm
|
||||
#include <codecvt>
|
||||
#include <string>
|
||||
#endif
|
||||
|
||||
BOOLEAN LoadItemInfo(UINT16 ubIndex, STR16 pNameString, STR16 pInfoString )
|
||||
@@ -1300,3 +1303,27 @@ void ParseCommandLine (
|
||||
++*numargs;
|
||||
}
|
||||
|
||||
inline std::string narrow(std::wstring const& text)
|
||||
{
|
||||
std::locale const loc("");
|
||||
wchar_t const* from = text.c_str();
|
||||
std::size_t const len = text.size();
|
||||
std::vector<char> buffer(len + 1);
|
||||
std::use_facet<std::ctype<wchar_t> >(loc).narrow(from, from + len, '_', &buffer[0]);
|
||||
|
||||
return std::string(&buffer[0], &buffer[len]);
|
||||
}
|
||||
|
||||
// convert UTF-8 string to wstring
|
||||
std::wstring utf8_to_wstring(const std::string& str)
|
||||
{
|
||||
std::wstring_convert<std::codecvt_utf8<wchar_t>> myconv;
|
||||
return myconv.from_bytes(str);
|
||||
}
|
||||
|
||||
// convert wstring to UTF-8 string
|
||||
std::string wstring_to_utf8(const std::wstring& str)
|
||||
{
|
||||
std::wstring_convert<std::codecvt_utf8<wchar_t>> myconv;
|
||||
return myconv.to_bytes(str);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user