string qUnicodeToAnsi(wstring &buf)
{
int len = ::WideCharToMultiByte(CP_ACP, 0, buf.data(), buf.size(), NULL, 0, NULL, NULL);
if (len == 0) return “”;
std::vectorutf8(len); len = ::WideCharToMultiByte(CP_ACP, 0, buf.data(), buf.size(), &utf8[0], len, NULL, NULL); return string(&utf8[0],len);
}
wstring qAnsiToUnicode(string &buf)
{
int len = ::MultiByteToWideChar(CP_ACP, 0, buf.data(), buf.size(), NULL, 0);
if (len == 0) return L"";
std::vectorunicode(len); len = ::MultiByteToWideChar(CP_ACP, 0, buf.data(), buf.size(), &unicode[0], len); return wstring(&unicode[0],len);
}
wstring qUtf8ToUnicode(string &buf)
{
int len = ::MultiByteToWideChar(CP_UTF8, 0, buf.data(), buf.size(), NULL, 0);
if (len == 0) return L"";
std::vectorunicode(len); len = ::MultiByteToWideChar(CP_UTF8, 0, buf.data(), buf.size(), &unicode[0], len); return wstring(&unicode[0],len);
}
string qUnicodeToUtf8(wstring &buf)
{
int len = ::WideCharToMultiByte(CP_UTF8, 0, buf.data(), buf.size(), NULL, 0, NULL, NULL);
if (len == 0) return “”;
std::vectorutf8(len); len = ::WideCharToMultiByte(CP_UTF8, 0, buf.data(), buf.size(), &utf8[0], len, NULL, NULL); return string(&utf8[0],len);
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)