diff --git a/include/nlohmann/detail/input/lexer.hpp b/include/nlohmann/detail/input/lexer.hpp index 92f1c0c82..623aa1128 100644 --- a/include/nlohmann/detail/input/lexer.hpp +++ b/include/nlohmann/detail/input/lexer.hpp @@ -3054,13 +3054,33 @@ scan_number_done: return result; } + /// seekable or token-tracking adapter: the token string begins at current + void restart_token_string_impl(std::true_type /*lazy*/) + { + restart_token_string_lazy(std::integral_constant {}); + } + /// seekable adapter: the token string begins at current, which was consumed - void restart_token_string_impl(std::true_type /*lazy*/) noexcept + void restart_token_string_lazy(std::false_type /*adapter_token*/) noexcept { const std::size_t consumed = ia.get_consumed_count(); token_string_start = (consumed > 0 && current != char_traits::eof()) ? consumed - 1 : consumed; } + /// token-tracking adapter: the token begins with current, or with the next + /// character if current was put back or is the end of input + void restart_token_string_lazy(std::true_type /*adapter_token*/) + { + if (!next_unget && current != char_traits::eof()) + { + ia.mark_token_start(current); + } + else + { + ia.begin_token(); + } + } + /// streaming adapter: the token string begins at current; a character /// that was put back is copied again when it is read again void restart_token_string_impl(std::false_type /*lazy*/) diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 63f5bad0f..cca2d2ebe 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -14656,13 +14656,33 @@ scan_number_done: return result; } + /// seekable or token-tracking adapter: the token string begins at current + void restart_token_string_impl(std::true_type /*lazy*/) + { + restart_token_string_lazy(std::integral_constant {}); + } + /// seekable adapter: the token string begins at current, which was consumed - void restart_token_string_impl(std::true_type /*lazy*/) noexcept + void restart_token_string_lazy(std::false_type /*adapter_token*/) noexcept { const std::size_t consumed = ia.get_consumed_count(); token_string_start = (consumed > 0 && current != char_traits::eof()) ? consumed - 1 : consumed; } + /// token-tracking adapter: the token begins with current, or with the next + /// character if current was put back or is the end of input + void restart_token_string_lazy(std::true_type /*adapter_token*/) + { + if (!next_unget && current != char_traits::eof()) + { + ia.mark_token_start(current); + } + else + { + ia.begin_token(); + } + } + /// streaming adapter: the token string begins at current; a character /// that was put back is copied again when it is read again void restart_token_string_impl(std::false_type /*lazy*/)