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.
| 8747 | /// (an arbitrary value that is not a valid char value, often -1), because |
| 8748 | /// 255 may legitimately occur. May contain NUL, which should be escaped. |
| 8749 | std::string get_token_string() const |
| 8750 | { |
| 8751 | // escape control characters |
| 8752 | std::string result; |
| 8753 | for (const auto c : token_string) |
| 8754 | { |
| 8755 | if (static_cast<unsigned char>(c) <= '\x1F') |
| 8756 | { |
| 8757 | // escape control characters |
| 8758 | std::array<char, 9> cs{{}}; |
| 8759 | static_cast<void>((std::snprintf)(cs.data(), cs.size(), "<U+%.4X>", static_cast<unsigned char>(c))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) |
| 8760 | result += cs.data(); |
| 8761 | } |
| 8762 | else |
| 8763 | { |
| 8764 | // add character as is |
| 8765 | result.push_back(static_cast<std::string::value_type>(c)); |
| 8766 | } |
| 8767 | } |
| 8768 | |
| 8769 | return result; |
| 8770 | } |
| 8771 | |
| 8772 | /// return syntax error message |
| 8773 | JSON_HEDLEY_RETURNS_NON_NULL |
no test coverage detected