MCPcopy Create free account
hub / github.com/OpenSteam001/OpenSteamTool / Utf8ToWide

Function Utf8ToWide

src/OSTPlatform/Encoding.cpp:42–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40}
41
42std::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

Callers 3

ResolveLibraryPathFunction · 0.85
OpenMethod · 0.85
GetLoadedFunction · 0.85

Calls 4

FitsWindowsIntFunction · 0.85
emptyMethod · 0.80
sizeMethod · 0.80
dataMethod · 0.80

Tested by

no test coverage detected