[Project64] Add codepage stdstr::ToUTF16

This commit is contained in:
zilmar 2015-11-30 06:25:09 +11:00
parent bc8d8b8fa1
commit 942e07569a
2 changed files with 10 additions and 4 deletions

View File

@ -216,12 +216,12 @@ stdstr & stdstr::FromUTF16(const wchar_t * UTF16Source, bool * bSuccess)
return *this;
}
std::wstring stdstr::ToUTF16(bool * bSuccess)
std::wstring stdstr::ToUTF16(UINT CodePage, bool * bSuccess)
{
bool bConverted = false;
std::wstring res;
DWORD nNeeded = MultiByteToWideChar(CP_UTF8, 0, this->c_str(), (int)this->length(), NULL, 0);
DWORD nNeeded = MultiByteToWideChar(CodePage, 0, this->c_str(), (int)this->length(), NULL, 0);
if (nNeeded > 0)
{
wchar_t * buf = (wchar_t *)alloca((nNeeded + 1) * sizeof(wchar_t));
@ -229,7 +229,7 @@ std::wstring stdstr::ToUTF16(bool * bSuccess)
{
memset(buf, 0, (nNeeded + 1) * sizeof(wchar_t));
nNeeded = MultiByteToWideChar(CP_UTF8, 0, this->c_str(), (int)this->length(), buf, nNeeded);
nNeeded = MultiByteToWideChar(CodePage, 0, this->c_str(), (int)this->length(), buf, nNeeded);
if (nNeeded)
{
res = buf;

View File

@ -13,6 +13,12 @@ class stdstr :
public std::string
{
public:
enum
{
CODEPAGE_UTF8 = 65001,
CODEPAGE_932 = 932,
};
stdstr();
stdstr(const std::string & str);
stdstr(const stdstr & str);
@ -33,7 +39,7 @@ public:
stdstr & TrimRight(const char * chars2remove = "\t ");
stdstr & FromUTF16(const wchar_t * UTF16Source, bool * bSuccess = NULL);
std::wstring ToUTF16(bool * bSuccess = NULL);
std::wstring ToUTF16(unsigned int CodePage = CODEPAGE_UTF8, bool * bSuccess = NULL);
void ArgFormat(const char * strFormat, va_list & args);
};