Revert "Update stringutils.cpp"

This reverts commit 8e65356e07f1db9cc971a3cf6f7dcd748fdb625a.
This commit is contained in:
恍兮惚兮 2024-03-26 15:07:42 +08:00
parent cda7fbaf53
commit d5fb0e4503

View File

@ -1,4 +1,4 @@
#include<MLang.h>
LPCSTR reverse_search_begin(const char *s, int maxsize ) LPCSTR reverse_search_begin(const char *s, int maxsize )
{ {
if (*s) if (*s)
@ -73,6 +73,22 @@ bool startWith(const std::wstring& s,const std::wstring& s2){return startWith_im
bool endWith(const std::string& s,const std::string& s2){return endWith_impl<std::string>(s,s2);} bool endWith(const std::string& s,const std::string& s2){return endWith_impl<std::string>(s,s2);}
bool endWith(const std::wstring& s,const std::wstring& s2){return endWith_impl<std::wstring>(s,s2);} bool endWith(const std::wstring& s,const std::wstring& s2){return endWith_impl<std::wstring>(s,s2);}
typedef HRESULT(WINAPI* CONVERTINETMULTIBYTETOUNICODE)(
LPDWORD lpdwMode,
DWORD dwSrcEncoding,
LPCSTR lpSrcStr,
LPINT lpnMultiCharCount,
LPWSTR lpDstStr,
LPINT lpnWideCharCount
);
typedef HRESULT(WINAPI* CONVERTINETUNICODETOMULTIBYTE)(
LPDWORD lpdwMode,
DWORD dwEncoding,
LPCWSTR lpSrcStr,
LPINT lpnWideCharCount,
LPSTR lpDstStr,
LPINT lpnMultiCharCount
);
std::optional<std::wstring> StringToWideString(const std::string& text, UINT encoding) std::optional<std::wstring> StringToWideString(const std::string& text, UINT encoding)
{ {
@ -81,9 +97,9 @@ std::optional<std::wstring> StringToWideString(const std::string& text, UINT enc
int _s = text.size(); int _s2 = buffer.size(); int _s = text.size(); int _s2 = buffer.size();
auto h=LoadLibrary(TEXT("mlang.dll")); auto h=LoadLibrary(TEXT("mlang.dll"));
if(h==0)return {}; if(h==0)return {};
auto pConvertINetMultiByteToUnicode = (decltype(&ConvertINetMultiByteToUnicode))GetProcAddress(h, "ConvertINetMultiByteToUnicode"); auto ConvertINetMultiByteToUnicode = (CONVERTINETMULTIBYTETOUNICODE)GetProcAddress(h, "ConvertINetMultiByteToUnicode");
if(pConvertINetMultiByteToUnicode==0)return {}; if(ConvertINetMultiByteToUnicode==0)return {};
auto hr=pConvertINetMultiByteToUnicode(0, encoding, text.c_str(), &_s, buffer.data(), &_s2); auto hr=ConvertINetMultiByteToUnicode(0, encoding, text.c_str(), &_s, buffer.data(), &_s2);
if(SUCCEEDED(hr)){ if(SUCCEEDED(hr)){
return std::wstring(buffer.data(), _s2 ); return std::wstring(buffer.data(), _s2 );
} }
@ -108,9 +124,9 @@ std::string WideStringToString(const std::wstring& text,UINT cp)
int _s = text.size(); int _s2 = buffer.size(); int _s = text.size(); int _s2 = buffer.size();
auto h=LoadLibrary(TEXT("mlang.dll")); auto h=LoadLibrary(TEXT("mlang.dll"));
if(h==0)return {}; if(h==0)return {};
auto pConvertINetUnicodeToMultiByte = (decltype(&ConvertINetUnicodeToMultiByte))GetProcAddress(h, "ConvertINetUnicodeToMultiByte"); auto ConvertINetUnicodeToMultiByte = (CONVERTINETUNICODETOMULTIBYTE)GetProcAddress(h, "ConvertINetUnicodeToMultiByte");
if(pConvertINetUnicodeToMultiByte==0)return {}; if(ConvertINetUnicodeToMultiByte==0)return {};
auto hr=pConvertINetUnicodeToMultiByte(0, cp, text.c_str(), &_s, buffer.data(), &_s2); auto hr=ConvertINetUnicodeToMultiByte(0, cp, text.c_str(), &_s, buffer.data(), &_s2);
if(SUCCEEDED(hr)){ if(SUCCEEDED(hr)){
return std::string(buffer.data(), _s2 ); return std::string(buffer.data(), _s2 );
} }