69,335
社区成员
发帖
与我相关
我的任务
分享
qp::StringW Global::AnsiToUnicode(const char* buf)
{
int len = ::MultiByteToWideChar(CP_ACP, 0, buf, -1, NULL, 0);
if (len == 0) return L"";
std::vector<wchar_t> unicode(len);
::MultiByteToWideChar(CP_ACP, 0, buf, -1, &unicode[0], len);
return &unicode[0];
}
qp::StringA Global::UnicodeToAnsi(const wchar_t* buf)
{
int len = ::WideCharToMultiByte(CP_ACP, 0, buf, -1, NULL, 0, NULL, NULL);
if (len == 0) return "";
std::vector<char> utf8(len);
::WideCharToMultiByte(CP_ACP, 0, buf, -1, &utf8[0], len, NULL, NULL);
return &utf8[0];
}
qp::StringW Global::Utf8ToUnicode(const char* buf)
{
int len = ::MultiByteToWideChar(CP_UTF8, 0, buf, -1, NULL, 0);
if (len == 0) return L"";
std::vector<wchar_t> unicode(len);
::MultiByteToWideChar(CP_UTF8, 0, buf, -1, &unicode[0], len);
return &unicode[0];
}
qp::StringA Global::UnicodeToUtf8(const wchar_t* buf)
{
int len = ::WideCharToMultiByte(CP_UTF8, 0, buf, -1, NULL, 0, NULL, NULL);
if (len == 0) return "";
std::vector<char> utf8(len);
::WideCharToMultiByte(CP_UTF8, 0, buf, -1, &utf8[0], len, NULL, NULL);
return &utf8[0];
}