admin
2025-04-08 5c9991be21f57781573f04961ec511ac2938ea3d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#pragma once
#include <afx.h>
#include <string>
#include <locale>  
#include <codecvt>
#include <iostream>
 
using namespace std;
 
class StringUtil {
 
public:
    static string wstringToString(wstring wt) {
        wstring_convert<codecvt_utf8<wchar_t>> conv;
        string result = conv.to_bytes(wt);
        return result;
    }
 
    static std::wstring Unescape(const std::string& input) {
        std::wstring wresult;
        for (size_t i = 0; i < input.length(); ) {
            if (input[i] == '\\' && input[i + 1] == 'u') {
                std::string code = input.substr(i + 2, 4);
                wchar_t unicode = stoi(code, nullptr, 16);
                wresult += unicode;
                i += 6;
            }
            else {
                wresult += input[i++];
            }
        }
        return wresult;
    }
 
    static std::string cstring2String(CString getbuf) {
        int iLen = WideCharToMultiByte(0, 0, getbuf, -1, NULL, 0, NULL, NULL);   //Ê×ÏȼÆËãTCHAR ³¤¶È¡£
        char* chRtn = new char[iLen * sizeof(char)];  //¶¨ÒåÒ»¸ö TCHAR ³¤¶È´óСµÄ CHAR ÀàÐÍ¡£
        WideCharToMultiByte(0, 0, getbuf, -1, chRtn, iLen, NULL, NULL);  //½«TCHAR ÀàÐ͵ÄÊý¾Ýת»»Îª CHAR ÀàÐÍ¡£
        std::string str(chRtn);
        return str;
    }
};