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.
| 7317 | /// (an arbitrary value that is not a valid char value, often -1), because |
| 7318 | /// 255 may legitimately occur. May contain NUL, which should be escaped. |
| 7319 | std::string get_token_string() const |
| 7320 | { |
| 7321 | // escape control characters |
| 7322 | std::string result; |
| 7323 | for (const auto c : token_string) |
| 7324 | { |
| 7325 | if (static_cast<unsigned char>(c) <= '\x1F') |
| 7326 | { |
| 7327 | // escape control characters |
| 7328 | std::array<char, 9> cs{ {} }; |
| 7329 | (std::snprintf)(cs.data(), cs.size(), "<U+%.4X>", static_cast<unsigned char>(c)); |
| 7330 | result += cs.data(); |
| 7331 | } |
| 7332 | else |
| 7333 | { |
| 7334 | // add character as is |
| 7335 | result.push_back(static_cast<std::string::value_type>(c)); |
| 7336 | } |
| 7337 | } |
| 7338 | |
| 7339 | return result; |
| 7340 | } |
| 7341 | |
| 7342 | /// return syntax error message |
| 7343 | JSON_HEDLEY_RETURNS_NON_NULL |
no test coverage detected