From 353024540ba60ef5d1e11050b8ae5809dd34a40e Mon Sep 17 00:00:00 2001 From: Daniel Parker Date: Fri, 15 Nov 2024 12:03:36 -0500 Subject: [PATCH] skip_space issue --- include/jsoncons/json_parser.hpp | 20 +++++++++++++++----- include/jsoncons/json_reader.hpp | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/include/jsoncons/json_parser.hpp b/include/jsoncons/json_parser.hpp index 7b70de4ba..c7dfc24d7 100644 --- a/include/jsoncons/json_parser.hpp +++ b/include/jsoncons/json_parser.hpp @@ -297,6 +297,7 @@ class basic_json_parser : public ser_context, public virtual basic_parser_input< void skip_space(std::error_code& ec) { + bool got_cr = false; const char_type* local_input_end = input_end_; while (true) { @@ -316,17 +317,25 @@ class basic_json_parser : public ser_context, public virtual basic_parser_input< ++position_; break; case '\r': - push_state(state_); ++input_ptr_; + ++line_; ++position_; - state_ = json_parse_state::cr; - return; + mark_position_ = position_; + got_cr = true; + break; case '\n': ++input_ptr_; - ++line_; + if (got_cr) + { + got_cr = false; + } + else + { + ++line_; + } ++position_; mark_position_ = position_; - return; + break; default: return; } @@ -335,6 +344,7 @@ class basic_json_parser : public ser_context, public virtual basic_parser_input< void skip_whitespace(std::error_code& ec) { + bool got_cr = false; const char_type* local_input_end = input_end_; while (true) diff --git a/include/jsoncons/json_reader.hpp b/include/jsoncons/json_reader.hpp index 868e5eab7..1e947880e 100644 --- a/include/jsoncons/json_reader.hpp +++ b/include/jsoncons/json_reader.hpp @@ -321,7 +321,7 @@ namespace jsoncons { while (!source_.eof()) { - parser_.skip_whitespace(ec); + parser_.skip_space(ec); if (parser_.source_exhausted()) { auto s1 = source_.read_buffer(ec);