diff options
author | Chris Robinson <[email protected]> | 2023-08-06 18:49:42 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2023-08-06 18:49:42 -0700 |
commit | 9296af5566afea4ba4cb78b374ef3ee0bf9bc04b (patch) | |
tree | ac71d8896956166aed320ed38ffb32847bc2cba7 /common/strutils.cpp | |
parent | 05d80f9b3283d7686a27e5d3ed0bac6086669368 (diff) |
Use a string_view for the backend open method
Diffstat (limited to 'common/strutils.cpp')
-rw-r--r-- | common/strutils.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/common/strutils.cpp b/common/strutils.cpp index 355cd030..f7868e2e 100644 --- a/common/strutils.cpp +++ b/common/strutils.cpp @@ -10,31 +10,32 @@ #define WIN32_LEAN_AND_MEAN #include <windows.h> -std::string wstr_to_utf8(const WCHAR *wstr) +std::string wstr_to_utf8(std::wstring_view wstr) { std::string ret; - int len = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, nullptr, 0, nullptr, nullptr); + int len{WideCharToMultiByte(CP_UTF8, 0, wstr.data(), static_cast<int>(wstr.length()), nullptr, + 0, nullptr, nullptr)}; if(len > 0) { ret.resize(len); - WideCharToMultiByte(CP_UTF8, 0, wstr, -1, &ret[0], len, nullptr, nullptr); - ret.pop_back(); + WideCharToMultiByte(CP_UTF8, 0, wstr.data(), static_cast<int>(wstr.length()), &ret[0], len, + nullptr, nullptr); } return ret; } -std::wstring utf8_to_wstr(const char *str) +std::wstring utf8_to_wstr(std::string_view str) { std::wstring ret; - int len = MultiByteToWideChar(CP_UTF8, 0, str, -1, nullptr, 0); + int len{MultiByteToWideChar(CP_UTF8, 0, str.data(), static_cast<int>(str.length()), nullptr, + 0)}; if(len > 0) { ret.resize(len); - MultiByteToWideChar(CP_UTF8, 0, str, -1, &ret[0], len); - ret.pop_back(); + MultiByteToWideChar(CP_UTF8, 0, str.data(), static_cast<int>(str.length()), &ret[0], len); } return ret; |