MCPcopy Create free account
hub / github.com/ClassicOldSong/Apollo / from_utf8

Function from_utf8

tools/utils.cpp:5–29  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3#include <windows.h>
4
5std::wstring from_utf8(const std::string_view &string) {
6 // No conversion needed if the string is empty
7 if (string.empty()) {
8 return {};
9 }
10
11 // Get the output size required to store the string
12 auto output_size = MultiByteToWideChar(CP_UTF8, 0, string.data(), string.size(), nullptr, 0);
13 if (output_size == 0) {
14 // auto winerr = GetLastError();
15 // BOOST_LOG(error) << "Failed to get UTF-16 buffer size: "sv << winerr;
16 return {};
17 }
18
19 // Perform the conversion
20 std::wstring output(output_size, L'\0');
21 output_size = MultiByteToWideChar(CP_UTF8, 0, string.data(), string.size(), output.data(), output.size());
22 if (output_size == 0) {
23 // auto winerr = GetLastError();
24 // BOOST_LOG(error) << "Failed to convert string to UTF-16: "sv << winerr;
25 return {};
26 }
27
28 return output;
29}
30
31std::string to_utf8(const std::wstring_view &string) {
32 // No conversion needed if the string is empty

Callers 1

print_deviceFunction · 0.70

Calls 2

dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected