97579aac1b 2024-01-23 顽雨沉风: local ffi = require("ffi")
97579aac1b 2024-01-23 顽雨沉风: local d_3 = {}
97579aac1b 2024-01-23 顽雨沉风: ffi.cdef([[
97579aac1b 2024-01-23 顽雨沉风: typedef unsigned int UINT;
97579aac1b 2024-01-23 顽雨沉风: typedef unsigned long DWORD;
97579aac1b 2024-01-23 顽雨沉风: typedef wchar_t WCHAR;
97579aac1b 2024-01-23 顽雨沉风: typedef WCHAR* LPWSTR;
97579aac1b 2024-01-23 顽雨沉风: typedef wchar_t* LPCWCH;
97579aac1b 2024-01-23 顽雨沉风: typedef char CHAR;
97579aac1b 2024-01-23 顽雨沉风: typedef CHAR* LPSTR;
97579aac1b 2024-01-23 顽雨沉风: typedef const char* LPCCH;
97579aac1b 2024-01-23 顽雨沉风: typedef int BOOL;
97579aac1b 2024-01-23 顽雨沉风: typedef BOOL* LPBOOL;
97579aac1b 2024-01-23 顽雨沉风: int MultiByteToWideChar(UINT CodePage, DWORD dwFlags, LPCCH lpMultiByteStr, int cbMultiByte, LPWSTR lpWideCharStr, int cchWideChar);
97579aac1b 2024-01-23 顽雨沉风: int WideCharToMultiByte(UINT CodePage, DWORD dwFlags, LPCWCH lpWideCharStr, int cchWideChar, LPSTR lpMultiByteStr, int cchMultiByte, LPCCH lpDefaultChar, LPBOOL pfUsedDefaultChar);
97579aac1b 2024-01-23 顽雨沉风: ]])
97579aac1b 2024-01-23 顽雨沉风: d_3.CP_ACP = 0
97579aac1b 2024-01-23 顽雨沉风: d_3.CP_UTF8 = 65001
97579aac1b 2024-01-23 顽雨沉风: function d_3.m2w(input, o1)
97579aac1b 2024-01-23 顽雨沉风: local wlen = ffi.C.MultiByteToWideChar(o1 or d_3.CP_ACP, 0, input, #input, nil, 0)
97579aac1b 2024-01-23 顽雨沉风: local wstr = ffi.new("wchar_t[?]", wlen + 1)
97579aac1b 2024-01-23 顽雨沉风: ffi.C.MultiByteToWideChar(o1 or d_3.CP_ACP, 0, input, #input, wstr, wlen)
97579aac1b 2024-01-23 顽雨沉风: return wstr, wlen
97579aac1b 2024-01-23 顽雨沉风: end
97579aac1b 2024-01-23 顽雨沉风: function d_3.w2m(wstr, wlen, o1)
97579aac1b 2024-01-23 顽雨沉风: local len = ffi.C.WideCharToMultiByte(o1 or d_3.CP_ACP, 0, wstr, wlen or -1, nil, 0, nil, nil)
97579aac1b 2024-01-23 顽雨沉风: local str = ffi.new("char[?]", len)
97579aac1b 2024-01-23 顽雨沉风: ffi.C.WideCharToMultiByte(o1 or d_3.CP_ACP, 0, wstr, wlen or -1, str, len, nil, nil)
97579aac1b 2024-01-23 顽雨沉风: return ffi.string(str, len)
97579aac1b 2024-01-23 顽雨沉风: end
97579aac1b 2024-01-23 顽雨沉风: function d_3.u8_to_a(input)
97579aac1b 2024-01-23 顽雨沉风: return d_3.w2m(d_3.m2w(input, d_3.CP_UTF8))
97579aac1b 2024-01-23 顽雨沉风: end
97579aac1b 2024-01-23 顽雨沉风: function d_3.a_to_u8(input)
97579aac1b 2024-01-23 顽雨沉风: local k1, k2 = d_3.m2w(input)
97579aac1b 2024-01-23 顽雨沉风: return d_3.w2m(k1, k2, d_3.CP_UTF8)
97579aac1b 2024-01-23 顽雨沉风: end
97579aac1b 2024-01-23 顽雨沉风: return d_3