init
This commit is contained in:
32
Helper/UtilHelper.h
Normal file
32
Helper/UtilHelper.h
Normal file
@@ -0,0 +1,32 @@
|
||||
//
|
||||
// Created by depre on 2024/1/16.
|
||||
//
|
||||
|
||||
#ifndef UTILHELPER_H
|
||||
#define UTILHELPER_H
|
||||
#ifdef _WIN32
|
||||
const auto ConvertWCharToChar = [](const std::wstring& strSrc) {
|
||||
size_t len = 0;
|
||||
len = WideCharToMultiByte(CP_ACP, 0, strSrc.c_str(), strSrc.length(), nullptr, 0, nullptr, nullptr);
|
||||
char* buffer = new char[len + 1];
|
||||
std::string res;
|
||||
WideCharToMultiByte(CP_ACP, 0, strSrc.c_str(), strSrc.size(), buffer, len, nullptr, nullptr);
|
||||
buffer[len] = '\0';
|
||||
res.append(buffer);
|
||||
delete[] buffer;
|
||||
return res;
|
||||
};
|
||||
|
||||
const auto ConvertCharToWCher = [](const std::string& strSrc) {
|
||||
size_t len = 0;
|
||||
len = MultiByteToWideChar(CP_ACP, 0, strSrc.c_str(), strSrc.size(), nullptr, NULL);
|
||||
wchar_t* buff = new wchar_t[len + 1];
|
||||
MultiByteToWideChar(CP_ACP, 0, strSrc.c_str(), strSrc.size(), buff, len);
|
||||
buff[len] = '\0';
|
||||
std::wstring res;
|
||||
res.append(buff);
|
||||
delete[] buff;
|
||||
return res;
|
||||
};
|
||||
#endif
|
||||
#endif //UTILHELPER_H
|
||||
Reference in New Issue
Block a user