Added scripting quality of life features #299

Merged
Pycorax merged 10 commits from SP3-6-c-scripting into main 2023-01-01 12:37:10 +08:00
1 changed files with 23 additions and 21 deletions
Showing only changes of commit 861e47812f - Show all commits

View File

@ -26,27 +26,29 @@ namespace SHADE
std::vector<std::wstring> SHStringUtilities::Split(const std::wstring& str, const wchar_t& delim) std::vector<std::wstring> SHStringUtilities::Split(const std::wstring& str, const wchar_t& delim)
{ {
return Split<wchar_t>(str, delim); return Split<wchar_t>(str, delim);
} }
std::string SHStringUtilities::WstrToStr(const std::wstring& wstr) std::string SHStringUtilities::WstrToStr(const std::wstring& wstr)
{ {
static std::vector<char> buffer; static std::vector<char> buffer;
const int STR_SIZE = WideCharToMultiByte(CP_UTF8, 0, wstr.data(), static_cast<int>(wstr.size()), nullptr, 0, nullptr, nullptr) + 1 /* Null Terminator */; buffer.clear();
buffer.resize(STR_SIZE); const int STR_SIZE = WideCharToMultiByte(CP_UTF8, 0, wstr.data(), static_cast<int>(wstr.size()), nullptr, 0, nullptr, nullptr) + 1 /* Null Terminator */;
WideCharToMultiByte(CP_UTF8, 0, wstr.data(), static_cast<int>(wstr.size()), buffer.data(), MAX_PATH, nullptr, nullptr); buffer.resize(STR_SIZE, '\0');
return std::string(buffer.data()); WideCharToMultiByte(CP_UTF8, 0, wstr.data(), static_cast<int>(wstr.size()), buffer.data(), MAX_PATH, nullptr, nullptr);
} return std::string(buffer.data());
std::wstring SHStringUtilities::StrToWstr(const std::string& str) }
{ std::wstring SHStringUtilities::StrToWstr(const std::string& str)
static std::vector<wchar_t> buffer; {
const int WSTR_SIZE = MultiByteToWideChar(CP_UTF8, 0, str.data(), static_cast<int>(str.size()), nullptr, 0) + 1 /* Null Terminator */; static std::vector<wchar_t> buffer;
buffer.resize(WSTR_SIZE); buffer.clear();
MultiByteToWideChar(CP_UTF8, 0, str.data(), static_cast<int>(str.size()), buffer.data(), WSTR_SIZE); const int WSTR_SIZE = MultiByteToWideChar(CP_UTF8, 0, str.data(), static_cast<int>(str.size()), nullptr, 0) + 1 /* Null Terminator */;
return std::wstring(buffer.data()); buffer.resize(WSTR_SIZE, '\0');
} MultiByteToWideChar(CP_UTF8, 0, str.data(), static_cast<int>(str.size()), buffer.data(), WSTR_SIZE);
return std::wstring(buffer.data());
}
std::string SHStringUtilities::GetWin32ErrorMessage(unsigned long errorCode) std::string SHStringUtilities::GetWin32ErrorMessage(unsigned long errorCode)
{ {
return std::system_category().message(errorCode); return std::system_category().message(errorCode);
} }
} }