CString& StrToHex(const TCHAR* src, CString& strDec) { BYTE* t = (BYTE*)src; int src_length = lstrlen(src) * sizeof(TCHAR); strDec.Empty(); #ifdef UNICODE char* temp = nullptr; UnicodeToMbcs(src, &temp, src_length); src_length -= 1; t = (BYTE*)temp; #else t = (BYTE*)src; src_length = lstrlen(src); #endif for(int i = 0; i < src_length; ++i, ++t) { TCHAR tc[3] = {0, 0, 0}; VALUETODOUBLECHAR(tc, *t); strDec += tc; } #ifdef UNICODE delete[] temp; #endif return strDec; }
char* Util::String::Utf8ToMbcs(const char* pUtf8) { assert(pUtf8); wchar_t* pUnicode = Utf8ToUnicode(pUtf8); char* pRet = UnicodeToMbcs(pUnicode); ReleaseData(pUnicode); return pRet; }
CString& HexUtf8ToStr(const TCHAR* src, CString& strDec) { char* temp = nullptr; WCHAR* pwsz = nullptr; int iLen = 0; int src_length = 0; strDec.Empty(); #ifdef UNICODE char* temp1 = new char[(src_length = lstrlen(src)) +1]; temp = temp1; while(*(temp1++) = (char)*(src++)); #else temp = (char*)src; src_length = lstrlen(src); #endif int i=0; for(; i < src_length / 2; ++i) { temp[i] = DOUBLECHARTOVALUE(temp + 2*i); } temp[i] = 0; Utf8ToUnicode(temp, &pwsz, iLen); #ifdef UNICODE strDec = pwsz; delete[] temp; #else char* psz = nullptr; UnicodeToMbcs(pwsz, &psz, iLen); strDec = psz; delete[] psz; #endif delete[] pwsz; return strDec; }