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; }
void write(void *pf, const utf8string &s) { FILE *f = check_file(pf); fputs(s.c_str(), f); }
void fprint(void *pf, const utf8string &s) { FILE *f = check_file(pf); fputs(s.c_str(), f); fputs("\n", f); }
/** * 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()); }