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