MCPcopy Create free account
hub / github.com/Tracktion/choc / parseUnicodeCharacterNumber

Method parseUnicodeCharacterNumber

choc/text/choc_JSON.h:501–530  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

499 }
500
501 uint32_t parseUnicodeCharacterNumber (bool isLowSurrogate)
502 {
503 uint32_t result = 0;
504
505 for (int i = 4; --i >= 0;)
506 {
507 auto errorPos = current;
508 auto digit = pop();
509
510 if (digit >= '0' && digit <= '9') digit -= '0';
511 else if (digit >= 'a' && digit <= 'f') digit = 10 + (digit - 'a');
512 else if (digit >= 'A' && digit <= 'F') digit = 10 + (digit - 'A');
513 else throwError ("Syntax error in unicode character", errorPos);
514
515 result = (result << 4) + digit;
516 }
517
518 if (isLowSurrogate && ! text::isUnicodeLowSurrogate (result))
519 throwError ("Expected a unicode low surrogate codepoint");
520
521 if (text::isUnicodeHighSurrogate (result))
522 {
523 if (! isLowSurrogate && popIf ("\\u"))
524 return text::createUnicodeFromHighAndLowSurrogates ({ result, parseUnicodeCharacterNumber (true) });
525
526 throwError ("Expected a unicode low surrogate codepoint");
527 }
528
529 return result;
530 }
531 };
532
533 Parser p { text, text };

Callers

nothing calls this directly

Calls 4

throwErrorFunction · 0.85
isUnicodeLowSurrogateFunction · 0.85
isUnicodeHighSurrogateFunction · 0.85

Tested by

no test coverage detected