示例#1
0
string Encoding::encodeURL(const utf8string &str){
	string encoded;

    for(auto &it=str.begin();it!=str.end();++it){
		if( isprint(*it) )
			encoded += *it;
		else{
			char tmp[40];
			sprintf(tmp, "%%%02X", *it);

			encoded += tmp;
         }
    }

	return encoded;
}
示例#2
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;
}
示例#3
0
void write(void *pf, const utf8string &s)
{
    FILE *f = check_file(pf);
    fputs(s.c_str(), f);
}
示例#4
0
void fprint(void *pf, const utf8string &s)
{
    FILE *f = check_file(pf);
    fputs(s.c_str(), f);
    fputs("\n", f);
}
示例#5
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());
}