Escape . Translates the next 'codeLength' characters into a hex number and returns the result. . Throws if it's not actually hex.
| 36 | // the result. |
| 37 | // . Throws if it's not actually hex. |
| 38 | std::string Escape(Stream& in, int codeLength) { |
| 39 | // grab string |
| 40 | std::string str; |
| 41 | for (int i = 0; i < codeLength; i++) |
| 42 | str += in.get(); |
| 43 | |
| 44 | // get the value |
| 45 | unsigned value = ParseHex(str, in.mark()); |
| 46 | |
| 47 | // legal unicode? |
| 48 | if ((value >= 0xD800 && value <= 0xDFFF) || value > 0x10FFFF) { |
| 49 | std::stringstream msg; |
| 50 | msg << ErrorMsg::INVALID_UNICODE << value; |
| 51 | throw ParserException(in.mark(), msg.str()); |
| 52 | } |
| 53 | |
| 54 | // now break it up into chars |
| 55 | if (value <= 0x7F) |
| 56 | return Str(value); |
| 57 | |
| 58 | if (value <= 0x7FF) |
| 59 | return Str(0xC0 + (value >> 6)) + Str(0x80 + (value & 0x3F)); |
| 60 | |
| 61 | if (value <= 0xFFFF) |
| 62 | return Str(0xE0 + (value >> 12)) + Str(0x80 + ((value >> 6) & 0x3F)) + |
| 63 | Str(0x80 + (value & 0x3F)); |
| 64 | |
| 65 | return Str(0xF0 + (value >> 18)) + Str(0x80 + ((value >> 12) & 0x3F)) + |
| 66 | Str(0x80 + ((value >> 6) & 0x3F)) + Str(0x80 + (value & 0x3F)); |
| 67 | } |
| 68 | |
| 69 | // Escape |
| 70 | // . Escapes the sequence starting 'in' (it must begin with a '\' or single |
no test coverage detected