Static std::wstring utf8towstring (const std::string& stext)
{
int nlenwidecharstr = MultiByteToWideChar (Cp_utf8, 0, Stext.c_str (),-1, NULL, 0);
Pwchar pwidecharstr = NULL;
Pwidecharstr = (pwstr) HeapAlloc (GetProcessHeap (), 0, nlenwidecharstr*sizeof (wchar_t));
memset (pwidecharstr,0,nlenwidecharstr*sizeof (wchar_t));
MultiByteToWideChar (Cp_utf8, 0, Stext.c_str (),-1, Pwidecharstr, NLENWIDECHARSTR);
std::wstring widestr = pwidecharstr;
HeapFree (GetProcessHeap (), 0, PWIDECHARSTR);
return widestr;
}
static std::string WStringToUtf8 (const std::wstring& stext)
{
int nlenwidecharstr = WideCharToMultiByte (Cp_utf8, 0, Stext.c_str (),-1, NULL, 0, NULL, NULL);
pchar pcharstr = NULL;
pcharstr = (PSTR) HeapAlloc (GetProcessHeap (), 0, nlenwidecharstr*sizeof (char));
memset (pcharstr,0,nlenwidecharstr*sizeof (char));
widechartomultibyte (Cp_utf8, 0, Stext.c_str (), 1, pcharstr, nlenwidecharstr, NULL, NULL);
std::string str = PCHARSTR;
heapfree (GetProcessHeap (), 0, PCHARSTR);
return str;
}
static std::string wstringtoansi (const std::wstring& stext)
{
int nlenwidecharstr = WideCharToMultiByte (CP_ACP, 0, Stext.c_str (),-1, NULL, 0, NULL, NULL);
pchar pcharstr = NULL;
pcharstr = (PSTR) HeapAlloc (GetProcessHeap (), 0, nlenwidecharstr*sizeof (char));
memset (pcharstr,0,nlenwidecharstr*sizeof (char));
widechartomultibyte (CP_ACP, 0, Stext.c_str (), 1, pcharstr, nlenwidecharstr, NULL, NULL);
std::string str = PCHARSTR;
heapfree (GetProcessHeap (), 0, PCHARSTR);
return str;
}
Static std::wstring ansitowstring (const std::string& stext)
{
int nlenwidecharstr = MultiByteToWideChar (CP_ACP, 0, Stext.c_str (),-1, NULL, 0);
Pwchar pwidecharstr = NULL;
Pwidecharstr = (pwstr) HeapAlloc (GetProcessHeap (), 0, nlenwidecharstr*sizeof (wchar_t));
memset (pwidecharstr,0,nlenwidecharstr*sizeof (wchar_t));
MultiByteToWideChar (CP_ACP, 0, Stext.c_str (),-1, Pwidecharstr, NLENWIDECHARSTR);
std::wstring widestr = pwidecharstr;
HeapFree (GetProcessHeap (), 0, PWIDECHARSTR);
return widestr;
}
Static std::string utf8toansi (const std::string& stext)
{
std::wstring ws = Utf8towstring (stext);
return Wstringtoansi (WS);
}
Static std::string AnsiToUtf8 (const std::string& stext)
{
std::wstring ws = Ansitowstring (stext);
return WStringToUtf8 (WS);
}
Character encoding conversion (using the Windows API)