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,2900 @@
|
|
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_PARSER_HPP
|
8
|
+
#define JSONCONS_JSON_PARSER_HPP
|
9
|
+
|
10
|
+
#include <memory> // std::allocator
|
11
|
+
#include <string>
|
12
|
+
#include <vector>
|
13
|
+
#include <stdexcept>
|
14
|
+
#include <system_error>
|
15
|
+
#include <unordered_map>
|
16
|
+
#include <limits> // std::numeric_limits
|
17
|
+
#include <functional> // std::function
|
18
|
+
#include <jsoncons/json_exception.hpp>
|
19
|
+
#include <jsoncons/json_filter.hpp>
|
20
|
+
#include <jsoncons/json_options.hpp>
|
21
|
+
#include <jsoncons/json_visitor.hpp>
|
22
|
+
#include <jsoncons/json_error.hpp>
|
23
|
+
#include <jsoncons/detail/parse_number.hpp>
|
24
|
+
|
25
|
+
#define JSONCONS_ILLEGAL_CONTROL_CHARACTER \
|
26
|
+
case 0x00:case 0x01:case 0x02:case 0x03:case 0x04:case 0x05:case 0x06:case 0x07:case 0x08:case 0x0b: \
|
27
|
+
case 0x0c:case 0x0e:case 0x0f:case 0x10:case 0x11:case 0x12:case 0x13:case 0x14:case 0x15:case 0x16: \
|
28
|
+
case 0x17:case 0x18:case 0x19:case 0x1a:case 0x1b:case 0x1c:case 0x1d:case 0x1e:case 0x1f
|
29
|
+
|
30
|
+
namespace jsoncons {
|
31
|
+
|
32
|
+
namespace detail {
|
33
|
+
|
34
|
+
}
|
35
|
+
|
36
|
+
enum class json_parse_state : uint8_t
|
37
|
+
{
|
38
|
+
root,
|
39
|
+
start,
|
40
|
+
accept,
|
41
|
+
slash,
|
42
|
+
slash_slash,
|
43
|
+
slash_star,
|
44
|
+
slash_star_star,
|
45
|
+
expect_comma_or_end,
|
46
|
+
object,
|
47
|
+
expect_member_name_or_end,
|
48
|
+
expect_member_name,
|
49
|
+
expect_colon,
|
50
|
+
expect_value_or_end,
|
51
|
+
expect_value,
|
52
|
+
array,
|
53
|
+
string,
|
54
|
+
member_name,
|
55
|
+
escape,
|
56
|
+
escape_u1,
|
57
|
+
escape_u2,
|
58
|
+
escape_u3,
|
59
|
+
escape_u4,
|
60
|
+
escape_expect_surrogate_pair1,
|
61
|
+
escape_expect_surrogate_pair2,
|
62
|
+
escape_u5,
|
63
|
+
escape_u6,
|
64
|
+
escape_u7,
|
65
|
+
escape_u8,
|
66
|
+
minus,
|
67
|
+
zero,
|
68
|
+
integer,
|
69
|
+
fraction1,
|
70
|
+
fraction2,
|
71
|
+
exp1,
|
72
|
+
exp2,
|
73
|
+
exp3,
|
74
|
+
n,
|
75
|
+
nu,
|
76
|
+
nul,
|
77
|
+
t,
|
78
|
+
tr,
|
79
|
+
tru,
|
80
|
+
f,
|
81
|
+
fa,
|
82
|
+
fal,
|
83
|
+
fals,
|
84
|
+
cr,
|
85
|
+
done
|
86
|
+
};
|
87
|
+
|
88
|
+
struct default_json_parsing
|
89
|
+
{
|
90
|
+
bool operator()(json_errc ec, const ser_context&) noexcept
|
91
|
+
{
|
92
|
+
if (ec == json_errc::illegal_comment)
|
93
|
+
{
|
94
|
+
return true; // Recover, allow comments
|
95
|
+
}
|
96
|
+
else
|
97
|
+
{
|
98
|
+
return false;
|
99
|
+
}
|
100
|
+
}
|
101
|
+
};
|
102
|
+
|
103
|
+
struct strict_json_parsing
|
104
|
+
{
|
105
|
+
bool operator()(json_errc, const ser_context&) noexcept
|
106
|
+
{
|
107
|
+
return false;
|
108
|
+
}
|
109
|
+
};
|
110
|
+
|
111
|
+
#if !defined(JSONCONS_NO_DEPRECATED)
|
112
|
+
JSONCONS_DEPRECATED_MSG("Instead, use default_json_parsing") typedef default_json_parsing default_parse_error_handler;
|
113
|
+
JSONCONS_DEPRECATED_MSG("Instead, use strict_json_parsing") typedef strict_json_parsing strict_parse_error_handler;
|
114
|
+
#endif
|
115
|
+
|
116
|
+
template <class CharT, class TempAllocator = std::allocator<char>>
|
117
|
+
class basic_json_parser : public ser_context
|
118
|
+
{
|
119
|
+
public:
|
120
|
+
using char_type = CharT;
|
121
|
+
using string_view_type = typename basic_json_visitor<CharT>::string_view_type;
|
122
|
+
private:
|
123
|
+
struct string_maps_to_double
|
124
|
+
{
|
125
|
+
string_view_type s;
|
126
|
+
|
127
|
+
bool operator()(const std::pair<string_view_type,double>& val) const
|
128
|
+
{
|
129
|
+
return val.first == s;
|
130
|
+
}
|
131
|
+
};
|
132
|
+
|
133
|
+
using temp_allocator_type = TempAllocator;
|
134
|
+
using char_allocator_type = typename std::allocator_traits<temp_allocator_type>:: template rebind_alloc<CharT>;
|
135
|
+
using parse_state_allocator_type = typename std::allocator_traits<temp_allocator_type>:: template rebind_alloc<json_parse_state>;
|
136
|
+
|
137
|
+
static constexpr std::size_t initial_string_buffer_capacity_ = 1024;
|
138
|
+
static constexpr std::size_t default_initial_stack_capacity_ = 100;
|
139
|
+
|
140
|
+
basic_json_decode_options<char_type> options_;
|
141
|
+
|
142
|
+
std::function<bool(json_errc,const ser_context&)> err_handler_;
|
143
|
+
int initial_stack_capacity_;
|
144
|
+
int nesting_depth_;
|
145
|
+
uint32_t cp_;
|
146
|
+
uint32_t cp2_;
|
147
|
+
std::size_t line_;
|
148
|
+
std::size_t position_;
|
149
|
+
std::size_t mark_position_;
|
150
|
+
std::size_t saved_position_;
|
151
|
+
const char_type* begin_input_;
|
152
|
+
const char_type* end_input_;
|
153
|
+
const char_type* input_ptr_;
|
154
|
+
json_parse_state state_;
|
155
|
+
bool more_;
|
156
|
+
bool done_;
|
157
|
+
|
158
|
+
std::basic_string<char_type,std::char_traits<char_type>,char_allocator_type> string_buffer_;
|
159
|
+
jsoncons::detail::chars_to to_double_;
|
160
|
+
|
161
|
+
std::vector<json_parse_state,parse_state_allocator_type> state_stack_;
|
162
|
+
std::vector<std::pair<string_view_type,double>> string_double_map_;
|
163
|
+
|
164
|
+
// Noncopyable and nonmoveable
|
165
|
+
basic_json_parser(const basic_json_parser&) = delete;
|
166
|
+
basic_json_parser& operator=(const basic_json_parser&) = delete;
|
167
|
+
|
168
|
+
public:
|
169
|
+
basic_json_parser(const TempAllocator& alloc = TempAllocator())
|
170
|
+
: basic_json_parser(basic_json_decode_options<char_type>(), default_json_parsing(), alloc)
|
171
|
+
{
|
172
|
+
}
|
173
|
+
|
174
|
+
basic_json_parser(std::function<bool(json_errc,const ser_context&)> err_handler,
|
175
|
+
const TempAllocator& alloc = TempAllocator())
|
176
|
+
: basic_json_parser(basic_json_decode_options<char_type>(), err_handler, alloc)
|
177
|
+
{
|
178
|
+
}
|
179
|
+
|
180
|
+
basic_json_parser(const basic_json_decode_options<char_type>& options,
|
181
|
+
const TempAllocator& alloc = TempAllocator())
|
182
|
+
: basic_json_parser(options, default_json_parsing(), alloc)
|
183
|
+
{
|
184
|
+
}
|
185
|
+
|
186
|
+
basic_json_parser(const basic_json_decode_options<char_type>& options,
|
187
|
+
std::function<bool(json_errc,const ser_context&)> err_handler,
|
188
|
+
const TempAllocator& alloc = TempAllocator())
|
189
|
+
: options_(options),
|
190
|
+
err_handler_(err_handler),
|
191
|
+
initial_stack_capacity_(default_initial_stack_capacity_),
|
192
|
+
nesting_depth_(0),
|
193
|
+
cp_(0),
|
194
|
+
cp2_(0),
|
195
|
+
line_(1),
|
196
|
+
position_(0),
|
197
|
+
mark_position_(0),
|
198
|
+
saved_position_(0),
|
199
|
+
begin_input_(nullptr),
|
200
|
+
end_input_(nullptr),
|
201
|
+
input_ptr_(nullptr),
|
202
|
+
state_(json_parse_state::start),
|
203
|
+
more_(true),
|
204
|
+
done_(false),
|
205
|
+
string_buffer_(alloc),
|
206
|
+
state_stack_(alloc)
|
207
|
+
{
|
208
|
+
string_buffer_.reserve(initial_string_buffer_capacity_);
|
209
|
+
|
210
|
+
state_stack_.reserve(initial_stack_capacity_);
|
211
|
+
push_state(json_parse_state::root);
|
212
|
+
|
213
|
+
if (options_.enable_str_to_nan())
|
214
|
+
{
|
215
|
+
string_double_map_.emplace_back(options_.nan_to_str(),std::nan(""));
|
216
|
+
}
|
217
|
+
if (options_.enable_str_to_inf())
|
218
|
+
{
|
219
|
+
string_double_map_.emplace_back(options_.inf_to_str(),std::numeric_limits<double>::infinity());
|
220
|
+
}
|
221
|
+
if (options_.enable_str_to_neginf())
|
222
|
+
{
|
223
|
+
string_double_map_.emplace_back(options_.neginf_to_str(),-std::numeric_limits<double>::infinity());
|
224
|
+
}
|
225
|
+
}
|
226
|
+
|
227
|
+
bool source_exhausted() const
|
228
|
+
{
|
229
|
+
return input_ptr_ == end_input_;
|
230
|
+
}
|
231
|
+
|
232
|
+
~basic_json_parser() noexcept
|
233
|
+
{
|
234
|
+
}
|
235
|
+
|
236
|
+
json_parse_state parent() const
|
237
|
+
{
|
238
|
+
JSONCONS_ASSERT(state_stack_.size() >= 1);
|
239
|
+
return state_stack_.back();
|
240
|
+
}
|
241
|
+
|
242
|
+
bool done() const
|
243
|
+
{
|
244
|
+
return done_;
|
245
|
+
}
|
246
|
+
|
247
|
+
bool enter() const
|
248
|
+
{
|
249
|
+
return state_ == json_parse_state::start;
|
250
|
+
}
|
251
|
+
|
252
|
+
bool accept() const
|
253
|
+
{
|
254
|
+
return state_ == json_parse_state::accept || done_;
|
255
|
+
}
|
256
|
+
|
257
|
+
bool stopped() const
|
258
|
+
{
|
259
|
+
return !more_;
|
260
|
+
}
|
261
|
+
|
262
|
+
json_parse_state state() const
|
263
|
+
{
|
264
|
+
return state_;
|
265
|
+
}
|
266
|
+
|
267
|
+
bool finished() const
|
268
|
+
{
|
269
|
+
return !more_ && state_ != json_parse_state::accept;
|
270
|
+
}
|
271
|
+
|
272
|
+
const char_type* first() const
|
273
|
+
{
|
274
|
+
return begin_input_;
|
275
|
+
}
|
276
|
+
|
277
|
+
const char_type* current() const
|
278
|
+
{
|
279
|
+
return input_ptr_;
|
280
|
+
}
|
281
|
+
|
282
|
+
const char_type* last() const
|
283
|
+
{
|
284
|
+
return end_input_;
|
285
|
+
}
|
286
|
+
|
287
|
+
void skip_space()
|
288
|
+
{
|
289
|
+
const char_type* local_input_end = end_input_;
|
290
|
+
while (input_ptr_ != local_input_end)
|
291
|
+
{
|
292
|
+
switch (*input_ptr_)
|
293
|
+
{
|
294
|
+
case ' ':
|
295
|
+
case '\t':
|
296
|
+
++input_ptr_;
|
297
|
+
++position_;
|
298
|
+
break;
|
299
|
+
case '\r':
|
300
|
+
push_state(state_);
|
301
|
+
++input_ptr_;
|
302
|
+
++position_;
|
303
|
+
state_ = json_parse_state::cr;
|
304
|
+
return;
|
305
|
+
case '\n':
|
306
|
+
++input_ptr_;
|
307
|
+
++line_;
|
308
|
+
++position_;
|
309
|
+
mark_position_ = position_;
|
310
|
+
return;
|
311
|
+
default:
|
312
|
+
return;
|
313
|
+
}
|
314
|
+
}
|
315
|
+
}
|
316
|
+
|
317
|
+
void skip_whitespace()
|
318
|
+
{
|
319
|
+
const char_type* local_input_end = end_input_;
|
320
|
+
|
321
|
+
while (input_ptr_ != local_input_end)
|
322
|
+
{
|
323
|
+
switch (state_)
|
324
|
+
{
|
325
|
+
case json_parse_state::cr:
|
326
|
+
++line_;
|
327
|
+
++position_;
|
328
|
+
mark_position_ = position_;
|
329
|
+
switch (*input_ptr_)
|
330
|
+
{
|
331
|
+
case '\n':
|
332
|
+
++input_ptr_;
|
333
|
+
++position_;
|
334
|
+
state_ = pop_state();
|
335
|
+
break;
|
336
|
+
default:
|
337
|
+
state_ = pop_state();
|
338
|
+
break;
|
339
|
+
}
|
340
|
+
break;
|
341
|
+
|
342
|
+
default:
|
343
|
+
switch (*input_ptr_)
|
344
|
+
{
|
345
|
+
case ' ':
|
346
|
+
case '\t':
|
347
|
+
case '\n':
|
348
|
+
case '\r':
|
349
|
+
skip_space();
|
350
|
+
break;
|
351
|
+
default:
|
352
|
+
return;
|
353
|
+
}
|
354
|
+
break;
|
355
|
+
}
|
356
|
+
}
|
357
|
+
}
|
358
|
+
|
359
|
+
void begin_object(basic_json_visitor<char_type>& visitor, std::error_code& ec)
|
360
|
+
{
|
361
|
+
if (JSONCONS_UNLIKELY(++nesting_depth_ > options_.max_nesting_depth()))
|
362
|
+
{
|
363
|
+
more_ = err_handler_(json_errc::max_nesting_depth_exceeded, *this);
|
364
|
+
if (!more_)
|
365
|
+
{
|
366
|
+
ec = json_errc::max_nesting_depth_exceeded;
|
367
|
+
return;
|
368
|
+
}
|
369
|
+
}
|
370
|
+
|
371
|
+
push_state(json_parse_state::object);
|
372
|
+
state_ = json_parse_state::expect_member_name_or_end;
|
373
|
+
more_ = visitor.begin_object(semantic_tag::none, *this, ec);
|
374
|
+
}
|
375
|
+
|
376
|
+
void end_object(basic_json_visitor<char_type>& visitor, std::error_code& ec)
|
377
|
+
{
|
378
|
+
if (JSONCONS_UNLIKELY(nesting_depth_ < 1))
|
379
|
+
{
|
380
|
+
err_handler_(json_errc::unexpected_rbrace, *this);
|
381
|
+
ec = json_errc::unexpected_rbrace;
|
382
|
+
more_ = false;
|
383
|
+
return;
|
384
|
+
}
|
385
|
+
--nesting_depth_;
|
386
|
+
state_ = pop_state();
|
387
|
+
if (state_ == json_parse_state::object)
|
388
|
+
{
|
389
|
+
more_ = visitor.end_object(*this, ec);
|
390
|
+
}
|
391
|
+
else if (state_ == json_parse_state::array)
|
392
|
+
{
|
393
|
+
err_handler_(json_errc::expected_comma_or_rbracket, *this);
|
394
|
+
ec = json_errc::expected_comma_or_rbracket;
|
395
|
+
more_ = false;
|
396
|
+
return;
|
397
|
+
}
|
398
|
+
else
|
399
|
+
{
|
400
|
+
err_handler_(json_errc::unexpected_rbrace, *this);
|
401
|
+
ec = json_errc::unexpected_rbrace;
|
402
|
+
more_ = false;
|
403
|
+
return;
|
404
|
+
}
|
405
|
+
|
406
|
+
if (parent() == json_parse_state::root)
|
407
|
+
{
|
408
|
+
state_ = json_parse_state::accept;
|
409
|
+
}
|
410
|
+
else
|
411
|
+
{
|
412
|
+
state_ = json_parse_state::expect_comma_or_end;
|
413
|
+
}
|
414
|
+
}
|
415
|
+
|
416
|
+
void begin_array(basic_json_visitor<char_type>& visitor, std::error_code& ec)
|
417
|
+
{
|
418
|
+
if (++nesting_depth_ > options_.max_nesting_depth())
|
419
|
+
{
|
420
|
+
more_ = err_handler_(json_errc::max_nesting_depth_exceeded, *this);
|
421
|
+
if (!more_)
|
422
|
+
{
|
423
|
+
ec = json_errc::max_nesting_depth_exceeded;
|
424
|
+
return;
|
425
|
+
}
|
426
|
+
}
|
427
|
+
|
428
|
+
push_state(json_parse_state::array);
|
429
|
+
state_ = json_parse_state::expect_value_or_end;
|
430
|
+
more_ = visitor.begin_array(semantic_tag::none, *this, ec);
|
431
|
+
}
|
432
|
+
|
433
|
+
void end_array(basic_json_visitor<char_type>& visitor, std::error_code& ec)
|
434
|
+
{
|
435
|
+
if (nesting_depth_ < 1)
|
436
|
+
{
|
437
|
+
err_handler_(json_errc::unexpected_rbracket, *this);
|
438
|
+
ec = json_errc::unexpected_rbracket;
|
439
|
+
more_ = false;
|
440
|
+
return;
|
441
|
+
}
|
442
|
+
--nesting_depth_;
|
443
|
+
state_ = pop_state();
|
444
|
+
if (state_ == json_parse_state::array)
|
445
|
+
{
|
446
|
+
more_ = visitor.end_array(*this, ec);
|
447
|
+
}
|
448
|
+
else if (state_ == json_parse_state::object)
|
449
|
+
{
|
450
|
+
err_handler_(json_errc::expected_comma_or_rbrace, *this);
|
451
|
+
ec = json_errc::expected_comma_or_rbrace;
|
452
|
+
more_ = false;
|
453
|
+
return;
|
454
|
+
}
|
455
|
+
else
|
456
|
+
{
|
457
|
+
err_handler_(json_errc::unexpected_rbracket, *this);
|
458
|
+
ec = json_errc::unexpected_rbracket;
|
459
|
+
more_ = false;
|
460
|
+
return;
|
461
|
+
}
|
462
|
+
if (parent() == json_parse_state::root)
|
463
|
+
{
|
464
|
+
state_ = json_parse_state::accept;
|
465
|
+
}
|
466
|
+
else
|
467
|
+
{
|
468
|
+
state_ = json_parse_state::expect_comma_or_end;
|
469
|
+
}
|
470
|
+
}
|
471
|
+
|
472
|
+
void reinitialize()
|
473
|
+
{
|
474
|
+
reset();
|
475
|
+
cp_ = 0;
|
476
|
+
cp2_ = 0;
|
477
|
+
saved_position_ = 0;
|
478
|
+
begin_input_ = nullptr;
|
479
|
+
end_input_ = nullptr;
|
480
|
+
input_ptr_ = nullptr;
|
481
|
+
string_buffer_.clear();
|
482
|
+
}
|
483
|
+
|
484
|
+
void reset()
|
485
|
+
{
|
486
|
+
state_stack_.clear();
|
487
|
+
state_stack_.reserve(initial_stack_capacity_);
|
488
|
+
push_state(json_parse_state::root);
|
489
|
+
state_ = json_parse_state::start;
|
490
|
+
more_ = true;
|
491
|
+
done_ = false;
|
492
|
+
line_ = 1;
|
493
|
+
position_ = 0;
|
494
|
+
mark_position_ = 0;
|
495
|
+
nesting_depth_ = 0;
|
496
|
+
}
|
497
|
+
|
498
|
+
void restart()
|
499
|
+
{
|
500
|
+
more_ = true;
|
501
|
+
}
|
502
|
+
|
503
|
+
void check_done()
|
504
|
+
{
|
505
|
+
std::error_code ec;
|
506
|
+
check_done(ec);
|
507
|
+
if (ec)
|
508
|
+
{
|
509
|
+
JSONCONS_THROW(ser_error(ec,line_,column()));
|
510
|
+
}
|
511
|
+
}
|
512
|
+
|
513
|
+
void check_done(std::error_code& ec)
|
514
|
+
{
|
515
|
+
for (; input_ptr_ != end_input_; ++input_ptr_)
|
516
|
+
{
|
517
|
+
char_type curr_char_ = *input_ptr_;
|
518
|
+
switch (curr_char_)
|
519
|
+
{
|
520
|
+
case '\n':
|
521
|
+
case '\r':
|
522
|
+
case '\t':
|
523
|
+
case ' ':
|
524
|
+
break;
|
525
|
+
default:
|
526
|
+
more_ = err_handler_(json_errc::extra_character, *this);
|
527
|
+
if (!more_)
|
528
|
+
{
|
529
|
+
ec = json_errc::extra_character;
|
530
|
+
return;
|
531
|
+
}
|
532
|
+
break;
|
533
|
+
}
|
534
|
+
}
|
535
|
+
}
|
536
|
+
|
537
|
+
void update(const string_view_type sv)
|
538
|
+
{
|
539
|
+
update(sv.data(),sv.length());
|
540
|
+
}
|
541
|
+
|
542
|
+
void update(const char_type* data, std::size_t length)
|
543
|
+
{
|
544
|
+
begin_input_ = data;
|
545
|
+
end_input_ = data + length;
|
546
|
+
input_ptr_ = begin_input_;
|
547
|
+
}
|
548
|
+
|
549
|
+
void parse_some(basic_json_visitor<char_type>& visitor)
|
550
|
+
{
|
551
|
+
std::error_code ec;
|
552
|
+
parse_some(visitor, ec);
|
553
|
+
if (ec)
|
554
|
+
{
|
555
|
+
JSONCONS_THROW(ser_error(ec,line_,column()));
|
556
|
+
}
|
557
|
+
}
|
558
|
+
|
559
|
+
void parse_some(basic_json_visitor<char_type>& visitor, std::error_code& ec)
|
560
|
+
{
|
561
|
+
parse_some_(visitor, ec);
|
562
|
+
}
|
563
|
+
|
564
|
+
void finish_parse(basic_json_visitor<char_type>& visitor)
|
565
|
+
{
|
566
|
+
std::error_code ec;
|
567
|
+
finish_parse(visitor, ec);
|
568
|
+
if (ec)
|
569
|
+
{
|
570
|
+
JSONCONS_THROW(ser_error(ec,line_,column()));
|
571
|
+
}
|
572
|
+
}
|
573
|
+
|
574
|
+
void finish_parse(basic_json_visitor<char_type>& visitor, std::error_code& ec)
|
575
|
+
{
|
576
|
+
while (!finished())
|
577
|
+
{
|
578
|
+
parse_some(visitor, ec);
|
579
|
+
}
|
580
|
+
}
|
581
|
+
|
582
|
+
void parse_some_(basic_json_visitor<char_type>& visitor, std::error_code& ec)
|
583
|
+
{
|
584
|
+
if (state_ == json_parse_state::accept)
|
585
|
+
{
|
586
|
+
visitor.flush();
|
587
|
+
done_ = true;
|
588
|
+
state_ = json_parse_state::done;
|
589
|
+
more_ = false;
|
590
|
+
return;
|
591
|
+
}
|
592
|
+
const char_type* local_input_end = end_input_;
|
593
|
+
|
594
|
+
if (input_ptr_ == local_input_end && more_)
|
595
|
+
{
|
596
|
+
switch (state_)
|
597
|
+
{
|
598
|
+
case json_parse_state::zero:
|
599
|
+
case json_parse_state::integer:
|
600
|
+
end_integer_value(visitor, ec);
|
601
|
+
if (ec) return;
|
602
|
+
break;
|
603
|
+
case json_parse_state::fraction2:
|
604
|
+
end_fraction_value(visitor, ec);
|
605
|
+
if (ec) return;
|
606
|
+
break;
|
607
|
+
case json_parse_state::exp3:
|
608
|
+
end_fraction_value(visitor, ec);
|
609
|
+
if (ec) return;
|
610
|
+
break;
|
611
|
+
case json_parse_state::accept:
|
612
|
+
visitor.flush();
|
613
|
+
done_ = true;
|
614
|
+
state_ = json_parse_state::done;
|
615
|
+
more_ = false;
|
616
|
+
break;
|
617
|
+
case json_parse_state::start:
|
618
|
+
case json_parse_state::done:
|
619
|
+
more_ = false;
|
620
|
+
break;
|
621
|
+
case json_parse_state::cr:
|
622
|
+
state_ = pop_state();
|
623
|
+
break;
|
624
|
+
default:
|
625
|
+
err_handler_(json_errc::unexpected_eof, *this);
|
626
|
+
ec = json_errc::unexpected_eof;
|
627
|
+
more_ = false;
|
628
|
+
return;
|
629
|
+
}
|
630
|
+
}
|
631
|
+
|
632
|
+
while ((input_ptr_ < local_input_end) && more_)
|
633
|
+
{
|
634
|
+
switch (state_)
|
635
|
+
{
|
636
|
+
case json_parse_state::accept:
|
637
|
+
visitor.flush();
|
638
|
+
done_ = true;
|
639
|
+
state_ = json_parse_state::done;
|
640
|
+
more_ = false;
|
641
|
+
break;
|
642
|
+
case json_parse_state::cr:
|
643
|
+
++line_;
|
644
|
+
mark_position_ = position_;
|
645
|
+
switch (*input_ptr_)
|
646
|
+
{
|
647
|
+
case '\n':
|
648
|
+
++input_ptr_;
|
649
|
+
++position_;
|
650
|
+
state_ = pop_state();
|
651
|
+
break;
|
652
|
+
default:
|
653
|
+
state_ = pop_state();
|
654
|
+
break;
|
655
|
+
}
|
656
|
+
break;
|
657
|
+
case json_parse_state::start:
|
658
|
+
{
|
659
|
+
switch (*input_ptr_)
|
660
|
+
{
|
661
|
+
JSONCONS_ILLEGAL_CONTROL_CHARACTER:
|
662
|
+
more_ = err_handler_(json_errc::illegal_control_character, *this);
|
663
|
+
if (!more_)
|
664
|
+
{
|
665
|
+
ec = json_errc::illegal_control_character;
|
666
|
+
return;
|
667
|
+
}
|
668
|
+
break;
|
669
|
+
case '\r':
|
670
|
+
push_state(state_);
|
671
|
+
++input_ptr_;
|
672
|
+
++position_;
|
673
|
+
state_ = json_parse_state::cr;
|
674
|
+
break;
|
675
|
+
case '\n':
|
676
|
+
++input_ptr_;
|
677
|
+
++line_;
|
678
|
+
++position_;
|
679
|
+
mark_position_ = position_;
|
680
|
+
break;
|
681
|
+
case ' ':case '\t':
|
682
|
+
skip_space();
|
683
|
+
break;
|
684
|
+
case '/':
|
685
|
+
++input_ptr_;
|
686
|
+
++position_;
|
687
|
+
push_state(state_);
|
688
|
+
state_ = json_parse_state::slash;
|
689
|
+
break;
|
690
|
+
case '{':
|
691
|
+
saved_position_ = position_;
|
692
|
+
++input_ptr_;
|
693
|
+
++position_;
|
694
|
+
begin_object(visitor, ec);
|
695
|
+
if (ec) return;
|
696
|
+
break;
|
697
|
+
case '[':
|
698
|
+
saved_position_ = position_;
|
699
|
+
++input_ptr_;
|
700
|
+
++position_;
|
701
|
+
begin_array(visitor, ec);
|
702
|
+
if (ec) return;
|
703
|
+
break;
|
704
|
+
case '\"':
|
705
|
+
state_ = json_parse_state::string;
|
706
|
+
saved_position_ = position_;
|
707
|
+
++input_ptr_;
|
708
|
+
++position_;
|
709
|
+
string_buffer_.clear();
|
710
|
+
parse_string(visitor, ec);
|
711
|
+
if (ec) return;
|
712
|
+
break;
|
713
|
+
case '-':
|
714
|
+
string_buffer_.clear();
|
715
|
+
string_buffer_.push_back('-');
|
716
|
+
saved_position_ = position_;
|
717
|
+
++input_ptr_;
|
718
|
+
++position_;
|
719
|
+
state_ = json_parse_state::minus;
|
720
|
+
parse_number(visitor, ec);
|
721
|
+
if (ec) {return;}
|
722
|
+
break;
|
723
|
+
case '0':
|
724
|
+
string_buffer_.clear();
|
725
|
+
string_buffer_.push_back(static_cast<char>(*input_ptr_));
|
726
|
+
state_ = json_parse_state::zero;
|
727
|
+
saved_position_ = position_;
|
728
|
+
++input_ptr_;
|
729
|
+
++position_;
|
730
|
+
parse_number(visitor, ec);
|
731
|
+
if (ec) {return;}
|
732
|
+
break;
|
733
|
+
case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9':
|
734
|
+
string_buffer_.clear();
|
735
|
+
string_buffer_.push_back(static_cast<char>(*input_ptr_));
|
736
|
+
saved_position_ = position_;
|
737
|
+
++input_ptr_;
|
738
|
+
++position_;
|
739
|
+
state_ = json_parse_state::integer;
|
740
|
+
parse_number(visitor, ec);
|
741
|
+
if (ec) {return;}
|
742
|
+
break;
|
743
|
+
case 'n':
|
744
|
+
parse_null(visitor, ec);
|
745
|
+
if (ec) {return;}
|
746
|
+
break;
|
747
|
+
case 't':
|
748
|
+
parse_true(visitor, ec);
|
749
|
+
if (ec) {return;}
|
750
|
+
break;
|
751
|
+
case 'f':
|
752
|
+
parse_false(visitor, ec);
|
753
|
+
if (ec) {return;}
|
754
|
+
break;
|
755
|
+
case '}':
|
756
|
+
err_handler_(json_errc::unexpected_rbrace, *this);
|
757
|
+
ec = json_errc::unexpected_rbrace;
|
758
|
+
more_ = false;
|
759
|
+
return;
|
760
|
+
case ']':
|
761
|
+
err_handler_(json_errc::unexpected_rbracket, *this);
|
762
|
+
ec = json_errc::unexpected_rbracket;
|
763
|
+
more_ = false;
|
764
|
+
return;
|
765
|
+
default:
|
766
|
+
err_handler_(json_errc::syntax_error, *this);
|
767
|
+
ec = json_errc::syntax_error;
|
768
|
+
more_ = false;
|
769
|
+
return;
|
770
|
+
}
|
771
|
+
}
|
772
|
+
break;
|
773
|
+
|
774
|
+
case json_parse_state::expect_comma_or_end:
|
775
|
+
{
|
776
|
+
switch (*input_ptr_)
|
777
|
+
{
|
778
|
+
JSONCONS_ILLEGAL_CONTROL_CHARACTER:
|
779
|
+
more_ = err_handler_(json_errc::illegal_control_character, *this);
|
780
|
+
if (!more_)
|
781
|
+
{
|
782
|
+
ec = json_errc::illegal_control_character;
|
783
|
+
return;
|
784
|
+
}
|
785
|
+
++input_ptr_;
|
786
|
+
++position_;
|
787
|
+
break;
|
788
|
+
case '\r':
|
789
|
+
++input_ptr_;
|
790
|
+
++position_;
|
791
|
+
push_state(state_);
|
792
|
+
state_ = json_parse_state::cr;
|
793
|
+
break;
|
794
|
+
case '\n':
|
795
|
+
++input_ptr_;
|
796
|
+
++line_;
|
797
|
+
++position_;
|
798
|
+
mark_position_ = position_;
|
799
|
+
break;
|
800
|
+
case ' ':case '\t':
|
801
|
+
skip_space();
|
802
|
+
break;
|
803
|
+
case '/':
|
804
|
+
++input_ptr_;
|
805
|
+
++position_;
|
806
|
+
push_state(state_);
|
807
|
+
state_ = json_parse_state::slash;
|
808
|
+
break;
|
809
|
+
case '}':
|
810
|
+
saved_position_ = position_;
|
811
|
+
++input_ptr_;
|
812
|
+
++position_;
|
813
|
+
end_object(visitor, ec);
|
814
|
+
if (ec) return;
|
815
|
+
break;
|
816
|
+
case ']':
|
817
|
+
saved_position_ = position_;
|
818
|
+
++input_ptr_;
|
819
|
+
++position_;
|
820
|
+
end_array(visitor, ec);
|
821
|
+
if (ec) return;
|
822
|
+
break;
|
823
|
+
case ',':
|
824
|
+
begin_member_or_element(ec);
|
825
|
+
if (ec) return;
|
826
|
+
++input_ptr_;
|
827
|
+
++position_;
|
828
|
+
break;
|
829
|
+
default:
|
830
|
+
if (parent() == json_parse_state::array)
|
831
|
+
{
|
832
|
+
more_ = err_handler_(json_errc::expected_comma_or_rbracket, *this);
|
833
|
+
if (!more_)
|
834
|
+
{
|
835
|
+
ec = json_errc::expected_comma_or_rbracket;
|
836
|
+
return;
|
837
|
+
}
|
838
|
+
}
|
839
|
+
else if (parent() == json_parse_state::object)
|
840
|
+
{
|
841
|
+
more_ = err_handler_(json_errc::expected_comma_or_rbrace, *this);
|
842
|
+
if (!more_)
|
843
|
+
{
|
844
|
+
ec = json_errc::expected_comma_or_rbrace;
|
845
|
+
return;
|
846
|
+
}
|
847
|
+
}
|
848
|
+
++input_ptr_;
|
849
|
+
++position_;
|
850
|
+
break;
|
851
|
+
}
|
852
|
+
}
|
853
|
+
break;
|
854
|
+
case json_parse_state::expect_member_name_or_end:
|
855
|
+
{
|
856
|
+
switch (*input_ptr_)
|
857
|
+
{
|
858
|
+
JSONCONS_ILLEGAL_CONTROL_CHARACTER:
|
859
|
+
more_ = err_handler_(json_errc::illegal_control_character, *this);
|
860
|
+
if (!more_)
|
861
|
+
{
|
862
|
+
ec = json_errc::illegal_control_character;
|
863
|
+
return;
|
864
|
+
}
|
865
|
+
++input_ptr_;
|
866
|
+
++position_;
|
867
|
+
break;
|
868
|
+
case '\r':
|
869
|
+
++input_ptr_;
|
870
|
+
++position_;
|
871
|
+
push_state(state_);
|
872
|
+
state_ = json_parse_state::cr;
|
873
|
+
break;
|
874
|
+
case '\n':
|
875
|
+
++input_ptr_;
|
876
|
+
++line_;
|
877
|
+
++position_;
|
878
|
+
mark_position_ = position_;
|
879
|
+
break;
|
880
|
+
case ' ':case '\t':
|
881
|
+
skip_space();
|
882
|
+
break;
|
883
|
+
case '/':
|
884
|
+
++input_ptr_;
|
885
|
+
++position_;
|
886
|
+
push_state(state_);
|
887
|
+
state_ = json_parse_state::slash;
|
888
|
+
break;
|
889
|
+
case '}':
|
890
|
+
saved_position_ = position_;
|
891
|
+
++input_ptr_;
|
892
|
+
++position_;
|
893
|
+
end_object(visitor, ec);
|
894
|
+
if (ec) return;
|
895
|
+
break;
|
896
|
+
case '\"':
|
897
|
+
saved_position_ = position_;
|
898
|
+
++input_ptr_;
|
899
|
+
++position_;
|
900
|
+
push_state(json_parse_state::member_name);
|
901
|
+
state_ = json_parse_state::string;
|
902
|
+
string_buffer_.clear();
|
903
|
+
parse_string(visitor, ec);
|
904
|
+
if (ec) return;
|
905
|
+
break;
|
906
|
+
case '\'':
|
907
|
+
more_ = err_handler_(json_errc::single_quote, *this);
|
908
|
+
if (!more_)
|
909
|
+
{
|
910
|
+
ec = json_errc::single_quote;
|
911
|
+
return;
|
912
|
+
}
|
913
|
+
++input_ptr_;
|
914
|
+
++position_;
|
915
|
+
break;
|
916
|
+
default:
|
917
|
+
more_ = err_handler_(json_errc::expected_key, *this);
|
918
|
+
if (!more_)
|
919
|
+
{
|
920
|
+
ec = json_errc::expected_key;
|
921
|
+
return;
|
922
|
+
}
|
923
|
+
++input_ptr_;
|
924
|
+
++position_;
|
925
|
+
break;
|
926
|
+
}
|
927
|
+
}
|
928
|
+
break;
|
929
|
+
case json_parse_state::expect_member_name:
|
930
|
+
{
|
931
|
+
switch (*input_ptr_)
|
932
|
+
{
|
933
|
+
JSONCONS_ILLEGAL_CONTROL_CHARACTER:
|
934
|
+
more_ = err_handler_(json_errc::illegal_control_character, *this);
|
935
|
+
if (!more_)
|
936
|
+
{
|
937
|
+
ec = json_errc::illegal_control_character;
|
938
|
+
return;
|
939
|
+
}
|
940
|
+
++input_ptr_;
|
941
|
+
++position_;
|
942
|
+
break;
|
943
|
+
case '\r':
|
944
|
+
++input_ptr_;
|
945
|
+
++position_;
|
946
|
+
push_state(state_);
|
947
|
+
state_ = json_parse_state::cr;
|
948
|
+
break;
|
949
|
+
case '\n':
|
950
|
+
++input_ptr_;
|
951
|
+
++line_;
|
952
|
+
++position_;
|
953
|
+
mark_position_ = position_;
|
954
|
+
break;
|
955
|
+
case ' ':case '\t':
|
956
|
+
skip_space();
|
957
|
+
break;
|
958
|
+
case '/':
|
959
|
+
++input_ptr_;
|
960
|
+
++position_;
|
961
|
+
push_state(state_);
|
962
|
+
state_ = json_parse_state::slash;
|
963
|
+
break;
|
964
|
+
case '\"':
|
965
|
+
saved_position_ = position_;
|
966
|
+
++input_ptr_;
|
967
|
+
++position_;
|
968
|
+
push_state(json_parse_state::member_name);
|
969
|
+
state_ = json_parse_state::string;
|
970
|
+
string_buffer_.clear();
|
971
|
+
parse_string(visitor, ec);
|
972
|
+
if (ec) return;
|
973
|
+
break;
|
974
|
+
case '}':
|
975
|
+
more_ = err_handler_(json_errc::extra_comma, *this);
|
976
|
+
if (!more_)
|
977
|
+
{
|
978
|
+
ec = json_errc::extra_comma;
|
979
|
+
return;
|
980
|
+
}
|
981
|
+
saved_position_ = position_;
|
982
|
+
++input_ptr_;
|
983
|
+
++position_;
|
984
|
+
end_object(visitor, ec); // Recover
|
985
|
+
if (ec) return;
|
986
|
+
break;
|
987
|
+
case '\'':
|
988
|
+
more_ = err_handler_(json_errc::single_quote, *this);
|
989
|
+
if (!more_)
|
990
|
+
{
|
991
|
+
ec = json_errc::single_quote;
|
992
|
+
return;
|
993
|
+
}
|
994
|
+
++input_ptr_;
|
995
|
+
++position_;
|
996
|
+
break;
|
997
|
+
default:
|
998
|
+
more_ = err_handler_(json_errc::expected_key, *this);
|
999
|
+
if (!more_)
|
1000
|
+
{
|
1001
|
+
ec = json_errc::expected_key;
|
1002
|
+
return;
|
1003
|
+
}
|
1004
|
+
++input_ptr_;
|
1005
|
+
++position_;
|
1006
|
+
break;
|
1007
|
+
}
|
1008
|
+
}
|
1009
|
+
break;
|
1010
|
+
case json_parse_state::expect_colon:
|
1011
|
+
{
|
1012
|
+
switch (*input_ptr_)
|
1013
|
+
{
|
1014
|
+
JSONCONS_ILLEGAL_CONTROL_CHARACTER:
|
1015
|
+
more_ = err_handler_(json_errc::illegal_control_character, *this);
|
1016
|
+
if (!more_)
|
1017
|
+
{
|
1018
|
+
ec = json_errc::illegal_control_character;
|
1019
|
+
return;
|
1020
|
+
}
|
1021
|
+
++input_ptr_;
|
1022
|
+
++position_;
|
1023
|
+
break;
|
1024
|
+
case '\r':
|
1025
|
+
push_state(state_);
|
1026
|
+
state_ = json_parse_state::cr;
|
1027
|
+
++input_ptr_;
|
1028
|
+
++position_;
|
1029
|
+
break;
|
1030
|
+
case '\n':
|
1031
|
+
++input_ptr_;
|
1032
|
+
++line_;
|
1033
|
+
++position_;
|
1034
|
+
mark_position_ = position_;
|
1035
|
+
break;
|
1036
|
+
case ' ':case '\t':
|
1037
|
+
skip_space();
|
1038
|
+
break;
|
1039
|
+
case '/':
|
1040
|
+
push_state(state_);
|
1041
|
+
state_ = json_parse_state::slash;
|
1042
|
+
++input_ptr_;
|
1043
|
+
++position_;
|
1044
|
+
break;
|
1045
|
+
case ':':
|
1046
|
+
state_ = json_parse_state::expect_value;
|
1047
|
+
++input_ptr_;
|
1048
|
+
++position_;
|
1049
|
+
break;
|
1050
|
+
default:
|
1051
|
+
more_ = err_handler_(json_errc::expected_colon, *this);
|
1052
|
+
if (!more_)
|
1053
|
+
{
|
1054
|
+
ec = json_errc::expected_colon;
|
1055
|
+
return;
|
1056
|
+
}
|
1057
|
+
++input_ptr_;
|
1058
|
+
++position_;
|
1059
|
+
break;
|
1060
|
+
}
|
1061
|
+
}
|
1062
|
+
break;
|
1063
|
+
|
1064
|
+
case json_parse_state::expect_value:
|
1065
|
+
{
|
1066
|
+
switch (*input_ptr_)
|
1067
|
+
{
|
1068
|
+
JSONCONS_ILLEGAL_CONTROL_CHARACTER:
|
1069
|
+
more_ = err_handler_(json_errc::illegal_control_character, *this);
|
1070
|
+
if (!more_)
|
1071
|
+
{
|
1072
|
+
ec = json_errc::illegal_control_character;
|
1073
|
+
return;
|
1074
|
+
}
|
1075
|
+
++input_ptr_;
|
1076
|
+
++position_;
|
1077
|
+
break;
|
1078
|
+
case '\r':
|
1079
|
+
push_state(state_);
|
1080
|
+
++input_ptr_;
|
1081
|
+
++position_;
|
1082
|
+
state_ = json_parse_state::cr;
|
1083
|
+
break;
|
1084
|
+
case '\n':
|
1085
|
+
++input_ptr_;
|
1086
|
+
++line_;
|
1087
|
+
++position_;
|
1088
|
+
mark_position_ = position_;
|
1089
|
+
break;
|
1090
|
+
case ' ':case '\t':
|
1091
|
+
skip_space();
|
1092
|
+
break;
|
1093
|
+
case '/':
|
1094
|
+
push_state(state_);
|
1095
|
+
++input_ptr_;
|
1096
|
+
++position_;
|
1097
|
+
state_ = json_parse_state::slash;
|
1098
|
+
break;
|
1099
|
+
case '{':
|
1100
|
+
saved_position_ = position_;
|
1101
|
+
++input_ptr_;
|
1102
|
+
++position_;
|
1103
|
+
begin_object(visitor, ec);
|
1104
|
+
if (ec) return;
|
1105
|
+
break;
|
1106
|
+
case '[':
|
1107
|
+
saved_position_ = position_;
|
1108
|
+
++input_ptr_;
|
1109
|
+
++position_;
|
1110
|
+
begin_array(visitor, ec);
|
1111
|
+
if (ec) return;
|
1112
|
+
break;
|
1113
|
+
case '\"':
|
1114
|
+
saved_position_ = position_;
|
1115
|
+
++input_ptr_;
|
1116
|
+
++position_;
|
1117
|
+
state_ = json_parse_state::string;
|
1118
|
+
string_buffer_.clear();
|
1119
|
+
parse_string(visitor, ec);
|
1120
|
+
if (ec) return;
|
1121
|
+
break;
|
1122
|
+
case '-':
|
1123
|
+
string_buffer_.clear();
|
1124
|
+
string_buffer_.push_back('-');
|
1125
|
+
saved_position_ = position_;
|
1126
|
+
++input_ptr_;
|
1127
|
+
++position_;
|
1128
|
+
state_ = json_parse_state::minus;
|
1129
|
+
parse_number(visitor, ec);
|
1130
|
+
if (ec) {return;}
|
1131
|
+
break;
|
1132
|
+
case '0':
|
1133
|
+
string_buffer_.clear();
|
1134
|
+
string_buffer_.push_back(static_cast<char>(*input_ptr_));
|
1135
|
+
saved_position_ = position_;
|
1136
|
+
++input_ptr_;
|
1137
|
+
++position_;
|
1138
|
+
state_ = json_parse_state::zero;
|
1139
|
+
parse_number(visitor, ec);
|
1140
|
+
if (ec) {return;}
|
1141
|
+
break;
|
1142
|
+
case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9':
|
1143
|
+
string_buffer_.clear();
|
1144
|
+
string_buffer_.push_back(static_cast<char>(*input_ptr_));
|
1145
|
+
saved_position_ = position_;
|
1146
|
+
++input_ptr_;
|
1147
|
+
++position_;
|
1148
|
+
state_ = json_parse_state::integer;
|
1149
|
+
parse_number(visitor, ec);
|
1150
|
+
if (ec) {return;}
|
1151
|
+
break;
|
1152
|
+
case 'n':
|
1153
|
+
parse_null(visitor, ec);
|
1154
|
+
if (ec) {return;}
|
1155
|
+
break;
|
1156
|
+
case 't':
|
1157
|
+
parse_true(visitor, ec);
|
1158
|
+
if (ec) {return;}
|
1159
|
+
break;
|
1160
|
+
case 'f':
|
1161
|
+
parse_false(visitor, ec);
|
1162
|
+
if (ec) {return;}
|
1163
|
+
break;
|
1164
|
+
case ']':
|
1165
|
+
saved_position_ = position_;
|
1166
|
+
++input_ptr_;
|
1167
|
+
++position_;
|
1168
|
+
if (parent() == json_parse_state::array)
|
1169
|
+
{
|
1170
|
+
more_ = err_handler_(json_errc::extra_comma, *this);
|
1171
|
+
if (!more_)
|
1172
|
+
{
|
1173
|
+
ec = json_errc::extra_comma;
|
1174
|
+
return;
|
1175
|
+
}
|
1176
|
+
end_array(visitor, ec); // Recover
|
1177
|
+
if (ec) return;
|
1178
|
+
}
|
1179
|
+
else
|
1180
|
+
{
|
1181
|
+
more_ = err_handler_(json_errc::expected_value, *this);
|
1182
|
+
if (!more_)
|
1183
|
+
{
|
1184
|
+
ec = json_errc::expected_value;
|
1185
|
+
return;
|
1186
|
+
}
|
1187
|
+
}
|
1188
|
+
break;
|
1189
|
+
case '\'':
|
1190
|
+
more_ = err_handler_(json_errc::single_quote, *this);
|
1191
|
+
if (!more_)
|
1192
|
+
{
|
1193
|
+
ec = json_errc::single_quote;
|
1194
|
+
return;
|
1195
|
+
}
|
1196
|
+
++input_ptr_;
|
1197
|
+
++position_;
|
1198
|
+
break;
|
1199
|
+
default:
|
1200
|
+
more_ = err_handler_(json_errc::expected_value, *this);
|
1201
|
+
if (!more_)
|
1202
|
+
{
|
1203
|
+
ec = json_errc::expected_value;
|
1204
|
+
return;
|
1205
|
+
}
|
1206
|
+
++input_ptr_;
|
1207
|
+
++position_;
|
1208
|
+
break;
|
1209
|
+
}
|
1210
|
+
}
|
1211
|
+
break;
|
1212
|
+
case json_parse_state::expect_value_or_end:
|
1213
|
+
{
|
1214
|
+
switch (*input_ptr_)
|
1215
|
+
{
|
1216
|
+
JSONCONS_ILLEGAL_CONTROL_CHARACTER:
|
1217
|
+
more_ = err_handler_(json_errc::illegal_control_character, *this);
|
1218
|
+
if (!more_)
|
1219
|
+
{
|
1220
|
+
ec = json_errc::illegal_control_character;
|
1221
|
+
return;
|
1222
|
+
}
|
1223
|
+
++input_ptr_;
|
1224
|
+
++position_;
|
1225
|
+
break;
|
1226
|
+
case '\r':
|
1227
|
+
++input_ptr_;
|
1228
|
+
++position_;
|
1229
|
+
push_state(state_);
|
1230
|
+
state_ = json_parse_state::cr;
|
1231
|
+
break;
|
1232
|
+
case '\n':
|
1233
|
+
++input_ptr_;
|
1234
|
+
++line_;
|
1235
|
+
++position_;
|
1236
|
+
mark_position_ = position_;
|
1237
|
+
break;
|
1238
|
+
case ' ':case '\t':
|
1239
|
+
skip_space();
|
1240
|
+
break;
|
1241
|
+
case '/':
|
1242
|
+
++input_ptr_;
|
1243
|
+
++position_;
|
1244
|
+
push_state(state_);
|
1245
|
+
state_ = json_parse_state::slash;
|
1246
|
+
break;
|
1247
|
+
case '{':
|
1248
|
+
saved_position_ = position_;
|
1249
|
+
++input_ptr_;
|
1250
|
+
++position_;
|
1251
|
+
begin_object(visitor, ec);
|
1252
|
+
if (ec) return;
|
1253
|
+
break;
|
1254
|
+
case '[':
|
1255
|
+
saved_position_ = position_;
|
1256
|
+
++input_ptr_;
|
1257
|
+
++position_;
|
1258
|
+
begin_array(visitor, ec);
|
1259
|
+
if (ec) return;
|
1260
|
+
break;
|
1261
|
+
case ']':
|
1262
|
+
saved_position_ = position_;
|
1263
|
+
++input_ptr_;
|
1264
|
+
++position_;
|
1265
|
+
end_array(visitor, ec);
|
1266
|
+
if (ec) return;
|
1267
|
+
break;
|
1268
|
+
case '\"':
|
1269
|
+
saved_position_ = position_;
|
1270
|
+
++input_ptr_;
|
1271
|
+
++position_;
|
1272
|
+
state_ = json_parse_state::string;
|
1273
|
+
string_buffer_.clear();
|
1274
|
+
parse_string(visitor, ec);
|
1275
|
+
if (ec) return;
|
1276
|
+
break;
|
1277
|
+
case '-':
|
1278
|
+
string_buffer_.clear();
|
1279
|
+
string_buffer_.push_back('-');
|
1280
|
+
saved_position_ = position_;
|
1281
|
+
++input_ptr_;
|
1282
|
+
++position_;
|
1283
|
+
state_ = json_parse_state::minus;
|
1284
|
+
parse_number(visitor, ec);
|
1285
|
+
if (ec) {return;}
|
1286
|
+
break;
|
1287
|
+
case '0':
|
1288
|
+
string_buffer_.clear();
|
1289
|
+
string_buffer_.push_back(static_cast<char>(*input_ptr_));
|
1290
|
+
saved_position_ = position_;
|
1291
|
+
++input_ptr_;
|
1292
|
+
++position_;
|
1293
|
+
state_ = json_parse_state::zero;
|
1294
|
+
parse_number(visitor, ec);
|
1295
|
+
if (ec) {return;}
|
1296
|
+
break;
|
1297
|
+
case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9':
|
1298
|
+
string_buffer_.clear();
|
1299
|
+
string_buffer_.push_back(static_cast<char>(*input_ptr_));
|
1300
|
+
saved_position_ = position_;
|
1301
|
+
++input_ptr_;
|
1302
|
+
++position_;
|
1303
|
+
state_ = json_parse_state::integer;
|
1304
|
+
parse_number(visitor, ec);
|
1305
|
+
if (ec) {return;}
|
1306
|
+
break;
|
1307
|
+
case 'n':
|
1308
|
+
parse_null(visitor, ec);
|
1309
|
+
if (ec) {return;}
|
1310
|
+
break;
|
1311
|
+
case 't':
|
1312
|
+
parse_true(visitor, ec);
|
1313
|
+
if (ec) {return;}
|
1314
|
+
break;
|
1315
|
+
case 'f':
|
1316
|
+
parse_false(visitor, ec);
|
1317
|
+
if (ec) {return;}
|
1318
|
+
break;
|
1319
|
+
case '\'':
|
1320
|
+
more_ = err_handler_(json_errc::single_quote, *this);
|
1321
|
+
if (!more_)
|
1322
|
+
{
|
1323
|
+
ec = json_errc::single_quote;
|
1324
|
+
return;
|
1325
|
+
}
|
1326
|
+
++input_ptr_;
|
1327
|
+
++position_;
|
1328
|
+
break;
|
1329
|
+
default:
|
1330
|
+
more_ = err_handler_(json_errc::expected_value, *this);
|
1331
|
+
if (!more_)
|
1332
|
+
{
|
1333
|
+
ec = json_errc::expected_value;
|
1334
|
+
return;
|
1335
|
+
}
|
1336
|
+
++input_ptr_;
|
1337
|
+
++position_;
|
1338
|
+
break;
|
1339
|
+
}
|
1340
|
+
}
|
1341
|
+
break;
|
1342
|
+
case json_parse_state::string:
|
1343
|
+
case json_parse_state::escape:
|
1344
|
+
case json_parse_state::escape_u1:
|
1345
|
+
case json_parse_state::escape_u2:
|
1346
|
+
case json_parse_state::escape_u3:
|
1347
|
+
case json_parse_state::escape_u4:
|
1348
|
+
case json_parse_state::escape_expect_surrogate_pair1:
|
1349
|
+
case json_parse_state::escape_expect_surrogate_pair2:
|
1350
|
+
case json_parse_state::escape_u5:
|
1351
|
+
case json_parse_state::escape_u6:
|
1352
|
+
case json_parse_state::escape_u7:
|
1353
|
+
case json_parse_state::escape_u8:
|
1354
|
+
parse_string(visitor, ec);
|
1355
|
+
if (ec) return;
|
1356
|
+
break;
|
1357
|
+
case json_parse_state::minus:
|
1358
|
+
case json_parse_state::zero:
|
1359
|
+
case json_parse_state::integer:
|
1360
|
+
case json_parse_state::fraction1:
|
1361
|
+
case json_parse_state::fraction2:
|
1362
|
+
case json_parse_state::exp1:
|
1363
|
+
case json_parse_state::exp2:
|
1364
|
+
case json_parse_state::exp3:
|
1365
|
+
parse_number(visitor, ec);
|
1366
|
+
if (ec) return;
|
1367
|
+
break;
|
1368
|
+
case json_parse_state::t:
|
1369
|
+
switch (*input_ptr_)
|
1370
|
+
{
|
1371
|
+
case 'r':
|
1372
|
+
++input_ptr_;
|
1373
|
+
++position_;
|
1374
|
+
state_ = json_parse_state::tr;
|
1375
|
+
break;
|
1376
|
+
default:
|
1377
|
+
err_handler_(json_errc::invalid_value, *this);
|
1378
|
+
ec = json_errc::invalid_value;
|
1379
|
+
more_ = false;
|
1380
|
+
return;
|
1381
|
+
}
|
1382
|
+
break;
|
1383
|
+
case json_parse_state::tr:
|
1384
|
+
switch (*input_ptr_)
|
1385
|
+
{
|
1386
|
+
case 'u':
|
1387
|
+
state_ = json_parse_state::tru;
|
1388
|
+
break;
|
1389
|
+
default:
|
1390
|
+
err_handler_(json_errc::invalid_value, *this);
|
1391
|
+
ec = json_errc::invalid_value;
|
1392
|
+
more_ = false;
|
1393
|
+
return;
|
1394
|
+
}
|
1395
|
+
++input_ptr_;
|
1396
|
+
++position_;
|
1397
|
+
break;
|
1398
|
+
case json_parse_state::tru:
|
1399
|
+
switch (*input_ptr_)
|
1400
|
+
{
|
1401
|
+
case 'e':
|
1402
|
+
++input_ptr_;
|
1403
|
+
++position_;
|
1404
|
+
more_ = visitor.bool_value(true, semantic_tag::none, *this, ec);
|
1405
|
+
if (parent() == json_parse_state::root)
|
1406
|
+
{
|
1407
|
+
state_ = json_parse_state::accept;
|
1408
|
+
}
|
1409
|
+
else
|
1410
|
+
{
|
1411
|
+
state_ = json_parse_state::expect_comma_or_end;
|
1412
|
+
}
|
1413
|
+
break;
|
1414
|
+
default:
|
1415
|
+
err_handler_(json_errc::invalid_value, *this);
|
1416
|
+
ec = json_errc::invalid_value;
|
1417
|
+
more_ = false;
|
1418
|
+
return;
|
1419
|
+
}
|
1420
|
+
break;
|
1421
|
+
case json_parse_state::f:
|
1422
|
+
switch (*input_ptr_)
|
1423
|
+
{
|
1424
|
+
case 'a':
|
1425
|
+
++input_ptr_;
|
1426
|
+
++position_;
|
1427
|
+
state_ = json_parse_state::fa;
|
1428
|
+
break;
|
1429
|
+
default:
|
1430
|
+
err_handler_(json_errc::invalid_value, *this);
|
1431
|
+
ec = json_errc::invalid_value;
|
1432
|
+
more_ = false;
|
1433
|
+
return;
|
1434
|
+
}
|
1435
|
+
break;
|
1436
|
+
case json_parse_state::fa:
|
1437
|
+
switch (*input_ptr_)
|
1438
|
+
{
|
1439
|
+
case 'l':
|
1440
|
+
state_ = json_parse_state::fal;
|
1441
|
+
break;
|
1442
|
+
default:
|
1443
|
+
err_handler_(json_errc::invalid_value, *this);
|
1444
|
+
ec = json_errc::invalid_value;
|
1445
|
+
more_ = false;
|
1446
|
+
return;
|
1447
|
+
}
|
1448
|
+
++input_ptr_;
|
1449
|
+
++position_;
|
1450
|
+
break;
|
1451
|
+
case json_parse_state::fal:
|
1452
|
+
switch (*input_ptr_)
|
1453
|
+
{
|
1454
|
+
case 's':
|
1455
|
+
state_ = json_parse_state::fals;
|
1456
|
+
break;
|
1457
|
+
default:
|
1458
|
+
err_handler_(json_errc::invalid_value, *this);
|
1459
|
+
ec = json_errc::invalid_value;
|
1460
|
+
more_ = false;
|
1461
|
+
return;
|
1462
|
+
}
|
1463
|
+
++input_ptr_;
|
1464
|
+
++position_;
|
1465
|
+
break;
|
1466
|
+
case json_parse_state::fals:
|
1467
|
+
switch (*input_ptr_)
|
1468
|
+
{
|
1469
|
+
case 'e':
|
1470
|
+
++input_ptr_;
|
1471
|
+
++position_;
|
1472
|
+
more_ = visitor.bool_value(false, semantic_tag::none, *this, ec);
|
1473
|
+
if (parent() == json_parse_state::root)
|
1474
|
+
{
|
1475
|
+
state_ = json_parse_state::accept;
|
1476
|
+
}
|
1477
|
+
else
|
1478
|
+
{
|
1479
|
+
state_ = json_parse_state::expect_comma_or_end;
|
1480
|
+
}
|
1481
|
+
break;
|
1482
|
+
default:
|
1483
|
+
err_handler_(json_errc::invalid_value, *this);
|
1484
|
+
ec = json_errc::invalid_value;
|
1485
|
+
more_ = false;
|
1486
|
+
return;
|
1487
|
+
}
|
1488
|
+
break;
|
1489
|
+
case json_parse_state::n:
|
1490
|
+
switch (*input_ptr_)
|
1491
|
+
{
|
1492
|
+
case 'u':
|
1493
|
+
++input_ptr_;
|
1494
|
+
++position_;
|
1495
|
+
state_ = json_parse_state::nu;
|
1496
|
+
break;
|
1497
|
+
default:
|
1498
|
+
err_handler_(json_errc::invalid_value, *this);
|
1499
|
+
ec = json_errc::invalid_value;
|
1500
|
+
more_ = false;
|
1501
|
+
return;
|
1502
|
+
}
|
1503
|
+
break;
|
1504
|
+
case json_parse_state::nu:
|
1505
|
+
switch (*input_ptr_)
|
1506
|
+
{
|
1507
|
+
case 'l':
|
1508
|
+
state_ = json_parse_state::nul;
|
1509
|
+
break;
|
1510
|
+
default:
|
1511
|
+
err_handler_(json_errc::invalid_value, *this);
|
1512
|
+
ec = json_errc::invalid_value;
|
1513
|
+
more_ = false;
|
1514
|
+
return;
|
1515
|
+
}
|
1516
|
+
++input_ptr_;
|
1517
|
+
++position_;
|
1518
|
+
break;
|
1519
|
+
case json_parse_state::nul:
|
1520
|
+
++position_;
|
1521
|
+
switch (*input_ptr_)
|
1522
|
+
{
|
1523
|
+
case 'l':
|
1524
|
+
more_ = visitor.null_value(semantic_tag::none, *this, ec);
|
1525
|
+
if (parent() == json_parse_state::root)
|
1526
|
+
{
|
1527
|
+
state_ = json_parse_state::accept;
|
1528
|
+
}
|
1529
|
+
else
|
1530
|
+
{
|
1531
|
+
state_ = json_parse_state::expect_comma_or_end;
|
1532
|
+
}
|
1533
|
+
break;
|
1534
|
+
default:
|
1535
|
+
err_handler_(json_errc::invalid_value, *this);
|
1536
|
+
ec = json_errc::invalid_value;
|
1537
|
+
more_ = false;
|
1538
|
+
return;
|
1539
|
+
}
|
1540
|
+
++input_ptr_;
|
1541
|
+
break;
|
1542
|
+
case json_parse_state::slash:
|
1543
|
+
{
|
1544
|
+
switch (*input_ptr_)
|
1545
|
+
{
|
1546
|
+
case '*':
|
1547
|
+
state_ = json_parse_state::slash_star;
|
1548
|
+
more_ = err_handler_(json_errc::illegal_comment, *this);
|
1549
|
+
if (!more_)
|
1550
|
+
{
|
1551
|
+
ec = json_errc::illegal_comment;
|
1552
|
+
return;
|
1553
|
+
}
|
1554
|
+
break;
|
1555
|
+
case '/':
|
1556
|
+
state_ = json_parse_state::slash_slash;
|
1557
|
+
more_ = err_handler_(json_errc::illegal_comment, *this);
|
1558
|
+
if (!more_)
|
1559
|
+
{
|
1560
|
+
ec = json_errc::illegal_comment;
|
1561
|
+
return;
|
1562
|
+
}
|
1563
|
+
break;
|
1564
|
+
default:
|
1565
|
+
more_ = err_handler_(json_errc::syntax_error, *this);
|
1566
|
+
if (!more_)
|
1567
|
+
{
|
1568
|
+
ec = json_errc::syntax_error;
|
1569
|
+
return;
|
1570
|
+
}
|
1571
|
+
break;
|
1572
|
+
}
|
1573
|
+
++input_ptr_;
|
1574
|
+
++position_;
|
1575
|
+
break;
|
1576
|
+
}
|
1577
|
+
case json_parse_state::slash_star:
|
1578
|
+
{
|
1579
|
+
switch (*input_ptr_)
|
1580
|
+
{
|
1581
|
+
case '\r':
|
1582
|
+
push_state(state_);
|
1583
|
+
++input_ptr_;
|
1584
|
+
++position_;
|
1585
|
+
state_ = json_parse_state::cr;
|
1586
|
+
break;
|
1587
|
+
case '\n':
|
1588
|
+
++input_ptr_;
|
1589
|
+
++line_;
|
1590
|
+
++position_;
|
1591
|
+
mark_position_ = position_;
|
1592
|
+
break;
|
1593
|
+
case '*':
|
1594
|
+
++input_ptr_;
|
1595
|
+
++position_;
|
1596
|
+
state_ = json_parse_state::slash_star_star;
|
1597
|
+
break;
|
1598
|
+
default:
|
1599
|
+
++input_ptr_;
|
1600
|
+
++position_;
|
1601
|
+
break;
|
1602
|
+
}
|
1603
|
+
break;
|
1604
|
+
}
|
1605
|
+
case json_parse_state::slash_slash:
|
1606
|
+
{
|
1607
|
+
switch (*input_ptr_)
|
1608
|
+
{
|
1609
|
+
case '\r':
|
1610
|
+
state_ = pop_state();
|
1611
|
+
break;
|
1612
|
+
case '\n':
|
1613
|
+
state_ = pop_state();
|
1614
|
+
break;
|
1615
|
+
default:
|
1616
|
+
++input_ptr_;
|
1617
|
+
++position_;
|
1618
|
+
}
|
1619
|
+
break;
|
1620
|
+
}
|
1621
|
+
case json_parse_state::slash_star_star:
|
1622
|
+
{
|
1623
|
+
switch (*input_ptr_)
|
1624
|
+
{
|
1625
|
+
case '/':
|
1626
|
+
state_ = pop_state();
|
1627
|
+
break;
|
1628
|
+
default:
|
1629
|
+
state_ = json_parse_state::slash_star;
|
1630
|
+
break;
|
1631
|
+
}
|
1632
|
+
++input_ptr_;
|
1633
|
+
++position_;
|
1634
|
+
break;
|
1635
|
+
}
|
1636
|
+
default:
|
1637
|
+
JSONCONS_ASSERT(false);
|
1638
|
+
break;
|
1639
|
+
}
|
1640
|
+
}
|
1641
|
+
}
|
1642
|
+
|
1643
|
+
void parse_true(basic_json_visitor<char_type>& visitor, std::error_code& ec)
|
1644
|
+
{
|
1645
|
+
saved_position_ = position_;
|
1646
|
+
if (JSONCONS_LIKELY(end_input_ - input_ptr_ >= 4))
|
1647
|
+
{
|
1648
|
+
if (*(input_ptr_+1) == 'r' && *(input_ptr_+2) == 'u' && *(input_ptr_+3) == 'e')
|
1649
|
+
{
|
1650
|
+
input_ptr_ += 4;
|
1651
|
+
position_ += 4;
|
1652
|
+
more_ = visitor.bool_value(true, semantic_tag::none, *this, ec);
|
1653
|
+
if (parent() == json_parse_state::root)
|
1654
|
+
{
|
1655
|
+
state_ = json_parse_state::accept;
|
1656
|
+
}
|
1657
|
+
else
|
1658
|
+
{
|
1659
|
+
state_ = json_parse_state::expect_comma_or_end;
|
1660
|
+
}
|
1661
|
+
}
|
1662
|
+
else
|
1663
|
+
{
|
1664
|
+
err_handler_(json_errc::invalid_value, *this);
|
1665
|
+
ec = json_errc::invalid_value;
|
1666
|
+
more_ = false;
|
1667
|
+
return;
|
1668
|
+
}
|
1669
|
+
}
|
1670
|
+
else
|
1671
|
+
{
|
1672
|
+
++input_ptr_;
|
1673
|
+
++position_;
|
1674
|
+
state_ = json_parse_state::t;
|
1675
|
+
}
|
1676
|
+
}
|
1677
|
+
|
1678
|
+
void parse_null(basic_json_visitor<char_type>& visitor, std::error_code& ec)
|
1679
|
+
{
|
1680
|
+
saved_position_ = position_;
|
1681
|
+
if (JSONCONS_LIKELY(end_input_ - input_ptr_ >= 4))
|
1682
|
+
{
|
1683
|
+
if (*(input_ptr_+1) == 'u' && *(input_ptr_+2) == 'l' && *(input_ptr_+3) == 'l')
|
1684
|
+
{
|
1685
|
+
input_ptr_ += 4;
|
1686
|
+
position_ += 4;
|
1687
|
+
more_ = visitor.null_value(semantic_tag::none, *this, ec);
|
1688
|
+
if (parent() == json_parse_state::root)
|
1689
|
+
{
|
1690
|
+
state_ = json_parse_state::accept;
|
1691
|
+
}
|
1692
|
+
else
|
1693
|
+
{
|
1694
|
+
state_ = json_parse_state::expect_comma_or_end;
|
1695
|
+
}
|
1696
|
+
}
|
1697
|
+
else
|
1698
|
+
{
|
1699
|
+
err_handler_(json_errc::invalid_value, *this);
|
1700
|
+
ec = json_errc::invalid_value;
|
1701
|
+
more_ = false;
|
1702
|
+
return;
|
1703
|
+
}
|
1704
|
+
}
|
1705
|
+
else
|
1706
|
+
{
|
1707
|
+
++input_ptr_;
|
1708
|
+
++position_;
|
1709
|
+
state_ = json_parse_state::n;
|
1710
|
+
}
|
1711
|
+
}
|
1712
|
+
|
1713
|
+
void parse_false(basic_json_visitor<char_type>& visitor, std::error_code& ec)
|
1714
|
+
{
|
1715
|
+
saved_position_ = position_;
|
1716
|
+
if (JSONCONS_LIKELY(end_input_ - input_ptr_ >= 5))
|
1717
|
+
{
|
1718
|
+
if (*(input_ptr_+1) == 'a' && *(input_ptr_+2) == 'l' && *(input_ptr_+3) == 's' && *(input_ptr_+4) == 'e')
|
1719
|
+
{
|
1720
|
+
input_ptr_ += 5;
|
1721
|
+
position_ += 5;
|
1722
|
+
more_ = visitor.bool_value(false, semantic_tag::none, *this, ec);
|
1723
|
+
if (parent() == json_parse_state::root)
|
1724
|
+
{
|
1725
|
+
state_ = json_parse_state::accept;
|
1726
|
+
}
|
1727
|
+
else
|
1728
|
+
{
|
1729
|
+
state_ = json_parse_state::expect_comma_or_end;
|
1730
|
+
}
|
1731
|
+
}
|
1732
|
+
else
|
1733
|
+
{
|
1734
|
+
err_handler_(json_errc::invalid_value, *this);
|
1735
|
+
ec = json_errc::invalid_value;
|
1736
|
+
more_ = false;
|
1737
|
+
return;
|
1738
|
+
}
|
1739
|
+
}
|
1740
|
+
else
|
1741
|
+
{
|
1742
|
+
++input_ptr_;
|
1743
|
+
++position_;
|
1744
|
+
state_ = json_parse_state::f;
|
1745
|
+
}
|
1746
|
+
}
|
1747
|
+
|
1748
|
+
void parse_number(basic_json_visitor<char_type>& visitor, std::error_code& ec)
|
1749
|
+
{
|
1750
|
+
const char_type* local_input_end = end_input_;
|
1751
|
+
|
1752
|
+
switch (state_)
|
1753
|
+
{
|
1754
|
+
case json_parse_state::minus:
|
1755
|
+
goto minus_sign;
|
1756
|
+
case json_parse_state::zero:
|
1757
|
+
goto zero;
|
1758
|
+
case json_parse_state::integer:
|
1759
|
+
goto integer;
|
1760
|
+
case json_parse_state::fraction1:
|
1761
|
+
goto fraction1;
|
1762
|
+
case json_parse_state::fraction2:
|
1763
|
+
goto fraction2;
|
1764
|
+
case json_parse_state::exp1:
|
1765
|
+
goto exp1;
|
1766
|
+
case json_parse_state::exp2:
|
1767
|
+
goto exp2;
|
1768
|
+
case json_parse_state::exp3:
|
1769
|
+
goto exp3;
|
1770
|
+
default:
|
1771
|
+
JSONCONS_UNREACHABLE();
|
1772
|
+
}
|
1773
|
+
minus_sign:
|
1774
|
+
if (JSONCONS_UNLIKELY(input_ptr_ >= local_input_end)) // Buffer exhausted
|
1775
|
+
{
|
1776
|
+
state_ = json_parse_state::minus;
|
1777
|
+
return;
|
1778
|
+
}
|
1779
|
+
switch (*input_ptr_)
|
1780
|
+
{
|
1781
|
+
case '0':
|
1782
|
+
string_buffer_.push_back(static_cast<char>(*input_ptr_));
|
1783
|
+
++input_ptr_;
|
1784
|
+
++position_;
|
1785
|
+
goto zero;
|
1786
|
+
case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9':
|
1787
|
+
string_buffer_.push_back(static_cast<char>(*input_ptr_));
|
1788
|
+
++input_ptr_;
|
1789
|
+
++position_;
|
1790
|
+
goto integer;
|
1791
|
+
default:
|
1792
|
+
err_handler_(json_errc::invalid_number, *this);
|
1793
|
+
ec = json_errc::expected_value;
|
1794
|
+
more_ = false;
|
1795
|
+
return;
|
1796
|
+
}
|
1797
|
+
zero:
|
1798
|
+
if (JSONCONS_UNLIKELY(input_ptr_ >= local_input_end)) // Buffer exhausted
|
1799
|
+
{
|
1800
|
+
state_ = json_parse_state::zero;
|
1801
|
+
return;
|
1802
|
+
}
|
1803
|
+
switch (*input_ptr_)
|
1804
|
+
{
|
1805
|
+
case '\r':
|
1806
|
+
end_integer_value(visitor, ec);
|
1807
|
+
if (ec) return;
|
1808
|
+
++input_ptr_;
|
1809
|
+
++position_;
|
1810
|
+
push_state(state_);
|
1811
|
+
state_ = json_parse_state::cr;
|
1812
|
+
return;
|
1813
|
+
case '\n':
|
1814
|
+
end_integer_value(visitor, ec);
|
1815
|
+
if (ec) return;
|
1816
|
+
++input_ptr_;
|
1817
|
+
++line_;
|
1818
|
+
++position_;
|
1819
|
+
mark_position_ = position_;
|
1820
|
+
return;
|
1821
|
+
case ' ':case '\t':
|
1822
|
+
end_integer_value(visitor, ec);
|
1823
|
+
if (ec) return;
|
1824
|
+
skip_space();
|
1825
|
+
return;
|
1826
|
+
case '/':
|
1827
|
+
end_integer_value(visitor, ec);
|
1828
|
+
if (ec) return;
|
1829
|
+
++input_ptr_;
|
1830
|
+
++position_;
|
1831
|
+
push_state(state_);
|
1832
|
+
state_ = json_parse_state::slash;
|
1833
|
+
return;
|
1834
|
+
case '}':
|
1835
|
+
end_integer_value(visitor, ec);
|
1836
|
+
if (ec) return;
|
1837
|
+
state_ = json_parse_state::expect_comma_or_end;
|
1838
|
+
return;
|
1839
|
+
case ']':
|
1840
|
+
end_integer_value(visitor, ec);
|
1841
|
+
if (ec) return;
|
1842
|
+
state_ = json_parse_state::expect_comma_or_end;
|
1843
|
+
return;
|
1844
|
+
case '.':
|
1845
|
+
string_buffer_.push_back(to_double_.get_decimal_point());
|
1846
|
+
++input_ptr_;
|
1847
|
+
++position_;
|
1848
|
+
goto fraction1;
|
1849
|
+
case 'e':case 'E':
|
1850
|
+
string_buffer_.push_back(static_cast<char>(*input_ptr_));
|
1851
|
+
++input_ptr_;
|
1852
|
+
++position_;
|
1853
|
+
goto exp1;
|
1854
|
+
case ',':
|
1855
|
+
end_integer_value(visitor, ec);
|
1856
|
+
if (ec) return;
|
1857
|
+
begin_member_or_element(ec);
|
1858
|
+
if (ec) return;
|
1859
|
+
++input_ptr_;
|
1860
|
+
++position_;
|
1861
|
+
return;
|
1862
|
+
case '0': case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9':
|
1863
|
+
err_handler_(json_errc::leading_zero, *this);
|
1864
|
+
ec = json_errc::leading_zero;
|
1865
|
+
more_ = false;
|
1866
|
+
state_ = json_parse_state::zero;
|
1867
|
+
return;
|
1868
|
+
default:
|
1869
|
+
err_handler_(json_errc::invalid_number, *this);
|
1870
|
+
ec = json_errc::invalid_number;
|
1871
|
+
more_ = false;
|
1872
|
+
state_ = json_parse_state::zero;
|
1873
|
+
return;
|
1874
|
+
}
|
1875
|
+
integer:
|
1876
|
+
if (JSONCONS_UNLIKELY(input_ptr_ >= local_input_end)) // Buffer exhausted
|
1877
|
+
{
|
1878
|
+
state_ = json_parse_state::integer;
|
1879
|
+
return;
|
1880
|
+
}
|
1881
|
+
switch (*input_ptr_)
|
1882
|
+
{
|
1883
|
+
case '\r':
|
1884
|
+
end_integer_value(visitor, ec);
|
1885
|
+
if (ec) return;
|
1886
|
+
push_state(state_);
|
1887
|
+
++input_ptr_;
|
1888
|
+
++position_;
|
1889
|
+
state_ = json_parse_state::cr;
|
1890
|
+
return;
|
1891
|
+
case '\n':
|
1892
|
+
end_integer_value(visitor, ec);
|
1893
|
+
if (ec) return;
|
1894
|
+
++input_ptr_;
|
1895
|
+
++line_;
|
1896
|
+
++position_;
|
1897
|
+
mark_position_ = position_;
|
1898
|
+
return;
|
1899
|
+
case ' ':case '\t':
|
1900
|
+
end_integer_value(visitor, ec);
|
1901
|
+
if (ec) return;
|
1902
|
+
skip_space();
|
1903
|
+
return;
|
1904
|
+
case '/':
|
1905
|
+
end_integer_value(visitor, ec);
|
1906
|
+
if (ec) return;
|
1907
|
+
push_state(state_);
|
1908
|
+
++input_ptr_;
|
1909
|
+
++position_;
|
1910
|
+
state_ = json_parse_state::slash;
|
1911
|
+
return;
|
1912
|
+
case '}':
|
1913
|
+
end_integer_value(visitor, ec);
|
1914
|
+
if (ec) return;
|
1915
|
+
state_ = json_parse_state::expect_comma_or_end;
|
1916
|
+
return;
|
1917
|
+
case ']':
|
1918
|
+
end_integer_value(visitor, ec);
|
1919
|
+
if (ec) return;
|
1920
|
+
state_ = json_parse_state::expect_comma_or_end;
|
1921
|
+
return;
|
1922
|
+
case '0': case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9':
|
1923
|
+
string_buffer_.push_back(static_cast<char>(*input_ptr_));
|
1924
|
+
++input_ptr_;
|
1925
|
+
++position_;
|
1926
|
+
goto integer;
|
1927
|
+
case '.':
|
1928
|
+
string_buffer_.push_back(to_double_.get_decimal_point());
|
1929
|
+
++input_ptr_;
|
1930
|
+
++position_;
|
1931
|
+
goto fraction1;
|
1932
|
+
case 'e':case 'E':
|
1933
|
+
string_buffer_.push_back(static_cast<char>(*input_ptr_));
|
1934
|
+
++input_ptr_;
|
1935
|
+
++position_;
|
1936
|
+
goto exp1;
|
1937
|
+
case ',':
|
1938
|
+
end_integer_value(visitor, ec);
|
1939
|
+
if (ec) return;
|
1940
|
+
begin_member_or_element(ec);
|
1941
|
+
if (ec) return;
|
1942
|
+
++input_ptr_;
|
1943
|
+
++position_;
|
1944
|
+
return;
|
1945
|
+
default:
|
1946
|
+
err_handler_(json_errc::invalid_number, *this);
|
1947
|
+
ec = json_errc::invalid_number;
|
1948
|
+
more_ = false;
|
1949
|
+
state_ = json_parse_state::integer;
|
1950
|
+
return;
|
1951
|
+
}
|
1952
|
+
fraction1:
|
1953
|
+
if (JSONCONS_UNLIKELY(input_ptr_ >= local_input_end)) // Buffer exhausted
|
1954
|
+
{
|
1955
|
+
state_ = json_parse_state::fraction1;
|
1956
|
+
return;
|
1957
|
+
}
|
1958
|
+
switch (*input_ptr_)
|
1959
|
+
{
|
1960
|
+
case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9':
|
1961
|
+
string_buffer_.push_back(static_cast<char>(*input_ptr_));
|
1962
|
+
++input_ptr_;
|
1963
|
+
++position_;
|
1964
|
+
goto fraction2;
|
1965
|
+
default:
|
1966
|
+
err_handler_(json_errc::invalid_number, *this);
|
1967
|
+
ec = json_errc::invalid_number;
|
1968
|
+
more_ = false;
|
1969
|
+
state_ = json_parse_state::fraction1;
|
1970
|
+
return;
|
1971
|
+
}
|
1972
|
+
fraction2:
|
1973
|
+
if (JSONCONS_UNLIKELY(input_ptr_ >= local_input_end)) // Buffer exhausted
|
1974
|
+
{
|
1975
|
+
state_ = json_parse_state::fraction2;
|
1976
|
+
return;
|
1977
|
+
}
|
1978
|
+
switch (*input_ptr_)
|
1979
|
+
{
|
1980
|
+
case '\r':
|
1981
|
+
end_fraction_value(visitor, ec);
|
1982
|
+
if (ec) return;
|
1983
|
+
push_state(state_);
|
1984
|
+
++input_ptr_;
|
1985
|
+
++position_;
|
1986
|
+
state_ = json_parse_state::cr;
|
1987
|
+
return;
|
1988
|
+
case '\n':
|
1989
|
+
end_fraction_value(visitor, ec);
|
1990
|
+
if (ec) return;
|
1991
|
+
++input_ptr_;
|
1992
|
+
++line_;
|
1993
|
+
++position_;
|
1994
|
+
mark_position_ = position_;
|
1995
|
+
return;
|
1996
|
+
case ' ':case '\t':
|
1997
|
+
end_fraction_value(visitor, ec);
|
1998
|
+
if (ec) return;
|
1999
|
+
skip_space();
|
2000
|
+
return;
|
2001
|
+
case '/':
|
2002
|
+
end_fraction_value(visitor, ec);
|
2003
|
+
if (ec) return;
|
2004
|
+
push_state(state_);
|
2005
|
+
++input_ptr_;
|
2006
|
+
++position_;
|
2007
|
+
state_ = json_parse_state::slash;
|
2008
|
+
return;
|
2009
|
+
case '}':
|
2010
|
+
end_fraction_value(visitor, ec);
|
2011
|
+
if (ec) return;
|
2012
|
+
state_ = json_parse_state::expect_comma_or_end;
|
2013
|
+
return;
|
2014
|
+
case ']':
|
2015
|
+
end_fraction_value(visitor, ec);
|
2016
|
+
if (ec) return;
|
2017
|
+
state_ = json_parse_state::expect_comma_or_end;
|
2018
|
+
return;
|
2019
|
+
case ',':
|
2020
|
+
end_fraction_value(visitor, ec);
|
2021
|
+
if (ec) return;
|
2022
|
+
begin_member_or_element(ec);
|
2023
|
+
if (ec) return;
|
2024
|
+
++input_ptr_;
|
2025
|
+
++position_;
|
2026
|
+
return;
|
2027
|
+
case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9':
|
2028
|
+
string_buffer_.push_back(static_cast<char>(*input_ptr_));
|
2029
|
+
++input_ptr_;
|
2030
|
+
++position_;
|
2031
|
+
goto fraction2;
|
2032
|
+
case 'e':case 'E':
|
2033
|
+
string_buffer_.push_back(static_cast<char>(*input_ptr_));
|
2034
|
+
++input_ptr_;
|
2035
|
+
++position_;
|
2036
|
+
goto exp1;
|
2037
|
+
default:
|
2038
|
+
err_handler_(json_errc::invalid_number, *this);
|
2039
|
+
ec = json_errc::invalid_number;
|
2040
|
+
more_ = false;
|
2041
|
+
state_ = json_parse_state::fraction2;
|
2042
|
+
return;
|
2043
|
+
}
|
2044
|
+
exp1:
|
2045
|
+
if (JSONCONS_UNLIKELY(input_ptr_ >= local_input_end)) // Buffer exhausted
|
2046
|
+
{
|
2047
|
+
state_ = json_parse_state::exp1;
|
2048
|
+
return;
|
2049
|
+
}
|
2050
|
+
switch (*input_ptr_)
|
2051
|
+
{
|
2052
|
+
case '+':
|
2053
|
+
++input_ptr_;
|
2054
|
+
++position_;
|
2055
|
+
goto exp2;
|
2056
|
+
case '-':
|
2057
|
+
string_buffer_.push_back(static_cast<char>(*input_ptr_));
|
2058
|
+
++input_ptr_;
|
2059
|
+
++position_;
|
2060
|
+
goto exp2;
|
2061
|
+
case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9':
|
2062
|
+
string_buffer_.push_back(static_cast<char>(*input_ptr_));
|
2063
|
+
++input_ptr_;
|
2064
|
+
++position_;
|
2065
|
+
goto exp3;
|
2066
|
+
default:
|
2067
|
+
err_handler_(json_errc::invalid_number, *this);
|
2068
|
+
ec = json_errc::expected_value;
|
2069
|
+
more_ = false;
|
2070
|
+
state_ = json_parse_state::exp1;
|
2071
|
+
return;
|
2072
|
+
}
|
2073
|
+
exp2:
|
2074
|
+
if (JSONCONS_UNLIKELY(input_ptr_ >= local_input_end)) // Buffer exhausted
|
2075
|
+
{
|
2076
|
+
state_ = json_parse_state::exp2;
|
2077
|
+
return;
|
2078
|
+
}
|
2079
|
+
switch (*input_ptr_)
|
2080
|
+
{
|
2081
|
+
case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9':
|
2082
|
+
string_buffer_.push_back(static_cast<char>(*input_ptr_));
|
2083
|
+
++input_ptr_;
|
2084
|
+
++position_;
|
2085
|
+
goto exp3;
|
2086
|
+
default:
|
2087
|
+
err_handler_(json_errc::invalid_number, *this);
|
2088
|
+
ec = json_errc::expected_value;
|
2089
|
+
more_ = false;
|
2090
|
+
state_ = json_parse_state::exp2;
|
2091
|
+
return;
|
2092
|
+
}
|
2093
|
+
|
2094
|
+
exp3:
|
2095
|
+
if (JSONCONS_UNLIKELY(input_ptr_ >= local_input_end)) // Buffer exhausted
|
2096
|
+
{
|
2097
|
+
state_ = json_parse_state::exp3;
|
2098
|
+
return;
|
2099
|
+
}
|
2100
|
+
switch (*input_ptr_)
|
2101
|
+
{
|
2102
|
+
case '\r':
|
2103
|
+
end_fraction_value(visitor, ec);
|
2104
|
+
if (ec) return;
|
2105
|
+
++input_ptr_;
|
2106
|
+
++position_;
|
2107
|
+
push_state(state_);
|
2108
|
+
state_ = json_parse_state::cr;
|
2109
|
+
return;
|
2110
|
+
case '\n':
|
2111
|
+
end_fraction_value(visitor, ec);
|
2112
|
+
if (ec) return;
|
2113
|
+
++input_ptr_;
|
2114
|
+
++line_;
|
2115
|
+
++position_;
|
2116
|
+
mark_position_ = position_;
|
2117
|
+
return;
|
2118
|
+
case ' ':case '\t':
|
2119
|
+
end_fraction_value(visitor, ec);
|
2120
|
+
if (ec) return;
|
2121
|
+
skip_space();
|
2122
|
+
return;
|
2123
|
+
case '/':
|
2124
|
+
end_fraction_value(visitor, ec);
|
2125
|
+
if (ec) return;
|
2126
|
+
push_state(state_);
|
2127
|
+
++input_ptr_;
|
2128
|
+
++position_;
|
2129
|
+
state_ = json_parse_state::slash;
|
2130
|
+
return;
|
2131
|
+
case '}':
|
2132
|
+
end_fraction_value(visitor, ec);
|
2133
|
+
if (ec) return;
|
2134
|
+
state_ = json_parse_state::expect_comma_or_end;
|
2135
|
+
return;
|
2136
|
+
case ']':
|
2137
|
+
end_fraction_value(visitor, ec);
|
2138
|
+
if (ec) return;
|
2139
|
+
state_ = json_parse_state::expect_comma_or_end;
|
2140
|
+
return;
|
2141
|
+
case ',':
|
2142
|
+
end_fraction_value(visitor, ec);
|
2143
|
+
if (ec) return;
|
2144
|
+
begin_member_or_element(ec);
|
2145
|
+
if (ec) return;
|
2146
|
+
++input_ptr_;
|
2147
|
+
++position_;
|
2148
|
+
return;
|
2149
|
+
case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9':
|
2150
|
+
string_buffer_.push_back(static_cast<char>(*input_ptr_));
|
2151
|
+
++input_ptr_;
|
2152
|
+
++position_;
|
2153
|
+
goto exp3;
|
2154
|
+
default:
|
2155
|
+
err_handler_(json_errc::invalid_number, *this);
|
2156
|
+
ec = json_errc::invalid_number;
|
2157
|
+
more_ = false;
|
2158
|
+
state_ = json_parse_state::exp3;
|
2159
|
+
return;
|
2160
|
+
}
|
2161
|
+
|
2162
|
+
JSONCONS_UNREACHABLE();
|
2163
|
+
}
|
2164
|
+
|
2165
|
+
void parse_string(basic_json_visitor<char_type>& visitor, std::error_code& ec)
|
2166
|
+
{
|
2167
|
+
const char_type* local_input_end = end_input_;
|
2168
|
+
const char_type* sb = input_ptr_;
|
2169
|
+
|
2170
|
+
switch (state_)
|
2171
|
+
{
|
2172
|
+
case json_parse_state::string:
|
2173
|
+
goto string_u1;
|
2174
|
+
case json_parse_state::escape:
|
2175
|
+
goto escape;
|
2176
|
+
case json_parse_state::escape_u1:
|
2177
|
+
goto escape_u1;
|
2178
|
+
case json_parse_state::escape_u2:
|
2179
|
+
goto escape_u2;
|
2180
|
+
case json_parse_state::escape_u3:
|
2181
|
+
goto escape_u3;
|
2182
|
+
case json_parse_state::escape_u4:
|
2183
|
+
goto escape_u4;
|
2184
|
+
case json_parse_state::escape_expect_surrogate_pair1:
|
2185
|
+
goto escape_expect_surrogate_pair1;
|
2186
|
+
case json_parse_state::escape_expect_surrogate_pair2:
|
2187
|
+
goto escape_expect_surrogate_pair2;
|
2188
|
+
case json_parse_state::escape_u5:
|
2189
|
+
goto escape_u5;
|
2190
|
+
case json_parse_state::escape_u6:
|
2191
|
+
goto escape_u6;
|
2192
|
+
case json_parse_state::escape_u7:
|
2193
|
+
goto escape_u7;
|
2194
|
+
case json_parse_state::escape_u8:
|
2195
|
+
goto escape_u8;
|
2196
|
+
default:
|
2197
|
+
JSONCONS_UNREACHABLE();
|
2198
|
+
}
|
2199
|
+
|
2200
|
+
string_u1:
|
2201
|
+
while (input_ptr_ < local_input_end)
|
2202
|
+
{
|
2203
|
+
switch (*input_ptr_)
|
2204
|
+
{
|
2205
|
+
JSONCONS_ILLEGAL_CONTROL_CHARACTER:
|
2206
|
+
{
|
2207
|
+
position_ += (input_ptr_ - sb + 1);
|
2208
|
+
more_ = err_handler_(json_errc::illegal_control_character, *this);
|
2209
|
+
if (!more_)
|
2210
|
+
{
|
2211
|
+
ec = json_errc::illegal_control_character;
|
2212
|
+
state_ = json_parse_state::string;
|
2213
|
+
return;
|
2214
|
+
}
|
2215
|
+
// recovery - skip
|
2216
|
+
string_buffer_.append(sb,input_ptr_-sb);
|
2217
|
+
++input_ptr_;
|
2218
|
+
state_ = json_parse_state::string;
|
2219
|
+
return;
|
2220
|
+
}
|
2221
|
+
case '\r':
|
2222
|
+
{
|
2223
|
+
position_ += (input_ptr_ - sb + 1);
|
2224
|
+
more_ = err_handler_(json_errc::illegal_character_in_string, *this);
|
2225
|
+
if (!more_)
|
2226
|
+
{
|
2227
|
+
ec = json_errc::illegal_character_in_string;
|
2228
|
+
state_ = json_parse_state::string;
|
2229
|
+
return;
|
2230
|
+
}
|
2231
|
+
// recovery - keep
|
2232
|
+
string_buffer_.append(sb, input_ptr_ - sb + 1);
|
2233
|
+
++input_ptr_;
|
2234
|
+
push_state(state_);
|
2235
|
+
state_ = json_parse_state::cr;
|
2236
|
+
return;
|
2237
|
+
}
|
2238
|
+
case '\n':
|
2239
|
+
{
|
2240
|
+
++line_;
|
2241
|
+
++position_;
|
2242
|
+
mark_position_ = position_;
|
2243
|
+
more_ = err_handler_(json_errc::illegal_character_in_string, *this);
|
2244
|
+
if (!more_)
|
2245
|
+
{
|
2246
|
+
ec = json_errc::illegal_character_in_string;
|
2247
|
+
state_ = json_parse_state::string;
|
2248
|
+
return;
|
2249
|
+
}
|
2250
|
+
// recovery - keep
|
2251
|
+
string_buffer_.append(sb, input_ptr_ - sb + 1);
|
2252
|
+
++input_ptr_;
|
2253
|
+
return;
|
2254
|
+
}
|
2255
|
+
case '\t':
|
2256
|
+
{
|
2257
|
+
position_ += (input_ptr_ - sb + 1);
|
2258
|
+
more_ = err_handler_(json_errc::illegal_character_in_string, *this);
|
2259
|
+
if (!more_)
|
2260
|
+
{
|
2261
|
+
ec = json_errc::illegal_character_in_string;
|
2262
|
+
state_ = json_parse_state::string;
|
2263
|
+
return;
|
2264
|
+
}
|
2265
|
+
// recovery - keep
|
2266
|
+
string_buffer_.append(sb, input_ptr_ - sb + 1);
|
2267
|
+
++input_ptr_;
|
2268
|
+
state_ = json_parse_state::string;
|
2269
|
+
return;
|
2270
|
+
}
|
2271
|
+
case '\\':
|
2272
|
+
{
|
2273
|
+
string_buffer_.append(sb,input_ptr_-sb);
|
2274
|
+
position_ += (input_ptr_ - sb + 1);
|
2275
|
+
++input_ptr_;
|
2276
|
+
goto escape;
|
2277
|
+
}
|
2278
|
+
case '\"':
|
2279
|
+
{
|
2280
|
+
position_ += (input_ptr_ - sb + 1);
|
2281
|
+
if (string_buffer_.length() == 0)
|
2282
|
+
{
|
2283
|
+
end_string_value(sb,input_ptr_-sb, visitor, ec);
|
2284
|
+
if (ec) {return;}
|
2285
|
+
}
|
2286
|
+
else
|
2287
|
+
{
|
2288
|
+
string_buffer_.append(sb,input_ptr_-sb);
|
2289
|
+
end_string_value(string_buffer_.data(),string_buffer_.length(), visitor, ec);
|
2290
|
+
if (ec) {return;}
|
2291
|
+
}
|
2292
|
+
++input_ptr_;
|
2293
|
+
return;
|
2294
|
+
}
|
2295
|
+
default:
|
2296
|
+
break;
|
2297
|
+
}
|
2298
|
+
++input_ptr_;
|
2299
|
+
}
|
2300
|
+
|
2301
|
+
// Buffer exhausted
|
2302
|
+
{
|
2303
|
+
string_buffer_.append(sb,input_ptr_-sb);
|
2304
|
+
position_ += (input_ptr_ - sb);
|
2305
|
+
state_ = json_parse_state::string;
|
2306
|
+
return;
|
2307
|
+
}
|
2308
|
+
|
2309
|
+
escape:
|
2310
|
+
if (JSONCONS_UNLIKELY(input_ptr_ >= local_input_end)) // Buffer exhausted
|
2311
|
+
{
|
2312
|
+
state_ = json_parse_state::escape;
|
2313
|
+
return;
|
2314
|
+
}
|
2315
|
+
switch (*input_ptr_)
|
2316
|
+
{
|
2317
|
+
case '\"':
|
2318
|
+
string_buffer_.push_back('\"');
|
2319
|
+
sb = ++input_ptr_;
|
2320
|
+
++position_;
|
2321
|
+
goto string_u1;
|
2322
|
+
case '\\':
|
2323
|
+
string_buffer_.push_back('\\');
|
2324
|
+
sb = ++input_ptr_;
|
2325
|
+
++position_;
|
2326
|
+
goto string_u1;
|
2327
|
+
case '/':
|
2328
|
+
string_buffer_.push_back('/');
|
2329
|
+
sb = ++input_ptr_;
|
2330
|
+
++position_;
|
2331
|
+
goto string_u1;
|
2332
|
+
case 'b':
|
2333
|
+
string_buffer_.push_back('\b');
|
2334
|
+
sb = ++input_ptr_;
|
2335
|
+
++position_;
|
2336
|
+
goto string_u1;
|
2337
|
+
case 'f':
|
2338
|
+
string_buffer_.push_back('\f');
|
2339
|
+
sb = ++input_ptr_;
|
2340
|
+
++position_;
|
2341
|
+
goto string_u1;
|
2342
|
+
case 'n':
|
2343
|
+
string_buffer_.push_back('\n');
|
2344
|
+
sb = ++input_ptr_;
|
2345
|
+
++position_;
|
2346
|
+
goto string_u1;
|
2347
|
+
case 'r':
|
2348
|
+
string_buffer_.push_back('\r');
|
2349
|
+
sb = ++input_ptr_;
|
2350
|
+
++position_;
|
2351
|
+
goto string_u1;
|
2352
|
+
case 't':
|
2353
|
+
string_buffer_.push_back('\t');
|
2354
|
+
sb = ++input_ptr_;
|
2355
|
+
++position_;
|
2356
|
+
goto string_u1;
|
2357
|
+
case 'u':
|
2358
|
+
cp_ = 0;
|
2359
|
+
++input_ptr_;
|
2360
|
+
++position_;
|
2361
|
+
goto escape_u1;
|
2362
|
+
default:
|
2363
|
+
err_handler_(json_errc::illegal_escaped_character, *this);
|
2364
|
+
ec = json_errc::illegal_escaped_character;
|
2365
|
+
more_ = false;
|
2366
|
+
state_ = json_parse_state::escape;
|
2367
|
+
return;
|
2368
|
+
}
|
2369
|
+
|
2370
|
+
escape_u1:
|
2371
|
+
if (JSONCONS_UNLIKELY(input_ptr_ >= local_input_end)) // Buffer exhausted
|
2372
|
+
{
|
2373
|
+
state_ = json_parse_state::escape_u1;
|
2374
|
+
return;
|
2375
|
+
}
|
2376
|
+
{
|
2377
|
+
cp_ = append_to_codepoint(0, *input_ptr_, ec);
|
2378
|
+
if (ec)
|
2379
|
+
{
|
2380
|
+
state_ = json_parse_state::escape_u1;
|
2381
|
+
return;
|
2382
|
+
}
|
2383
|
+
++input_ptr_;
|
2384
|
+
++position_;
|
2385
|
+
goto escape_u2;
|
2386
|
+
}
|
2387
|
+
|
2388
|
+
escape_u2:
|
2389
|
+
if (JSONCONS_UNLIKELY(input_ptr_ >= local_input_end)) // Buffer exhausted
|
2390
|
+
{
|
2391
|
+
state_ = json_parse_state::escape_u2;
|
2392
|
+
return;
|
2393
|
+
}
|
2394
|
+
{
|
2395
|
+
cp_ = append_to_codepoint(cp_, *input_ptr_, ec);
|
2396
|
+
if (ec)
|
2397
|
+
{
|
2398
|
+
state_ = json_parse_state::escape_u2;
|
2399
|
+
return;
|
2400
|
+
}
|
2401
|
+
++input_ptr_;
|
2402
|
+
++position_;
|
2403
|
+
goto escape_u3;
|
2404
|
+
}
|
2405
|
+
|
2406
|
+
escape_u3:
|
2407
|
+
if (JSONCONS_UNLIKELY(input_ptr_ >= local_input_end)) // Buffer exhausted
|
2408
|
+
{
|
2409
|
+
state_ = json_parse_state::escape_u3;
|
2410
|
+
return;
|
2411
|
+
}
|
2412
|
+
{
|
2413
|
+
cp_ = append_to_codepoint(cp_, *input_ptr_, ec);
|
2414
|
+
if (ec)
|
2415
|
+
{
|
2416
|
+
state_ = json_parse_state::escape_u3;
|
2417
|
+
return;
|
2418
|
+
}
|
2419
|
+
++input_ptr_;
|
2420
|
+
++position_;
|
2421
|
+
goto escape_u4;
|
2422
|
+
}
|
2423
|
+
|
2424
|
+
escape_u4:
|
2425
|
+
if (JSONCONS_UNLIKELY(input_ptr_ >= local_input_end)) // Buffer exhausted
|
2426
|
+
{
|
2427
|
+
state_ = json_parse_state::escape_u4;
|
2428
|
+
return;
|
2429
|
+
}
|
2430
|
+
{
|
2431
|
+
cp_ = append_to_codepoint(cp_, *input_ptr_, ec);
|
2432
|
+
if (ec)
|
2433
|
+
{
|
2434
|
+
state_ = json_parse_state::escape_u4;
|
2435
|
+
return;
|
2436
|
+
}
|
2437
|
+
if (unicode_traits::is_high_surrogate(cp_))
|
2438
|
+
{
|
2439
|
+
++input_ptr_;
|
2440
|
+
++position_;
|
2441
|
+
goto escape_expect_surrogate_pair1;
|
2442
|
+
}
|
2443
|
+
else
|
2444
|
+
{
|
2445
|
+
unicode_traits::convert(&cp_, 1, string_buffer_);
|
2446
|
+
sb = ++input_ptr_;
|
2447
|
+
++position_;
|
2448
|
+
state_ = json_parse_state::string;
|
2449
|
+
return;
|
2450
|
+
}
|
2451
|
+
}
|
2452
|
+
|
2453
|
+
escape_expect_surrogate_pair1:
|
2454
|
+
if (JSONCONS_UNLIKELY(input_ptr_ >= local_input_end)) // Buffer exhausted
|
2455
|
+
{
|
2456
|
+
state_ = json_parse_state::escape_expect_surrogate_pair1;
|
2457
|
+
return;
|
2458
|
+
}
|
2459
|
+
{
|
2460
|
+
switch (*input_ptr_)
|
2461
|
+
{
|
2462
|
+
case '\\':
|
2463
|
+
cp2_ = 0;
|
2464
|
+
++input_ptr_;
|
2465
|
+
++position_;
|
2466
|
+
goto escape_expect_surrogate_pair2;
|
2467
|
+
default:
|
2468
|
+
err_handler_(json_errc::expected_codepoint_surrogate_pair, *this);
|
2469
|
+
ec = json_errc::expected_codepoint_surrogate_pair;
|
2470
|
+
more_ = false;
|
2471
|
+
state_ = json_parse_state::escape_expect_surrogate_pair1;
|
2472
|
+
return;
|
2473
|
+
}
|
2474
|
+
}
|
2475
|
+
|
2476
|
+
escape_expect_surrogate_pair2:
|
2477
|
+
if (JSONCONS_UNLIKELY(input_ptr_ >= local_input_end)) // Buffer exhausted
|
2478
|
+
{
|
2479
|
+
state_ = json_parse_state::escape_expect_surrogate_pair2;
|
2480
|
+
return;
|
2481
|
+
}
|
2482
|
+
{
|
2483
|
+
switch (*input_ptr_)
|
2484
|
+
{
|
2485
|
+
case 'u':
|
2486
|
+
++input_ptr_;
|
2487
|
+
++position_;
|
2488
|
+
goto escape_u5;
|
2489
|
+
default:
|
2490
|
+
err_handler_(json_errc::expected_codepoint_surrogate_pair, *this);
|
2491
|
+
ec = json_errc::expected_codepoint_surrogate_pair;
|
2492
|
+
more_ = false;
|
2493
|
+
state_ = json_parse_state::escape_expect_surrogate_pair2;
|
2494
|
+
return;
|
2495
|
+
}
|
2496
|
+
}
|
2497
|
+
|
2498
|
+
escape_u5:
|
2499
|
+
if (JSONCONS_UNLIKELY(input_ptr_ >= local_input_end)) // Buffer exhausted
|
2500
|
+
{
|
2501
|
+
state_ = json_parse_state::escape_u5;
|
2502
|
+
return;
|
2503
|
+
}
|
2504
|
+
{
|
2505
|
+
cp2_ = append_to_codepoint(0, *input_ptr_, ec);
|
2506
|
+
if (ec)
|
2507
|
+
{
|
2508
|
+
state_ = json_parse_state::escape_u5;
|
2509
|
+
return;
|
2510
|
+
}
|
2511
|
+
}
|
2512
|
+
++input_ptr_;
|
2513
|
+
++position_;
|
2514
|
+
goto escape_u6;
|
2515
|
+
|
2516
|
+
escape_u6:
|
2517
|
+
if (JSONCONS_UNLIKELY(input_ptr_ >= local_input_end)) // Buffer exhausted
|
2518
|
+
{
|
2519
|
+
state_ = json_parse_state::escape_u6;
|
2520
|
+
return;
|
2521
|
+
}
|
2522
|
+
{
|
2523
|
+
cp2_ = append_to_codepoint(cp2_, *input_ptr_, ec);
|
2524
|
+
if (ec)
|
2525
|
+
{
|
2526
|
+
state_ = json_parse_state::escape_u6;
|
2527
|
+
return;
|
2528
|
+
}
|
2529
|
+
++input_ptr_;
|
2530
|
+
++position_;
|
2531
|
+
goto escape_u7;
|
2532
|
+
}
|
2533
|
+
|
2534
|
+
escape_u7:
|
2535
|
+
if (JSONCONS_UNLIKELY(input_ptr_ >= local_input_end)) // Buffer exhausted
|
2536
|
+
{
|
2537
|
+
state_ = json_parse_state::escape_u7;
|
2538
|
+
return;
|
2539
|
+
}
|
2540
|
+
{
|
2541
|
+
cp2_ = append_to_codepoint(cp2_, *input_ptr_, ec);
|
2542
|
+
if (ec)
|
2543
|
+
{
|
2544
|
+
state_ = json_parse_state::escape_u7;
|
2545
|
+
return;
|
2546
|
+
}
|
2547
|
+
++input_ptr_;
|
2548
|
+
++position_;
|
2549
|
+
goto escape_u8;
|
2550
|
+
}
|
2551
|
+
|
2552
|
+
escape_u8:
|
2553
|
+
if (JSONCONS_UNLIKELY(input_ptr_ >= local_input_end)) // Buffer exhausted
|
2554
|
+
{
|
2555
|
+
state_ = json_parse_state::escape_u8;
|
2556
|
+
return;
|
2557
|
+
}
|
2558
|
+
{
|
2559
|
+
cp2_ = append_to_codepoint(cp2_, *input_ptr_, ec);
|
2560
|
+
if (ec)
|
2561
|
+
{
|
2562
|
+
state_ = json_parse_state::escape_u8;
|
2563
|
+
return;
|
2564
|
+
}
|
2565
|
+
uint32_t cp = 0x10000 + ((cp_ & 0x3FF) << 10) + (cp2_ & 0x3FF);
|
2566
|
+
unicode_traits::convert(&cp, 1, string_buffer_);
|
2567
|
+
sb = ++input_ptr_;
|
2568
|
+
++position_;
|
2569
|
+
goto string_u1;
|
2570
|
+
}
|
2571
|
+
|
2572
|
+
JSONCONS_UNREACHABLE();
|
2573
|
+
}
|
2574
|
+
|
2575
|
+
void translate_conv_errc(unicode_traits::conv_errc result, std::error_code& ec)
|
2576
|
+
{
|
2577
|
+
switch (result)
|
2578
|
+
{
|
2579
|
+
case unicode_traits::conv_errc():
|
2580
|
+
break;
|
2581
|
+
case unicode_traits::conv_errc::over_long_utf8_sequence:
|
2582
|
+
more_ = err_handler_(json_errc::over_long_utf8_sequence, *this);
|
2583
|
+
if (!more_)
|
2584
|
+
{
|
2585
|
+
ec = json_errc::over_long_utf8_sequence;
|
2586
|
+
return;
|
2587
|
+
}
|
2588
|
+
break;
|
2589
|
+
case unicode_traits::conv_errc::unpaired_high_surrogate:
|
2590
|
+
more_ = err_handler_(json_errc::unpaired_high_surrogate, *this);
|
2591
|
+
if (!more_)
|
2592
|
+
{
|
2593
|
+
ec = json_errc::unpaired_high_surrogate;
|
2594
|
+
return;
|
2595
|
+
}
|
2596
|
+
break;
|
2597
|
+
case unicode_traits::conv_errc::expected_continuation_byte:
|
2598
|
+
more_ = err_handler_(json_errc::expected_continuation_byte, *this);
|
2599
|
+
if (!more_)
|
2600
|
+
{
|
2601
|
+
ec = json_errc::expected_continuation_byte;
|
2602
|
+
return;
|
2603
|
+
}
|
2604
|
+
break;
|
2605
|
+
case unicode_traits::conv_errc::illegal_surrogate_value:
|
2606
|
+
more_ = err_handler_(json_errc::illegal_surrogate_value, *this);
|
2607
|
+
if (!more_)
|
2608
|
+
{
|
2609
|
+
ec = json_errc::illegal_surrogate_value;
|
2610
|
+
return;
|
2611
|
+
}
|
2612
|
+
break;
|
2613
|
+
default:
|
2614
|
+
more_ = err_handler_(json_errc::illegal_codepoint, *this);
|
2615
|
+
if (!more_)
|
2616
|
+
{
|
2617
|
+
ec = json_errc::illegal_codepoint;
|
2618
|
+
return;
|
2619
|
+
}
|
2620
|
+
break;
|
2621
|
+
}
|
2622
|
+
}
|
2623
|
+
|
2624
|
+
#if !defined(JSONCONS_NO_DEPRECATED)
|
2625
|
+
|
2626
|
+
JSONCONS_DEPRECATED_MSG("Instead, use finish_parse(basic_json_visitor<char_type>&)")
|
2627
|
+
void end_parse(basic_json_visitor<char_type>& visitor)
|
2628
|
+
{
|
2629
|
+
std::error_code ec;
|
2630
|
+
finish_parse(visitor, ec);
|
2631
|
+
if (ec)
|
2632
|
+
{
|
2633
|
+
JSONCONS_THROW(ser_error(ec,line_,column()));
|
2634
|
+
}
|
2635
|
+
}
|
2636
|
+
|
2637
|
+
JSONCONS_DEPRECATED_MSG("Instead, use finish_parse(basic_json_visitor<char_type>&, std::error_code&)")
|
2638
|
+
void end_parse(basic_json_visitor<char_type>& visitor, std::error_code& ec)
|
2639
|
+
{
|
2640
|
+
while (!finished())
|
2641
|
+
{
|
2642
|
+
parse_some(visitor, ec);
|
2643
|
+
}
|
2644
|
+
}
|
2645
|
+
|
2646
|
+
JSONCONS_DEPRECATED_MSG("Instead, use update(const char_type*, std::size_t)")
|
2647
|
+
void set_source(const char_type* data, std::size_t length)
|
2648
|
+
{
|
2649
|
+
begin_input_ = data;
|
2650
|
+
end_input_ = data + length;
|
2651
|
+
input_ptr_ = begin_input_;
|
2652
|
+
}
|
2653
|
+
#endif
|
2654
|
+
|
2655
|
+
std::size_t line() const override
|
2656
|
+
{
|
2657
|
+
return line_;
|
2658
|
+
}
|
2659
|
+
|
2660
|
+
std::size_t column() const override
|
2661
|
+
{
|
2662
|
+
return (position_ - mark_position_) + 1;
|
2663
|
+
}
|
2664
|
+
|
2665
|
+
std::size_t position() const override
|
2666
|
+
{
|
2667
|
+
return saved_position_;
|
2668
|
+
}
|
2669
|
+
|
2670
|
+
std::size_t end_position() const override
|
2671
|
+
{
|
2672
|
+
return position_;
|
2673
|
+
}
|
2674
|
+
|
2675
|
+
std::size_t offset() const
|
2676
|
+
{
|
2677
|
+
return input_ptr_ - begin_input_;
|
2678
|
+
}
|
2679
|
+
private:
|
2680
|
+
|
2681
|
+
void end_integer_value(basic_json_visitor<char_type>& visitor, std::error_code& ec)
|
2682
|
+
{
|
2683
|
+
if (string_buffer_[0] == '-')
|
2684
|
+
{
|
2685
|
+
end_negative_value(visitor, ec);
|
2686
|
+
}
|
2687
|
+
else
|
2688
|
+
{
|
2689
|
+
end_positive_value(visitor, ec);
|
2690
|
+
}
|
2691
|
+
}
|
2692
|
+
|
2693
|
+
void end_negative_value(basic_json_visitor<char_type>& visitor, std::error_code& ec)
|
2694
|
+
{
|
2695
|
+
int64_t val;
|
2696
|
+
auto result = jsoncons::detail::to_integer_unchecked(string_buffer_.data(), string_buffer_.length(), val);
|
2697
|
+
if (result)
|
2698
|
+
{
|
2699
|
+
more_ = visitor.int64_value(val, semantic_tag::none, *this, ec);
|
2700
|
+
}
|
2701
|
+
else // Must be overflow
|
2702
|
+
{
|
2703
|
+
more_ = visitor.string_value(string_buffer_, semantic_tag::bigint, *this, ec);
|
2704
|
+
}
|
2705
|
+
after_value(ec);
|
2706
|
+
}
|
2707
|
+
|
2708
|
+
void end_positive_value(basic_json_visitor<char_type>& visitor, std::error_code& ec)
|
2709
|
+
{
|
2710
|
+
uint64_t val;
|
2711
|
+
auto result = jsoncons::detail::to_integer_unchecked(string_buffer_.data(), string_buffer_.length(), val);
|
2712
|
+
if (result)
|
2713
|
+
{
|
2714
|
+
more_ = visitor.uint64_value(val, semantic_tag::none, *this, ec);
|
2715
|
+
}
|
2716
|
+
else // Must be overflow
|
2717
|
+
{
|
2718
|
+
more_ = visitor.string_value(string_buffer_, semantic_tag::bigint, *this, ec);
|
2719
|
+
}
|
2720
|
+
after_value(ec);
|
2721
|
+
}
|
2722
|
+
|
2723
|
+
void end_fraction_value(basic_json_visitor<char_type>& visitor, std::error_code& ec)
|
2724
|
+
{
|
2725
|
+
JSONCONS_TRY
|
2726
|
+
{
|
2727
|
+
if (options_.lossless_number())
|
2728
|
+
{
|
2729
|
+
more_ = visitor.string_value(string_buffer_, semantic_tag::bigdec, *this, ec);
|
2730
|
+
}
|
2731
|
+
else
|
2732
|
+
{
|
2733
|
+
double d = to_double_(string_buffer_.c_str(), string_buffer_.length());
|
2734
|
+
more_ = visitor.double_value(d, semantic_tag::none, *this, ec);
|
2735
|
+
}
|
2736
|
+
}
|
2737
|
+
JSONCONS_CATCH(...)
|
2738
|
+
{
|
2739
|
+
more_ = err_handler_(json_errc::invalid_number, *this);
|
2740
|
+
if (!more_)
|
2741
|
+
{
|
2742
|
+
ec = json_errc::invalid_number;
|
2743
|
+
return;
|
2744
|
+
}
|
2745
|
+
more_ = visitor.null_value(semantic_tag::none, *this, ec); // recovery
|
2746
|
+
}
|
2747
|
+
|
2748
|
+
after_value(ec);
|
2749
|
+
}
|
2750
|
+
|
2751
|
+
void end_string_value(const char_type* s, std::size_t length, basic_json_visitor<char_type>& visitor, std::error_code& ec)
|
2752
|
+
{
|
2753
|
+
string_view_type sv(s, length);
|
2754
|
+
auto result = unicode_traits::validate(s, length);
|
2755
|
+
if (result.ec != unicode_traits::conv_errc())
|
2756
|
+
{
|
2757
|
+
translate_conv_errc(result.ec,ec);
|
2758
|
+
position_ += (result.ptr - s);
|
2759
|
+
return;
|
2760
|
+
}
|
2761
|
+
switch (parent())
|
2762
|
+
{
|
2763
|
+
case json_parse_state::member_name:
|
2764
|
+
more_ = visitor.key(sv, *this, ec);
|
2765
|
+
pop_state();
|
2766
|
+
state_ = json_parse_state::expect_colon;
|
2767
|
+
break;
|
2768
|
+
case json_parse_state::object:
|
2769
|
+
case json_parse_state::array:
|
2770
|
+
{
|
2771
|
+
auto it = std::find_if(string_double_map_.begin(), string_double_map_.end(), string_maps_to_double{ sv });
|
2772
|
+
if (it != string_double_map_.end())
|
2773
|
+
{
|
2774
|
+
more_ = visitor.double_value(it->second, semantic_tag::none, *this, ec);
|
2775
|
+
}
|
2776
|
+
else
|
2777
|
+
{
|
2778
|
+
more_ = visitor.string_value(sv, semantic_tag::none, *this, ec);
|
2779
|
+
}
|
2780
|
+
state_ = json_parse_state::expect_comma_or_end;
|
2781
|
+
break;
|
2782
|
+
}
|
2783
|
+
case json_parse_state::root:
|
2784
|
+
{
|
2785
|
+
auto it = std::find_if(string_double_map_.begin(),string_double_map_.end(),string_maps_to_double{sv});
|
2786
|
+
if (it != string_double_map_.end())
|
2787
|
+
{
|
2788
|
+
more_ = visitor.double_value(it->second, semantic_tag::none, *this, ec);
|
2789
|
+
}
|
2790
|
+
else
|
2791
|
+
{
|
2792
|
+
more_ = visitor.string_value(sv, semantic_tag::none, *this, ec);
|
2793
|
+
}
|
2794
|
+
state_ = json_parse_state::accept;
|
2795
|
+
break;
|
2796
|
+
}
|
2797
|
+
default:
|
2798
|
+
more_ = err_handler_(json_errc::syntax_error, *this);
|
2799
|
+
if (!more_)
|
2800
|
+
{
|
2801
|
+
ec = json_errc::syntax_error;
|
2802
|
+
return;
|
2803
|
+
}
|
2804
|
+
break;
|
2805
|
+
}
|
2806
|
+
}
|
2807
|
+
|
2808
|
+
void begin_member_or_element(std::error_code& ec)
|
2809
|
+
{
|
2810
|
+
switch (parent())
|
2811
|
+
{
|
2812
|
+
case json_parse_state::object:
|
2813
|
+
state_ = json_parse_state::expect_member_name;
|
2814
|
+
break;
|
2815
|
+
case json_parse_state::array:
|
2816
|
+
state_ = json_parse_state::expect_value;
|
2817
|
+
break;
|
2818
|
+
case json_parse_state::root:
|
2819
|
+
break;
|
2820
|
+
default:
|
2821
|
+
more_ = err_handler_(json_errc::syntax_error, *this);
|
2822
|
+
if (!more_)
|
2823
|
+
{
|
2824
|
+
ec = json_errc::syntax_error;
|
2825
|
+
return;
|
2826
|
+
}
|
2827
|
+
break;
|
2828
|
+
}
|
2829
|
+
}
|
2830
|
+
|
2831
|
+
void after_value(std::error_code& ec)
|
2832
|
+
{
|
2833
|
+
switch (parent())
|
2834
|
+
{
|
2835
|
+
case json_parse_state::array:
|
2836
|
+
case json_parse_state::object:
|
2837
|
+
state_ = json_parse_state::expect_comma_or_end;
|
2838
|
+
break;
|
2839
|
+
case json_parse_state::root:
|
2840
|
+
state_ = json_parse_state::accept;
|
2841
|
+
break;
|
2842
|
+
default:
|
2843
|
+
more_ = err_handler_(json_errc::syntax_error, *this);
|
2844
|
+
if (!more_)
|
2845
|
+
{
|
2846
|
+
ec = json_errc::syntax_error;
|
2847
|
+
return;
|
2848
|
+
}
|
2849
|
+
break;
|
2850
|
+
}
|
2851
|
+
}
|
2852
|
+
|
2853
|
+
void push_state(json_parse_state state)
|
2854
|
+
{
|
2855
|
+
state_stack_.push_back(state);
|
2856
|
+
}
|
2857
|
+
|
2858
|
+
json_parse_state pop_state()
|
2859
|
+
{
|
2860
|
+
JSONCONS_ASSERT(!state_stack_.empty())
|
2861
|
+
json_parse_state state = state_stack_.back();
|
2862
|
+
state_stack_.pop_back();
|
2863
|
+
return state;
|
2864
|
+
}
|
2865
|
+
|
2866
|
+
uint32_t append_to_codepoint(uint32_t cp, int c, std::error_code& ec)
|
2867
|
+
{
|
2868
|
+
cp *= 16;
|
2869
|
+
if (c >= '0' && c <= '9')
|
2870
|
+
{
|
2871
|
+
cp += c - '0';
|
2872
|
+
}
|
2873
|
+
else if (c >= 'a' && c <= 'f')
|
2874
|
+
{
|
2875
|
+
cp += c - 'a' + 10;
|
2876
|
+
}
|
2877
|
+
else if (c >= 'A' && c <= 'F')
|
2878
|
+
{
|
2879
|
+
cp += c - 'A' + 10;
|
2880
|
+
}
|
2881
|
+
else
|
2882
|
+
{
|
2883
|
+
more_ = err_handler_(json_errc::invalid_unicode_escape_sequence, *this);
|
2884
|
+
if (!more_)
|
2885
|
+
{
|
2886
|
+
ec = json_errc::invalid_unicode_escape_sequence;
|
2887
|
+
return cp;
|
2888
|
+
}
|
2889
|
+
}
|
2890
|
+
return cp;
|
2891
|
+
}
|
2892
|
+
};
|
2893
|
+
|
2894
|
+
using json_parser = basic_json_parser<char>;
|
2895
|
+
using wjson_parser = basic_json_parser<wchar_t>;
|
2896
|
+
|
2897
|
+
}
|
2898
|
+
|
2899
|
+
#endif
|
2900
|
+
|