Skip to content

Commit

Permalink
CHANGELOG update
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Jul 2, 2024
1 parent 5a4f9d2 commit 905e126
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 283 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
master
-------

- Removed deprecated functions and type names identified in #487

0.176.0
-------

Expand Down
283 changes: 0 additions & 283 deletions include/jsoncons/json_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,289 +408,6 @@ namespace jsoncons {
}
};

template<class CharT,class Source=jsoncons::stream_source<CharT>,class TempAllocator=std::allocator<char>>
class legacy_basic_json_reader
{
public:
using char_type = CharT;
using source_type = Source;
using string_view_type = jsoncons::basic_string_view<CharT>;
private:
using char_allocator_type = typename std::allocator_traits<TempAllocator>:: template rebind_alloc<CharT>;

static constexpr size_t default_max_buffer_size = 16384;

json_source_adaptor<Source> source_;
basic_default_json_visitor<CharT> default_visitor_;
basic_json_visitor<CharT>& visitor_;
basic_json_parser<CharT,TempAllocator> parser_;

// Noncopyable and nonmoveable
legacy_basic_json_reader(const legacy_basic_json_reader&) = delete;
legacy_basic_json_reader& operator=(const legacy_basic_json_reader&) = delete;

public:
template <class Sourceable>
explicit legacy_basic_json_reader(Sourceable&& source, const TempAllocator& temp_alloc = TempAllocator())
: legacy_basic_json_reader(std::forward<Sourceable>(source),
default_visitor_,
basic_json_decode_options<CharT>(),
default_json_parsing(),
temp_alloc)
{
}

template <class Sourceable>
legacy_basic_json_reader(Sourceable&& source,
const basic_json_decode_options<CharT>& options,
const TempAllocator& temp_alloc = TempAllocator())
: legacy_basic_json_reader(std::forward<Sourceable>(source),
default_visitor_,
options,
default_json_parsing(),
temp_alloc)
{
}

template <class Sourceable>
legacy_basic_json_reader(Sourceable&& source,
std::function<bool(json_errc,const ser_context&)> err_handler,
const TempAllocator& temp_alloc = TempAllocator())
: legacy_basic_json_reader(std::forward<Sourceable>(source),
default_visitor_,
basic_json_decode_options<CharT>(),
err_handler,
temp_alloc)
{
}

template <class Sourceable>
legacy_basic_json_reader(Sourceable&& source,
const basic_json_decode_options<CharT>& options,
std::function<bool(json_errc,const ser_context&)> err_handler,
const TempAllocator& temp_alloc = TempAllocator())
: legacy_basic_json_reader(std::forward<Sourceable>(source),
default_visitor_,
options,
err_handler,
temp_alloc)
{
}

template <class Sourceable>
legacy_basic_json_reader(Sourceable&& source,
basic_json_visitor<CharT>& visitor,
const TempAllocator& temp_alloc = TempAllocator())
: legacy_basic_json_reader(std::forward<Sourceable>(source),
visitor,
basic_json_decode_options<CharT>(),
default_json_parsing(),
temp_alloc)
{
}

template <class Sourceable>
legacy_basic_json_reader(Sourceable&& source,
basic_json_visitor<CharT>& visitor,
const basic_json_decode_options<CharT>& options,
const TempAllocator& temp_alloc = TempAllocator())
: legacy_basic_json_reader(std::forward<Sourceable>(source),
visitor,
options,
default_json_parsing(),
temp_alloc)
{
}

template <class Sourceable>
legacy_basic_json_reader(Sourceable&& source,
basic_json_visitor<CharT>& visitor,
std::function<bool(json_errc,const ser_context&)> err_handler,
const TempAllocator& temp_alloc = TempAllocator())
: legacy_basic_json_reader(std::forward<Sourceable>(source),
visitor,
basic_json_decode_options<CharT>(),
err_handler,
temp_alloc)
{
}

template <class Sourceable>
legacy_basic_json_reader(Sourceable&& source,
basic_json_visitor<CharT>& visitor,
const basic_json_decode_options<CharT>& options,
std::function<bool(json_errc,const ser_context&)> err_handler,
const TempAllocator& temp_alloc = TempAllocator(),
typename std::enable_if<!std::is_constructible<jsoncons::basic_string_view<CharT>,Sourceable>::value>::type* = 0)
: source_(std::forward<Sourceable>(source)),
visitor_(visitor),
parser_(options,err_handler,temp_alloc)
{
}

template <class Sourceable>
legacy_basic_json_reader(Sourceable&& source,
basic_json_visitor<CharT>& visitor,
const basic_json_decode_options<CharT>& options,
std::function<bool(json_errc,const ser_context&)> err_handler,
const TempAllocator& temp_alloc = TempAllocator(),
typename std::enable_if<std::is_constructible<jsoncons::basic_string_view<CharT>,Sourceable>::value>::type* = 0)
: source_(),
visitor_(visitor),
parser_(options,err_handler,temp_alloc)
{
jsoncons::basic_string_view<CharT> sv(std::forward<Sourceable>(source));

auto r = unicode_traits::detect_json_encoding(sv.data(), sv.size());
if (!(r.encoding == unicode_traits::encoding_kind::utf8 || r.encoding == unicode_traits::encoding_kind::undetected))
{
JSONCONS_THROW(ser_error(json_errc::illegal_unicode_character,parser_.line(),parser_.column()));
}
std::size_t offset = (r.ptr - sv.data());
parser_.update(sv.data()+offset,sv.size()-offset);
}

void read_next()
{
std::error_code ec;
read_next(ec);
if (ec)
{
JSONCONS_THROW(ser_error(ec,parser_.line(),parser_.column()));
}
}

void read_next(std::error_code& ec)
{
if (source_.is_error())
{
ec = json_errc::source_error;
return;
}
parser_.reset();
while (!parser_.stopped())
{
if (parser_.source_exhausted())
{
auto s = source_.read_buffer(ec);
if (ec) return;
if (s.size() > 0)
{
parser_.update(s.data(),s.size());
}
}
bool eof = parser_.source_exhausted();
parser_.parse_some(visitor_, ec);
if (ec) return;
if (eof)
{
if (parser_.enter())
{
break;
}
else if (!parser_.accept())
{
ec = json_errc::unexpected_eof;
return;
}
}
}

while (!source_.eof())
{
parser_.skip_whitespace();
if (parser_.source_exhausted())
{
auto s = source_.read_buffer(ec);
if (ec) return;
if (s.size() > 0)
{
parser_.update(s.data(),s.size());
}
}
else
{
break;
}
}
}

void check_done()
{
std::error_code ec;
check_done(ec);
if (ec)
{
JSONCONS_THROW(ser_error(ec,parser_.line(),parser_.column()));
}
}

std::size_t line() const
{
return parser_.line();
}

std::size_t column() const
{
return parser_.column();
}

void check_done(std::error_code& ec)
{
if (source_.is_error())
{
ec = json_errc::source_error;
return;
}
if (source_.eof())
{
parser_.check_done(ec);
if (ec) return;
}
else
{
do
{
if (parser_.source_exhausted())
{
auto s = source_.read_buffer(ec);
if (ec) return;
if (s.size() > 0)
{
parser_.update(s.data(),s.size());
}
}
if (!parser_.source_exhausted())
{
parser_.check_done(ec);
if (ec) return;
}
}
while (!eof());
}
}

bool eof() const
{
return parser_.source_exhausted() && source_.eof();
}

void read()
{
read_next();
check_done();
}

void read(std::error_code& ec)
{
read_next(ec);
if (!ec)
{
check_done(ec);
}
}
};

using json_string_reader = basic_json_reader<char,string_source<char>>;
using wjson_string_reader = basic_json_reader<wchar_t,string_source<wchar_t>>;
using json_stream_reader = basic_json_reader<char,stream_source<char>>;
Expand Down

0 comments on commit 905e126

Please sign in to comment.