MCPcopy Create free account
hub / github.com/AllentDan/LibtorchTutorials / get_codepoint

Method get_codepoint

lesson6-Segmentation/json.hpp:6040–6071  ·  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

6038 non-hex character)
6039 */
6040 int get_codepoint()
6041 {
6042 // this function only makes sense after reading `\u`
6043 JSON_ASSERT(current == 'u');
6044 int codepoint = 0;
6045
6046 const auto factors = { 12u, 8u, 4u, 0u };
6047 for (const auto factor : factors)
6048 {
6049 get();
6050
6051 if (current >= '0' && current <= '9')
6052 {
6053 codepoint += static_cast<int>((static_cast<unsigned int>(current) - 0x30u) << factor);
6054 }
6055 else if (current >= 'A' && current <= 'F')
6056 {
6057 codepoint += static_cast<int>((static_cast<unsigned int>(current) - 0x37u) << factor);
6058 }
6059 else if (current >= 'a' && current <= 'f')
6060 {
6061 codepoint += static_cast<int>((static_cast<unsigned int>(current) - 0x57u) << factor);
6062 }
6063 else
6064 {
6065 return -1;
6066 }
6067 }
6068
6069 JSON_ASSERT(0x0000 <= codepoint && codepoint <= 0xFFFF);
6070 return codepoint;
6071 }
6072
6073 /*!
6074 @brief check if the next byte(s) are inside a given range

Callers

nothing calls this directly

Calls 1

getFunction · 0.85

Tested by

no test coverage detected