| 81 | } |
| 82 | |
| 83 | int internal::utf16_to_utf8::convert(wstring_view s) { |
| 84 | if (s.size() > INT_MAX) return ERROR_INVALID_PARAMETER; |
| 85 | int s_size = static_cast<int>(s.size()); |
| 86 | if (s_size == 0) { |
| 87 | // WideCharToMultiByte does not support zero length, handle separately. |
| 88 | buffer_.resize(1); |
| 89 | buffer_[0] = 0; |
| 90 | return 0; |
| 91 | } |
| 92 | |
| 93 | int length = WideCharToMultiByte(CP_UTF8, 0, s.data(), s_size, nullptr, 0, |
| 94 | nullptr, nullptr); |
| 95 | if (length == 0) return GetLastError(); |
| 96 | buffer_.resize(length + 1); |
| 97 | length = WideCharToMultiByte(CP_UTF8, 0, s.data(), s_size, &buffer_[0], |
| 98 | length, nullptr, nullptr); |
| 99 | if (length == 0) return GetLastError(); |
| 100 | buffer_[length] = 0; |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | void windows_error::init(int err_code, string_view format_str, |
| 105 | format_args args) { |