Ejemplo 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;
}
Ejemplo n.º 2
0
void write(void *pf, const utf8string &s)
{
    FILE *f = check_file(pf);
    fputs(s.c_str(), f);
}
Ejemplo n.º 3
0
void fprint(void *pf, const utf8string &s)
{
    FILE *f = check_file(pf);
    fputs(s.c_str(), f);
    fputs("\n", f);
}
Ejemplo n.º 4
0
/**
 * Encode a wide string in UTF-8 and output it in hexadecimal.
 * @param[in]	lpszW	The wide string to encode
 * @return				The encoded string.
 */
static string encodestring(const wchar_t *lpszW) {
	const utf8string u8 = convstring(lpszW);
	return bin2hex(u8.size(), (const unsigned char*)u8.c_str());
}