MCPcopy Create free account
hub / github.com/CalcProgrammer1/OpenRGB / get_codepoint

Method get_codepoint

dependencies/json/json.hpp:6108–6139  ·  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

6106 non-hex character)
6107 */
6108 int get_codepoint()
6109 {
6110 // this function only makes sense after reading `\u`
6111 JSON_ASSERT(current == 'u');
6112 int codepoint = 0;
6113
6114 const auto factors = { 12u, 8u, 4u, 0u };
6115 for (const auto factor : factors)
6116 {
6117 get();
6118
6119 if (current >= '0' && current <= '9')
6120 {
6121 codepoint += static_cast<int>((static_cast<unsigned int>(current) - 0x30u) << factor);
6122 }
6123 else if (current >= 'A' && current <= 'F')
6124 {
6125 codepoint += static_cast<int>((static_cast<unsigned int>(current) - 0x37u) << factor);
6126 }
6127 else if (current >= 'a' && current <= 'f')
6128 {
6129 codepoint += static_cast<int>((static_cast<unsigned int>(current) - 0x57u) << factor);
6130 }
6131 else
6132 {
6133 return -1;
6134 }
6135 }
6136
6137 JSON_ASSERT(0x0000 <= codepoint && codepoint <= 0xFFFF);
6138 return codepoint;
6139 }
6140
6141 /*!
6142 @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