MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / get_codepoint

Method get_codepoint

examples/server/json.hpp:7470–7501  ·  view source on GitHub ↗

! @brief get codepoint from 4 hex characters following `\u` For input "\u c1 c2 c3 c4" the codepoint is: (c1 * 0x1000) + (c2 * 0x0100) + (c3 * 0x0010) + c4 = (c1 << 12) + (c2 << 8) + (c3 << 4) + (c4 << 0) Furthermore, the possible characters '0'..'9', 'A'..'F', and 'a'..'f' must be converted to the integers 0x0..0x9, 0xA..0xF, 0xA..0xF, resp. The conversion is done

Source from the content-addressed store, hash-verified

7468 non-hex character)
7469 */
7470 int get_codepoint()
7471 {
7472 // this function only makes sense after reading `\u`
7473 JSON_ASSERT(current == 'u');
7474 int codepoint = 0;
7475
7476 const auto factors = { 12u, 8u, 4u, 0u };
7477 for (const auto factor : factors)
7478 {
7479 get();
7480
7481 if (current >= '0' && current <= '9')
7482 {
7483 codepoint += static_cast<int>((static_cast<unsigned int>(current) - 0x30u) << factor);
7484 }
7485 else if (current >= 'A' && current <= 'F')
7486 {
7487 codepoint += static_cast<int>((static_cast<unsigned int>(current) - 0x37u) << factor);
7488 }
7489 else if (current >= 'a' && current <= 'f')
7490 {
7491 codepoint += static_cast<int>((static_cast<unsigned int>(current) - 0x57u) << factor);
7492 }
7493 else
7494 {
7495 return -1;
7496 }
7497 }
7498
7499 JSON_ASSERT(0x0000 <= codepoint && codepoint <= 0xFFFF);
7500 return codepoint;
7501 }
7502
7503 /*!
7504 @brief check if the next byte(s) are inside a given range

Callers

nothing calls this directly

Calls 1

getFunction · 0.70

Tested by

no test coverage detected