MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ wide_to_utf8()

std::string MayaFlux::Core::wide_to_utf8 ( const wchar_t *  ws)

Encode a null-terminated wide string as UTF-8.

Parameters
wsWide string such as a HIDAPI product string or error message, or null.
Returns
UTF-8 text; empty for null. Unpaired surrogates and invalid code points become '?'.

Handles both 16-bit (Windows) and 32-bit wchar_t.

Definition at line 7 of file InputStrings.cpp.

8{
9 if (!ws)
10 return {};
11
12 std::string out;
13 for (const wchar_t* p = ws; *p != L'\0'; ++p) {
14 auto cp = static_cast<utf8proc_int32_t>(static_cast<uint32_t>(*p));
15
16 if constexpr (sizeof(wchar_t) == 2) {
17 if (cp >= 0xD800 && cp <= 0xDBFF && p[1] >= 0xDC00 && p[1] <= 0xDFFF) {
18 cp = 0x10000 + ((cp - 0xD800) << 10)
19 + (static_cast<utf8proc_int32_t>(*++p) - 0xDC00);
20 }
21 }
22
23 std::array<utf8proc_uint8_t, 4> bytes {};
24 const utf8proc_ssize_t length = utf8proc_encode_char(cp, bytes.data());
25 if (length <= 0) {
26 out.push_back('?');
27 continue;
28 }
29 out.append(reinterpret_cast<const char*>(bytes.data()),
30 static_cast<size_t>(length));
31 }
32 return out;
33}
uint64_t length
Definition Composite.cpp:11
std::vector< float > * out

References length, and out.

Referenced by MayaFlux::Core::HIDBackend::refresh_devices(), and MayaFlux::Core::TabletBackend::refresh_devices().

+ Here is the caller graph for this function: