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.
| 7385 | /// (an arbitrary value that is not a valid char value, often -1), because |
| 7386 | /// 255 may legitimately occur. May contain NUL, which should be escaped. |
| 7387 | std::string get_token_string() const |
| 7388 | { |
| 7389 | // escape control characters |
| 7390 | std::string result; |
| 7391 | for (const auto c : token_string) |
| 7392 | { |
| 7393 | if (static_cast<unsigned char>(c) <= '\x1F') |
| 7394 | { |
| 7395 | // escape control characters |
| 7396 | std::array<char, 9> cs{{}}; |
| 7397 | (std::snprintf)(cs.data(), cs.size(), "<U+%.4X>", static_cast<unsigned char>(c)); |
| 7398 | result += cs.data(); |
| 7399 | } |
| 7400 | else |
| 7401 | { |
| 7402 | // add character as is |
| 7403 | result.push_back(static_cast<std::string::value_type>(c)); |
| 7404 | } |
| 7405 | } |
| 7406 | |
| 7407 | return result; |
| 7408 | } |
| 7409 | |
| 7410 | /// return syntax error message |
| 7411 | JSON_HEDLEY_RETURNS_NON_NULL |
no test coverage detected