Skip to content

Commit

Permalink
Revert 1.0.0 parsing change
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Jan 8, 2025
1 parent 5c8f03d commit ec77f55
Show file tree
Hide file tree
Showing 9 changed files with 254 additions and 395 deletions.
53 changes: 1 addition & 52 deletions examples/src/json_parser_examples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include <jsoncons/json.hpp>
#include <iostream>

#if JSONCONS_VERSION_MAJOR == 0 && JSONCONS_VERSION_MINOR < 179

void incremental_parsing_example()
{
jsoncons::json_decoder<jsoncons::json> decoder;
Expand Down Expand Up @@ -43,51 +41,6 @@ void incremental_parsing_example()
}
}

#else

void incremental_parsing_example()
{
std::vector<std::string> chunks = {"[fal", "se,", "9", "0]"};
std::size_t index = 0;

auto read_chunk = [&](jsoncons::parser_input& input, std::error_code& /*ec*/) -> bool
{
if (index < chunks.size())
{
input.set_buffer(chunks[index].data(), chunks[index].size());
++index;
return true;
}
else
{
return false;
}
};

jsoncons::json_decoder<jsoncons::json> decoder;
jsoncons::json_parser parser{read_chunk};

parser.reset();
try
{
parser.parse_some(decoder);
std::cout << "(1) done: " << std::boolalpha << parser.done() << ", source_exhausted: " << parser.source_exhausted() << "\n\n";
parser.finish_parse(decoder);
std::cout << "(2) done: " << std::boolalpha << parser.done() << ", source_exhausted: " << parser.source_exhausted() << "\n\n";
parser.check_done();
std::cout << "(3) done: " << std::boolalpha << parser.done() << ", source_exhausted: " << parser.source_exhausted() << "\n\n";

jsoncons::json j = decoder.get_result();
std::cout << "(4) " << j << "\n\n";
}
catch (const jsoncons::ser_error& e)
{
std::cout << e.what() << '\n';
}
}

#endif

void parse_nan_replacement_example()
{
std::string s = R"(
Expand All @@ -106,11 +59,7 @@ void parse_nan_replacement_example()
jsoncons::json_parser parser(options);
try
{
#if JSONCONS_VERSION_MAJOR == 0 && JSONCONS_VERSION_MINOR < 179
parser.update(s); // until 1.0.0
#else
parser.set_buffer(s.data(), s.size()); // since 1.0.0
#endif
parser.update(s.data(), s.size()); // since 1.0.0
parser.parse_some(decoder);
parser.finish_parse(decoder);
parser.check_done();
Expand Down
68 changes: 0 additions & 68 deletions include/jsoncons/chunk_reader.hpp

This file was deleted.

20 changes: 14 additions & 6 deletions include/jsoncons/json_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,28 @@
#ifndef JSONCONS_JSON_PARSER_HPP
#define JSONCONS_JSON_PARSER_HPP

#include <cstddef>
#include <cstdint>
#include <functional> // std::function
#include <limits> // std::numeric_limits
#include <memory> // std::allocator
#include <string>
#include <vector>
#include <stdexcept>
#include <system_error>
#include <unordered_map>
#include <limits> // std::numeric_limits
#include <functional> // std::function
#include <utility>
#include <vector>

#include <jsoncons/config/compiler_support.hpp>
#include <jsoncons/chunk_reader.hpp>
#include <jsoncons/detail/parse_number.hpp>
#include <jsoncons/json_error.hpp>
#include <jsoncons/json_exception.hpp>
#include <jsoncons/json_filter.hpp>
#include <jsoncons/json_options.hpp>
#include <jsoncons/json_visitor.hpp>
#include <jsoncons/json_error.hpp>
#include <jsoncons/detail/parse_number.hpp>
#include <jsoncons/ser_context.hpp>
#include <jsoncons/tag_type.hpp>
#include <jsoncons/utility/unicode_traits.hpp>

#define JSONCONS_ILLEGAL_CONTROL_CHARACTER \
case 0x00:case 0x01:case 0x02:case 0x03:case 0x04:case 0x05:case 0x06:case 0x07:case 0x08:case 0x0b: \
Expand Down
15 changes: 10 additions & 5 deletions include/jsoncons/json_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,23 @@
#ifndef JSONCONS_JSON_READER_HPP
#define JSONCONS_JSON_READER_HPP

#include <cstddef>
#include <functional>
#include <ios>
#include <memory> // std::allocator
#include <string>
#include <vector>
#include <stdexcept>
#include <system_error>
#include <ios>
#include <utility> // std::move
#include <jsoncons/source.hpp>

#include <jsoncons/config/compiler_support.hpp>
#include <jsoncons/json_exception.hpp>
#include <jsoncons/json_visitor.hpp>
#include <jsoncons/json_parser.hpp>
#include <jsoncons/json_visitor.hpp>
#include <jsoncons/ser_context.hpp>
#include <jsoncons/source.hpp>
#include <jsoncons/source_adaptor.hpp>
#include <jsoncons/tag_type.hpp>
#include <jsoncons/utility/unicode_traits.hpp>

namespace jsoncons {

Expand Down
6 changes: 3 additions & 3 deletions include/jsoncons_ext/csv/csv_cursor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ class basic_csv_cursor : public basic_staj_cursor<CharT>, private virtual ser_co
JSONCONS_THROW(ser_error(json_errc::illegal_unicode_character,parser_.line(),parser_.column()));
}
std::size_t offset = (r.ptr - sv.data());
parser_.set_buffer(sv.data()+offset,sv.size()-offset);
parser_.update(sv.data()+offset,sv.size()-offset);
if (!done())
{
next();
Expand All @@ -304,7 +304,7 @@ class basic_csv_cursor : public basic_staj_cursor<CharT>, private virtual ser_co
return;
}
std::size_t offset = (r.ptr - sv.data());
parser_.set_buffer(sv.data()+offset,sv.size()-offset);
parser_.update(sv.data()+offset,sv.size()-offset);
if (!done())
{
next(ec);
Expand All @@ -327,7 +327,7 @@ class basic_csv_cursor : public basic_staj_cursor<CharT>, private virtual ser_co
if (ec) {return;}
if (s.size() > 0)
{
parser_.set_buffer(s.data(),s.size());
parser_.update(s.data(),s.size());
}
}
parser_.parse_some(visitor, ec);
Expand Down
Loading

0 comments on commit ec77f55

Please sign in to comment.