MCPcopy Create free account
hub / github.com/HumbleUI/JWM / StringUTF16

Method StringUTF16

shared/cc/StringUTF16.cc:4–58  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2#include <vector>
3
4jwm::StringUTF16::StringUTF16(const char* str) {
5 std::vector<uint32_t> wide;
6 // convert from utf8 to 32-bit wide symbols
7 while(*str)
8 {
9 if (*str & 0b10000000)
10 {
11 uint32_t t;
12 // utf8 symbol
13 if ((*str & 0b11110000) == 0b11110000)
14 {
15 // 4-byte symbol
16 t = *(str++) & 0b111;
17 t <<= 6;
18 t |= *(str++) & 0b111111;
19 t <<= 6;
20 t |= *(str++) & 0b111111;
21 t <<= 6;
22 t |= *(str++) & 0b111111;
23 wide.push_back(t);
24 } else if ((*str & 0b11100000) == 0b11100000)
25 {
26 // 3-byte symbol
27 t = *(str++) & 0b1111;
28 t <<= 6;
29 t |= *(str++) & 0b111111;
30 t <<= 6;
31 t |= *(str++) & 0b111111;
32 wide.push_back(t);
33 } else
34 {
35 // 2-byte symbol
36 t = *(str++) & 0b11111;
37 t <<= 6;
38 t |= *(str++) & 0b111111;
39 wide.push_back(t);
40 }
41 } else
42 {
43 // ascii symbol
44 wide.push_back(*(str++));
45 }
46 }
47
48 // convert from 32-bit wide symbols to utf16
49 for (uint32_t c : wide) {
50 if (c <= 0xffff) {
51 push_back(static_cast<jchar>(c));
52 } else {
53 c -= 0x10000;
54 push_back(static_cast<jchar>((c >> 10) + 0xd800));
55 push_back(static_cast<jchar>((c & 0x3ff) + 0xdc00));
56 }
57 }
58}
59
60jwm::StringUTF16::StringUTF16(const uint32_t *str) {
61 for (uint32_t c = *str; c != 0; c = *(str += 1)) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected