Esempio n. 1
0
string Encoding::decodeUTF8(const utf8string &str){
	string decoded;

#ifdef TARGET_WIN32
	int wstrlen = MultiByteToWideChar(CP_UTF8, 0, (char *)str.c_str(),str.length(), NULL,NULL);
	wchar_t *wstr = new wchar_t[wstrlen + 1];

	MultiByteToWideChar(CP_UTF8, 0, (char *)str.c_str(),str.length(), wstr, wstrlen);

	int cstrlen = WideCharToMultiByte(CP_ACP, 0, wstr,wstrlen, NULL,NULL, 0,0);
	char *cstr = new char[cstrlen + 1];

	WideCharToMultiByte(CP_ACP, 0, wstr,wstrlen, cstr,cstrlen, 0,0);
	cstr[cstrlen] = '\0';

	decoded.assign( cstr );

	delete[] wstr;
	delete[] cstr;
#else
#endif

	return decoded;
}