| 40 | } |
| 41 | |
| 42 | std::wstring Utf8ToWide(std::string_view value) { |
| 43 | if (value.empty()) return {}; |
| 44 | if (!FitsWindowsInt(value.size(), "Utf8ToWide")) return {}; |
| 45 | |
| 46 | const int size = MultiByteToWideChar(CP_UTF8, 0, value.data(), static_cast<int>(value.size()), nullptr, 0); |
| 47 | if (size <= 0) { |
| 48 | OSTP_LOG_DEBUG("MultiByteToWideChar(size query) failed (error={})", GetLastError()); |
| 49 | return {}; |
| 50 | } |
| 51 | |
| 52 | std::wstring result(static_cast<size_t>(size), L'\0'); |
| 53 | const int written = MultiByteToWideChar(CP_UTF8, 0, value.data(), static_cast<int>(value.size()), result.data(), size); |
| 54 | if (written != size) { |
| 55 | OSTP_LOG_DEBUG("MultiByteToWideChar(convert) failed (written={}, expected={}, error={})", |
| 56 | written, size, GetLastError()); |
| 57 | return {}; |
| 58 | } |
| 59 | return result; |
| 60 | } |
| 61 | |
| 62 | } // namespace OSTPlatform::Encoding |
no test coverage detected