jsoncons 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/ext/jsoncons/extconf.rb +43 -0
- data/ext/jsoncons/jsoncons.cpp +161 -0
- data/ext/jsoncons/jsoncons.h +10 -0
- data/jsoncons.gemspec +44 -0
- data/lib/jsoncons/jsoncons/examples/input/address-book.json +13 -0
- data/lib/jsoncons/jsoncons/examples/input/books.json +28 -0
- data/lib/jsoncons/jsoncons/examples/input/countries.json +7 -0
- data/lib/jsoncons/jsoncons/examples/input/employees.json +30 -0
- data/lib/jsoncons/jsoncons/examples/input/jsonschema/name.json +15 -0
- data/lib/jsoncons/jsoncons/examples/input/multiple-json-objects.json +3 -0
- data/lib/jsoncons/jsoncons/examples/input/sales.csv +6 -0
- data/lib/jsoncons/jsoncons/examples/input/store.json +28 -0
- data/lib/jsoncons/jsoncons/examples/input/tasks.csv +6 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/allocator_holder.hpp +38 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/basic_json.hpp +5905 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/bigint.hpp +1611 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/byte_string.hpp +820 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/config/binary_config.hpp +226 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/config/compiler_support.hpp +375 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/config/jsoncons_config.hpp +309 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/config/version.hpp +40 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/conv_error.hpp +218 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/decode_json.hpp +209 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/decode_traits.hpp +651 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/endian.hpp +44 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/grisu3.hpp +312 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/optional.hpp +483 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/parse_number.hpp +1133 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/span.hpp +188 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/string_view.hpp +537 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/string_wrapper.hpp +370 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/write_number.hpp +567 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/encode_json.hpp +315 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/encode_traits.hpp +378 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json.hpp +18 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_array.hpp +324 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_content_handler.hpp +12 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_cursor.hpp +448 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_decoder.hpp +420 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_encoder.hpp +1587 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_error.hpp +156 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_exception.hpp +241 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_filter.hpp +653 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_fwd.hpp +23 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_object.hpp +1772 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_options.hpp +862 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_parser.hpp +2900 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_reader.hpp +731 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_traits_macros.hpp +1072 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_traits_macros_deprecated.hpp +144 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_type.hpp +206 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_type_traits.hpp +1830 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_visitor.hpp +1560 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_visitor2.hpp +2079 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/pretty_print.hpp +89 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/ser_context.hpp +62 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/sink.hpp +289 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/source.hpp +777 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/source_adaptor.hpp +148 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/staj2_cursor.hpp +1189 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/staj_cursor.hpp +1254 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/staj_iterator.hpp +449 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/tag_type.hpp +245 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/text_source_adaptor.hpp +144 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/traits_extension.hpp +884 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/typed_array_view.hpp +250 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/unicode_traits.hpp +1330 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/uri.hpp +635 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/value_converter.hpp +340 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson.hpp +23 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_cursor.hpp +320 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_decimal128.hpp +865 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_encoder.hpp +585 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_error.hpp +103 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_oid.hpp +245 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_options.hpp +75 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_parser.hpp +645 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_reader.hpp +92 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_type.hpp +44 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/decode_bson.hpp +201 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/encode_bson.hpp +144 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor.hpp +26 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_cursor.hpp +351 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_cursor2.hpp +265 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_detail.hpp +93 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_encoder.hpp +1766 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_error.hpp +105 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_options.hpp +113 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_parser.hpp +1942 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_reader.hpp +116 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/decode_cbor.hpp +203 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/encode_cbor.hpp +151 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv.hpp +17 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_cursor.hpp +358 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_encoder.hpp +954 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_error.hpp +85 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_options.hpp +973 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_parser.hpp +2099 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_reader.hpp +348 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_serializer.hpp +12 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/decode_csv.hpp +208 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/encode_csv.hpp +122 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jmespath/jmespath.hpp +5215 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jmespath/jmespath_error.hpp +215 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpatch/jsonpatch.hpp +579 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpatch/jsonpatch_error.hpp +121 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/expression.hpp +3329 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/flatten.hpp +432 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/json_location.hpp +445 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/json_query.hpp +115 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath.hpp +13 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath_error.hpp +240 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp +2612 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath_selector.hpp +1322 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpointer/jsonpointer.hpp +1577 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpointer/jsonpointer_error.hpp +119 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/format_validator.hpp +968 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/json_validator.hpp +120 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/jsonschema.hpp +13 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/jsonschema_error.hpp +105 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/jsonschema_version.hpp +18 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/keyword_validator.hpp +1745 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/keyword_validator_factory.hpp +556 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/schema_draft7.hpp +198 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/schema_location.hpp +200 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/schema_version.hpp +35 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/subschema.hpp +144 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/mergepatch/mergepatch.hpp +103 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/decode_msgpack.hpp +202 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/encode_msgpack.hpp +142 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack.hpp +24 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_cursor.hpp +343 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_cursor2.hpp +259 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_encoder.hpp +753 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_error.hpp +94 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_options.hpp +74 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_parser.hpp +748 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_reader.hpp +116 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_type.hpp +63 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/decode_ubjson.hpp +201 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/encode_ubjson.hpp +142 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson.hpp +23 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_cursor.hpp +307 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_encoder.hpp +502 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_error.hpp +100 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_options.hpp +87 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_parser.hpp +880 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_reader.hpp +92 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_type.hpp +43 -0
- data/lib/jsoncons/version.rb +5 -0
- data/lib/jsoncons.rb +33 -0
- data/test/jsoncons_test.rb +108 -0
- data/test/test_helper.rb +7 -0
- metadata +268 -0
@@ -0,0 +1,731 @@
|
|
1
|
+
// Copyright 2015 Daniel Parker
|
2
|
+
// Distributed under the Boost license, Version 1.0.
|
3
|
+
// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
4
|
+
|
5
|
+
// See https://github.com/danielaparker/jsoncons for latest version
|
6
|
+
|
7
|
+
#ifndef JSONCONS_JSON_READER_HPP
|
8
|
+
#define JSONCONS_JSON_READER_HPP
|
9
|
+
|
10
|
+
#include <memory> // std::allocator
|
11
|
+
#include <string>
|
12
|
+
#include <vector>
|
13
|
+
#include <stdexcept>
|
14
|
+
#include <system_error>
|
15
|
+
#include <ios>
|
16
|
+
#include <utility> // std::move
|
17
|
+
#include <jsoncons/source.hpp>
|
18
|
+
#include <jsoncons/json_exception.hpp>
|
19
|
+
#include <jsoncons/json_visitor.hpp>
|
20
|
+
#include <jsoncons/json_parser.hpp>
|
21
|
+
#include <jsoncons/source_adaptor.hpp>
|
22
|
+
|
23
|
+
namespace jsoncons {
|
24
|
+
|
25
|
+
// utf8_other_json_input_adapter
|
26
|
+
|
27
|
+
template <class CharT>
|
28
|
+
class json_utf8_to_other_visitor_adaptor : public json_visitor
|
29
|
+
{
|
30
|
+
public:
|
31
|
+
using json_visitor::string_view_type;
|
32
|
+
private:
|
33
|
+
basic_default_json_visitor<CharT> default_visitor_;
|
34
|
+
basic_json_visitor<CharT>& other_visitor_;
|
35
|
+
//std::function<bool(json_errc,const ser_context&)> err_handler_;
|
36
|
+
|
37
|
+
// noncopyable and nonmoveable
|
38
|
+
json_utf8_to_other_visitor_adaptor(const json_utf8_to_other_visitor_adaptor<CharT>&) = delete;
|
39
|
+
json_utf8_to_other_visitor_adaptor<CharT>& operator=(const json_utf8_to_other_visitor_adaptor<CharT>&) = delete;
|
40
|
+
|
41
|
+
public:
|
42
|
+
json_utf8_to_other_visitor_adaptor()
|
43
|
+
: other_visitor_(default_visitor_)
|
44
|
+
{
|
45
|
+
}
|
46
|
+
|
47
|
+
json_utf8_to_other_visitor_adaptor(basic_json_visitor<CharT>& other_visitor/*,
|
48
|
+
std::function<bool(json_errc,const ser_context&)> err_handler*/)
|
49
|
+
: other_visitor_(other_visitor)/*,
|
50
|
+
err_handler_(err_handler)*/
|
51
|
+
{
|
52
|
+
}
|
53
|
+
|
54
|
+
private:
|
55
|
+
|
56
|
+
void visit_flush() override
|
57
|
+
{
|
58
|
+
other_visitor_.flush();
|
59
|
+
}
|
60
|
+
|
61
|
+
bool visit_begin_object(semantic_tag tag, const ser_context& context, std::error_code& ec) override
|
62
|
+
{
|
63
|
+
return other_visitor_.begin_object(tag, context, ec);
|
64
|
+
}
|
65
|
+
|
66
|
+
bool visit_end_object(const ser_context& context, std::error_code& ec) override
|
67
|
+
{
|
68
|
+
return other_visitor_.end_object(context, ec);
|
69
|
+
}
|
70
|
+
|
71
|
+
bool visit_begin_array(semantic_tag tag, const ser_context& context, std::error_code& ec) override
|
72
|
+
{
|
73
|
+
return other_visitor_.begin_array(tag, context, ec);
|
74
|
+
}
|
75
|
+
|
76
|
+
bool visit_end_array(const ser_context& context, std::error_code& ec) override
|
77
|
+
{
|
78
|
+
return other_visitor_.end_array(context, ec);
|
79
|
+
}
|
80
|
+
|
81
|
+
bool visit_key(const string_view_type& name, const ser_context& context, std::error_code& ec) override
|
82
|
+
{
|
83
|
+
std::basic_string<CharT> target;
|
84
|
+
auto result = unicode_traits::convert(
|
85
|
+
name.data(), name.size(), target,
|
86
|
+
unicode_traits::conv_flags::strict);
|
87
|
+
if (result.ec != unicode_traits::conv_errc())
|
88
|
+
{
|
89
|
+
JSONCONS_THROW(ser_error(result.ec,context.line(),context.column()));
|
90
|
+
}
|
91
|
+
return other_visitor_.key(target, context, ec);
|
92
|
+
}
|
93
|
+
|
94
|
+
bool visit_string(const string_view_type& value, semantic_tag tag, const ser_context& context, std::error_code& ec) override
|
95
|
+
{
|
96
|
+
std::basic_string<CharT> target;
|
97
|
+
auto result = unicode_traits::convert(
|
98
|
+
value.data(), value.size(), target,
|
99
|
+
unicode_traits::conv_flags::strict);
|
100
|
+
if (result.ec != unicode_traits::conv_errc())
|
101
|
+
{
|
102
|
+
ec = result.ec;
|
103
|
+
return false;
|
104
|
+
}
|
105
|
+
return other_visitor_.string_value(target, tag, context, ec);
|
106
|
+
}
|
107
|
+
|
108
|
+
bool visit_int64(int64_t value,
|
109
|
+
semantic_tag tag,
|
110
|
+
const ser_context& context,
|
111
|
+
std::error_code& ec) override
|
112
|
+
{
|
113
|
+
return other_visitor_.int64_value(value, tag, context, ec);
|
114
|
+
}
|
115
|
+
|
116
|
+
bool visit_uint64(uint64_t value,
|
117
|
+
semantic_tag tag,
|
118
|
+
const ser_context& context,
|
119
|
+
std::error_code& ec) override
|
120
|
+
{
|
121
|
+
return other_visitor_.uint64_value(value, tag, context, ec);
|
122
|
+
}
|
123
|
+
|
124
|
+
bool visit_half(uint16_t value,
|
125
|
+
semantic_tag tag,
|
126
|
+
const ser_context& context,
|
127
|
+
std::error_code& ec) override
|
128
|
+
{
|
129
|
+
return other_visitor_.half_value(value, tag, context, ec);
|
130
|
+
}
|
131
|
+
|
132
|
+
bool visit_double(double value,
|
133
|
+
semantic_tag tag,
|
134
|
+
const ser_context& context,
|
135
|
+
std::error_code& ec) override
|
136
|
+
{
|
137
|
+
return other_visitor_.double_value(value, tag, context, ec);
|
138
|
+
}
|
139
|
+
|
140
|
+
bool visit_bool(bool value, semantic_tag tag, const ser_context& context, std::error_code& ec) override
|
141
|
+
{
|
142
|
+
return other_visitor_.bool_value(value, tag, context, ec);
|
143
|
+
}
|
144
|
+
|
145
|
+
bool visit_null(semantic_tag tag, const ser_context& context, std::error_code& ec) override
|
146
|
+
{
|
147
|
+
return other_visitor_.null_value(tag, context, ec);
|
148
|
+
}
|
149
|
+
};
|
150
|
+
|
151
|
+
template<class CharT,class Source=jsoncons::stream_source<CharT>,class Allocator=std::allocator<char>>
|
152
|
+
class basic_json_reader
|
153
|
+
{
|
154
|
+
public:
|
155
|
+
using char_type = CharT;
|
156
|
+
using source_type = Source;
|
157
|
+
using string_view_type = jsoncons::basic_string_view<CharT>;
|
158
|
+
private:
|
159
|
+
typedef typename std::allocator_traits<Allocator>:: template rebind_alloc<CharT> char_allocator_type;
|
160
|
+
|
161
|
+
static constexpr size_t default_max_buffer_size = 16384;
|
162
|
+
|
163
|
+
json_source_adaptor<Source> source_;
|
164
|
+
basic_default_json_visitor<CharT> default_visitor_;
|
165
|
+
basic_json_visitor<CharT>& visitor_;
|
166
|
+
basic_json_parser<CharT,Allocator> parser_;
|
167
|
+
|
168
|
+
// Noncopyable and nonmoveable
|
169
|
+
basic_json_reader(const basic_json_reader&) = delete;
|
170
|
+
basic_json_reader& operator=(const basic_json_reader&) = delete;
|
171
|
+
|
172
|
+
public:
|
173
|
+
template <class Sourceable>
|
174
|
+
explicit basic_json_reader(Sourceable&& source, const Allocator& alloc = Allocator())
|
175
|
+
: basic_json_reader(std::forward<Sourceable>(source),
|
176
|
+
default_visitor_,
|
177
|
+
basic_json_decode_options<CharT>(),
|
178
|
+
default_json_parsing(),
|
179
|
+
alloc)
|
180
|
+
{
|
181
|
+
}
|
182
|
+
|
183
|
+
template <class Sourceable>
|
184
|
+
basic_json_reader(Sourceable&& source,
|
185
|
+
const basic_json_decode_options<CharT>& options,
|
186
|
+
const Allocator& alloc = Allocator())
|
187
|
+
: basic_json_reader(std::forward<Sourceable>(source),
|
188
|
+
default_visitor_,
|
189
|
+
options,
|
190
|
+
default_json_parsing(),
|
191
|
+
alloc)
|
192
|
+
{
|
193
|
+
}
|
194
|
+
|
195
|
+
template <class Sourceable>
|
196
|
+
basic_json_reader(Sourceable&& source,
|
197
|
+
std::function<bool(json_errc,const ser_context&)> err_handler,
|
198
|
+
const Allocator& alloc = Allocator())
|
199
|
+
: basic_json_reader(std::forward<Sourceable>(source),
|
200
|
+
default_visitor_,
|
201
|
+
basic_json_decode_options<CharT>(),
|
202
|
+
err_handler,
|
203
|
+
alloc)
|
204
|
+
{
|
205
|
+
}
|
206
|
+
|
207
|
+
template <class Sourceable>
|
208
|
+
basic_json_reader(Sourceable&& source,
|
209
|
+
const basic_json_decode_options<CharT>& options,
|
210
|
+
std::function<bool(json_errc,const ser_context&)> err_handler,
|
211
|
+
const Allocator& alloc = Allocator())
|
212
|
+
: basic_json_reader(std::forward<Sourceable>(source),
|
213
|
+
default_visitor_,
|
214
|
+
options,
|
215
|
+
err_handler,
|
216
|
+
alloc)
|
217
|
+
{
|
218
|
+
}
|
219
|
+
|
220
|
+
template <class Sourceable>
|
221
|
+
basic_json_reader(Sourceable&& source,
|
222
|
+
basic_json_visitor<CharT>& visitor,
|
223
|
+
const Allocator& alloc = Allocator())
|
224
|
+
: basic_json_reader(std::forward<Sourceable>(source),
|
225
|
+
visitor,
|
226
|
+
basic_json_decode_options<CharT>(),
|
227
|
+
default_json_parsing(),
|
228
|
+
alloc)
|
229
|
+
{
|
230
|
+
}
|
231
|
+
|
232
|
+
template <class Sourceable>
|
233
|
+
basic_json_reader(Sourceable&& source,
|
234
|
+
basic_json_visitor<CharT>& visitor,
|
235
|
+
const basic_json_decode_options<CharT>& options,
|
236
|
+
const Allocator& alloc = Allocator())
|
237
|
+
: basic_json_reader(std::forward<Sourceable>(source),
|
238
|
+
visitor,
|
239
|
+
options,
|
240
|
+
default_json_parsing(),
|
241
|
+
alloc)
|
242
|
+
{
|
243
|
+
}
|
244
|
+
|
245
|
+
template <class Sourceable>
|
246
|
+
basic_json_reader(Sourceable&& source,
|
247
|
+
basic_json_visitor<CharT>& visitor,
|
248
|
+
std::function<bool(json_errc,const ser_context&)> err_handler,
|
249
|
+
const Allocator& alloc = Allocator())
|
250
|
+
: basic_json_reader(std::forward<Sourceable>(source),
|
251
|
+
visitor,
|
252
|
+
basic_json_decode_options<CharT>(),
|
253
|
+
err_handler,
|
254
|
+
alloc)
|
255
|
+
{
|
256
|
+
}
|
257
|
+
|
258
|
+
template <class Sourceable>
|
259
|
+
basic_json_reader(Sourceable&& source,
|
260
|
+
basic_json_visitor<CharT>& visitor,
|
261
|
+
const basic_json_decode_options<CharT>& options,
|
262
|
+
std::function<bool(json_errc,const ser_context&)> err_handler,
|
263
|
+
const Allocator& alloc = Allocator())
|
264
|
+
: source_(std::forward<Sourceable>(source)),
|
265
|
+
visitor_(visitor),
|
266
|
+
parser_(options,err_handler,alloc)
|
267
|
+
{
|
268
|
+
}
|
269
|
+
|
270
|
+
#if !defined(JSONCONS_NO_DEPRECATED)
|
271
|
+
JSONCONS_DEPRECATED_MSG("Instead, use max_nesting_depth() on options")
|
272
|
+
int max_nesting_depth() const
|
273
|
+
{
|
274
|
+
return parser_.max_nesting_depth();
|
275
|
+
}
|
276
|
+
|
277
|
+
JSONCONS_DEPRECATED_MSG("Instead, use max_nesting_depth(int) on options")
|
278
|
+
void max_nesting_depth(int depth)
|
279
|
+
{
|
280
|
+
parser_.max_nesting_depth(depth);
|
281
|
+
}
|
282
|
+
#endif
|
283
|
+
void read_next()
|
284
|
+
{
|
285
|
+
std::error_code ec;
|
286
|
+
read_next(ec);
|
287
|
+
if (ec)
|
288
|
+
{
|
289
|
+
JSONCONS_THROW(ser_error(ec,parser_.line(),parser_.column()));
|
290
|
+
}
|
291
|
+
}
|
292
|
+
|
293
|
+
void read_next(std::error_code& ec)
|
294
|
+
{
|
295
|
+
if (source_.is_error())
|
296
|
+
{
|
297
|
+
ec = json_errc::source_error;
|
298
|
+
return;
|
299
|
+
}
|
300
|
+
parser_.reset();
|
301
|
+
while (!parser_.stopped())
|
302
|
+
{
|
303
|
+
if (parser_.source_exhausted())
|
304
|
+
{
|
305
|
+
auto s = source_.read_buffer(ec);
|
306
|
+
if (ec) return;
|
307
|
+
if (s.size() > 0)
|
308
|
+
{
|
309
|
+
parser_.update(s.data(),s.size());
|
310
|
+
}
|
311
|
+
}
|
312
|
+
bool eof = parser_.source_exhausted();
|
313
|
+
parser_.parse_some(visitor_, ec);
|
314
|
+
if (ec) return;
|
315
|
+
if (eof)
|
316
|
+
{
|
317
|
+
if (parser_.enter())
|
318
|
+
{
|
319
|
+
break;
|
320
|
+
}
|
321
|
+
else if (!parser_.accept())
|
322
|
+
{
|
323
|
+
ec = json_errc::unexpected_eof;
|
324
|
+
return;
|
325
|
+
}
|
326
|
+
}
|
327
|
+
}
|
328
|
+
|
329
|
+
while (!source_.eof())
|
330
|
+
{
|
331
|
+
parser_.skip_whitespace();
|
332
|
+
if (parser_.source_exhausted())
|
333
|
+
{
|
334
|
+
auto s = source_.read_buffer(ec);
|
335
|
+
if (ec) return;
|
336
|
+
if (s.size() > 0)
|
337
|
+
{
|
338
|
+
parser_.update(s.data(),s.size());
|
339
|
+
}
|
340
|
+
}
|
341
|
+
else
|
342
|
+
{
|
343
|
+
break;
|
344
|
+
}
|
345
|
+
}
|
346
|
+
}
|
347
|
+
|
348
|
+
void check_done()
|
349
|
+
{
|
350
|
+
std::error_code ec;
|
351
|
+
check_done(ec);
|
352
|
+
if (ec)
|
353
|
+
{
|
354
|
+
JSONCONS_THROW(ser_error(ec,parser_.line(),parser_.column()));
|
355
|
+
}
|
356
|
+
}
|
357
|
+
|
358
|
+
std::size_t line() const
|
359
|
+
{
|
360
|
+
return parser_.line();
|
361
|
+
}
|
362
|
+
|
363
|
+
std::size_t column() const
|
364
|
+
{
|
365
|
+
return parser_.column();
|
366
|
+
}
|
367
|
+
|
368
|
+
void check_done(std::error_code& ec)
|
369
|
+
{
|
370
|
+
if (source_.is_error())
|
371
|
+
{
|
372
|
+
ec = json_errc::source_error;
|
373
|
+
return;
|
374
|
+
}
|
375
|
+
if (source_.eof())
|
376
|
+
{
|
377
|
+
parser_.check_done(ec);
|
378
|
+
if (ec) return;
|
379
|
+
}
|
380
|
+
else
|
381
|
+
{
|
382
|
+
do
|
383
|
+
{
|
384
|
+
if (parser_.source_exhausted())
|
385
|
+
{
|
386
|
+
auto s = source_.read_buffer(ec);
|
387
|
+
if (ec) return;
|
388
|
+
if (s.size() > 0)
|
389
|
+
{
|
390
|
+
parser_.update(s.data(),s.size());
|
391
|
+
}
|
392
|
+
}
|
393
|
+
if (!parser_.source_exhausted())
|
394
|
+
{
|
395
|
+
parser_.check_done(ec);
|
396
|
+
if (ec) return;
|
397
|
+
}
|
398
|
+
}
|
399
|
+
while (!eof());
|
400
|
+
}
|
401
|
+
}
|
402
|
+
|
403
|
+
bool eof() const
|
404
|
+
{
|
405
|
+
return parser_.source_exhausted() && source_.eof();
|
406
|
+
}
|
407
|
+
|
408
|
+
void read()
|
409
|
+
{
|
410
|
+
read_next();
|
411
|
+
check_done();
|
412
|
+
}
|
413
|
+
|
414
|
+
void read(std::error_code& ec)
|
415
|
+
{
|
416
|
+
read_next(ec);
|
417
|
+
if (!ec)
|
418
|
+
{
|
419
|
+
check_done(ec);
|
420
|
+
}
|
421
|
+
}
|
422
|
+
};
|
423
|
+
|
424
|
+
template<class CharT,class Source=jsoncons::stream_source<CharT>,class Allocator=std::allocator<char>>
|
425
|
+
class legacy_basic_json_reader
|
426
|
+
{
|
427
|
+
public:
|
428
|
+
using char_type = CharT;
|
429
|
+
using source_type = Source;
|
430
|
+
using string_view_type = jsoncons::basic_string_view<CharT>;
|
431
|
+
private:
|
432
|
+
typedef typename std::allocator_traits<Allocator>:: template rebind_alloc<CharT> char_allocator_type;
|
433
|
+
|
434
|
+
static constexpr size_t default_max_buffer_size = 16384;
|
435
|
+
|
436
|
+
json_source_adaptor<Source> source_;
|
437
|
+
basic_default_json_visitor<CharT> default_visitor_;
|
438
|
+
basic_json_visitor<CharT>& visitor_;
|
439
|
+
basic_json_parser<CharT,Allocator> parser_;
|
440
|
+
|
441
|
+
// Noncopyable and nonmoveable
|
442
|
+
legacy_basic_json_reader(const legacy_basic_json_reader&) = delete;
|
443
|
+
legacy_basic_json_reader& operator=(const legacy_basic_json_reader&) = delete;
|
444
|
+
|
445
|
+
public:
|
446
|
+
template <class Sourceable>
|
447
|
+
explicit legacy_basic_json_reader(Sourceable&& source, const Allocator& alloc = Allocator())
|
448
|
+
: legacy_basic_json_reader(std::forward<Sourceable>(source),
|
449
|
+
default_visitor_,
|
450
|
+
basic_json_decode_options<CharT>(),
|
451
|
+
default_json_parsing(),
|
452
|
+
alloc)
|
453
|
+
{
|
454
|
+
}
|
455
|
+
|
456
|
+
template <class Sourceable>
|
457
|
+
legacy_basic_json_reader(Sourceable&& source,
|
458
|
+
const basic_json_decode_options<CharT>& options,
|
459
|
+
const Allocator& alloc = Allocator())
|
460
|
+
: legacy_basic_json_reader(std::forward<Sourceable>(source),
|
461
|
+
default_visitor_,
|
462
|
+
options,
|
463
|
+
default_json_parsing(),
|
464
|
+
alloc)
|
465
|
+
{
|
466
|
+
}
|
467
|
+
|
468
|
+
template <class Sourceable>
|
469
|
+
legacy_basic_json_reader(Sourceable&& source,
|
470
|
+
std::function<bool(json_errc,const ser_context&)> err_handler,
|
471
|
+
const Allocator& alloc = Allocator())
|
472
|
+
: legacy_basic_json_reader(std::forward<Sourceable>(source),
|
473
|
+
default_visitor_,
|
474
|
+
basic_json_decode_options<CharT>(),
|
475
|
+
err_handler,
|
476
|
+
alloc)
|
477
|
+
{
|
478
|
+
}
|
479
|
+
|
480
|
+
template <class Sourceable>
|
481
|
+
legacy_basic_json_reader(Sourceable&& source,
|
482
|
+
const basic_json_decode_options<CharT>& options,
|
483
|
+
std::function<bool(json_errc,const ser_context&)> err_handler,
|
484
|
+
const Allocator& alloc = Allocator())
|
485
|
+
: legacy_basic_json_reader(std::forward<Sourceable>(source),
|
486
|
+
default_visitor_,
|
487
|
+
options,
|
488
|
+
err_handler,
|
489
|
+
alloc)
|
490
|
+
{
|
491
|
+
}
|
492
|
+
|
493
|
+
template <class Sourceable>
|
494
|
+
legacy_basic_json_reader(Sourceable&& source,
|
495
|
+
basic_json_visitor<CharT>& visitor,
|
496
|
+
const Allocator& alloc = Allocator())
|
497
|
+
: legacy_basic_json_reader(std::forward<Sourceable>(source),
|
498
|
+
visitor,
|
499
|
+
basic_json_decode_options<CharT>(),
|
500
|
+
default_json_parsing(),
|
501
|
+
alloc)
|
502
|
+
{
|
503
|
+
}
|
504
|
+
|
505
|
+
template <class Sourceable>
|
506
|
+
legacy_basic_json_reader(Sourceable&& source,
|
507
|
+
basic_json_visitor<CharT>& visitor,
|
508
|
+
const basic_json_decode_options<CharT>& options,
|
509
|
+
const Allocator& alloc = Allocator())
|
510
|
+
: legacy_basic_json_reader(std::forward<Sourceable>(source),
|
511
|
+
visitor,
|
512
|
+
options,
|
513
|
+
default_json_parsing(),
|
514
|
+
alloc)
|
515
|
+
{
|
516
|
+
}
|
517
|
+
|
518
|
+
template <class Sourceable>
|
519
|
+
legacy_basic_json_reader(Sourceable&& source,
|
520
|
+
basic_json_visitor<CharT>& visitor,
|
521
|
+
std::function<bool(json_errc,const ser_context&)> err_handler,
|
522
|
+
const Allocator& alloc = Allocator())
|
523
|
+
: legacy_basic_json_reader(std::forward<Sourceable>(source),
|
524
|
+
visitor,
|
525
|
+
basic_json_decode_options<CharT>(),
|
526
|
+
err_handler,
|
527
|
+
alloc)
|
528
|
+
{
|
529
|
+
}
|
530
|
+
|
531
|
+
template <class Sourceable>
|
532
|
+
legacy_basic_json_reader(Sourceable&& source,
|
533
|
+
basic_json_visitor<CharT>& visitor,
|
534
|
+
const basic_json_decode_options<CharT>& options,
|
535
|
+
std::function<bool(json_errc,const ser_context&)> err_handler,
|
536
|
+
const Allocator& alloc = Allocator(),
|
537
|
+
typename std::enable_if<!std::is_constructible<jsoncons::basic_string_view<CharT>,Sourceable>::value>::type* = 0)
|
538
|
+
: source_(std::forward<Sourceable>(source)),
|
539
|
+
visitor_(visitor),
|
540
|
+
parser_(options,err_handler,alloc)
|
541
|
+
{
|
542
|
+
}
|
543
|
+
|
544
|
+
template <class Sourceable>
|
545
|
+
legacy_basic_json_reader(Sourceable&& source,
|
546
|
+
basic_json_visitor<CharT>& visitor,
|
547
|
+
const basic_json_decode_options<CharT>& options,
|
548
|
+
std::function<bool(json_errc,const ser_context&)> err_handler,
|
549
|
+
const Allocator& alloc = Allocator(),
|
550
|
+
typename std::enable_if<std::is_constructible<jsoncons::basic_string_view<CharT>,Sourceable>::value>::type* = 0)
|
551
|
+
: source_(),
|
552
|
+
visitor_(visitor),
|
553
|
+
parser_(options,err_handler,alloc)
|
554
|
+
{
|
555
|
+
jsoncons::basic_string_view<CharT> sv(std::forward<Sourceable>(source));
|
556
|
+
|
557
|
+
auto r = unicode_traits::detect_json_encoding(sv.data(), sv.size());
|
558
|
+
if (!(r.encoding == unicode_traits::encoding_kind::utf8 || r.encoding == unicode_traits::encoding_kind::undetected))
|
559
|
+
{
|
560
|
+
JSONCONS_THROW(ser_error(json_errc::illegal_unicode_character,parser_.line(),parser_.column()));
|
561
|
+
}
|
562
|
+
std::size_t offset = (r.ptr - sv.data());
|
563
|
+
parser_.update(sv.data()+offset,sv.size()-offset);
|
564
|
+
}
|
565
|
+
|
566
|
+
#if !defined(JSONCONS_NO_DEPRECATED)
|
567
|
+
JSONCONS_DEPRECATED_MSG("Instead, use max_nesting_depth() on options")
|
568
|
+
int max_nesting_depth() const
|
569
|
+
{
|
570
|
+
return parser_.max_nesting_depth();
|
571
|
+
}
|
572
|
+
|
573
|
+
JSONCONS_DEPRECATED_MSG("Instead, use max_nesting_depth(int) on options")
|
574
|
+
void max_nesting_depth(int depth)
|
575
|
+
{
|
576
|
+
parser_.max_nesting_depth(depth);
|
577
|
+
}
|
578
|
+
#endif
|
579
|
+
void read_next()
|
580
|
+
{
|
581
|
+
std::error_code ec;
|
582
|
+
read_next(ec);
|
583
|
+
if (ec)
|
584
|
+
{
|
585
|
+
JSONCONS_THROW(ser_error(ec,parser_.line(),parser_.column()));
|
586
|
+
}
|
587
|
+
}
|
588
|
+
|
589
|
+
void read_next(std::error_code& ec)
|
590
|
+
{
|
591
|
+
if (source_.is_error())
|
592
|
+
{
|
593
|
+
ec = json_errc::source_error;
|
594
|
+
return;
|
595
|
+
}
|
596
|
+
parser_.reset();
|
597
|
+
while (!parser_.stopped())
|
598
|
+
{
|
599
|
+
if (parser_.source_exhausted())
|
600
|
+
{
|
601
|
+
auto s = source_.read_buffer(ec);
|
602
|
+
if (ec) return;
|
603
|
+
if (s.size() > 0)
|
604
|
+
{
|
605
|
+
parser_.update(s.data(),s.size());
|
606
|
+
}
|
607
|
+
}
|
608
|
+
bool eof = parser_.source_exhausted();
|
609
|
+
parser_.parse_some(visitor_, ec);
|
610
|
+
if (ec) return;
|
611
|
+
if (eof)
|
612
|
+
{
|
613
|
+
if (parser_.enter())
|
614
|
+
{
|
615
|
+
break;
|
616
|
+
}
|
617
|
+
else if (!parser_.accept())
|
618
|
+
{
|
619
|
+
ec = json_errc::unexpected_eof;
|
620
|
+
return;
|
621
|
+
}
|
622
|
+
}
|
623
|
+
}
|
624
|
+
|
625
|
+
while (!source_.eof())
|
626
|
+
{
|
627
|
+
parser_.skip_whitespace();
|
628
|
+
if (parser_.source_exhausted())
|
629
|
+
{
|
630
|
+
auto s = source_.read_buffer(ec);
|
631
|
+
if (ec) return;
|
632
|
+
if (s.size() > 0)
|
633
|
+
{
|
634
|
+
parser_.update(s.data(),s.size());
|
635
|
+
}
|
636
|
+
}
|
637
|
+
else
|
638
|
+
{
|
639
|
+
break;
|
640
|
+
}
|
641
|
+
}
|
642
|
+
}
|
643
|
+
|
644
|
+
void check_done()
|
645
|
+
{
|
646
|
+
std::error_code ec;
|
647
|
+
check_done(ec);
|
648
|
+
if (ec)
|
649
|
+
{
|
650
|
+
JSONCONS_THROW(ser_error(ec,parser_.line(),parser_.column()));
|
651
|
+
}
|
652
|
+
}
|
653
|
+
|
654
|
+
std::size_t line() const
|
655
|
+
{
|
656
|
+
return parser_.line();
|
657
|
+
}
|
658
|
+
|
659
|
+
std::size_t column() const
|
660
|
+
{
|
661
|
+
return parser_.column();
|
662
|
+
}
|
663
|
+
|
664
|
+
void check_done(std::error_code& ec)
|
665
|
+
{
|
666
|
+
if (source_.is_error())
|
667
|
+
{
|
668
|
+
ec = json_errc::source_error;
|
669
|
+
return;
|
670
|
+
}
|
671
|
+
if (source_.eof())
|
672
|
+
{
|
673
|
+
parser_.check_done(ec);
|
674
|
+
if (ec) return;
|
675
|
+
}
|
676
|
+
else
|
677
|
+
{
|
678
|
+
do
|
679
|
+
{
|
680
|
+
if (parser_.source_exhausted())
|
681
|
+
{
|
682
|
+
auto s = source_.read_buffer(ec);
|
683
|
+
if (ec) return;
|
684
|
+
if (s.size() > 0)
|
685
|
+
{
|
686
|
+
parser_.update(s.data(),s.size());
|
687
|
+
}
|
688
|
+
}
|
689
|
+
if (!parser_.source_exhausted())
|
690
|
+
{
|
691
|
+
parser_.check_done(ec);
|
692
|
+
if (ec) return;
|
693
|
+
}
|
694
|
+
}
|
695
|
+
while (!eof());
|
696
|
+
}
|
697
|
+
}
|
698
|
+
|
699
|
+
bool eof() const
|
700
|
+
{
|
701
|
+
return parser_.source_exhausted() && source_.eof();
|
702
|
+
}
|
703
|
+
|
704
|
+
void read()
|
705
|
+
{
|
706
|
+
read_next();
|
707
|
+
check_done();
|
708
|
+
}
|
709
|
+
|
710
|
+
void read(std::error_code& ec)
|
711
|
+
{
|
712
|
+
read_next(ec);
|
713
|
+
if (!ec)
|
714
|
+
{
|
715
|
+
check_done(ec);
|
716
|
+
}
|
717
|
+
}
|
718
|
+
};
|
719
|
+
|
720
|
+
#if !defined(JSONCONS_NO_DEPRECATED)
|
721
|
+
using json_reader = legacy_basic_json_reader<char>;
|
722
|
+
using wjson_reader = legacy_basic_json_reader<wchar_t>;
|
723
|
+
#endif
|
724
|
+
using json_string_reader = basic_json_reader<char,string_source<char>>;
|
725
|
+
using wjson_string_reader = basic_json_reader<wchar_t,string_source<wchar_t>>;
|
726
|
+
using json_stream_reader = basic_json_reader<char,stream_source<char>>;
|
727
|
+
using wjson_stream_reader = basic_json_reader<wchar_t,stream_source<wchar_t>>;
|
728
|
+
}
|
729
|
+
|
730
|
+
#endif
|
731
|
+
|