1
0
mirror of https://github.com/nlohmann/json.git synced 2025-07-28 12:02:00 +03:00

🐛 fixed a bug in the unget function

This commit is contained in:
Niels Lohmann
2018-10-07 16:48:45 +02:00
parent 011b15dd08
commit 6d09cdec34
4 changed files with 21 additions and 16 deletions

View File

@ -795,11 +795,6 @@ class parse_error : public exception
static std::string position_string(const position_t& pos)
{
if (pos.chars_read_total == 0)
{
return "";
}
return " at line " + std::to_string(pos.lines_read + 1) +
", column " + std::to_string(pos.chars_read_current_line);
}
@ -3595,12 +3590,18 @@ scan_number_done:
next_unget = true;
--position.chars_read_total;
--position.chars_read_current_line;
// in case we "unget" a newline, we have to also decrement the lines_read
if (position.lines_read != 0 and position.chars_read_current_line == 0)
if (position.chars_read_current_line == 0)
{
--position.lines_read;
if (position.lines_read > 0)
{
--position.lines_read;
}
}
else
{
--position.chars_read_current_line;
}
if (JSON_LIKELY(current != std::char_traits<char>::eof()))