Skip to content

Commit

Permalink
parse_false parse_true parse_null
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Nov 7, 2024
1 parent 9fc63b3 commit 0a7743a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
25 changes: 10 additions & 15 deletions include/jsoncons/json_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,23 +273,18 @@ namespace jsoncons {
{
//std::cout << "UPDATE BUFFER\n";
bool success = false;
if (!parser_.stopped())
auto s = source_.read_buffer(ec);
if (ec) return false;
if (s.size() > 0)
{
//if (parser_.source_exhausted())
{
auto s = source_.read_buffer(ec);
if (ec) return false;
if (s.size() > 0)
{
parser_.update(s.data(),s.size());
success = true;
}
else
{
eof_ = true;
}
}
parser_.update(s.data(),s.size());
success = true;
}
else
{
eof_ = true;
}

return success;
}

Expand Down
13 changes: 10 additions & 3 deletions test/corelib/src/json_reader_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ TEST_CASE("test json_reader buffered read")
std::stringstream is(str2);

auto j = json::parse(is);

//CHECK(j[1].as<double>() == -123456789.123456789);
REQUIRE(j.is_array());
REQUIRE(j.size() == 2);
CHECK_FALSE(j[1].as<bool>());

}

Expand All @@ -74,6 +75,9 @@ TEST_CASE("test json_reader buffered read")
std::stringstream is(str2);

auto j = json::parse(is);
REQUIRE(j.is_array());
REQUIRE(j.size() == 2);
CHECK(j[1].as<bool>());
}

SECTION("null with split buffer")
Expand All @@ -84,12 +88,15 @@ TEST_CASE("test json_reader buffered read")
str2.append(stream_source<char>::default_max_buffer_size - 5, 'a');
str2.push_back('"');
str2.push_back(',');
str2.append("true");
str2.append("null");
str2.push_back(']');

std::stringstream is(str2);

auto j = json::parse(is);
REQUIRE(j.is_array());
REQUIRE(j.size() == 2);
CHECK(j[1].is_null());
}
}

Expand Down

0 comments on commit 0a7743a

Please sign in to comment.