return the last read token (for errors only). Will never contain EOF (an arbitrary value that is not a valid char value, often -1), because 255 may legitimately occur. May contain NUL, which should be escaped.
| 8818 | /// (an arbitrary value that is not a valid char value, often -1), because |
| 8819 | /// 255 may legitimately occur. May contain NUL, which should be escaped. |
| 8820 | std::string get_token_string() const |
| 8821 | { |
| 8822 | // escape control characters |
| 8823 | std::string result; |
| 8824 | for (const auto c : token_string) |
| 8825 | { |
| 8826 | if (static_cast<unsigned char>(c) <= '\x1F') |
| 8827 | { |
| 8828 | // escape control characters |
| 8829 | std::array<char, 9> cs{{}}; |
| 8830 | static_cast<void>((std::snprintf)(cs.data(), cs.size(), "<U+%.4X>", static_cast<unsigned char>(c))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) |
| 8831 | result += cs.data(); |
| 8832 | } |
| 8833 | else |
| 8834 | { |
| 8835 | // add character as is |
| 8836 | result.push_back(static_cast<std::string::value_type>(c)); |
| 8837 | } |
| 8838 | } |
| 8839 | |
| 8840 | return result; |
| 8841 | } |
| 8842 | |
| 8843 | /// return syntax error message |
| 8844 | JSON_HEDLEY_RETURNS_NON_NULL |
no test coverage detected