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