CString& StrToUtf8Hex(const TCHAR* src, CString& strDec) { char* t = nullptr; WCHAR* temp = nullptr; int src_length = 0; strDec.Empty(); #ifndef UNICODE MbcsToUnicode(src, &temp, src_length); #else temp = (TCHAR*)src; #endif UnicodeToUtf8(temp, &t, src_length); src_length -= 1; for(int i = 0; i < src_length; ++i) { TCHAR tc[3] = {0, 0, 0}; VALUETODOUBLECHAR(tc, t[i]); strDec += tc; } #ifndef UNICODE delete[] temp; #endif delete[] t; return strDec; }
char* Util::String::MbcsToUtf8(const char* pMbcs) { assert(pMbcs); wchar_t* pUnicode = MbcsToUnicode(pMbcs); char*pRet = UnicodeToUtf8(pUnicode); ReleaseData(pUnicode); return pRet; }
CString& HexToStr(const TCHAR* src, CString& strDec) { char* temp = nullptr; 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); //t = strDec.GetBuffer(src_length/2 + 1); #endif int i=0; for(; i < src_length / 2; ++i) { temp[i] = DOUBLECHARTOVALUE(temp + 2 * i); } temp[i] = 0; #ifdef UNICODE int iLen = 0; WCHAR* wh = nullptr; MbcsToUnicode(temp, &wh, iLen); strDec = wh; delete[] wh; delete[] temp; #else strDec.ReleaseBuffer(); #endif return strDec; }