string qUnicodeToAnsi(wstring &buf)
{
int len = ::WideCharToMultiByte(CP_ACP, 0, buf.data(), buf.size(), NULL, 0, NULL, NULL);
if (len == 0) return “”;
std::vector<char> utf8(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::vector<wchar_t> unicode(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::vector<wchar_t> unicode(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::vector<char> utf8(len);
len = ::WideCharToMultiByte(CP_UTF8, 0, buf.data(), buf.size(), &utf8[0], len, NULL, NULL);
return string(&utf8[0],len);
}