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

Function WideToUtf8

src/OSTPlatform/Encoding.cpp:20–40  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18} // namespace
19
20std::string WideToUtf8(std::wstring_view value) {
21 if (value.empty()) return {};
22 if (!FitsWindowsInt(value.size(), "WideToUtf8")) return {};
23
24 const int size = WideCharToMultiByte(CP_UTF8, 0, value.data(), static_cast<int>(value.size()),
25 nullptr, 0, nullptr, nullptr);
26 if (size <= 0) {
27 OSTP_LOG_DEBUG("WideCharToMultiByte(size query) failed (error={})", GetLastError());
28 return {};
29 }
30
31 std::string result(static_cast<size_t>(size), '\0');
32 const int written = WideCharToMultiByte(CP_UTF8, 0, value.data(), static_cast<int>(value.size()),
33 result.data(), size, nullptr, nullptr);
34 if (written != size) {
35 OSTP_LOG_DEBUG("WideCharToMultiByte(convert) failed (written={}, expected={}, error={})",
36 written, size, GetLastError());
37 return {};
38 }
39 return result;
40}
41
42std::wstring Utf8ToWide(std::string_view value) {
43 if (value.empty()) return {};

Callers 11

ParseStrictFunction · 0.85
ParseHexIntegerFunction · 0.85
ResolveRemoteExportFunction · 0.85
FindEnvironmentVariableFunction · 0.85
GetImagePathFunction · 0.85
EnumerateModulesFunction · 0.85
IsSystemModulePathFunction · 0.85
ExecuteFunction · 0.85
DrainMethod · 0.85
WidePathToUtf8Function · 0.85
GetActiveUserFunction · 0.85

Calls 4

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

Tested by

no test coverage detected