aboutsummaryrefslogtreecommitdiff
path: root/src/win/string.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/win/string.cpp')
-rw-r--r--src/win/string.cpp22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/win/string.cpp b/src/win/string.cpp
index fb9811eb..5518e6af 100644
--- a/src/win/string.cpp
+++ b/src/win/string.cpp
@@ -8,9 +8,9 @@ namespace cru::platform::win {
std::string ToUtf8String(const std::wstring_view& string) {
if (string.empty()) return std::string{};
- const auto length =
- ::WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, string.data(), -1,
- nullptr, 0, nullptr, nullptr);
+ const auto length = ::WideCharToMultiByte(
+ CP_UTF8, WC_ERR_INVALID_CHARS, string.data(),
+ static_cast<int>(string.size()), nullptr, 0, nullptr, nullptr);
if (length == 0) {
throw Win32Error(::GetLastError(),
"Failed to convert wide string to UTF-8.");
@@ -18,9 +18,10 @@ std::string ToUtf8String(const std::wstring_view& string) {
std::string result;
result.resize(length);
- if (::WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, string.data(), -1,
- result.data(), static_cast<int>(result.size()),
- nullptr, nullptr) == 0)
+ if (::WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, string.data(),
+ static_cast<int>(string.size()), result.data(),
+ static_cast<int>(result.size()), nullptr,
+ nullptr) == 0)
throw Win32Error(::GetLastError(),
"Failed to convert wide string to UTF-8.");
return result;
@@ -29,8 +30,9 @@ std::string ToUtf8String(const std::wstring_view& string) {
std::wstring ToUtf16String(const std::string_view& string) {
if (string.empty()) return std::wstring{};
- const auto length = ::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS,
- string.data(), -1, nullptr, 0);
+ const auto length =
+ ::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, string.data(),
+ static_cast<int>(string.size()), nullptr, 0);
if (length == 0) {
throw Win32Error(::GetLastError(),
"Failed to convert wide string to UTF-16.");
@@ -38,8 +40,8 @@ std::wstring ToUtf16String(const std::string_view& string) {
std::wstring result;
result.resize(length);
- if (::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, string.data(), -1,
- result.data(),
+ if (::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, string.data(),
+ static_cast<int>(string.size()), result.data(),
static_cast<int>(result.size())) == 0)
throw win::Win32Error(::GetLastError(),
"Failed to convert wide string to UTF-16.");