MCPcopy Create free account
hub / github.com/Selectively11/CloudRedirect / WideToUtf8

Method WideToUtf8

src/platform/linux/platform_linux.cpp:24–35  ·  view source on GitHub ↗

WideToUtf8 - proper UTF-32 to UTF-8 conversion for Linux (wchar_t is 32-bit)

Source from the content-addressed store, hash-verified

22
23 // WideToUtf8 - proper UTF-32 to UTF-8 conversion for Linux (wchar_t is 32-bit)
24 std::string WideToUtf8(const wchar_t* w) override {
25 if (!w || !*w) return {};
26 std::string result;
27 for (; *w; ++w) {
28 uint32_t cp = static_cast<uint32_t>(*w);
29 if (cp < 0x80) { result += (char)cp; }
30 else if (cp < 0x800) { result += (char)(0xC0|(cp>>6)); result += (char)(0x80|(cp&0x3F)); }
31 else if (cp < 0x10000) { result += (char)(0xE0|(cp>>12)); result += (char)(0x80|((cp>>6)&0x3F)); result += (char)(0x80|(cp&0x3F)); }
32 else if (cp < 0x110000) { result += (char)(0xF0|(cp>>18)); result += (char)(0x80|((cp>>12)&0x3F)); result += (char)(0x80|((cp>>6)&0x3F)); result += (char)(0x80|(cp&0x3F)); }
33 }
34 return result;
35 }
36
37 std::string WideToUtf8(const wchar_t* w, size_t len) override {
38 if (!w || len == 0) return {};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected