|
|
@@ -168,7 +168,8 @@ std::string CLewaimaiString::UrlDecode(const std::string& str)
|
|
|
return strTemp;
|
|
|
}
|
|
|
|
|
|
-std::string CLewaimaiString::UnicodeToUTF8(const std::wstring& wstr)
|
|
|
+/*
|
|
|
+std::string CLewaimaiString::UnicodeToUTF8(const std::wstring wstr)
|
|
|
{
|
|
|
std::string ret;
|
|
|
|
|
|
@@ -184,9 +185,10 @@ std::string CLewaimaiString::UnicodeToUTF8(const std::wstring& wstr)
|
|
|
}
|
|
|
|
|
|
return ret;
|
|
|
-}
|
|
|
+}*/
|
|
|
|
|
|
-std::wstring CLewaimaiString::UTF8ToUnicode(const std::string& str)
|
|
|
+/*
|
|
|
+std::wstring CLewaimaiString::UTF8ToUnicode(const std::string str)
|
|
|
{
|
|
|
std::wstring ret;
|
|
|
|
|
|
@@ -202,48 +204,109 @@ std::wstring CLewaimaiString::UTF8ToUnicode(const std::string& str)
|
|
|
}
|
|
|
|
|
|
return ret;
|
|
|
+}*/
|
|
|
+
|
|
|
+std::string CLewaimaiString::UnicodeToUTF8(const std::wstring wstr)
|
|
|
+{
|
|
|
+ char* pElementText;
|
|
|
+ int iTextLen;
|
|
|
+ // wide char to multi char
|
|
|
+ iTextLen = WideCharToMultiByte(CP_UTF8,
|
|
|
+ 0,
|
|
|
+ wstr.c_str(),
|
|
|
+ -1,
|
|
|
+ NULL,
|
|
|
+ 0,
|
|
|
+ NULL,
|
|
|
+ NULL);
|
|
|
+ pElementText = new char[iTextLen + 1];
|
|
|
+ memset((void*)pElementText, 0, sizeof(char) * (iTextLen + 1));
|
|
|
+ ::WideCharToMultiByte(CP_UTF8,
|
|
|
+ 0,
|
|
|
+ wstr.c_str(),
|
|
|
+ -1,
|
|
|
+ pElementText,
|
|
|
+ iTextLen,
|
|
|
+ NULL,
|
|
|
+ NULL);
|
|
|
+ string strText;
|
|
|
+ strText = pElementText;
|
|
|
+ delete[] pElementText;
|
|
|
+ return strText;
|
|
|
+}
|
|
|
+
|
|
|
+std::wstring CLewaimaiString::UTF8ToUnicode(const std::string str)
|
|
|
+{
|
|
|
+ int len = 0;
|
|
|
+ len = str.length();
|
|
|
+ int unicodeLen = ::MultiByteToWideChar(CP_UTF8,
|
|
|
+ 0,
|
|
|
+ str.c_str(),
|
|
|
+ -1,
|
|
|
+ NULL,
|
|
|
+ 0);
|
|
|
+ wchar_t* pUnicode;
|
|
|
+ pUnicode = new wchar_t[unicodeLen + 1];
|
|
|
+ memset(pUnicode, 0, (unicodeLen + 1) * sizeof(wchar_t));
|
|
|
+ ::MultiByteToWideChar(CP_UTF8,
|
|
|
+ 0,
|
|
|
+ str.c_str(),
|
|
|
+ -1,
|
|
|
+ (LPWSTR)pUnicode,
|
|
|
+ unicodeLen);
|
|
|
+ wstring rt;
|
|
|
+ rt = (wchar_t*)pUnicode;
|
|
|
+ delete pUnicode;
|
|
|
+
|
|
|
+ return rt;
|
|
|
}
|
|
|
|
|
|
-std::string CLewaimaiString::UnicodeToANSI(const std::wstring& wstr)
|
|
|
+std::string CLewaimaiString::UnicodeToANSI(const std::wstring wstr)
|
|
|
{
|
|
|
unsigned len = wstr.size() * 4;
|
|
|
- if (len == 0)
|
|
|
- {
|
|
|
- return "";
|
|
|
- }
|
|
|
+ if(len == 0)
|
|
|
+ {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
|
|
|
setlocale(LC_CTYPE, "");
|
|
|
- char *p = new char[len];
|
|
|
+ char* p = new char[len];
|
|
|
wcstombs(p, wstr.c_str(), len);
|
|
|
std::string str1(p);
|
|
|
delete[] p;
|
|
|
return str1;
|
|
|
}
|
|
|
|
|
|
-std::wstring CLewaimaiString::ANSIToUnicode(const std::string& str)
|
|
|
+std::wstring CLewaimaiString::ANSIToUnicode(const std::string str)
|
|
|
{
|
|
|
unsigned len = str.size() * 2;// 预留字节数
|
|
|
- if (len == 0)
|
|
|
- {
|
|
|
- return L"";
|
|
|
- }
|
|
|
+ if(len == 0)
|
|
|
+ {
|
|
|
+ return L"";
|
|
|
+ }
|
|
|
|
|
|
setlocale(LC_CTYPE, ""); //必须调用此函数
|
|
|
- wchar_t *p = new wchar_t[len];// 申请一段内存存放转换后的字符串
|
|
|
+ wchar_t* p = new wchar_t[len];// 申请一段内存存放转换后的字符串
|
|
|
mbstowcs(p, str.c_str(), len);// 转换
|
|
|
std::wstring str1(p);
|
|
|
delete[] p;// 释放申请的内存
|
|
|
return str1;
|
|
|
}
|
|
|
|
|
|
-std::string CLewaimaiString::UTF8ToANSI(const std::string& str)
|
|
|
+std::string CLewaimaiString::UTF8ToANSI(const std::string str)
|
|
|
{
|
|
|
- return UnicodeToANSI(UTF8ToUnicode(str));
|
|
|
+ std::wstring wsUnicode = CLewaimaiString::UTF8ToUnicode(str);
|
|
|
+ std::string sAnsi = CLewaimaiString::UnicodeToANSI(wsUnicode);
|
|
|
+
|
|
|
+ return sAnsi;
|
|
|
}
|
|
|
|
|
|
-std::string CLewaimaiString::ANSIToUTF8(const std::string& str)
|
|
|
+std::string CLewaimaiString::ANSIToUTF8(const std::string str)
|
|
|
{
|
|
|
- return UnicodeToUTF8(ANSIToUnicode(str));
|
|
|
+ std::wstring wsUnicode = CLewaimaiString::ANSIToUnicode(str);
|
|
|
+ std::string sUtf8 = CLewaimaiString::UnicodeToUTF8(wsUnicode);
|
|
|
+
|
|
|
+ return sUtf8;
|
|
|
}
|
|
|
|
|
|
std::string CLewaimaiString::DoubleToString(const double value, unsigned int precisionAfterPoint)
|