Garbled Code cannot afford to hurt ....
The following is the conversion code...
Inline wstring utf8ToUnicode (string str)
{
// UTF8 to Unicode
Size_t wcsLen =: MultiByteToWideChar (CP_UTF8, NULL, str. c_str (), str. length (), NULL, 0 );
// Leave a space for ''to allocate space. MultiByteToWideChar will not give'' Space
Wchar_t * wszString = new wchar_t [wcsLen + 1];
Memset (wszString, 0, sizeof (wchar_t) * (wcsLen + 1 ));
// Conversion
: MultiByteToWideChar (CP_UTF8, NULL, str. c_str (), str. length (), wszString, wcsLen );
Wstring wstr = wszString;
Delete wszString;
Return wstr;
}
Inline string unicode2utf8 (wstring wstr)
{
Int len; www.2cto.com
Len = WideCharToMultiByte (CP_UTF8, 0, wstr. c_str (),-1, NULL, 0, NULL, NULL );
Char * szUtf8 = new char [len * 2 + 2];
Memset (szUtf8, 0, len * 2 + 2 );
WideCharToMultiByte (CP_UTF8, 0, (LPCWSTR) wstr. c_str (),-1, szUtf8, len, NULL, NULL );
String str = szUtf8;
Delete szUtf8;
Return str;
}
From ccSec | cc@insight-labs.org