! @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
| 7540 | non-hex character) |
| 7541 | */ |
| 7542 | int get_codepoint() |
| 7543 | { |
| 7544 | // this function only makes sense after reading `\u` |
| 7545 | JSON_ASSERT(current == 'u'); |
| 7546 | int codepoint = 0; |
| 7547 | |
| 7548 | const auto factors = { 12u, 8u, 4u, 0u }; |
| 7549 | for (const auto factor : factors) |
| 7550 | { |
| 7551 | get(); |
| 7552 | |
| 7553 | if (current >= '0' && current <= '9') |
| 7554 | { |
| 7555 | codepoint += static_cast<int>((static_cast<unsigned int>(current) - 0x30u) << factor); |
| 7556 | } |
| 7557 | else if (current >= 'A' && current <= 'F') |
| 7558 | { |
| 7559 | codepoint += static_cast<int>((static_cast<unsigned int>(current) - 0x37u) << factor); |
| 7560 | } |
| 7561 | else if (current >= 'a' && current <= 'f') |
| 7562 | { |
| 7563 | codepoint += static_cast<int>((static_cast<unsigned int>(current) - 0x57u) << factor); |
| 7564 | } |
| 7565 | else |
| 7566 | { |
| 7567 | return -1; |
| 7568 | } |
| 7569 | } |
| 7570 | |
| 7571 | JSON_ASSERT(0x0000 <= codepoint && codepoint <= 0xFFFF); |
| 7572 | return codepoint; |
| 7573 | } |
| 7574 | |
| 7575 | /*! |
| 7576 | @brief check if the next byte(s) are inside a given range |