MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / DecodeUtf8Codepoint

Function DecodeUtf8Codepoint

engine/Poseidon/Foundation/Strings/Mbcs.cpp:155–201  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

153}
154
155int DecodeUtf8Codepoint(const char* text, uint32_t* outCodepoint)
156{
157 if (outCodepoint)
158 *outCodepoint = 0xFFFD;
159 if (!text || !*text)
160 return 0;
161
162 const unsigned char lead = static_cast<unsigned char>(text[0]);
163 if (lead < 0x80)
164 {
165 if (outCodepoint)
166 *outCodepoint = lead;
167 return 1;
168 }
169
170 const int required = Utf8SequenceLength(lead);
171 const int bytes = Utf8CodepointBytes(text);
172 if (bytes <= 0)
173 return 0;
174 if (required == 1 || bytes < required)
175 return bytes;
176
177 switch (required)
178 {
179 case 2:
180 if (outCodepoint)
181 *outCodepoint = ((lead & 0x1F) << 6) | (static_cast<unsigned char>(text[1]) & 0x3F);
182 return 2;
183 case 3:
184 if (outCodepoint)
185 {
186 *outCodepoint = ((lead & 0x0F) << 12) | ((static_cast<unsigned char>(text[1]) & 0x3F) << 6) |
187 (static_cast<unsigned char>(text[2]) & 0x3F);
188 }
189 return 3;
190 case 4:
191 if (outCodepoint)
192 {
193 *outCodepoint = ((lead & 0x07) << 18) | ((static_cast<unsigned char>(text[1]) & 0x3F) << 12) |
194 ((static_cast<unsigned char>(text[2]) & 0x3F) << 6) |
195 (static_cast<unsigned char>(text[3]) & 0x3F);
196 }
197 return 4;
198 default:
199 return 1;
200 }
201}
202
203int CountUtf8Codepoints(const char* text)
204{

Callers 5

DecodeUTF8Method · 0.85
TriSendTextImplFunction · 0.85
TriTypeTextFunction · 0.85

Calls 2

Utf8SequenceLengthFunction · 0.85
Utf8CodepointBytesFunction · 0.85

Tested by 2

TriSendTextImplFunction · 0.68
TriTypeTextFunction · 0.68