MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
InputStrings.cpp
Go to the documentation of this file.
1#include "InputBackend.hpp"
2
3#include <utf8proc.h>
4
5namespace MayaFlux::Core {
6
7std::string wide_to_utf8(const wchar_t* ws)
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}
34
35} // namespace MayaFlux::Core
uint64_t length
Definition Composite.cpp:11
std::vector< float > * out
MAYAFLUX_API std::string wide_to_utf8(const wchar_t *ws)
Encode a null-terminated wide string as UTF-8.