MCPcopy Create free account
hub / github.com/3Shain/dxmt / encodeTypedChar

Function encodeTypedChar

src/util/util_string.cpp:93–140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

91}
92
93size_t encodeTypedChar(uint8_t *begin, uint8_t *end, uint32_t ch) {
94 if (likely(ch < 0x80)) {
95 if (begin) {
96 if (unlikely(begin + 1 > end))
97 return 0;
98
99 begin[0] = uint8_t(ch);
100 }
101
102 return 1;
103 } else if (ch < 0x800) {
104 if (begin) {
105 if (unlikely(begin + 2 > end))
106 return 0;
107
108 begin[0] = uint8_t(0xC0 | (ch >> 6));
109 begin[1] = uint8_t(0x80 | (ch & 0x3F));
110 }
111
112 return 2;
113 } else if (ch < 0x10000) {
114 if (begin) {
115 if (unlikely(begin + 3 > end))
116 return 0;
117
118 begin[0] = uint8_t(0xE0 | ((ch >> 12)));
119 begin[1] = uint8_t(0x80 | ((ch >> 6) & 0x3F));
120 begin[2] = uint8_t(0x80 | ((ch >> 0) & 0x3F));
121 }
122
123 return 3;
124 } else if (ch < 0x200000) {
125 if (begin) {
126 if (unlikely(begin + 4 < end))
127 return 0;
128
129 begin[0] = uint8_t(0xF0 | ((ch >> 18)));
130 begin[1] = uint8_t(0x80 | ((ch >> 12) & 0x3F));
131 begin[2] = uint8_t(0x80 | ((ch >> 6) & 0x3F));
132 begin[3] = uint8_t(0x80 | ((ch >> 0) & 0x3F));
133 }
134
135 return 4;
136 } else {
137 // Invalid code point for UTF-8
138 return 0;
139 }
140}
141
142size_t encodeTypedChar(uint16_t *begin, uint16_t *end, uint32_t ch) {
143 if (likely(ch < 0xD800)) {

Callers 1

encodeCharFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected