Share the position-counter bump between get() and get_ignoring_pending_unget()

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann
2026-09-05 22:19:36 +02:00
committed by GitHub
parent 3eb414f832
commit 780ff80b17
2 changed files with 22 additions and 8 deletions
+11 -4
View File
@@ -1446,8 +1446,7 @@ scan_number_done:
*/ */
char_int_type get() char_int_type get()
{ {
++position.chars_read_total; advance_position();
++position.chars_read_current_line;
if (next_unget) if (next_unget)
{ {
@@ -1462,6 +1461,15 @@ scan_number_done:
return track_after_read(); return track_after_read();
} }
/// shared head of get() / get_ignoring_pending_unget(): bump the
/// per-character position counters (line-count-on-'\n' bookkeeping is
/// handled afterwards, in track_after_read(), once `current` is known)
void advance_position() noexcept
{
++position.chars_read_total;
++position.chars_read_current_line;
}
/// shared tail of get() / get_ignoring_pending_unget(): capture the /// shared tail of get() / get_ignoring_pending_unget(): capture the
/// character for error messages (if needed) and update line/column /// character for error messages (if needed) and update line/column
/// bookkeeping for the character now in `current` /// bookkeeping for the character now in `current`
@@ -1497,8 +1505,7 @@ scan_number_done:
{ {
JSON_ASSERT(!next_unget); JSON_ASSERT(!next_unget);
++position.chars_read_total; advance_position();
++position.chars_read_current_line;
current = ia.get_character(); current = ia.get_character();
return track_after_read(); return track_after_read();
+11 -4
View File
@@ -9229,8 +9229,7 @@ scan_number_done:
*/ */
char_int_type get() char_int_type get()
{ {
++position.chars_read_total; advance_position();
++position.chars_read_current_line;
if (next_unget) if (next_unget)
{ {
@@ -9245,6 +9244,15 @@ scan_number_done:
return track_after_read(); return track_after_read();
} }
/// shared head of get() / get_ignoring_pending_unget(): bump the
/// per-character position counters (line-count-on-'\n' bookkeeping is
/// handled afterwards, in track_after_read(), once `current` is known)
void advance_position() noexcept
{
++position.chars_read_total;
++position.chars_read_current_line;
}
/// shared tail of get() / get_ignoring_pending_unget(): capture the /// shared tail of get() / get_ignoring_pending_unget(): capture the
/// character for error messages (if needed) and update line/column /// character for error messages (if needed) and update line/column
/// bookkeeping for the character now in `current` /// bookkeeping for the character now in `current`
@@ -9280,8 +9288,7 @@ scan_number_done:
{ {
JSON_ASSERT(!next_unget); JSON_ASSERT(!next_unget);
++position.chars_read_total; advance_position();
++position.chars_read_current_line;
current = ia.get_character(); current = ia.get_character();
return track_after_read(); return track_after_read();