// gbk_2_utf8
string My_gbk_two_utf8(const string text)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
wstring tes = [=]()
{
setlocale(LC_ALL, "chs");
const char* _tsur = text.c_str();
size_t _tsize = text.size() + 1;
wchar_t* _tdest = new wchar_t[_tsize];
wmemset(_tdest, 0, _tsize);
mbstowcs(_tdest, _tsur, _tsize);
std::wstring result = _tdest;
delete[] _tdest;
setlocale(LC_ALL, "C");
return result;
}();
int asciSize = WideCharToMultiByte(CP_UTF8, 0, tes.c_str(), tes.size(), NULL, 0, NULL, NULL);
if(asciSize == ERROR_NO_UNICODE_TRANSLATION || asciSize == 0)
{
return string();
}
char* resultString = new char[asciSize];
int conveResult = WideCharToMultiByte(CP_UTF8, 0, tes.c_str(), tes.size(), resultString, asciSize, NULL, NULL);
if(conveResult != asciSize)
{
return string();
}
string buffer = "";
buffer.append(resultString, asciSize);
delete[] resultString;
return buffer;
#else
return text;
#endif
}
cocos2d-x win32 log 中文乱码解决办法
最新推荐文章于 2023-10-10 15:50:17 发布