MCPcopy Create free account
hub / github.com/BernardoGiordano/Checkpoint / nextCodepoint

Function nextCodepoint

3ds/source/util.cpp:284–303  ·  view source on GitHub ↗

Decodes the UTF-8 codepoint starting at s[i] (BMP only — the cache key is u16). `extraBytes` is how many continuation bytes follow the lead byte; invalid or truncated sequences decode as 0xFFFF with no advance.

Source from the content-addressed store, hash-verified

282 // u16). `extraBytes` is how many continuation bytes follow the lead byte;
283 // invalid or truncated sequences decode as 0xFFFF with no advance.
284 u16 nextCodepoint(const std::string& s, size_t i, int& extraBytes)
285 {
286 u16 codepoint = 0xFFFF;
287 extraBytes = 0;
288 if (s[i] & 0x80 && s[i] & 0x40 && s[i] & 0x20 && !(s[i] & 0x10) && i + 2 < s.size()) {
289 codepoint = s[i] & 0x0F;
290 codepoint = codepoint << 6 | (s[i + 1] & 0x3F);
291 codepoint = codepoint << 6 | (s[i + 2] & 0x3F);
292 extraBytes = 2;
293 }
294 else if (s[i] & 0x80 && s[i] & 0x40 && !(s[i] & 0x20) && i + 1 < s.size()) {
295 codepoint = s[i] & 0x1F;
296 codepoint = codepoint << 6 | (s[i + 1] & 0x3F);
297 extraBytes = 1;
298 }
299 else if (!(s[i] & 0x80)) {
300 codepoint = s[i];
301 }
302 return codepoint;
303 }
304
305 float glyphWidth(u16 codepoint, float scaleX)
306 {

Callers 2

splitWordMethod · 0.85
textWidthMethod · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected