65,211
社区成员
发帖
与我相关
我的任务
分享
shared_ptr<wstring> UT2WC(const char* buf)
{
int len = MultiByteToWideChar(CP_UTF8, 0, buf, -1, NULL, 0);
if (len == 0) return shared_ptr<wstring>(new wstring(L""));
vector<wchar_t> unicode(len);
MultiByteToWideChar(CP_UTF8, 0, buf, -1, &unicode[0], len);
return shared_ptr<wstring>(new wstring(&unicode[0]));
}
shared_ptr<string> WC2UT(const wchar_t* buf)
{
int len = WideCharToMultiByte(CP_UTF8, 0, buf, -1, NULL, 0, NULL, NULL);
if (len == 0) return shared_ptr<string>(new string(""));
vector<char> utf8(len);
WideCharToMultiByte(CP_UTF8, 0, buf, -1, &utf8[0], len, NULL, NULL);
return shared_ptr<string>(new string(&utf8[0]));
}
shared_ptr<wstring> MB2WC(const char* buf)
{
int len = MultiByteToWideChar(CP_ACP, 0, buf, -1, NULL, 0);
if (len == 0) return shared_ptr<wstring>(new wstring(L""));
vector<wchar_t> unicode(len);
MultiByteToWideChar(CP_ACP, 0, buf, -1, &unicode[0], len);
return shared_ptr<wstring>(new wstring(&unicode[0]));
}
shared_ptr<string> WC2MB(const wchar_t* buf)
{
int len = WideCharToMultiByte(CP_ACP, 0, buf, -1, NULL, 0, NULL, NULL);
if (len == 0) return shared_ptr<string>(new string(""));
vector<char> utf8(len);
WideCharToMultiByte(CP_ACP, 0, buf, -1, &utf8[0], len, NULL, NULL);
return shared_ptr<string>(new string(&utf8[0]));
}