wstring PublicFun::utf8tounicode(const char* buf)
{
int len = MultiByteToWideChar(CP_UTF8, 0, buf, -1, NULL, 0);
if (len == 0) return (L"");
WCHAR* wtemp = new WCHAR[len];
MultiByteToWideChar(CP_UTF8, 0, buf, -1, wtemp, len);
wstring str = wtemp;
delete []wtemp;
return str;
}
string PublicFun::unicodetoutf8(const wchar_t* buf)
{
int len = WideCharToMultiByte(CP_UTF8, 0, buf, -1, NULL, 0, NULL, NULL);
if (len == 0) return "";
char* ctemp = new char[len];
WideCharToMultiByte(CP_UTF8, 0, buf, -1, ctemp, len, NULL, NULL);
string str = ctemp;
delete []ctemp;
return str;
}
wstring PublicFun::gb2312tounicode(const char* buf)
{
int len = MultiByteToWideChar(CP_ACP, 0, buf, -1, NULL, 0);
if (len == 0) return (L"");
WCHAR* wtemp = new WCHAR[len];
MultiByteToWideChar(CP_ACP, 0, buf, -1, wtemp, len);
wstring str = wtemp;
delete []wtemp;
return str;
}
string PublicFun::unicodetogb2312(const wchar_t* buf)
{
int len = WideCharToMultiByte(CP_ACP, 0, buf, -1, NULL, 0, NULL, NULL);
if (len == 0) return "";
char* ctemp = new char[len];
WideCharToMultiByte(CP_ACP, 0, buf, -1, ctemp, len, NULL, NULL);
string str = ctemp;
delete []ctemp;
return str;
}
std::string PublicFun::gb2312toutf8( const char* buf )
{
std::wstring wstr = gb2312tounicode(buf);
return unicodetoutf8(wstr.c_str());
}
std::string PublicFun::utf8togb2312( const char* buf )
{
std::wstring wstr = utf8tounicode(buf);
return unicodetogb2312(wstr.c_str());
}