Skip to content

Commit

Permalink
Improve skip_space
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Nov 15, 2024
1 parent 3530245 commit 9fb6fac
Showing 1 changed file with 6 additions and 56 deletions.
62 changes: 6 additions & 56 deletions include/jsoncons/json_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +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;
bool prev_char_is_cr = false;
const char_type* local_input_end = input_end_;
while (true)
{
Expand All @@ -313,24 +313,25 @@ class basic_json_parser : public ser_context, public virtual basic_parser_input<
{
case ' ':
case '\t':
prev_char_is_cr = false;
++input_ptr_;
++position_;
break;
case '\r':
prev_char_is_cr = true;
++input_ptr_;
++line_;
++position_;
mark_position_ = position_;
got_cr = true;
break;
case '\n':
++input_ptr_;
if (got_cr)
if (prev_char_is_cr)
{
got_cr = false;
prev_char_is_cr = false;
}
else
{
{
++line_;
}
++position_;
Expand All @@ -342,57 +343,6 @@ 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)
{
if (input_ptr_ == local_input_end)
{
if (!chunk_rdr_->read_chunk(*this, ec))
{
break;
}
local_input_end = input_end_;
}
switch (state_)
{
case json_parse_state::cr:
++line_;
++position_;
mark_position_ = position_;
switch (*input_ptr_)
{
case '\n':
++input_ptr_;
++position_;
state_ = pop_state();
break;
default:
state_ = pop_state();
break;
}
break;

default:
switch (*input_ptr_)
{
case ' ':
case '\t':
case '\n':
case '\r':
skip_space(ec);
break;
default:
return;
}
break;
}
}
}

void begin_object(basic_json_visitor<char_type>& visitor, std::error_code& ec)
{
if (JSONCONS_UNLIKELY(++nesting_depth_ > options_.max_nesting_depth()))
Expand Down

0 comments on commit 9fb6fac

Please sign in to comment.