| 736 | } |
| 737 | |
| 738 | template <typename String, typename Iter> inline bool _parse_codepoint(String &out, input<Iter> &in) { |
| 739 | int uni_ch; |
| 740 | if ((uni_ch = _parse_quadhex(in)) == -1) { |
| 741 | return false; |
| 742 | } |
| 743 | if (0xd800 <= uni_ch && uni_ch <= 0xdfff) { |
| 744 | if (0xdc00 <= uni_ch) { |
| 745 | // a second 16-bit of a surrogate pair appeared |
| 746 | return false; |
| 747 | } |
| 748 | // first 16-bit of surrogate pair, get the next one |
| 749 | if (in.getc() != '\\' || in.getc() != 'u') { |
| 750 | in.ungetc(); |
| 751 | return false; |
| 752 | } |
| 753 | int second = _parse_quadhex(in); |
| 754 | if (!(0xdc00 <= second && second <= 0xdfff)) { |
| 755 | return false; |
| 756 | } |
| 757 | uni_ch = ((uni_ch - 0xd800) << 10) | ((second - 0xdc00) & 0x3ff); |
| 758 | uni_ch += 0x10000; |
| 759 | } |
| 760 | if (uni_ch < 0x80) { |
| 761 | out.push_back(static_cast<char>(uni_ch)); |
| 762 | } else { |
| 763 | if (uni_ch < 0x800) { |
| 764 | out.push_back(static_cast<char>(0xc0 | (uni_ch >> 6))); |
| 765 | } else { |
| 766 | if (uni_ch < 0x10000) { |
| 767 | out.push_back(static_cast<char>(0xe0 | (uni_ch >> 12))); |
| 768 | } else { |
| 769 | out.push_back(static_cast<char>(0xf0 | (uni_ch >> 18))); |
| 770 | out.push_back(static_cast<char>(0x80 | ((uni_ch >> 12) & 0x3f))); |
| 771 | } |
| 772 | out.push_back(static_cast<char>(0x80 | ((uni_ch >> 6) & 0x3f))); |
| 773 | } |
| 774 | out.push_back(static_cast<char>(0x80 | (uni_ch & 0x3f))); |
| 775 | } |
| 776 | return true; |
| 777 | } |
| 778 | |
| 779 | template <typename String, typename Iter> inline bool _parse_string(String &out, input<Iter> &in) { |
| 780 | while (1) { |
no test coverage detected