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 by subtracting the offset (0x30, 0x37, and 0x57) between the ASCII value of the character and the desired integer value.
- Returns
- codepoint (0x0000..0xFFFF) or -1 in case of an error (e.g. EOF or non-hex character)
Definition at line 6749 of file json.hpp.
6750 {
6751
6753 int codepoint = 0;
6754 const auto factors = { 12u, 8u, 4u, 0u };
6755
6756 for (const auto factor : factors)
6757 {
6758 get();
6759
6761 {
6762 codepoint +=
static_cast<int>((
static_cast<unsigned int>(
current) - 0x30u) << factor);
6763 }
6764
6766 {
6767 codepoint +=
static_cast<int>((
static_cast<unsigned int>(
current) - 0x37u) << factor);
6768 }
6769
6771 {
6772 codepoint +=
static_cast<int>((
static_cast<unsigned int>(
current) - 0x57u) << factor);
6773 }
6774
6775 else
6776 {
6777 return -1;
6778 }
6779 }
6780
6781 JSON_ASSERT(0x0000 <= codepoint && codepoint <= 0xFFFF);
6782 return codepoint;
6783 }
char_int_type current
the current character