/work/stage/include/boost/json/basic_parser_impl.hpp
Line | Count | Source (jump to first uncovered line) |
1 | | // |
2 | | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) |
3 | | // Copyright (c) 2020 Krystian Stasiowski (sdkrystian@gmail.com) |
4 | | // |
5 | | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
6 | | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
7 | | // |
8 | | // Official repository: https://github.com/boostorg/json |
9 | | // |
10 | | |
11 | | #ifndef BOOST_JSON_BASIC_PARSER_IMPL_HPP |
12 | | #define BOOST_JSON_BASIC_PARSER_IMPL_HPP |
13 | | |
14 | | #include <boost/json/detail/config.hpp> |
15 | | #include <boost/json/detail/literals.hpp> |
16 | | #include <boost/json/basic_parser.hpp> |
17 | | #include <boost/json/error.hpp> |
18 | | #include <boost/json/detail/buffer.hpp> |
19 | | #include <boost/json/detail/charconv/from_chars.hpp> |
20 | | #include <boost/json/detail/sse2.hpp> |
21 | | #include <boost/mp11/algorithm.hpp> |
22 | | #include <boost/mp11/integral.hpp> |
23 | | #include <cmath> |
24 | | #include <limits> |
25 | | #include <cstring> |
26 | | |
27 | | #ifdef _MSC_VER |
28 | | #pragma warning(push) |
29 | | #pragma warning(disable: 4702) // unreachable code |
30 | | #pragma warning(disable: 4127) // conditional expression is constant |
31 | | #endif |
32 | | |
33 | | /* This file must be manually included to get the |
34 | | function template definitions for basic_parser. |
35 | | */ |
36 | | |
37 | | /* Reference: |
38 | | |
39 | | https://www.json.org/ |
40 | | |
41 | | RFC 7159: The JavaScript Object Notation (JSON) Data Interchange Format |
42 | | https://tools.ietf.org/html/rfc7159 |
43 | | |
44 | | https://ampl.com/netlib/fp/dtoa.c |
45 | | */ |
46 | | |
47 | | #ifndef BOOST_JSON_DOCS |
48 | | |
49 | | namespace boost { |
50 | | namespace json { |
51 | | namespace detail { |
52 | | |
53 | | inline |
54 | | double |
55 | | pow10(int exp) noexcept |
56 | 27.2k | { |
57 | 27.2k | static double const tab[618] = { |
58 | 27.2k | 1e-308, 1e-307, 1e-306, 1e-305, 1e-304, 1e-303, 1e-302, 1e-301, |
59 | | |
60 | 27.2k | 1e-300, 1e-299, 1e-298, 1e-297, 1e-296, 1e-295, 1e-294, 1e-293, 1e-292, 1e-291, |
61 | 27.2k | 1e-290, 1e-289, 1e-288, 1e-287, 1e-286, 1e-285, 1e-284, 1e-283, 1e-282, 1e-281, |
62 | 27.2k | 1e-280, 1e-279, 1e-278, 1e-277, 1e-276, 1e-275, 1e-274, 1e-273, 1e-272, 1e-271, |
63 | 27.2k | 1e-270, 1e-269, 1e-268, 1e-267, 1e-266, 1e-265, 1e-264, 1e-263, 1e-262, 1e-261, |
64 | 27.2k | 1e-260, 1e-259, 1e-258, 1e-257, 1e-256, 1e-255, 1e-254, 1e-253, 1e-252, 1e-251, |
65 | 27.2k | 1e-250, 1e-249, 1e-248, 1e-247, 1e-246, 1e-245, 1e-244, 1e-243, 1e-242, 1e-241, |
66 | 27.2k | 1e-240, 1e-239, 1e-238, 1e-237, 1e-236, 1e-235, 1e-234, 1e-233, 1e-232, 1e-231, |
67 | 27.2k | 1e-230, 1e-229, 1e-228, 1e-227, 1e-226, 1e-225, 1e-224, 1e-223, 1e-222, 1e-221, |
68 | 27.2k | 1e-220, 1e-219, 1e-218, 1e-217, 1e-216, 1e-215, 1e-214, 1e-213, 1e-212, 1e-211, |
69 | 27.2k | 1e-210, 1e-209, 1e-208, 1e-207, 1e-206, 1e-205, 1e-204, 1e-203, 1e-202, 1e-201, |
70 | | |
71 | 27.2k | 1e-200, 1e-199, 1e-198, 1e-197, 1e-196, 1e-195, 1e-194, 1e-193, 1e-192, 1e-191, |
72 | 27.2k | 1e-190, 1e-189, 1e-188, 1e-187, 1e-186, 1e-185, 1e-184, 1e-183, 1e-182, 1e-181, |
73 | 27.2k | 1e-180, 1e-179, 1e-178, 1e-177, 1e-176, 1e-175, 1e-174, 1e-173, 1e-172, 1e-171, |
74 | 27.2k | 1e-170, 1e-169, 1e-168, 1e-167, 1e-166, 1e-165, 1e-164, 1e-163, 1e-162, 1e-161, |
75 | 27.2k | 1e-160, 1e-159, 1e-158, 1e-157, 1e-156, 1e-155, 1e-154, 1e-153, 1e-152, 1e-151, |
76 | 27.2k | 1e-150, 1e-149, 1e-148, 1e-147, 1e-146, 1e-145, 1e-144, 1e-143, 1e-142, 1e-141, |
77 | 27.2k | 1e-140, 1e-139, 1e-138, 1e-137, 1e-136, 1e-135, 1e-134, 1e-133, 1e-132, 1e-131, |
78 | 27.2k | 1e-130, 1e-129, 1e-128, 1e-127, 1e-126, 1e-125, 1e-124, 1e-123, 1e-122, 1e-121, |
79 | 27.2k | 1e-120, 1e-119, 1e-118, 1e-117, 1e-116, 1e-115, 1e-114, 1e-113, 1e-112, 1e-111, |
80 | 27.2k | 1e-110, 1e-109, 1e-108, 1e-107, 1e-106, 1e-105, 1e-104, 1e-103, 1e-102, 1e-101, |
81 | | |
82 | 27.2k | 1e-100, 1e-099, 1e-098, 1e-097, 1e-096, 1e-095, 1e-094, 1e-093, 1e-092, 1e-091, |
83 | 27.2k | 1e-090, 1e-089, 1e-088, 1e-087, 1e-086, 1e-085, 1e-084, 1e-083, 1e-082, 1e-081, |
84 | 27.2k | 1e-080, 1e-079, 1e-078, 1e-077, 1e-076, 1e-075, 1e-074, 1e-073, 1e-072, 1e-071, |
85 | 27.2k | 1e-070, 1e-069, 1e-068, 1e-067, 1e-066, 1e-065, 1e-064, 1e-063, 1e-062, 1e-061, |
86 | 27.2k | 1e-060, 1e-059, 1e-058, 1e-057, 1e-056, 1e-055, 1e-054, 1e-053, 1e-052, 1e-051, |
87 | 27.2k | 1e-050, 1e-049, 1e-048, 1e-047, 1e-046, 1e-045, 1e-044, 1e-043, 1e-042, 1e-041, |
88 | 27.2k | 1e-040, 1e-039, 1e-038, 1e-037, 1e-036, 1e-035, 1e-034, 1e-033, 1e-032, 1e-031, |
89 | 27.2k | 1e-030, 1e-029, 1e-028, 1e-027, 1e-026, 1e-025, 1e-024, 1e-023, 1e-022, 1e-021, |
90 | 27.2k | 1e-020, 1e-019, 1e-018, 1e-017, 1e-016, 1e-015, 1e-014, 1e-013, 1e-012, 1e-011, |
91 | 27.2k | 1e-010, 1e-009, 1e-008, 1e-007, 1e-006, 1e-005, 1e-004, 1e-003, 1e-002, 1e-001, |
92 | | |
93 | 27.2k | 1e+000, 1e+001, 1e+002, 1e+003, 1e+004, 1e+005, 1e+006, 1e+007, 1e+008, 1e+009, |
94 | 27.2k | 1e+010, 1e+011, 1e+012, 1e+013, 1e+014, 1e+015, 1e+016, 1e+017, 1e+018, 1e+019, |
95 | 27.2k | 1e+020, 1e+021, 1e+022, 1e+023, 1e+024, 1e+025, 1e+026, 1e+027, 1e+028, 1e+029, |
96 | 27.2k | 1e+030, 1e+031, 1e+032, 1e+033, 1e+034, 1e+035, 1e+036, 1e+037, 1e+038, 1e+039, |
97 | 27.2k | 1e+040, 1e+041, 1e+042, 1e+043, 1e+044, 1e+045, 1e+046, 1e+047, 1e+048, 1e+049, |
98 | 27.2k | 1e+050, 1e+051, 1e+052, 1e+053, 1e+054, 1e+055, 1e+056, 1e+057, 1e+058, 1e+059, |
99 | 27.2k | 1e+060, 1e+061, 1e+062, 1e+063, 1e+064, 1e+065, 1e+066, 1e+067, 1e+068, 1e+069, |
100 | 27.2k | 1e+070, 1e+071, 1e+072, 1e+073, 1e+074, 1e+075, 1e+076, 1e+077, 1e+078, 1e+079, |
101 | 27.2k | 1e+080, 1e+081, 1e+082, 1e+083, 1e+084, 1e+085, 1e+086, 1e+087, 1e+088, 1e+089, |
102 | 27.2k | 1e+090, 1e+091, 1e+092, 1e+093, 1e+094, 1e+095, 1e+096, 1e+097, 1e+098, 1e+099, |
103 | | |
104 | 27.2k | 1e+100, 1e+101, 1e+102, 1e+103, 1e+104, 1e+105, 1e+106, 1e+107, 1e+108, 1e+109, |
105 | 27.2k | 1e+110, 1e+111, 1e+112, 1e+113, 1e+114, 1e+115, 1e+116, 1e+117, 1e+118, 1e+119, |
106 | 27.2k | 1e+120, 1e+121, 1e+122, 1e+123, 1e+124, 1e+125, 1e+126, 1e+127, 1e+128, 1e+129, |
107 | 27.2k | 1e+130, 1e+131, 1e+132, 1e+133, 1e+134, 1e+135, 1e+136, 1e+137, 1e+138, 1e+139, |
108 | 27.2k | 1e+140, 1e+141, 1e+142, 1e+143, 1e+144, 1e+145, 1e+146, 1e+147, 1e+148, 1e+149, |
109 | 27.2k | 1e+150, 1e+151, 1e+152, 1e+153, 1e+154, 1e+155, 1e+156, 1e+157, 1e+158, 1e+159, |
110 | 27.2k | 1e+160, 1e+161, 1e+162, 1e+163, 1e+164, 1e+165, 1e+166, 1e+167, 1e+168, 1e+169, |
111 | 27.2k | 1e+170, 1e+171, 1e+172, 1e+173, 1e+174, 1e+175, 1e+176, 1e+177, 1e+178, 1e+179, |
112 | 27.2k | 1e+180, 1e+181, 1e+182, 1e+183, 1e+184, 1e+185, 1e+186, 1e+187, 1e+188, 1e+189, |
113 | 27.2k | 1e+190, 1e+191, 1e+192, 1e+193, 1e+194, 1e+195, 1e+196, 1e+197, 1e+198, 1e+199, |
114 | | |
115 | 27.2k | 1e+200, 1e+201, 1e+202, 1e+203, 1e+204, 1e+205, 1e+206, 1e+207, 1e+208, 1e+209, |
116 | 27.2k | 1e+210, 1e+211, 1e+212, 1e+213, 1e+214, 1e+215, 1e+216, 1e+217, 1e+218, 1e+219, |
117 | 27.2k | 1e+220, 1e+221, 1e+222, 1e+223, 1e+224, 1e+225, 1e+226, 1e+227, 1e+228, 1e+229, |
118 | 27.2k | 1e+230, 1e+231, 1e+232, 1e+233, 1e+234, 1e+235, 1e+236, 1e+237, 1e+238, 1e+239, |
119 | 27.2k | 1e+240, 1e+241, 1e+242, 1e+243, 1e+244, 1e+245, 1e+246, 1e+247, 1e+248, 1e+249, |
120 | 27.2k | 1e+250, 1e+251, 1e+252, 1e+253, 1e+254, 1e+255, 1e+256, 1e+257, 1e+258, 1e+259, |
121 | 27.2k | 1e+260, 1e+261, 1e+262, 1e+263, 1e+264, 1e+265, 1e+266, 1e+267, 1e+268, 1e+269, |
122 | 27.2k | 1e+270, 1e+271, 1e+272, 1e+273, 1e+274, 1e+275, 1e+276, 1e+277, 1e+278, 1e+279, |
123 | 27.2k | 1e+280, 1e+281, 1e+282, 1e+283, 1e+284, 1e+285, 1e+286, 1e+287, 1e+288, 1e+289, |
124 | 27.2k | 1e+290, 1e+291, 1e+292, 1e+293, 1e+294, 1e+295, 1e+296, 1e+297, 1e+298, 1e+299, |
125 | | |
126 | 27.2k | 1e+300, 1e+301, 1e+302, 1e+303, 1e+304, 1e+305, 1e+306, 1e+307, 1e+308 }; |
127 | | |
128 | 27.2k | if( exp > 308 ) |
129 | 6.69k | { |
130 | 6.69k | return std::numeric_limits<double>::infinity(); |
131 | 6.69k | } |
132 | 20.5k | else if( exp < -308 ) |
133 | 4.19k | { |
134 | | // due to the way pow10 is used by dec_to_float, |
135 | | // we can afford to return 0.0 here |
136 | 4.19k | return 0.0; |
137 | 4.19k | } |
138 | 16.3k | else |
139 | 16.3k | { |
140 | 16.3k | exp += 308; |
141 | 16.3k | BOOST_ASSERT(exp >= 0 && exp < 618); |
142 | 16.3k | return tab[exp]; |
143 | 16.3k | } |
144 | 27.2k | } |
145 | | |
146 | | inline |
147 | | double |
148 | | dec_to_float( |
149 | | std::uint64_t m, |
150 | | std::int32_t e, |
151 | | bool neg) noexcept |
152 | 27.2k | { |
153 | | // convert to double explicitly to silence warnings |
154 | 27.2k | double x = static_cast<double>(m); |
155 | 27.2k | if(neg) |
156 | 11.1k | x = -x; |
157 | | |
158 | 27.2k | if(e < -305) |
159 | 4.25k | { |
160 | 4.25k | x *= 1e-305 ; |
161 | 4.25k | e += 305; |
162 | 4.25k | } |
163 | | |
164 | 27.2k | if(e >= -22 && e < 0) |
165 | 9.30k | return x / pow10(-e); |
166 | | |
167 | 17.9k | return x * pow10(e); |
168 | 27.2k | } |
169 | | |
170 | | inline |
171 | | bool |
172 | | is_control(char c) noexcept |
173 | 0 | { |
174 | 0 | return static_cast<unsigned char>(c) < 32; |
175 | 0 | } |
176 | | |
177 | | inline |
178 | | int |
179 | | hex_digit(unsigned char c) noexcept |
180 | 701k | { |
181 | | // by Peter Dimov |
182 | 701k | if( c >= '0' && c <= '9' ) |
183 | 120k | return c - '0'; |
184 | 581k | c &= ~0x20; |
185 | 581k | if( c >= 'A' && c <= 'F' ) |
186 | 580k | return 10 + c - 'A'; |
187 | 357 | return -1; |
188 | 581k | } |
189 | | |
190 | | } // detail |
191 | | |
192 | | //---------------------------------------------------------- |
193 | | |
194 | | template< class Handler > |
195 | | template< bool StackEmpty_, char First_ > |
196 | | struct basic_parser<Handler>:: |
197 | | parse_number_helper |
198 | | { |
199 | | basic_parser* parser; |
200 | | char const* p; |
201 | | |
202 | | template< std::size_t N > |
203 | | char const* |
204 | | operator()( mp11::mp_size_t<N> ) const |
205 | 1.17M | { |
206 | 1.17M | return parser->parse_number( |
207 | 1.17M | p, |
208 | 1.17M | std::integral_constant<bool, StackEmpty_>(), |
209 | 1.17M | std::integral_constant<char, First_>(), |
210 | 1.17M | std::integral_constant< |
211 | 1.17M | number_precision, static_cast<number_precision>(N)>() ); |
212 | 1.17M | } char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_number_helper<true, (char)48>::operator()<0ul>(std::__1::integral_constant<unsigned long, 0ul>) const Line | Count | Source | 205 | 21.5k | { | 206 | 21.5k | return parser->parse_number( | 207 | 21.5k | p, | 208 | 21.5k | std::integral_constant<bool, StackEmpty_>(), | 209 | 21.5k | std::integral_constant<char, First_>(), | 210 | 21.5k | std::integral_constant< | 211 | 21.5k | number_precision, static_cast<number_precision>(N)>() ); | 212 | 21.5k | } |
Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_number_helper<true, (char)48>::operator()<1ul>(std::__1::integral_constant<unsigned long, 1ul>) const Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_number_helper<true, (char)48>::operator()<2ul>(std::__1::integral_constant<unsigned long, 2ul>) const char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_number_helper<true, (char)45>::operator()<0ul>(std::__1::integral_constant<unsigned long, 0ul>) const Line | Count | Source | 205 | 42.8k | { | 206 | 42.8k | return parser->parse_number( | 207 | 42.8k | p, | 208 | 42.8k | std::integral_constant<bool, StackEmpty_>(), | 209 | 42.8k | std::integral_constant<char, First_>(), | 210 | 42.8k | std::integral_constant< | 211 | 42.8k | number_precision, static_cast<number_precision>(N)>() ); | 212 | 42.8k | } |
Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_number_helper<true, (char)45>::operator()<1ul>(std::__1::integral_constant<unsigned long, 1ul>) const Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_number_helper<true, (char)45>::operator()<2ul>(std::__1::integral_constant<unsigned long, 2ul>) const char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_number_helper<true, (char)43>::operator()<0ul>(std::__1::integral_constant<unsigned long, 0ul>) const Line | Count | Source | 205 | 1.11M | { | 206 | 1.11M | return parser->parse_number( | 207 | 1.11M | p, | 208 | 1.11M | std::integral_constant<bool, StackEmpty_>(), | 209 | 1.11M | std::integral_constant<char, First_>(), | 210 | 1.11M | std::integral_constant< | 211 | 1.11M | number_precision, static_cast<number_precision>(N)>() ); | 212 | 1.11M | } |
Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_number_helper<true, (char)43>::operator()<1ul>(std::__1::integral_constant<unsigned long, 1ul>) const Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_number_helper<true, (char)43>::operator()<2ul>(std::__1::integral_constant<unsigned long, 2ul>) const Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_number_helper<false, (char)0>::operator()<0ul>(std::__1::integral_constant<unsigned long, 0ul>) const Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_number_helper<false, (char)0>::operator()<1ul>(std::__1::integral_constant<unsigned long, 1ul>) const Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_number_helper<false, (char)0>::operator()<2ul>(std::__1::integral_constant<unsigned long, 2ul>) const |
213 | | }; |
214 | | |
215 | | //---------------------------------------------------------- |
216 | | |
217 | | template<class Handler> |
218 | | void |
219 | | basic_parser<Handler>:: |
220 | | reserve() |
221 | 0 | { |
222 | 0 | if(BOOST_JSON_LIKELY( |
223 | 0 | ! st_.empty())) |
224 | 0 | return; |
225 | | // Reserve the largest stack we need, |
226 | | // to avoid reallocation during suspend. |
227 | 0 | st_.reserve( |
228 | 0 | sizeof(state) + // document parsing state |
229 | 0 | (sizeof(state) + |
230 | 0 | sizeof(std::size_t)) * depth() + // array and object state + size |
231 | 0 | sizeof(state) + // value parsing state |
232 | 0 | sizeof(std::size_t) + // string size |
233 | 0 | sizeof(state)); // comment state |
234 | 0 | } |
235 | | |
236 | | //---------------------------------------------------------- |
237 | | // |
238 | | // The sentinel value is returned by parse functions |
239 | | // to indicate that the parser failed, or suspended. |
240 | | // this is used as it is distinct from all valid values |
241 | | // for data in write |
242 | | |
243 | | template<class Handler> |
244 | | const char* |
245 | | basic_parser<Handler>:: |
246 | | sentinel() |
247 | 1.74M | { |
248 | | // the "+1" ensures that the returned pointer is unique even if |
249 | | // the given input buffer borders on this object |
250 | 1.74M | return reinterpret_cast< |
251 | 1.74M | const char*>(this) + 1; |
252 | 1.74M | } |
253 | | |
254 | | template<class Handler> |
255 | | bool |
256 | | basic_parser<Handler>:: |
257 | | incomplete( |
258 | | const detail::const_stream_wrapper& cs) |
259 | 1.69M | { |
260 | 1.69M | return cs.begin() == sentinel(); |
261 | 1.69M | } |
262 | | |
263 | | //---------------------------------------------------------- |
264 | | // |
265 | | // These functions are declared with the BOOST_NOINLINE |
266 | | // attribute to avoid polluting the parsers hot-path. |
267 | | // They return the canary value to indicate suspension |
268 | | // or failure. |
269 | | |
270 | | template<class Handler> |
271 | | const char* |
272 | | basic_parser<Handler>:: |
273 | | suspend_or_fail(state st) |
274 | | { |
275 | | if(BOOST_JSON_LIKELY( |
276 | | ! ec_ && more_)) |
277 | | { |
278 | | // suspend |
279 | | reserve(); |
280 | | st_.push_unchecked(st); |
281 | | } |
282 | | return sentinel(); |
283 | | } |
284 | | |
285 | | template<class Handler> |
286 | | const char* |
287 | | basic_parser<Handler>:: |
288 | | suspend_or_fail( |
289 | | state st, |
290 | | std::size_t n) |
291 | 8.66k | { |
292 | 8.66k | if(BOOST_JSON_LIKELY( |
293 | 8.66k | ! ec_ && more_)) |
294 | 0 | { |
295 | | // suspend |
296 | 0 | reserve(); |
297 | 0 | st_.push_unchecked(n); |
298 | 0 | st_.push_unchecked(st); |
299 | 0 | } |
300 | 8.66k | return sentinel(); |
301 | 8.66k | } |
302 | | |
303 | | |
304 | | template<class Handler> |
305 | | const char* |
306 | | basic_parser<Handler>:: |
307 | | fail(const char* p) noexcept |
308 | 3.18k | { |
309 | 3.18k | BOOST_ASSERT( p != sentinel() ); |
310 | 3.18k | end_ = p; |
311 | 3.18k | return sentinel(); |
312 | 3.18k | } |
313 | | |
314 | | template<class Handler> |
315 | | const char* |
316 | | basic_parser<Handler>:: |
317 | | fail( |
318 | | const char* p, |
319 | | error ev, |
320 | | source_location const* loc) noexcept |
321 | 1.83k | { |
322 | 1.83k | BOOST_ASSERT( p != sentinel() ); |
323 | 1.83k | end_ = p; |
324 | 1.83k | ec_.assign(ev, loc); |
325 | 1.83k | return sentinel(); |
326 | 1.83k | } |
327 | | |
328 | | template<class Handler> |
329 | | const char* |
330 | | basic_parser<Handler>:: |
331 | | maybe_suspend( |
332 | | const char* p, |
333 | | state st) |
334 | 229 | { |
335 | 229 | if( p != sentinel() ) |
336 | 229 | end_ = p; |
337 | 229 | if(BOOST_JSON_LIKELY(more_)) |
338 | 0 | { |
339 | | // suspend |
340 | 0 | reserve(); |
341 | 0 | st_.push_unchecked(st); |
342 | 0 | } |
343 | 229 | return sentinel(); |
344 | 229 | } |
345 | | |
346 | | template<class Handler> |
347 | | const char* |
348 | | basic_parser<Handler>:: |
349 | | maybe_suspend( |
350 | | const char* p, |
351 | | state st, |
352 | | std::size_t n) |
353 | 3.42k | { |
354 | 3.42k | BOOST_ASSERT( p != sentinel() ); |
355 | 3.42k | end_ = p; |
356 | 3.42k | if(BOOST_JSON_LIKELY(more_)) |
357 | 0 | { |
358 | | // suspend |
359 | 0 | reserve(); |
360 | 0 | st_.push_unchecked(n); |
361 | 0 | st_.push_unchecked(st); |
362 | 0 | } |
363 | 3.42k | return sentinel(); |
364 | 3.42k | } |
365 | | |
366 | | template<class Handler> |
367 | | const char* |
368 | | basic_parser<Handler>:: |
369 | | maybe_suspend( |
370 | | const char* p, |
371 | | state st, |
372 | | const number& num) |
373 | 90 | { |
374 | 90 | BOOST_ASSERT( p != sentinel() ); |
375 | 90 | end_ = p; |
376 | 90 | if(BOOST_JSON_LIKELY(more_)) |
377 | 0 | { |
378 | | // suspend |
379 | 0 | num_ = num; |
380 | 0 | reserve(); |
381 | 0 | st_.push_unchecked(st);; |
382 | 0 | } |
383 | 90 | return sentinel(); |
384 | 90 | } |
385 | | |
386 | | template<class Handler> |
387 | | const char* |
388 | | basic_parser<Handler>:: |
389 | | suspend( |
390 | | const char* p, |
391 | | state st) |
392 | 0 | { |
393 | 0 | BOOST_ASSERT( p != sentinel() ); |
394 | 0 | end_ = p; |
395 | | // suspend |
396 | 0 | reserve(); |
397 | 0 | st_.push_unchecked(st); |
398 | 0 | return sentinel(); |
399 | 0 | } |
400 | | |
401 | | template<class Handler> |
402 | | const char* |
403 | | basic_parser<Handler>:: |
404 | | suspend( |
405 | | const char* p, |
406 | | state st, |
407 | | const number& num) |
408 | 0 | { |
409 | 0 | BOOST_ASSERT( p != sentinel() ); |
410 | 0 | end_ = p; |
411 | | // suspend |
412 | 0 | num_ = num; |
413 | 0 | reserve(); |
414 | 0 | st_.push_unchecked(st); |
415 | 0 | return sentinel(); |
416 | 0 | } |
417 | | |
418 | | template<class Handler> |
419 | | template< |
420 | | bool StackEmpty_/*, |
421 | | bool Terminal_*/> |
422 | | const char* |
423 | | basic_parser<Handler>:: |
424 | | parse_comment(const char* p, |
425 | | std::integral_constant<bool, StackEmpty_> stack_empty, |
426 | | /*std::integral_constant<bool, Terminal_>*/ bool terminal) |
427 | 0 | { |
428 | 0 | detail::const_stream_wrapper cs(p, end_); |
429 | 0 | const char* start = cs.begin(); |
430 | 0 | std::size_t remain; |
431 | 0 | if(! stack_empty && ! st_.empty()) |
432 | 0 | { |
433 | 0 | state st; |
434 | 0 | st_.pop(st); |
435 | 0 | switch(st) |
436 | 0 | { |
437 | 0 | default: BOOST_JSON_UNREACHABLE(); |
438 | 0 | case state::com1: goto do_com1; |
439 | 0 | case state::com2: goto do_com2; |
440 | 0 | case state::com3: goto do_com3; |
441 | 0 | case state::com4: goto do_com4; |
442 | 0 | } |
443 | 0 | } |
444 | 0 | BOOST_ASSERT(*cs == '/'); |
445 | 0 | ++cs; |
446 | 0 | do_com1: |
447 | 0 | if(BOOST_JSON_UNLIKELY(! cs)) |
448 | 0 | return maybe_suspend(cs.begin(), state::com1); |
449 | 0 | switch(*cs) |
450 | 0 | { |
451 | 0 | default: |
452 | 0 | { |
453 | 0 | BOOST_STATIC_CONSTEXPR source_location loc |
454 | 0 | = BOOST_CURRENT_LOCATION; |
455 | 0 | return fail(cs.begin(), error::syntax, &loc); |
456 | 0 | } |
457 | 0 | case '/': |
458 | 0 | ++cs; |
459 | 0 | do_com2: |
460 | | // KRYSTIAN TODO: this is a mess, we have to fix this |
461 | 0 | remain = cs.remain(); |
462 | 0 | cs = remain ? static_cast<const char*>( |
463 | 0 | std::memchr(cs.begin(), '\n', remain)) : sentinel(); |
464 | 0 | if(! cs.begin()) |
465 | 0 | cs = sentinel(); |
466 | 0 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) |
467 | 0 | { |
468 | | // if the doc does not terminate |
469 | | // with a newline, treat it as the |
470 | | // end of the comment |
471 | 0 | if(terminal && ! more_) |
472 | 0 | { |
473 | 0 | if(BOOST_JSON_UNLIKELY(! h_.on_comment( |
474 | 0 | {start, cs.remain(start)}, ec_))) |
475 | 0 | return fail(cs.end()); |
476 | 0 | return cs.end(); |
477 | 0 | } |
478 | 0 | if(BOOST_JSON_UNLIKELY(! h_.on_comment_part( |
479 | 0 | {start, cs.remain(start)}, ec_))) |
480 | 0 | return fail(cs.end()); |
481 | 0 | if(terminal) |
482 | 0 | return suspend(cs.end(), state::com2); |
483 | 0 | return maybe_suspend(cs.end(), state::com2); |
484 | 0 | } |
485 | 0 | break; |
486 | 0 | case '*': |
487 | 0 | do |
488 | 0 | { |
489 | 0 | ++cs; |
490 | 0 | do_com3: |
491 | | // KRYSTIAN TODO: this is a mess, we have to fix this |
492 | 0 | remain = cs.remain(); |
493 | 0 | cs = remain ? static_cast<const char*>( |
494 | 0 | std::memchr(cs.begin(), '*', remain)) : sentinel(); |
495 | 0 | if(! cs.begin()) |
496 | 0 | cs = sentinel(); |
497 | | // stopped inside a c comment |
498 | 0 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) |
499 | 0 | { |
500 | 0 | if(BOOST_JSON_UNLIKELY(! h_.on_comment_part( |
501 | 0 | {start, cs.remain(start)}, ec_))) |
502 | 0 | return fail(cs.end()); |
503 | 0 | return maybe_suspend(cs.end(), state::com3); |
504 | 0 | } |
505 | | // found a asterisk, check if the next char is a slash |
506 | 0 | ++cs; |
507 | 0 | do_com4: |
508 | 0 | if(BOOST_JSON_UNLIKELY(! cs)) |
509 | 0 | { |
510 | 0 | if(BOOST_JSON_UNLIKELY(! h_.on_comment_part( |
511 | 0 | {start, cs.used(start)}, ec_))) |
512 | 0 | return fail(cs.begin()); |
513 | 0 | return maybe_suspend(cs.begin(), state::com4); |
514 | 0 | } |
515 | 0 | } |
516 | 0 | while(*cs != '/'); |
517 | 0 | } |
518 | 0 | ++cs; |
519 | 0 | if(BOOST_JSON_UNLIKELY(! h_.on_comment( |
520 | 0 | {start, cs.used(start)}, ec_))) |
521 | 0 | return fail(cs.begin()); |
522 | 0 | return cs.begin(); |
523 | 0 | } Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_comment<true>(char const*, std::__1::integral_constant<bool, true>, bool) Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_comment<false>(char const*, std::__1::integral_constant<bool, false>, bool) |
524 | | |
525 | | template<class Handler> |
526 | | template<bool StackEmpty_> |
527 | | const char* |
528 | | basic_parser<Handler>:: |
529 | | parse_document(const char* p, |
530 | | std::integral_constant<bool, StackEmpty_> stack_empty) |
531 | 8.84k | { |
532 | 8.84k | detail::const_stream_wrapper cs(p, end_); |
533 | 8.84k | if(! stack_empty && ! st_.empty()) |
534 | 0 | { |
535 | 0 | state st; |
536 | 0 | st_.peek(st); |
537 | 0 | switch(st) |
538 | 0 | { |
539 | 0 | default: goto do_doc2; |
540 | 0 | case state::doc1: |
541 | 0 | st_.pop(st); |
542 | 0 | goto do_doc1; |
543 | 0 | case state::doc3: |
544 | 0 | st_.pop(st); |
545 | 0 | goto do_doc3; |
546 | 0 | case state::com1: case state::com2: |
547 | 0 | case state::com3: case state::com4: |
548 | 0 | goto do_doc4; |
549 | 0 | } |
550 | 0 | } |
551 | 8.84k | do_doc1: |
552 | 8.84k | cs = detail::count_whitespace(cs.begin(), cs.end()); |
553 | 8.84k | if(BOOST_JSON_UNLIKELY(! cs)) |
554 | 24 | return maybe_suspend(cs.begin(), state::doc1); |
555 | 8.81k | do_doc2: |
556 | 8.81k | switch(+opt_.allow_comments | |
557 | 8.81k | (opt_.allow_trailing_commas << 1) | |
558 | 8.81k | (opt_.allow_invalid_utf8 << 2)) |
559 | 8.81k | { |
560 | | // no extensions |
561 | 8.81k | default: |
562 | 8.81k | cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::false_type(), std::false_type(), opt_.allow_invalid_utf16); |
563 | 8.81k | break; |
564 | | // comments |
565 | 0 | case 1: |
566 | 0 | cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::false_type(), std::false_type(), opt_.allow_invalid_utf16); |
567 | 0 | break; |
568 | | // trailing |
569 | 0 | case 2: |
570 | 0 | cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::true_type(), std::false_type(), opt_.allow_invalid_utf16); |
571 | 0 | break; |
572 | | // comments & trailing |
573 | 0 | case 3: |
574 | 0 | cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::true_type(), std::false_type(), opt_.allow_invalid_utf16); |
575 | 0 | break; |
576 | | // skip validation |
577 | 0 | case 4: |
578 | 0 | cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::false_type(), std::true_type(), opt_.allow_invalid_utf16); |
579 | 0 | break; |
580 | | // comments & skip validation |
581 | 0 | case 5: |
582 | 0 | cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::false_type(), std::true_type(), opt_.allow_invalid_utf16); |
583 | 0 | break; |
584 | | // trailing & skip validation |
585 | 0 | case 6: |
586 | 0 | cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::true_type(), std::true_type(), opt_.allow_invalid_utf16); |
587 | 0 | break; |
588 | | // comments & trailing & skip validation |
589 | 0 | case 7: |
590 | 0 | cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::true_type(), std::true_type(), opt_.allow_invalid_utf16); |
591 | 0 | break; |
592 | 8.81k | } |
593 | 8.81k | if(BOOST_JSON_UNLIKELY(incomplete(cs))) |
594 | | // the appropriate state has already been pushed into stack |
595 | 8.74k | return sentinel(); |
596 | 73 | do_doc3: |
597 | 73 | cs = detail::count_whitespace(cs.begin(), cs.end()); |
598 | 73 | if(BOOST_JSON_UNLIKELY(! cs)) |
599 | 20 | { |
600 | 20 | if(more_) |
601 | 0 | return suspend(cs.begin(), state::doc3); |
602 | 20 | } |
603 | 53 | else if(opt_.allow_comments && *cs == '/') |
604 | 0 | { |
605 | 0 | do_doc4: |
606 | 0 | cs = parse_comment(cs.begin(), stack_empty, std::true_type()); |
607 | 0 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) |
608 | 0 | return sentinel(); |
609 | 0 | goto do_doc3; |
610 | 0 | } |
611 | 73 | return cs.begin(); |
612 | 73 | } char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_document<true>(char const*, std::__1::integral_constant<bool, true>) Line | Count | Source | 531 | 8.84k | { | 532 | 8.84k | detail::const_stream_wrapper cs(p, end_); | 533 | 8.84k | if(! stack_empty && ! st_.empty()) | 534 | 0 | { | 535 | 0 | state st; | 536 | 0 | st_.peek(st); | 537 | 0 | switch(st) | 538 | 0 | { | 539 | 0 | default: goto do_doc2; | 540 | 0 | case state::doc1: | 541 | 0 | st_.pop(st); | 542 | 0 | goto do_doc1; | 543 | 0 | case state::doc3: | 544 | 0 | st_.pop(st); | 545 | 0 | goto do_doc3; | 546 | 0 | case state::com1: case state::com2: | 547 | 0 | case state::com3: case state::com4: | 548 | 0 | goto do_doc4; | 549 | 0 | } | 550 | 0 | } | 551 | 8.84k | do_doc1: | 552 | 8.84k | cs = detail::count_whitespace(cs.begin(), cs.end()); | 553 | 8.84k | if(BOOST_JSON_UNLIKELY(! cs)) | 554 | 24 | return maybe_suspend(cs.begin(), state::doc1); | 555 | 8.81k | do_doc2: | 556 | 8.81k | switch(+opt_.allow_comments | | 557 | 8.81k | (opt_.allow_trailing_commas << 1) | | 558 | 8.81k | (opt_.allow_invalid_utf8 << 2)) | 559 | 8.81k | { | 560 | | // no extensions | 561 | 8.81k | default: | 562 | 8.81k | cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::false_type(), std::false_type(), opt_.allow_invalid_utf16); | 563 | 8.81k | break; | 564 | | // comments | 565 | 0 | case 1: | 566 | 0 | cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::false_type(), std::false_type(), opt_.allow_invalid_utf16); | 567 | 0 | break; | 568 | | // trailing | 569 | 0 | case 2: | 570 | 0 | cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::true_type(), std::false_type(), opt_.allow_invalid_utf16); | 571 | 0 | break; | 572 | | // comments & trailing | 573 | 0 | case 3: | 574 | 0 | cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::true_type(), std::false_type(), opt_.allow_invalid_utf16); | 575 | 0 | break; | 576 | | // skip validation | 577 | 0 | case 4: | 578 | 0 | cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::false_type(), std::true_type(), opt_.allow_invalid_utf16); | 579 | 0 | break; | 580 | | // comments & skip validation | 581 | 0 | case 5: | 582 | 0 | cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::false_type(), std::true_type(), opt_.allow_invalid_utf16); | 583 | 0 | break; | 584 | | // trailing & skip validation | 585 | 0 | case 6: | 586 | 0 | cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::true_type(), std::true_type(), opt_.allow_invalid_utf16); | 587 | 0 | break; | 588 | | // comments & trailing & skip validation | 589 | 0 | case 7: | 590 | 0 | cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::true_type(), std::true_type(), opt_.allow_invalid_utf16); | 591 | 0 | break; | 592 | 8.81k | } | 593 | 8.81k | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 594 | | // the appropriate state has already been pushed into stack | 595 | 8.74k | return sentinel(); | 596 | 73 | do_doc3: | 597 | 73 | cs = detail::count_whitespace(cs.begin(), cs.end()); | 598 | 73 | if(BOOST_JSON_UNLIKELY(! cs)) | 599 | 20 | { | 600 | 20 | if(more_) | 601 | 0 | return suspend(cs.begin(), state::doc3); | 602 | 20 | } | 603 | 53 | else if(opt_.allow_comments && *cs == '/') | 604 | 0 | { | 605 | 0 | do_doc4: | 606 | 0 | cs = parse_comment(cs.begin(), stack_empty, std::true_type()); | 607 | 0 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 608 | 0 | return sentinel(); | 609 | 0 | goto do_doc3; | 610 | 0 | } | 611 | 73 | return cs.begin(); | 612 | 73 | } |
Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_document<false>(char const*, std::__1::integral_constant<bool, false>) |
613 | | |
614 | | template<class Handler> |
615 | | template< |
616 | | bool StackEmpty_, |
617 | | bool AllowComments_/*, |
618 | | bool AllowTrailing_, |
619 | | bool AllowBadUTF8_*/> |
620 | | const char* |
621 | | basic_parser<Handler>:: |
622 | | parse_value(const char* p, |
623 | | std::integral_constant<bool, StackEmpty_> stack_empty, |
624 | | std::integral_constant<bool, AllowComments_> allow_comments, |
625 | | /*std::integral_constant<bool, AllowTrailing_>*/ bool allow_trailing, |
626 | | /*std::integral_constant<bool, AllowBadUTF8_>*/ bool allow_bad_utf8, |
627 | | bool allow_bad_utf16) |
628 | 1.41M | { |
629 | 1.41M | if(stack_empty || st_.empty()) |
630 | 1.41M | { |
631 | 1.41M | loop: |
632 | 1.41M | switch(*p) |
633 | 1.41M | { |
634 | 21.5k | case '0': |
635 | 21.5k | return mp11::mp_with_index<3>( |
636 | 21.5k | static_cast<unsigned char>(opt_.numbers), |
637 | 21.5k | parse_number_helper<true, '0'>{ this, p }); |
638 | 42.8k | case '-': |
639 | 42.8k | return mp11::mp_with_index<3>( |
640 | 42.8k | static_cast<unsigned char>(opt_.numbers), |
641 | 42.8k | parse_number_helper<true, '-'>{ this, p }); |
642 | 122k | case '1': case '2': case '3': |
643 | 1.10M | case '4': case '5': case '6': |
644 | 1.11M | case '7': case '8': case '9': |
645 | 1.11M | return mp11::mp_with_index<3>( |
646 | 1.11M | static_cast<unsigned char>(opt_.numbers), |
647 | 1.11M | parse_number_helper<true, '+'>{ this, p }); |
648 | 2.96k | case 'n': |
649 | 2.96k | return parse_literal( p, detail::literals_c<detail::literals::null>() ); |
650 | 115k | case 't': |
651 | 115k | return parse_literal( p, detail::literals_c<detail::literals::true_>() ); |
652 | 1.05k | case 'f': |
653 | 1.05k | return parse_literal( p, detail::literals_c<detail::literals::false_>() ); |
654 | 1 | case 'I': |
655 | 1 | if( !opt_.allow_infinity_and_nan ) |
656 | 1 | { |
657 | 1 | BOOST_STATIC_CONSTEXPR source_location loc |
658 | 1 | = BOOST_CURRENT_LOCATION; |
659 | 1 | return fail(p, error::syntax, &loc); |
660 | 1 | } |
661 | 0 | return parse_literal( p, detail::literals_c<detail::literals::infinity>() ); |
662 | 1 | case 'N': |
663 | 1 | if( !opt_.allow_infinity_and_nan ) |
664 | 1 | { |
665 | 1 | BOOST_STATIC_CONSTEXPR source_location loc |
666 | 1 | = BOOST_CURRENT_LOCATION; |
667 | 1 | return fail(p, error::syntax, &loc); |
668 | 1 | } |
669 | 0 | return parse_literal(p, detail::literals_c<detail::literals::nan>() ); |
670 | 91.8k | case '"': |
671 | 91.8k | return parse_string(p, std::true_type(), std::false_type(), allow_bad_utf8, allow_bad_utf16); |
672 | 14.5k | case '[': |
673 | 14.5k | return parse_array(p, std::true_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); |
674 | 11.1k | case '{': |
675 | 11.1k | return parse_object(p, std::true_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); |
676 | 2 | case '/': |
677 | 2 | if(! allow_comments) |
678 | 2 | { |
679 | 2 | BOOST_STATIC_CONSTEXPR source_location loc |
680 | 2 | = BOOST_CURRENT_LOCATION; |
681 | 2 | return fail(p, error::syntax, &loc); |
682 | 2 | } |
683 | 0 | p = parse_comment(p, stack_empty, std::false_type()); |
684 | | // KRYSTIAN NOTE: incomplete takes const_stream, we either |
685 | | // can add an overload, change the existing one to take a pointer, |
686 | | // or just leave it as is |
687 | 0 | if(BOOST_JSON_UNLIKELY(p == sentinel())) |
688 | 0 | return maybe_suspend(p, state::val2); |
689 | 0 | BOOST_FALLTHROUGH; |
690 | 0 | case ' ': |
691 | 0 | case '\t': |
692 | 0 | case '\n': |
693 | 0 | case '\r': |
694 | 0 | p = detail::count_whitespace(p, end_); |
695 | 0 | if(BOOST_JSON_UNLIKELY(p == end_)) |
696 | 0 | return maybe_suspend(p, state::val1); |
697 | 0 | goto loop; |
698 | 222 | default: |
699 | 222 | { |
700 | 222 | BOOST_STATIC_CONSTEXPR source_location loc |
701 | 222 | = BOOST_CURRENT_LOCATION; |
702 | 222 | return fail(p, error::syntax, &loc); |
703 | 0 | } |
704 | 1.41M | } |
705 | 1.41M | } |
706 | 0 | return resume_value(p, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); |
707 | 1.41M | } char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_value<true, false>(char const*, std::__1::integral_constant<bool, true>, std::__1::integral_constant<bool, false>, bool, bool, bool) Line | Count | Source | 628 | 1.41M | { | 629 | 1.41M | if(stack_empty || st_.empty()) | 630 | 1.41M | { | 631 | 1.41M | loop: | 632 | 1.41M | switch(*p) | 633 | 1.41M | { | 634 | 21.5k | case '0': | 635 | 21.5k | return mp11::mp_with_index<3>( | 636 | 21.5k | static_cast<unsigned char>(opt_.numbers), | 637 | 21.5k | parse_number_helper<true, '0'>{ this, p }); | 638 | 42.8k | case '-': | 639 | 42.8k | return mp11::mp_with_index<3>( | 640 | 42.8k | static_cast<unsigned char>(opt_.numbers), | 641 | 42.8k | parse_number_helper<true, '-'>{ this, p }); | 642 | 122k | case '1': case '2': case '3': | 643 | 1.10M | case '4': case '5': case '6': | 644 | 1.11M | case '7': case '8': case '9': | 645 | 1.11M | return mp11::mp_with_index<3>( | 646 | 1.11M | static_cast<unsigned char>(opt_.numbers), | 647 | 1.11M | parse_number_helper<true, '+'>{ this, p }); | 648 | 2.96k | case 'n': | 649 | 2.96k | return parse_literal( p, detail::literals_c<detail::literals::null>() ); | 650 | 115k | case 't': | 651 | 115k | return parse_literal( p, detail::literals_c<detail::literals::true_>() ); | 652 | 1.05k | case 'f': | 653 | 1.05k | return parse_literal( p, detail::literals_c<detail::literals::false_>() ); | 654 | 1 | case 'I': | 655 | 1 | if( !opt_.allow_infinity_and_nan ) | 656 | 1 | { | 657 | 1 | BOOST_STATIC_CONSTEXPR source_location loc | 658 | 1 | = BOOST_CURRENT_LOCATION; | 659 | 1 | return fail(p, error::syntax, &loc); | 660 | 1 | } | 661 | 0 | return parse_literal( p, detail::literals_c<detail::literals::infinity>() ); | 662 | 1 | case 'N': | 663 | 1 | if( !opt_.allow_infinity_and_nan ) | 664 | 1 | { | 665 | 1 | BOOST_STATIC_CONSTEXPR source_location loc | 666 | 1 | = BOOST_CURRENT_LOCATION; | 667 | 1 | return fail(p, error::syntax, &loc); | 668 | 1 | } | 669 | 0 | return parse_literal(p, detail::literals_c<detail::literals::nan>() ); | 670 | 91.8k | case '"': | 671 | 91.8k | return parse_string(p, std::true_type(), std::false_type(), allow_bad_utf8, allow_bad_utf16); | 672 | 14.5k | case '[': | 673 | 14.5k | return parse_array(p, std::true_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | 674 | 11.1k | case '{': | 675 | 11.1k | return parse_object(p, std::true_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | 676 | 2 | case '/': | 677 | 2 | if(! allow_comments) | 678 | 2 | { | 679 | 2 | BOOST_STATIC_CONSTEXPR source_location loc | 680 | 2 | = BOOST_CURRENT_LOCATION; | 681 | 2 | return fail(p, error::syntax, &loc); | 682 | 2 | } | 683 | 0 | p = parse_comment(p, stack_empty, std::false_type()); | 684 | | // KRYSTIAN NOTE: incomplete takes const_stream, we either | 685 | | // can add an overload, change the existing one to take a pointer, | 686 | | // or just leave it as is | 687 | 0 | if(BOOST_JSON_UNLIKELY(p == sentinel())) | 688 | 0 | return maybe_suspend(p, state::val2); | 689 | 0 | BOOST_FALLTHROUGH; | 690 | 0 | case ' ': | 691 | 0 | case '\t': | 692 | 0 | case '\n': | 693 | 0 | case '\r': | 694 | 0 | p = detail::count_whitespace(p, end_); | 695 | 0 | if(BOOST_JSON_UNLIKELY(p == end_)) | 696 | 0 | return maybe_suspend(p, state::val1); | 697 | 0 | goto loop; | 698 | 222 | default: | 699 | 222 | { | 700 | 222 | BOOST_STATIC_CONSTEXPR source_location loc | 701 | 222 | = BOOST_CURRENT_LOCATION; | 702 | 222 | return fail(p, error::syntax, &loc); | 703 | 0 | } | 704 | 1.41M | } | 705 | 1.41M | } | 706 | 0 | return resume_value(p, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | 707 | 1.41M | } |
Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_value<true, true>(char const*, std::__1::integral_constant<bool, true>, std::__1::integral_constant<bool, true>, bool, bool, bool) Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_value<false, false>(char const*, std::__1::integral_constant<bool, false>, std::__1::integral_constant<bool, false>, bool, bool, bool) Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_value<false, true>(char const*, std::__1::integral_constant<bool, false>, std::__1::integral_constant<bool, true>, bool, bool, bool) |
708 | | |
709 | | template<class Handler> |
710 | | template< |
711 | | bool AllowComments_/*, |
712 | | bool AllowTrailing_, |
713 | | bool AllowBadUTF8_*/> |
714 | | const char* |
715 | | basic_parser<Handler>:: |
716 | | resume_value(const char* p, |
717 | | std::integral_constant<bool, AllowComments_> allow_comments, |
718 | | /*std::integral_constant<bool, AllowTrailing_>*/ bool allow_trailing, |
719 | | /*std::integral_constant<bool, AllowBadUTF8_>*/ bool allow_bad_utf8, |
720 | | bool allow_bad_utf16) |
721 | 0 | { |
722 | 0 | state st; |
723 | 0 | st_.peek(st); |
724 | 0 | switch(st) |
725 | 0 | { |
726 | 0 | default: BOOST_JSON_UNREACHABLE(); |
727 | 0 | case state::lit1: |
728 | 0 | return parse_literal(p, detail::literals_c<detail::literals::resume>() ); |
729 | | |
730 | 0 | case state::str1: case state::str2: |
731 | 0 | case state::str8: |
732 | 0 | return parse_string(p, std::false_type(), std::false_type(), allow_bad_utf8, allow_bad_utf16); |
733 | | |
734 | 0 | case state::arr1: case state::arr2: |
735 | 0 | case state::arr3: case state::arr4: |
736 | 0 | case state::arr5: case state::arr6: |
737 | 0 | return parse_array(p, std::false_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); |
738 | | |
739 | 0 | case state::obj1: case state::obj2: |
740 | 0 | case state::obj3: case state::obj4: |
741 | 0 | case state::obj5: case state::obj6: |
742 | 0 | case state::obj7: case state::obj8: |
743 | 0 | case state::obj9: case state::obj10: |
744 | 0 | case state::obj11: |
745 | 0 | return parse_object(p, std::false_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); |
746 | | |
747 | 0 | case state::num1: case state::num2: |
748 | 0 | case state::num3: case state::num4: |
749 | 0 | case state::num5: case state::num6: |
750 | 0 | case state::num7: case state::num8: |
751 | 0 | case state::exp1: case state::exp2: |
752 | 0 | case state::exp3: |
753 | 0 | return mp11::mp_with_index<3>( |
754 | 0 | static_cast<unsigned char>(opt_.numbers), |
755 | 0 | parse_number_helper<false, 0>{ this, p }); |
756 | | |
757 | | // KRYSTIAN NOTE: these are special cases |
758 | 0 | case state::val1: |
759 | 0 | { |
760 | 0 | st_.pop(st); |
761 | 0 | BOOST_ASSERT(st_.empty()); |
762 | 0 | p = detail::count_whitespace(p, end_); |
763 | 0 | if(BOOST_JSON_UNLIKELY(p == end_)) |
764 | 0 | return maybe_suspend(p, state::val1); |
765 | 0 | return parse_value(p, std::true_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); |
766 | 0 | } |
767 | | |
768 | 0 | case state::val2: |
769 | 0 | { |
770 | 0 | st_.pop(st); |
771 | 0 | p = parse_comment(p, std::false_type(), std::false_type()); |
772 | 0 | if(BOOST_JSON_UNLIKELY(p == sentinel())) |
773 | 0 | return maybe_suspend(p, state::val2); |
774 | 0 | if(BOOST_JSON_UNLIKELY( p == end_ )) |
775 | 0 | return maybe_suspend(p, state::val3); |
776 | 0 | BOOST_ASSERT(st_.empty()); |
777 | 0 | return parse_value(p, std::true_type(), std::true_type(), allow_trailing, allow_bad_utf8, allow_bad_utf16); |
778 | 0 | } |
779 | | |
780 | 0 | case state::val3: |
781 | 0 | { |
782 | 0 | st_.pop(st); |
783 | 0 | return parse_value(p, std::true_type(), std::true_type(), allow_trailing, allow_bad_utf8, allow_bad_utf16); |
784 | 0 | } |
785 | 0 | } |
786 | 0 | } Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::resume_value<false>(char const*, std::__1::integral_constant<bool, false>, bool, bool, bool) Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::resume_value<true>(char const*, std::__1::integral_constant<bool, true>, bool, bool, bool) |
787 | | |
788 | | template<class Handler> |
789 | | template<class Literal> |
790 | | const char* |
791 | | basic_parser<Handler>:: |
792 | | parse_literal(const char* p, Literal) |
793 | 119k | { |
794 | 119k | using L = detail::literals; |
795 | | |
796 | 119k | std::size_t cur_lit; |
797 | 119k | std::size_t offset; |
798 | | |
799 | 119k | detail::const_stream_wrapper cs(p, end_); |
800 | | BOOST_IF_CONSTEXPR( Literal::value != L::resume ) |
801 | 119k | { |
802 | 119k | constexpr std::size_t index = literal_index(Literal::value); |
803 | 119k | constexpr char const* literal = detail::literal_strings[index]; |
804 | 119k | constexpr std::size_t sz = detail::literal_sizes[index]; |
805 | | |
806 | 119k | if(BOOST_JSON_LIKELY( cs.remain() >= sz )) |
807 | 119k | { |
808 | 119k | int const cmp = std::memcmp(cs.begin(), literal, sz); |
809 | 119k | if( cmp != 0 ) |
810 | 41 | { |
811 | 41 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; |
812 | 41 | return fail(cs.begin(), error::syntax, &loc); |
813 | 41 | } |
814 | | |
815 | 119k | BOOST_IF_CONSTEXPR( Literal::value == L::null ) |
816 | 119k | { |
817 | 2.91k | if(BOOST_JSON_UNLIKELY( |
818 | 2.91k | ! h_.on_null(ec_))) |
819 | 51 | return fail(cs.begin()); |
820 | | } |
821 | 116k | else BOOST_IF_CONSTEXPR( Literal::value == L::true_ ) |
822 | 116k | { |
823 | 115k | if(BOOST_JSON_UNLIKELY( |
824 | 115k | ! h_.on_bool(true, ec_))) |
825 | 52 | return fail(cs.begin()); |
826 | | } |
827 | 974 | else BOOST_IF_CONSTEXPR( Literal::value == L::false_ ) |
828 | 974 | { |
829 | 974 | if(BOOST_JSON_UNLIKELY( |
830 | 974 | ! h_.on_bool(false, ec_))) |
831 | 4 | return fail(cs.begin()); |
832 | | } |
833 | 0 | else BOOST_IF_CONSTEXPR( Literal::value == L::infinity ) |
834 | 0 | { |
835 | 0 | if(BOOST_JSON_UNLIKELY( |
836 | 0 | ! h_.on_double( |
837 | 0 | std::numeric_limits<double>::infinity(), |
838 | 0 | string_view(literal, sz), |
839 | 0 | ec_))) |
840 | 0 | return fail(cs.begin()); |
841 | | } |
842 | 0 | else BOOST_IF_CONSTEXPR( Literal::value == L::neg_infinity ) |
843 | 0 | { |
844 | 0 | if(BOOST_JSON_UNLIKELY( |
845 | 0 | ! h_.on_double( |
846 | 0 | -std::numeric_limits<double>::infinity(), |
847 | 0 | string_view(literal, sz), |
848 | 0 | ec_))) |
849 | 0 | return fail(cs.begin()); |
850 | | } |
851 | 0 | else BOOST_IF_CONSTEXPR( Literal::value == L::nan ) |
852 | 0 | { |
853 | 0 | if(BOOST_JSON_UNLIKELY( |
854 | 0 | ! h_.on_double( |
855 | 0 | std::numeric_limits<double>::quiet_NaN(), |
856 | 0 | string_view(literal, sz), |
857 | 0 | ec_))) |
858 | 0 | return fail(cs.begin()); |
859 | | } |
860 | | else |
861 | | { |
862 | | BOOST_JSON_UNREACHABLE(); |
863 | | } |
864 | | |
865 | 119k | cs += sz; |
866 | 119k | return cs.begin(); |
867 | 119k | } |
868 | | |
869 | 142 | offset = 0; |
870 | 142 | cur_lit = index; |
871 | | } |
872 | | else |
873 | 0 | { |
874 | 0 | state st; |
875 | 0 | st_.pop(st); |
876 | 0 | BOOST_ASSERT( st == state::lit1 ); |
877 | | |
878 | 0 | cur_lit = cur_lit_; |
879 | 0 | offset = lit_offset_; |
880 | 0 | } |
881 | | |
882 | 0 | std::size_t const lit_size = detail::literal_sizes[cur_lit]; |
883 | 119k | std::size_t const size = (std::min)( lit_size - offset, cs.remain() ); |
884 | 119k | int cmp = 0; |
885 | 119k | if(BOOST_JSON_LIKELY( cs.begin() )) |
886 | 142 | cmp = std::memcmp( |
887 | 142 | cs.begin(), detail::literal_strings[cur_lit] + offset, size ); |
888 | 119k | if( cmp != 0 ) |
889 | 116 | { |
890 | 116 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; |
891 | 116 | return fail(cs.begin(), error::syntax, &loc); |
892 | 116 | } |
893 | | |
894 | 119k | if(BOOST_JSON_UNLIKELY( offset + size < lit_size )) |
895 | 26 | { |
896 | 26 | BOOST_ASSERT( cur_lit < 256 ); |
897 | 26 | cur_lit_ = static_cast<unsigned char>( cur_lit ); |
898 | 26 | BOOST_ASSERT( offset + size < 256 ); |
899 | 26 | lit_offset_ = static_cast<unsigned char>( offset + size ); |
900 | 26 | return maybe_suspend(cs.begin() + size, state::lit1); |
901 | 26 | } |
902 | | |
903 | 119k | switch( static_cast<L>(cur_lit) ) |
904 | 119k | { |
905 | 0 | case L::null: |
906 | 0 | if(BOOST_JSON_UNLIKELY( |
907 | 0 | ! h_.on_null(ec_))) |
908 | 0 | return fail(cs.begin()); |
909 | 0 | break; |
910 | 0 | case L::true_: |
911 | 0 | if(BOOST_JSON_UNLIKELY( |
912 | 0 | ! h_.on_bool(true, ec_))) |
913 | 0 | return fail(cs.begin()); |
914 | 0 | break; |
915 | 0 | case L::false_: |
916 | 0 | if(BOOST_JSON_UNLIKELY( |
917 | 0 | ! h_.on_bool(false, ec_))) |
918 | 0 | return fail(cs.begin()); |
919 | 0 | break; |
920 | 0 | case L::infinity: |
921 | 0 | if(BOOST_JSON_UNLIKELY( |
922 | 0 | ! h_.on_double( |
923 | 0 | std::numeric_limits<double>::infinity(), |
924 | 0 | string_view( |
925 | 0 | detail::literal_strings[ literal_index(L::infinity) ], |
926 | 0 | detail::literal_sizes[ literal_index(L::infinity) ]), |
927 | 0 | ec_))) |
928 | 0 | return fail(cs.begin()); |
929 | 0 | break; |
930 | 0 | case L::neg_infinity: |
931 | 0 | if(BOOST_JSON_UNLIKELY( |
932 | 0 | ! h_.on_double( |
933 | 0 | -std::numeric_limits<double>::infinity(), |
934 | 0 | string_view( |
935 | 0 | detail::literal_strings[ literal_index(L::neg_infinity) ], |
936 | 0 | detail::literal_sizes[ literal_index(L::neg_infinity) ]), |
937 | 0 | ec_))) |
938 | 0 | return fail(cs.begin()); |
939 | 0 | break; |
940 | 0 | case L::nan: |
941 | 0 | if(BOOST_JSON_UNLIKELY( |
942 | 0 | ! h_.on_double( |
943 | 0 | std::numeric_limits<double>::quiet_NaN(), |
944 | 0 | string_view( |
945 | 0 | detail::literal_strings[ literal_index(L::nan) ], |
946 | 0 | detail::literal_sizes[ literal_index(L::nan) ]), |
947 | 0 | ec_))) |
948 | 0 | return fail(cs.begin()); |
949 | 0 | break; |
950 | 0 | default: BOOST_JSON_UNREACHABLE(); |
951 | 119k | } |
952 | | |
953 | 0 | cs += size; |
954 | 0 | return cs.begin(); |
955 | 119k | } Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_literal<std::__1::integral_constant<boost::json::detail::literals, (boost::json::detail::literals)4> >(char const*, std::__1::integral_constant<boost::json::detail::literals, (boost::json::detail::literals)4>) Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_literal<std::__1::integral_constant<boost::json::detail::literals, (boost::json::detail::literals)6> >(char const*, std::__1::integral_constant<boost::json::detail::literals, (boost::json::detail::literals)6>) char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_literal<std::__1::integral_constant<boost::json::detail::literals, (boost::json::detail::literals)0> >(char const*, std::__1::integral_constant<boost::json::detail::literals, (boost::json::detail::literals)0>) Line | Count | Source | 793 | 2.96k | { | 794 | 2.96k | using L = detail::literals; | 795 | | | 796 | 2.96k | std::size_t cur_lit; | 797 | 2.96k | std::size_t offset; | 798 | | | 799 | 2.96k | detail::const_stream_wrapper cs(p, end_); | 800 | | BOOST_IF_CONSTEXPR( Literal::value != L::resume ) | 801 | 2.96k | { | 802 | 2.96k | constexpr std::size_t index = literal_index(Literal::value); | 803 | 2.96k | constexpr char const* literal = detail::literal_strings[index]; | 804 | 2.96k | constexpr std::size_t sz = detail::literal_sizes[index]; | 805 | | | 806 | 2.96k | if(BOOST_JSON_LIKELY( cs.remain() >= sz )) | 807 | 2.92k | { | 808 | 2.92k | int const cmp = std::memcmp(cs.begin(), literal, sz); | 809 | 2.92k | if( cmp != 0 ) | 810 | 6 | { | 811 | 6 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 812 | 6 | return fail(cs.begin(), error::syntax, &loc); | 813 | 6 | } | 814 | | | 815 | 2.91k | BOOST_IF_CONSTEXPR( Literal::value == L::null ) | 816 | 2.91k | { | 817 | 2.91k | if(BOOST_JSON_UNLIKELY( | 818 | 2.91k | ! h_.on_null(ec_))) | 819 | 51 | return fail(cs.begin()); | 820 | | } | 821 | | else BOOST_IF_CONSTEXPR( Literal::value == L::true_ ) | 822 | | { | 823 | | if(BOOST_JSON_UNLIKELY( | 824 | | ! h_.on_bool(true, ec_))) | 825 | | return fail(cs.begin()); | 826 | | } | 827 | | else BOOST_IF_CONSTEXPR( Literal::value == L::false_ ) | 828 | | { | 829 | | if(BOOST_JSON_UNLIKELY( | 830 | | ! h_.on_bool(false, ec_))) | 831 | | return fail(cs.begin()); | 832 | | } | 833 | | else BOOST_IF_CONSTEXPR( Literal::value == L::infinity ) | 834 | | { | 835 | | if(BOOST_JSON_UNLIKELY( | 836 | | ! h_.on_double( | 837 | | std::numeric_limits<double>::infinity(), | 838 | | string_view(literal, sz), | 839 | | ec_))) | 840 | | return fail(cs.begin()); | 841 | | } | 842 | | else BOOST_IF_CONSTEXPR( Literal::value == L::neg_infinity ) | 843 | | { | 844 | | if(BOOST_JSON_UNLIKELY( | 845 | | ! h_.on_double( | 846 | | -std::numeric_limits<double>::infinity(), | 847 | | string_view(literal, sz), | 848 | | ec_))) | 849 | | return fail(cs.begin()); | 850 | | } | 851 | | else BOOST_IF_CONSTEXPR( Literal::value == L::nan ) | 852 | | { | 853 | | if(BOOST_JSON_UNLIKELY( | 854 | | ! h_.on_double( | 855 | | std::numeric_limits<double>::quiet_NaN(), | 856 | | string_view(literal, sz), | 857 | | ec_))) | 858 | | return fail(cs.begin()); | 859 | | } | 860 | | else | 861 | | { | 862 | | BOOST_JSON_UNREACHABLE(); | 863 | | } | 864 | | | 865 | 2.86k | cs += sz; | 866 | 2.91k | return cs.begin(); | 867 | 2.92k | } | 868 | | | 869 | 45 | offset = 0; | 870 | 45 | cur_lit = index; | 871 | | } | 872 | | else | 873 | | { | 874 | | state st; | 875 | | st_.pop(st); | 876 | | BOOST_ASSERT( st == state::lit1 ); | 877 | | | 878 | | cur_lit = cur_lit_; | 879 | | offset = lit_offset_; | 880 | | } | 881 | | | 882 | 0 | std::size_t const lit_size = detail::literal_sizes[cur_lit]; | 883 | 2.96k | std::size_t const size = (std::min)( lit_size - offset, cs.remain() ); | 884 | 2.96k | int cmp = 0; | 885 | 2.96k | if(BOOST_JSON_LIKELY( cs.begin() )) | 886 | 45 | cmp = std::memcmp( | 887 | 45 | cs.begin(), detail::literal_strings[cur_lit] + offset, size ); | 888 | 2.96k | if( cmp != 0 ) | 889 | 37 | { | 890 | 37 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 891 | 37 | return fail(cs.begin(), error::syntax, &loc); | 892 | 37 | } | 893 | | | 894 | 2.93k | if(BOOST_JSON_UNLIKELY( offset + size < lit_size )) | 895 | 8 | { | 896 | 8 | BOOST_ASSERT( cur_lit < 256 ); | 897 | 8 | cur_lit_ = static_cast<unsigned char>( cur_lit ); | 898 | 8 | BOOST_ASSERT( offset + size < 256 ); | 899 | 8 | lit_offset_ = static_cast<unsigned char>( offset + size ); | 900 | 8 | return maybe_suspend(cs.begin() + size, state::lit1); | 901 | 8 | } | 902 | | | 903 | 2.92k | switch( static_cast<L>(cur_lit) ) | 904 | 2.92k | { | 905 | 0 | case L::null: | 906 | 0 | if(BOOST_JSON_UNLIKELY( | 907 | 0 | ! h_.on_null(ec_))) | 908 | 0 | return fail(cs.begin()); | 909 | 0 | break; | 910 | 0 | case L::true_: | 911 | 0 | if(BOOST_JSON_UNLIKELY( | 912 | 0 | ! h_.on_bool(true, ec_))) | 913 | 0 | return fail(cs.begin()); | 914 | 0 | break; | 915 | 0 | case L::false_: | 916 | 0 | if(BOOST_JSON_UNLIKELY( | 917 | 0 | ! h_.on_bool(false, ec_))) | 918 | 0 | return fail(cs.begin()); | 919 | 0 | break; | 920 | 0 | case L::infinity: | 921 | 0 | if(BOOST_JSON_UNLIKELY( | 922 | 0 | ! h_.on_double( | 923 | 0 | std::numeric_limits<double>::infinity(), | 924 | 0 | string_view( | 925 | 0 | detail::literal_strings[ literal_index(L::infinity) ], | 926 | 0 | detail::literal_sizes[ literal_index(L::infinity) ]), | 927 | 0 | ec_))) | 928 | 0 | return fail(cs.begin()); | 929 | 0 | break; | 930 | 0 | case L::neg_infinity: | 931 | 0 | if(BOOST_JSON_UNLIKELY( | 932 | 0 | ! h_.on_double( | 933 | 0 | -std::numeric_limits<double>::infinity(), | 934 | 0 | string_view( | 935 | 0 | detail::literal_strings[ literal_index(L::neg_infinity) ], | 936 | 0 | detail::literal_sizes[ literal_index(L::neg_infinity) ]), | 937 | 0 | ec_))) | 938 | 0 | return fail(cs.begin()); | 939 | 0 | break; | 940 | 0 | case L::nan: | 941 | 0 | if(BOOST_JSON_UNLIKELY( | 942 | 0 | ! h_.on_double( | 943 | 0 | std::numeric_limits<double>::quiet_NaN(), | 944 | 0 | string_view( | 945 | 0 | detail::literal_strings[ literal_index(L::nan) ], | 946 | 0 | detail::literal_sizes[ literal_index(L::nan) ]), | 947 | 0 | ec_))) | 948 | 0 | return fail(cs.begin()); | 949 | 0 | break; | 950 | 0 | default: BOOST_JSON_UNREACHABLE(); | 951 | 2.92k | } | 952 | | | 953 | 0 | cs += size; | 954 | 0 | return cs.begin(); | 955 | 2.92k | } |
char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_literal<std::__1::integral_constant<boost::json::detail::literals, (boost::json::detail::literals)1> >(char const*, std::__1::integral_constant<boost::json::detail::literals, (boost::json::detail::literals)1>) Line | Count | Source | 793 | 115k | { | 794 | 115k | using L = detail::literals; | 795 | | | 796 | 115k | std::size_t cur_lit; | 797 | 115k | std::size_t offset; | 798 | | | 799 | 115k | detail::const_stream_wrapper cs(p, end_); | 800 | | BOOST_IF_CONSTEXPR( Literal::value != L::resume ) | 801 | 115k | { | 802 | 115k | constexpr std::size_t index = literal_index(Literal::value); | 803 | 115k | constexpr char const* literal = detail::literal_strings[index]; | 804 | 115k | constexpr std::size_t sz = detail::literal_sizes[index]; | 805 | | | 806 | 115k | if(BOOST_JSON_LIKELY( cs.remain() >= sz )) | 807 | 115k | { | 808 | 115k | int const cmp = std::memcmp(cs.begin(), literal, sz); | 809 | 115k | if( cmp != 0 ) | 810 | 14 | { | 811 | 14 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 812 | 14 | return fail(cs.begin(), error::syntax, &loc); | 813 | 14 | } | 814 | | | 815 | 115k | BOOST_IF_CONSTEXPR( Literal::value == L::null ) | 816 | 115k | { | 817 | 115k | if(BOOST_JSON_UNLIKELY( | 818 | 115k | ! h_.on_null(ec_))) | 819 | 115k | return fail(cs.begin()); | 820 | 115k | } | 821 | 115k | else BOOST_IF_CONSTEXPR( Literal::value == L::true_ ) | 822 | 115k | { | 823 | 115k | if(BOOST_JSON_UNLIKELY( | 824 | 115k | ! h_.on_bool(true, ec_))) | 825 | 52 | return fail(cs.begin()); | 826 | | } | 827 | | else BOOST_IF_CONSTEXPR( Literal::value == L::false_ ) | 828 | | { | 829 | | if(BOOST_JSON_UNLIKELY( | 830 | | ! h_.on_bool(false, ec_))) | 831 | | return fail(cs.begin()); | 832 | | } | 833 | | else BOOST_IF_CONSTEXPR( Literal::value == L::infinity ) | 834 | | { | 835 | | if(BOOST_JSON_UNLIKELY( | 836 | | ! h_.on_double( | 837 | | std::numeric_limits<double>::infinity(), | 838 | | string_view(literal, sz), | 839 | | ec_))) | 840 | | return fail(cs.begin()); | 841 | | } | 842 | | else BOOST_IF_CONSTEXPR( Literal::value == L::neg_infinity ) | 843 | | { | 844 | | if(BOOST_JSON_UNLIKELY( | 845 | | ! h_.on_double( | 846 | | -std::numeric_limits<double>::infinity(), | 847 | | string_view(literal, sz), | 848 | | ec_))) | 849 | | return fail(cs.begin()); | 850 | | } | 851 | | else BOOST_IF_CONSTEXPR( Literal::value == L::nan ) | 852 | | { | 853 | | if(BOOST_JSON_UNLIKELY( | 854 | | ! h_.on_double( | 855 | | std::numeric_limits<double>::quiet_NaN(), | 856 | | string_view(literal, sz), | 857 | | ec_))) | 858 | | return fail(cs.begin()); | 859 | | } | 860 | | else | 861 | | { | 862 | | BOOST_JSON_UNREACHABLE(); | 863 | | } | 864 | | | 865 | 115k | cs += sz; | 866 | 115k | return cs.begin(); | 867 | 115k | } | 868 | | | 869 | 41 | offset = 0; | 870 | 41 | cur_lit = index; | 871 | | } | 872 | | else | 873 | | { | 874 | | state st; | 875 | | st_.pop(st); | 876 | | BOOST_ASSERT( st == state::lit1 ); | 877 | | | 878 | | cur_lit = cur_lit_; | 879 | | offset = lit_offset_; | 880 | | } | 881 | | | 882 | 0 | std::size_t const lit_size = detail::literal_sizes[cur_lit]; | 883 | 115k | std::size_t const size = (std::min)( lit_size - offset, cs.remain() ); | 884 | 115k | int cmp = 0; | 885 | 115k | if(BOOST_JSON_LIKELY( cs.begin() )) | 886 | 41 | cmp = std::memcmp( | 887 | 41 | cs.begin(), detail::literal_strings[cur_lit] + offset, size ); | 888 | 115k | if( cmp != 0 ) | 889 | 33 | { | 890 | 33 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 891 | 33 | return fail(cs.begin(), error::syntax, &loc); | 892 | 33 | } | 893 | | | 894 | 115k | if(BOOST_JSON_UNLIKELY( offset + size < lit_size )) | 895 | 8 | { | 896 | 8 | BOOST_ASSERT( cur_lit < 256 ); | 897 | 8 | cur_lit_ = static_cast<unsigned char>( cur_lit ); | 898 | 8 | BOOST_ASSERT( offset + size < 256 ); | 899 | 8 | lit_offset_ = static_cast<unsigned char>( offset + size ); | 900 | 8 | return maybe_suspend(cs.begin() + size, state::lit1); | 901 | 8 | } | 902 | | | 903 | 115k | switch( static_cast<L>(cur_lit) ) | 904 | 115k | { | 905 | 0 | case L::null: | 906 | 0 | if(BOOST_JSON_UNLIKELY( | 907 | 0 | ! h_.on_null(ec_))) | 908 | 0 | return fail(cs.begin()); | 909 | 0 | break; | 910 | 0 | case L::true_: | 911 | 0 | if(BOOST_JSON_UNLIKELY( | 912 | 0 | ! h_.on_bool(true, ec_))) | 913 | 0 | return fail(cs.begin()); | 914 | 0 | break; | 915 | 0 | case L::false_: | 916 | 0 | if(BOOST_JSON_UNLIKELY( | 917 | 0 | ! h_.on_bool(false, ec_))) | 918 | 0 | return fail(cs.begin()); | 919 | 0 | break; | 920 | 0 | case L::infinity: | 921 | 0 | if(BOOST_JSON_UNLIKELY( | 922 | 0 | ! h_.on_double( | 923 | 0 | std::numeric_limits<double>::infinity(), | 924 | 0 | string_view( | 925 | 0 | detail::literal_strings[ literal_index(L::infinity) ], | 926 | 0 | detail::literal_sizes[ literal_index(L::infinity) ]), | 927 | 0 | ec_))) | 928 | 0 | return fail(cs.begin()); | 929 | 0 | break; | 930 | 0 | case L::neg_infinity: | 931 | 0 | if(BOOST_JSON_UNLIKELY( | 932 | 0 | ! h_.on_double( | 933 | 0 | -std::numeric_limits<double>::infinity(), | 934 | 0 | string_view( | 935 | 0 | detail::literal_strings[ literal_index(L::neg_infinity) ], | 936 | 0 | detail::literal_sizes[ literal_index(L::neg_infinity) ]), | 937 | 0 | ec_))) | 938 | 0 | return fail(cs.begin()); | 939 | 0 | break; | 940 | 0 | case L::nan: | 941 | 0 | if(BOOST_JSON_UNLIKELY( | 942 | 0 | ! h_.on_double( | 943 | 0 | std::numeric_limits<double>::quiet_NaN(), | 944 | 0 | string_view( | 945 | 0 | detail::literal_strings[ literal_index(L::nan) ], | 946 | 0 | detail::literal_sizes[ literal_index(L::nan) ]), | 947 | 0 | ec_))) | 948 | 0 | return fail(cs.begin()); | 949 | 0 | break; | 950 | 0 | default: BOOST_JSON_UNREACHABLE(); | 951 | 115k | } | 952 | | | 953 | 0 | cs += size; | 954 | 0 | return cs.begin(); | 955 | 115k | } |
char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_literal<std::__1::integral_constant<boost::json::detail::literals, (boost::json::detail::literals)2> >(char const*, std::__1::integral_constant<boost::json::detail::literals, (boost::json::detail::literals)2>) Line | Count | Source | 793 | 1.05k | { | 794 | 1.05k | using L = detail::literals; | 795 | | | 796 | 1.05k | std::size_t cur_lit; | 797 | 1.05k | std::size_t offset; | 798 | | | 799 | 1.05k | detail::const_stream_wrapper cs(p, end_); | 800 | | BOOST_IF_CONSTEXPR( Literal::value != L::resume ) | 801 | 1.05k | { | 802 | 1.05k | constexpr std::size_t index = literal_index(Literal::value); | 803 | 1.05k | constexpr char const* literal = detail::literal_strings[index]; | 804 | 1.05k | constexpr std::size_t sz = detail::literal_sizes[index]; | 805 | | | 806 | 1.05k | if(BOOST_JSON_LIKELY( cs.remain() >= sz )) | 807 | 995 | { | 808 | 995 | int const cmp = std::memcmp(cs.begin(), literal, sz); | 809 | 995 | if( cmp != 0 ) | 810 | 21 | { | 811 | 21 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 812 | 21 | return fail(cs.begin(), error::syntax, &loc); | 813 | 21 | } | 814 | | | 815 | 974 | BOOST_IF_CONSTEXPR( Literal::value == L::null ) | 816 | 974 | { | 817 | 974 | if(BOOST_JSON_UNLIKELY( | 818 | 974 | ! h_.on_null(ec_))) | 819 | 974 | return fail(cs.begin()); | 820 | 974 | } | 821 | 974 | else BOOST_IF_CONSTEXPR( Literal::value == L::true_ ) | 822 | 974 | { | 823 | 974 | if(BOOST_JSON_UNLIKELY( | 824 | 974 | ! h_.on_bool(true, ec_))) | 825 | 974 | return fail(cs.begin()); | 826 | 974 | } | 827 | 974 | else BOOST_IF_CONSTEXPR( Literal::value == L::false_ ) | 828 | 974 | { | 829 | 974 | if(BOOST_JSON_UNLIKELY( | 830 | 974 | ! h_.on_bool(false, ec_))) | 831 | 4 | return fail(cs.begin()); | 832 | | } | 833 | | else BOOST_IF_CONSTEXPR( Literal::value == L::infinity ) | 834 | | { | 835 | | if(BOOST_JSON_UNLIKELY( | 836 | | ! h_.on_double( | 837 | | std::numeric_limits<double>::infinity(), | 838 | | string_view(literal, sz), | 839 | | ec_))) | 840 | | return fail(cs.begin()); | 841 | | } | 842 | | else BOOST_IF_CONSTEXPR( Literal::value == L::neg_infinity ) | 843 | | { | 844 | | if(BOOST_JSON_UNLIKELY( | 845 | | ! h_.on_double( | 846 | | -std::numeric_limits<double>::infinity(), | 847 | | string_view(literal, sz), | 848 | | ec_))) | 849 | | return fail(cs.begin()); | 850 | | } | 851 | | else BOOST_IF_CONSTEXPR( Literal::value == L::nan ) | 852 | | { | 853 | | if(BOOST_JSON_UNLIKELY( | 854 | | ! h_.on_double( | 855 | | std::numeric_limits<double>::quiet_NaN(), | 856 | | string_view(literal, sz), | 857 | | ec_))) | 858 | | return fail(cs.begin()); | 859 | | } | 860 | | else | 861 | | { | 862 | | BOOST_JSON_UNREACHABLE(); | 863 | | } | 864 | | | 865 | 970 | cs += sz; | 866 | 974 | return cs.begin(); | 867 | 995 | } | 868 | | | 869 | 56 | offset = 0; | 870 | 56 | cur_lit = index; | 871 | | } | 872 | | else | 873 | | { | 874 | | state st; | 875 | | st_.pop(st); | 876 | | BOOST_ASSERT( st == state::lit1 ); | 877 | | | 878 | | cur_lit = cur_lit_; | 879 | | offset = lit_offset_; | 880 | | } | 881 | | | 882 | 0 | std::size_t const lit_size = detail::literal_sizes[cur_lit]; | 883 | 1.05k | std::size_t const size = (std::min)( lit_size - offset, cs.remain() ); | 884 | 1.05k | int cmp = 0; | 885 | 1.05k | if(BOOST_JSON_LIKELY( cs.begin() )) | 886 | 56 | cmp = std::memcmp( | 887 | 56 | cs.begin(), detail::literal_strings[cur_lit] + offset, size ); | 888 | 1.05k | if( cmp != 0 ) | 889 | 46 | { | 890 | 46 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 891 | 46 | return fail(cs.begin(), error::syntax, &loc); | 892 | 46 | } | 893 | | | 894 | 1.00k | if(BOOST_JSON_UNLIKELY( offset + size < lit_size )) | 895 | 10 | { | 896 | 10 | BOOST_ASSERT( cur_lit < 256 ); | 897 | 10 | cur_lit_ = static_cast<unsigned char>( cur_lit ); | 898 | 10 | BOOST_ASSERT( offset + size < 256 ); | 899 | 10 | lit_offset_ = static_cast<unsigned char>( offset + size ); | 900 | 10 | return maybe_suspend(cs.begin() + size, state::lit1); | 901 | 10 | } | 902 | | | 903 | 995 | switch( static_cast<L>(cur_lit) ) | 904 | 995 | { | 905 | 0 | case L::null: | 906 | 0 | if(BOOST_JSON_UNLIKELY( | 907 | 0 | ! h_.on_null(ec_))) | 908 | 0 | return fail(cs.begin()); | 909 | 0 | break; | 910 | 0 | case L::true_: | 911 | 0 | if(BOOST_JSON_UNLIKELY( | 912 | 0 | ! h_.on_bool(true, ec_))) | 913 | 0 | return fail(cs.begin()); | 914 | 0 | break; | 915 | 0 | case L::false_: | 916 | 0 | if(BOOST_JSON_UNLIKELY( | 917 | 0 | ! h_.on_bool(false, ec_))) | 918 | 0 | return fail(cs.begin()); | 919 | 0 | break; | 920 | 0 | case L::infinity: | 921 | 0 | if(BOOST_JSON_UNLIKELY( | 922 | 0 | ! h_.on_double( | 923 | 0 | std::numeric_limits<double>::infinity(), | 924 | 0 | string_view( | 925 | 0 | detail::literal_strings[ literal_index(L::infinity) ], | 926 | 0 | detail::literal_sizes[ literal_index(L::infinity) ]), | 927 | 0 | ec_))) | 928 | 0 | return fail(cs.begin()); | 929 | 0 | break; | 930 | 0 | case L::neg_infinity: | 931 | 0 | if(BOOST_JSON_UNLIKELY( | 932 | 0 | ! h_.on_double( | 933 | 0 | -std::numeric_limits<double>::infinity(), | 934 | 0 | string_view( | 935 | 0 | detail::literal_strings[ literal_index(L::neg_infinity) ], | 936 | 0 | detail::literal_sizes[ literal_index(L::neg_infinity) ]), | 937 | 0 | ec_))) | 938 | 0 | return fail(cs.begin()); | 939 | 0 | break; | 940 | 0 | case L::nan: | 941 | 0 | if(BOOST_JSON_UNLIKELY( | 942 | 0 | ! h_.on_double( | 943 | 0 | std::numeric_limits<double>::quiet_NaN(), | 944 | 0 | string_view( | 945 | 0 | detail::literal_strings[ literal_index(L::nan) ], | 946 | 0 | detail::literal_sizes[ literal_index(L::nan) ]), | 947 | 0 | ec_))) | 948 | 0 | return fail(cs.begin()); | 949 | 0 | break; | 950 | 0 | default: BOOST_JSON_UNREACHABLE(); | 951 | 995 | } | 952 | | | 953 | 0 | cs += size; | 954 | 0 | return cs.begin(); | 955 | 995 | } |
Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_literal<std::__1::integral_constant<boost::json::detail::literals, (boost::json::detail::literals)3> >(char const*, std::__1::integral_constant<boost::json::detail::literals, (boost::json::detail::literals)3>) Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_literal<std::__1::integral_constant<boost::json::detail::literals, (boost::json::detail::literals)5> >(char const*, std::__1::integral_constant<boost::json::detail::literals, (boost::json::detail::literals)5>) |
956 | | |
957 | | //---------------------------------------------------------- |
958 | | |
959 | | template<class Handler> |
960 | | template<bool StackEmpty_, bool IsKey_> |
961 | | const char* |
962 | | basic_parser<Handler>:: |
963 | | parse_string(const char* p, |
964 | | std::integral_constant<bool, StackEmpty_> stack_empty, |
965 | | std::integral_constant<bool, IsKey_> is_key, |
966 | | bool allow_bad_utf8, |
967 | | bool allow_bad_utf16) |
968 | 358k | { |
969 | 358k | detail::const_stream_wrapper cs(p, end_); |
970 | 358k | std::size_t total; |
971 | 358k | char const* start; |
972 | 358k | std::size_t size; |
973 | 358k | if(! stack_empty && ! st_.empty()) |
974 | 0 | { |
975 | 0 | state st; |
976 | 0 | st_.pop(st); |
977 | 0 | st_.pop(total); |
978 | 0 | switch(st) |
979 | 0 | { |
980 | 0 | default: BOOST_JSON_UNREACHABLE(); |
981 | 0 | case state::str2: goto do_str2; |
982 | 0 | case state::str8: goto do_str8; |
983 | 0 | case state::str1: break; |
984 | 0 | } |
985 | 0 | } |
986 | 358k | else |
987 | 358k | { |
988 | 358k | BOOST_ASSERT(*cs == '\x22'); // '"' |
989 | 358k | ++cs; |
990 | 358k | total = 0; |
991 | 358k | } |
992 | | |
993 | 372k | do_str1: |
994 | 372k | start = cs.begin(); |
995 | 372k | cs = allow_bad_utf8? |
996 | 0 | detail::count_valid<true>(cs.begin(), cs.end()): |
997 | 372k | detail::count_valid<false>(cs.begin(), cs.end()); |
998 | 372k | size = cs.used(start); |
999 | 372k | if(is_key) |
1000 | 270k | { |
1001 | 270k | BOOST_ASSERT(total <= Handler::max_key_size); |
1002 | 270k | if(BOOST_JSON_UNLIKELY(size > |
1003 | 270k | Handler::max_key_size - total)) |
1004 | 0 | { |
1005 | 0 | BOOST_STATIC_CONSTEXPR source_location loc |
1006 | 0 | = BOOST_CURRENT_LOCATION; |
1007 | 0 | return fail(cs.begin(), error::key_too_large, &loc); |
1008 | 0 | } |
1009 | 270k | } |
1010 | 101k | else |
1011 | 101k | { |
1012 | 101k | BOOST_ASSERT(total <= Handler::max_string_size); |
1013 | 101k | if(BOOST_JSON_UNLIKELY(size > |
1014 | 101k | Handler::max_string_size - total)) |
1015 | 0 | { |
1016 | 0 | BOOST_STATIC_CONSTEXPR source_location loc |
1017 | 0 | = BOOST_CURRENT_LOCATION; |
1018 | 0 | return fail(cs.begin(), error::string_too_large, &loc); |
1019 | 0 | } |
1020 | 101k | } |
1021 | 372k | total += size; |
1022 | 372k | if(BOOST_JSON_UNLIKELY(! cs)) |
1023 | 532 | { |
1024 | | // call handler if the string isn't empty |
1025 | 532 | if(BOOST_JSON_LIKELY(size)) |
1026 | 366 | { |
1027 | 366 | { |
1028 | 366 | bool r = is_key? |
1029 | 124 | h_.on_key_part( {start, size}, total, ec_ ): |
1030 | 366 | h_.on_string_part( {start, size}, total, ec_ ); |
1031 | | |
1032 | 366 | if(BOOST_JSON_UNLIKELY(!r)) |
1033 | 102 | { |
1034 | 102 | return fail(cs.begin()); |
1035 | 102 | } |
1036 | 366 | } |
1037 | 366 | } |
1038 | 430 | return maybe_suspend(cs.begin(), state::str1, total); |
1039 | 532 | } |
1040 | | // at this point all valid characters have been skipped, so any remaining |
1041 | | // if there are any more characters, they are either escaped, or incomplete |
1042 | | // utf8, or invalid utf8 |
1043 | 371k | if(BOOST_JSON_UNLIKELY(*cs != '\x22')) // '"' |
1044 | 14.8k | { |
1045 | | // sequence is invalid or incomplete |
1046 | 14.8k | if((*cs & 0x80) && !allow_bad_utf8) |
1047 | 218 | { |
1048 | 218 | seq_.save(cs.begin(), cs.remain()); |
1049 | 218 | if(BOOST_JSON_UNLIKELY(seq_.complete())) |
1050 | 195 | { |
1051 | 195 | BOOST_STATIC_CONSTEXPR source_location loc |
1052 | 195 | = BOOST_CURRENT_LOCATION; |
1053 | 195 | return fail(cs.begin(), error::syntax, &loc); |
1054 | 195 | } |
1055 | 23 | if(BOOST_JSON_LIKELY(size)) |
1056 | 10 | { |
1057 | 10 | bool const r = is_key? |
1058 | 2 | h_.on_key_part( {start, size}, total, ec_ ): |
1059 | 10 | h_.on_string_part( {start, size}, total, ec_ ); |
1060 | 10 | if(BOOST_JSON_UNLIKELY( !r )) |
1061 | 4 | return fail( cs.begin() ); |
1062 | 10 | } |
1063 | 19 | return maybe_suspend(cs.end(), state::str8, total); |
1064 | 23 | } |
1065 | 14.6k | else if(BOOST_JSON_LIKELY(*cs == '\\')) |
1066 | 14.6k | { |
1067 | | // flush unescaped run from input |
1068 | 14.6k | if(BOOST_JSON_LIKELY(size)) |
1069 | 10.3k | { |
1070 | 10.3k | bool const r = is_key? |
1071 | 3.70k | h_.on_key_part( {start, size}, total, ec_ ): |
1072 | 10.3k | h_.on_string_part( {start, size}, total, ec_ ); |
1073 | 10.3k | if(BOOST_JSON_UNLIKELY( !r )) |
1074 | 3 | return fail( cs.begin() ); |
1075 | 10.3k | } |
1076 | 14.6k | do_str2: |
1077 | 14.6k | cs = parse_escaped(cs.begin(), total, stack_empty, is_key, allow_bad_utf16); |
1078 | 14.6k | if(BOOST_JSON_UNLIKELY( incomplete(cs) )) |
1079 | 785 | return suspend_or_fail(state::str2, total); |
1080 | | |
1081 | 13.8k | goto do_str1; |
1082 | 14.6k | } |
1083 | | // illegal control |
1084 | 38 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; |
1085 | 38 | return fail(cs.begin(), error::syntax, &loc); |
1086 | 14.8k | } |
1087 | | |
1088 | 356k | { |
1089 | 356k | bool r = is_key? |
1090 | 266k | h_.on_key( {start, size}, total, ec_ ): |
1091 | 356k | h_.on_string( {start, size}, total, ec_ ); |
1092 | | |
1093 | 356k | if(BOOST_JSON_UNLIKELY(!r)) |
1094 | 56 | { |
1095 | 56 | return fail(cs.begin()); |
1096 | 56 | } |
1097 | 356k | } |
1098 | | |
1099 | 356k | ++cs; |
1100 | 356k | return cs.begin(); |
1101 | | |
1102 | 0 | do_str8: |
1103 | 0 | uint8_t needed = seq_.needed(); |
1104 | 0 | if(BOOST_JSON_UNLIKELY( !seq_.append(cs.begin(), cs.remain()) )) |
1105 | 0 | return maybe_suspend(cs.end(), state::str8, total); |
1106 | 0 | if(BOOST_JSON_UNLIKELY( !seq_.valid() )) |
1107 | 0 | { |
1108 | 0 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; |
1109 | 0 | return fail(cs.begin(), error::syntax, &loc); |
1110 | 0 | } |
1111 | 0 | { |
1112 | 0 | bool const r = is_key? |
1113 | 0 | h_.on_key_part( {seq_.data(), seq_.length()}, total, ec_ ): |
1114 | 0 | h_.on_string_part( {seq_.data(), seq_.length()}, total, ec_ ); |
1115 | 0 | if(BOOST_JSON_UNLIKELY( !r )) |
1116 | 0 | return fail( cs.begin() ); |
1117 | 0 | } |
1118 | 0 | cs += needed; |
1119 | 0 | goto do_str1; |
1120 | 0 | } char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_string<true, false>(char const*, std::__1::integral_constant<bool, true>, std::__1::integral_constant<bool, false>, bool, bool) Line | Count | Source | 968 | 91.8k | { | 969 | 91.8k | detail::const_stream_wrapper cs(p, end_); | 970 | 91.8k | std::size_t total; | 971 | 91.8k | char const* start; | 972 | 91.8k | std::size_t size; | 973 | 91.8k | if(! stack_empty && ! st_.empty()) | 974 | 0 | { | 975 | 0 | state st; | 976 | 0 | st_.pop(st); | 977 | 0 | st_.pop(total); | 978 | 0 | switch(st) | 979 | 0 | { | 980 | 0 | default: BOOST_JSON_UNREACHABLE(); | 981 | 0 | case state::str2: goto do_str2; | 982 | 0 | case state::str8: goto do_str8; | 983 | 0 | case state::str1: break; | 984 | 0 | } | 985 | 0 | } | 986 | 91.8k | else | 987 | 91.8k | { | 988 | 91.8k | BOOST_ASSERT(*cs == '\x22'); // '"' | 989 | 91.8k | ++cs; | 990 | 91.8k | total = 0; | 991 | 91.8k | } | 992 | | | 993 | 101k | do_str1: | 994 | 101k | start = cs.begin(); | 995 | 101k | cs = allow_bad_utf8? | 996 | 0 | detail::count_valid<true>(cs.begin(), cs.end()): | 997 | 101k | detail::count_valid<false>(cs.begin(), cs.end()); | 998 | 101k | size = cs.used(start); | 999 | 101k | if(is_key) | 1000 | 0 | { | 1001 | 0 | BOOST_ASSERT(total <= Handler::max_key_size); | 1002 | 0 | if(BOOST_JSON_UNLIKELY(size > | 1003 | 0 | Handler::max_key_size - total)) | 1004 | 0 | { | 1005 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1006 | 0 | = BOOST_CURRENT_LOCATION; | 1007 | 0 | return fail(cs.begin(), error::key_too_large, &loc); | 1008 | 0 | } | 1009 | 0 | } | 1010 | 101k | else | 1011 | 101k | { | 1012 | 101k | BOOST_ASSERT(total <= Handler::max_string_size); | 1013 | 101k | if(BOOST_JSON_UNLIKELY(size > | 1014 | 101k | Handler::max_string_size - total)) | 1015 | 0 | { | 1016 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1017 | 0 | = BOOST_CURRENT_LOCATION; | 1018 | 0 | return fail(cs.begin(), error::string_too_large, &loc); | 1019 | 0 | } | 1020 | 101k | } | 1021 | 101k | total += size; | 1022 | 101k | if(BOOST_JSON_UNLIKELY(! cs)) | 1023 | 306 | { | 1024 | | // call handler if the string isn't empty | 1025 | 306 | if(BOOST_JSON_LIKELY(size)) | 1026 | 242 | { | 1027 | 242 | { | 1028 | 242 | bool r = is_key? | 1029 | 0 | h_.on_key_part( {start, size}, total, ec_ ): | 1030 | 242 | h_.on_string_part( {start, size}, total, ec_ ); | 1031 | | | 1032 | 242 | if(BOOST_JSON_UNLIKELY(!r)) | 1033 | 102 | { | 1034 | 102 | return fail(cs.begin()); | 1035 | 102 | } | 1036 | 242 | } | 1037 | 242 | } | 1038 | 204 | return maybe_suspend(cs.begin(), state::str1, total); | 1039 | 306 | } | 1040 | | // at this point all valid characters have been skipped, so any remaining | 1041 | | // if there are any more characters, they are either escaped, or incomplete | 1042 | | // utf8, or invalid utf8 | 1043 | 100k | if(BOOST_JSON_UNLIKELY(*cs != '\x22')) // '"' | 1044 | 10.2k | { | 1045 | | // sequence is invalid or incomplete | 1046 | 10.2k | if((*cs & 0x80) && !allow_bad_utf8) | 1047 | 97 | { | 1048 | 97 | seq_.save(cs.begin(), cs.remain()); | 1049 | 97 | if(BOOST_JSON_UNLIKELY(seq_.complete())) | 1050 | 82 | { | 1051 | 82 | BOOST_STATIC_CONSTEXPR source_location loc | 1052 | 82 | = BOOST_CURRENT_LOCATION; | 1053 | 82 | return fail(cs.begin(), error::syntax, &loc); | 1054 | 82 | } | 1055 | 15 | if(BOOST_JSON_LIKELY(size)) | 1056 | 8 | { | 1057 | 8 | bool const r = is_key? | 1058 | 0 | h_.on_key_part( {start, size}, total, ec_ ): | 1059 | 8 | h_.on_string_part( {start, size}, total, ec_ ); | 1060 | 8 | if(BOOST_JSON_UNLIKELY( !r )) | 1061 | 4 | return fail( cs.begin() ); | 1062 | 8 | } | 1063 | 11 | return maybe_suspend(cs.end(), state::str8, total); | 1064 | 15 | } | 1065 | 10.1k | else if(BOOST_JSON_LIKELY(*cs == '\\')) | 1066 | 10.0k | { | 1067 | | // flush unescaped run from input | 1068 | 10.0k | if(BOOST_JSON_LIKELY(size)) | 1069 | 6.68k | { | 1070 | 6.68k | bool const r = is_key? | 1071 | 0 | h_.on_key_part( {start, size}, total, ec_ ): | 1072 | 6.68k | h_.on_string_part( {start, size}, total, ec_ ); | 1073 | 6.68k | if(BOOST_JSON_UNLIKELY( !r )) | 1074 | 3 | return fail( cs.begin() ); | 1075 | 6.68k | } | 1076 | 10.0k | do_str2: | 1077 | 10.0k | cs = parse_escaped(cs.begin(), total, stack_empty, is_key, allow_bad_utf16); | 1078 | 10.0k | if(BOOST_JSON_UNLIKELY( incomplete(cs) )) | 1079 | 630 | return suspend_or_fail(state::str2, total); | 1080 | | | 1081 | 9.45k | goto do_str1; | 1082 | 10.0k | } | 1083 | | // illegal control | 1084 | 19 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 1085 | 19 | return fail(cs.begin(), error::syntax, &loc); | 1086 | 10.2k | } | 1087 | | | 1088 | 90.7k | { | 1089 | 90.7k | bool r = is_key? | 1090 | 0 | h_.on_key( {start, size}, total, ec_ ): | 1091 | 90.7k | h_.on_string( {start, size}, total, ec_ ); | 1092 | | | 1093 | 90.7k | if(BOOST_JSON_UNLIKELY(!r)) | 1094 | 56 | { | 1095 | 56 | return fail(cs.begin()); | 1096 | 56 | } | 1097 | 90.7k | } | 1098 | | | 1099 | 90.7k | ++cs; | 1100 | 90.7k | return cs.begin(); | 1101 | | | 1102 | 0 | do_str8: | 1103 | 0 | uint8_t needed = seq_.needed(); | 1104 | 0 | if(BOOST_JSON_UNLIKELY( !seq_.append(cs.begin(), cs.remain()) )) | 1105 | 0 | return maybe_suspend(cs.end(), state::str8, total); | 1106 | 0 | if(BOOST_JSON_UNLIKELY( !seq_.valid() )) | 1107 | 0 | { | 1108 | 0 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 1109 | 0 | return fail(cs.begin(), error::syntax, &loc); | 1110 | 0 | } | 1111 | 0 | { | 1112 | 0 | bool const r = is_key? | 1113 | 0 | h_.on_key_part( {seq_.data(), seq_.length()}, total, ec_ ): | 1114 | 0 | h_.on_string_part( {seq_.data(), seq_.length()}, total, ec_ ); | 1115 | 0 | if(BOOST_JSON_UNLIKELY( !r )) | 1116 | 0 | return fail( cs.begin() ); | 1117 | 0 | } | 1118 | 0 | cs += needed; | 1119 | 0 | goto do_str1; | 1120 | 0 | } |
char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_string<true, true>(char const*, std::__1::integral_constant<bool, true>, std::__1::integral_constant<bool, true>, bool, bool) Line | Count | Source | 968 | 266k | { | 969 | 266k | detail::const_stream_wrapper cs(p, end_); | 970 | 266k | std::size_t total; | 971 | 266k | char const* start; | 972 | 266k | std::size_t size; | 973 | 266k | if(! stack_empty && ! st_.empty()) | 974 | 0 | { | 975 | 0 | state st; | 976 | 0 | st_.pop(st); | 977 | 0 | st_.pop(total); | 978 | 0 | switch(st) | 979 | 0 | { | 980 | 0 | default: BOOST_JSON_UNREACHABLE(); | 981 | 0 | case state::str2: goto do_str2; | 982 | 0 | case state::str8: goto do_str8; | 983 | 0 | case state::str1: break; | 984 | 0 | } | 985 | 0 | } | 986 | 266k | else | 987 | 266k | { | 988 | 266k | BOOST_ASSERT(*cs == '\x22'); // '"' | 989 | 266k | ++cs; | 990 | 266k | total = 0; | 991 | 266k | } | 992 | | | 993 | 270k | do_str1: | 994 | 270k | start = cs.begin(); | 995 | 270k | cs = allow_bad_utf8? | 996 | 0 | detail::count_valid<true>(cs.begin(), cs.end()): | 997 | 270k | detail::count_valid<false>(cs.begin(), cs.end()); | 998 | 270k | size = cs.used(start); | 999 | 270k | if(is_key) | 1000 | 270k | { | 1001 | 270k | BOOST_ASSERT(total <= Handler::max_key_size); | 1002 | 270k | if(BOOST_JSON_UNLIKELY(size > | 1003 | 270k | Handler::max_key_size - total)) | 1004 | 0 | { | 1005 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1006 | 0 | = BOOST_CURRENT_LOCATION; | 1007 | 0 | return fail(cs.begin(), error::key_too_large, &loc); | 1008 | 0 | } | 1009 | 270k | } | 1010 | 0 | else | 1011 | 0 | { | 1012 | 0 | BOOST_ASSERT(total <= Handler::max_string_size); | 1013 | 0 | if(BOOST_JSON_UNLIKELY(size > | 1014 | 0 | Handler::max_string_size - total)) | 1015 | 0 | { | 1016 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1017 | 0 | = BOOST_CURRENT_LOCATION; | 1018 | 0 | return fail(cs.begin(), error::string_too_large, &loc); | 1019 | 0 | } | 1020 | 0 | } | 1021 | 270k | total += size; | 1022 | 270k | if(BOOST_JSON_UNLIKELY(! cs)) | 1023 | 226 | { | 1024 | | // call handler if the string isn't empty | 1025 | 226 | if(BOOST_JSON_LIKELY(size)) | 1026 | 124 | { | 1027 | 124 | { | 1028 | 124 | bool r = is_key? | 1029 | 124 | h_.on_key_part( {start, size}, total, ec_ ): | 1030 | 124 | h_.on_string_part( {start, size}, total, ec_ ); | 1031 | | | 1032 | 124 | if(BOOST_JSON_UNLIKELY(!r)) | 1033 | 0 | { | 1034 | 0 | return fail(cs.begin()); | 1035 | 0 | } | 1036 | 124 | } | 1037 | 124 | } | 1038 | 226 | return maybe_suspend(cs.begin(), state::str1, total); | 1039 | 226 | } | 1040 | | // at this point all valid characters have been skipped, so any remaining | 1041 | | // if there are any more characters, they are either escaped, or incomplete | 1042 | | // utf8, or invalid utf8 | 1043 | 270k | if(BOOST_JSON_UNLIKELY(*cs != '\x22')) // '"' | 1044 | 4.67k | { | 1045 | | // sequence is invalid or incomplete | 1046 | 4.67k | if((*cs & 0x80) && !allow_bad_utf8) | 1047 | 121 | { | 1048 | 121 | seq_.save(cs.begin(), cs.remain()); | 1049 | 121 | if(BOOST_JSON_UNLIKELY(seq_.complete())) | 1050 | 113 | { | 1051 | 113 | BOOST_STATIC_CONSTEXPR source_location loc | 1052 | 113 | = BOOST_CURRENT_LOCATION; | 1053 | 113 | return fail(cs.begin(), error::syntax, &loc); | 1054 | 113 | } | 1055 | 8 | if(BOOST_JSON_LIKELY(size)) | 1056 | 2 | { | 1057 | 2 | bool const r = is_key? | 1058 | 2 | h_.on_key_part( {start, size}, total, ec_ ): | 1059 | 2 | h_.on_string_part( {start, size}, total, ec_ ); | 1060 | 2 | if(BOOST_JSON_UNLIKELY( !r )) | 1061 | 0 | return fail( cs.begin() ); | 1062 | 2 | } | 1063 | 8 | return maybe_suspend(cs.end(), state::str8, total); | 1064 | 8 | } | 1065 | 4.55k | else if(BOOST_JSON_LIKELY(*cs == '\\')) | 1066 | 4.53k | { | 1067 | | // flush unescaped run from input | 1068 | 4.53k | if(BOOST_JSON_LIKELY(size)) | 1069 | 3.70k | { | 1070 | 3.70k | bool const r = is_key? | 1071 | 3.70k | h_.on_key_part( {start, size}, total, ec_ ): | 1072 | 3.70k | h_.on_string_part( {start, size}, total, ec_ ); | 1073 | 3.70k | if(BOOST_JSON_UNLIKELY( !r )) | 1074 | 0 | return fail( cs.begin() ); | 1075 | 3.70k | } | 1076 | 4.53k | do_str2: | 1077 | 4.53k | cs = parse_escaped(cs.begin(), total, stack_empty, is_key, allow_bad_utf16); | 1078 | 4.53k | if(BOOST_JSON_UNLIKELY( incomplete(cs) )) | 1079 | 155 | return suspend_or_fail(state::str2, total); | 1080 | | | 1081 | 4.38k | goto do_str1; | 1082 | 4.53k | } | 1083 | | // illegal control | 1084 | 19 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 1085 | 19 | return fail(cs.begin(), error::syntax, &loc); | 1086 | 4.67k | } | 1087 | | | 1088 | 266k | { | 1089 | 266k | bool r = is_key? | 1090 | 266k | h_.on_key( {start, size}, total, ec_ ): | 1091 | 266k | h_.on_string( {start, size}, total, ec_ ); | 1092 | | | 1093 | 266k | if(BOOST_JSON_UNLIKELY(!r)) | 1094 | 0 | { | 1095 | 0 | return fail(cs.begin()); | 1096 | 0 | } | 1097 | 266k | } | 1098 | | | 1099 | 266k | ++cs; | 1100 | 266k | return cs.begin(); | 1101 | | | 1102 | 0 | do_str8: | 1103 | 0 | uint8_t needed = seq_.needed(); | 1104 | 0 | if(BOOST_JSON_UNLIKELY( !seq_.append(cs.begin(), cs.remain()) )) | 1105 | 0 | return maybe_suspend(cs.end(), state::str8, total); | 1106 | 0 | if(BOOST_JSON_UNLIKELY( !seq_.valid() )) | 1107 | 0 | { | 1108 | 0 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 1109 | 0 | return fail(cs.begin(), error::syntax, &loc); | 1110 | 0 | } | 1111 | 0 | { | 1112 | 0 | bool const r = is_key? | 1113 | 0 | h_.on_key_part( {seq_.data(), seq_.length()}, total, ec_ ): | 1114 | 0 | h_.on_string_part( {seq_.data(), seq_.length()}, total, ec_ ); | 1115 | 0 | if(BOOST_JSON_UNLIKELY( !r )) | 1116 | 0 | return fail( cs.begin() ); | 1117 | 0 | } | 1118 | 0 | cs += needed; | 1119 | 0 | goto do_str1; | 1120 | 0 | } |
Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_string<false, false>(char const*, std::__1::integral_constant<bool, false>, std::__1::integral_constant<bool, false>, bool, bool) Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_string<false, true>(char const*, std::__1::integral_constant<bool, false>, std::__1::integral_constant<bool, true>, bool, bool) |
1121 | | |
1122 | | template<class Handler> |
1123 | | template<bool StackEmpty_> |
1124 | | const char* |
1125 | | basic_parser<Handler>:: |
1126 | | parse_escaped( |
1127 | | const char* p, |
1128 | | std::size_t& total, |
1129 | | std::integral_constant<bool, StackEmpty_> stack_empty, |
1130 | | bool is_key, |
1131 | | bool allow_bad_utf16) |
1132 | 14.6k | { |
1133 | 14.6k | constexpr unsigned urc = 0xFFFD; // Unicode replacement character |
1134 | 14.6k | auto const ev_too_large = is_key? |
1135 | 10.0k | error::key_too_large : error::string_too_large; |
1136 | 14.6k | auto const max_size = is_key? |
1137 | 10.0k | Handler::max_key_size : Handler::max_string_size; |
1138 | 14.6k | int digit; |
1139 | | |
1140 | | //--------------------------------------------------------------- |
1141 | | // |
1142 | | // To handle escapes, a local temporary buffer accumulates |
1143 | | // the unescaped result. The algorithm attempts to fill the |
1144 | | // buffer to capacity before invoking the handler. |
1145 | | // In some cases the temporary buffer needs to be flushed |
1146 | | // before it is full: |
1147 | | // * When the closing double quote is seen |
1148 | | // * When there in no more input (and more is expected later) |
1149 | | // A goal of the algorithm is to call the handler as few times |
1150 | | // as possible. Thus, when the first escape is encountered, |
1151 | | // the algorithm attempts to fill the temporary buffer first. |
1152 | | // |
1153 | 14.6k | detail::buffer<BOOST_JSON_STACK_BUFFER_SIZE> temp; |
1154 | | |
1155 | | // Unescaped JSON is never larger than its escaped version. |
1156 | | // To efficiently process only what will fit in the temporary buffer, |
1157 | | // the size of the input stream is temporarily "clipped" to the size |
1158 | | // of the temporary buffer. |
1159 | | // handle escaped character |
1160 | 14.6k | detail::clipped_const_stream cs(p, end_); |
1161 | 14.6k | cs.clip(temp.max_size()); |
1162 | | |
1163 | 14.6k | if(! stack_empty && ! st_.empty()) |
1164 | 0 | { |
1165 | 0 | state st; |
1166 | 0 | st_.pop(st); |
1167 | 0 | switch(st) |
1168 | 0 | { |
1169 | 0 | default: BOOST_JSON_UNREACHABLE(); |
1170 | 0 | case state::str3: goto do_str3; |
1171 | 0 | case state::str4: goto do_str4; |
1172 | 0 | case state::str5: goto do_str5; |
1173 | 0 | case state::str6: goto do_str6; |
1174 | 0 | case state::str7: goto do_str7; |
1175 | 0 | case state::sur1: goto do_sur1; |
1176 | 0 | case state::sur2: goto do_sur2; |
1177 | 0 | case state::sur3: goto do_sur3; |
1178 | 0 | case state::sur4: goto do_sur4; |
1179 | 0 | case state::sur5: goto do_sur5; |
1180 | 0 | case state::sur6: goto do_sur6; |
1181 | 0 | } |
1182 | 0 | } |
1183 | | |
1184 | 4.42M | while(true) |
1185 | 4.42M | { |
1186 | 4.42M | BOOST_ASSERT( temp.capacity() ); |
1187 | 4.42M | BOOST_ASSERT(*cs == '\\'); |
1188 | 4.42M | ++cs; |
1189 | 4.42M | do_str3: |
1190 | 4.42M | if(BOOST_JSON_UNLIKELY(! cs)) |
1191 | 712 | { |
1192 | 712 | if(BOOST_JSON_LIKELY(! temp.empty())) |
1193 | 673 | { |
1194 | 673 | BOOST_ASSERT(total <= max_size); |
1195 | 673 | if(BOOST_JSON_UNLIKELY( |
1196 | 673 | temp.size() > max_size - total)) |
1197 | 0 | { |
1198 | 0 | BOOST_STATIC_CONSTEXPR source_location loc |
1199 | 0 | = BOOST_CURRENT_LOCATION; |
1200 | 0 | return fail(cs.begin(), ev_too_large, &loc); |
1201 | 0 | } |
1202 | 673 | total += temp.size(); |
1203 | 673 | { |
1204 | 673 | bool r = is_key |
1205 | 673 | ? h_.on_key_part(temp.get(), total, ec_) |
1206 | 673 | : h_.on_string_part(temp.get(), total, ec_); |
1207 | | |
1208 | 673 | if(BOOST_JSON_UNLIKELY(!r)) |
1209 | 13 | { |
1210 | 13 | return fail(cs.begin()); |
1211 | 13 | } |
1212 | 673 | } |
1213 | 660 | temp.clear(); |
1214 | 660 | } |
1215 | 699 | cs.clip(temp.max_size()); |
1216 | 699 | if(BOOST_JSON_UNLIKELY(! cs)) |
1217 | 84 | return maybe_suspend(cs.begin(), state::str3); |
1218 | 699 | } |
1219 | 4.42M | switch(*cs) |
1220 | 4.42M | { |
1221 | 41 | default: |
1222 | 41 | { |
1223 | 41 | BOOST_STATIC_CONSTEXPR source_location loc |
1224 | 41 | = BOOST_CURRENT_LOCATION; |
1225 | 41 | return fail(cs.begin(), error::syntax, &loc); |
1226 | 0 | } |
1227 | 2.86k | case '\x22': // '"' |
1228 | 2.86k | temp.push_back('\x22'); |
1229 | 2.86k | ++cs; |
1230 | 2.86k | break; |
1231 | 4.31M | case '\\': |
1232 | 4.31M | temp.push_back('\\'); |
1233 | 4.31M | ++cs; |
1234 | 4.31M | break; |
1235 | 3.69k | case '/': |
1236 | 3.69k | temp.push_back('/'); |
1237 | 3.69k | ++cs; |
1238 | 3.69k | break; |
1239 | 960 | case 'b': |
1240 | 960 | temp.push_back('\x08'); |
1241 | 960 | ++cs; |
1242 | 960 | break; |
1243 | 2.43k | case 'f': |
1244 | 2.43k | temp.push_back('\x0c'); |
1245 | 2.43k | ++cs; |
1246 | 2.43k | break; |
1247 | 669 | case 'n': |
1248 | 669 | temp.push_back('\x0a'); |
1249 | 669 | ++cs; |
1250 | 669 | break; |
1251 | 2.38k | case 'r': |
1252 | 2.38k | temp.push_back('\x0d'); |
1253 | 2.38k | ++cs; |
1254 | 2.38k | break; |
1255 | 1.07k | case 't': |
1256 | 1.07k | temp.push_back('\x09'); |
1257 | 1.07k | ++cs; |
1258 | 1.07k | break; |
1259 | 91.8k | case 'u': |
1260 | | // utf16 escape |
1261 | | // |
1262 | | // fast path only when the buffer |
1263 | | // is large enough for 2 surrogates |
1264 | 91.8k | if(BOOST_JSON_LIKELY(cs.remain() > 10)) |
1265 | 90.1k | { |
1266 | | // KRYSTIAN TODO: this could be done |
1267 | | // with fewer instructions |
1268 | 90.1k | digit = detail::load_little_endian<4>( |
1269 | 90.1k | cs.begin() + 1); |
1270 | 90.1k | int d4 = detail::hex_digit(static_cast< |
1271 | 90.1k | unsigned char>(digit >> 24)); |
1272 | 90.1k | int d3 = detail::hex_digit(static_cast< |
1273 | 90.1k | unsigned char>(digit >> 16)); |
1274 | 90.1k | int d2 = detail::hex_digit(static_cast< |
1275 | 90.1k | unsigned char>(digit >> 8)); |
1276 | 90.1k | int d1 = detail::hex_digit(static_cast< |
1277 | 90.1k | unsigned char>(digit)); |
1278 | 90.1k | if(BOOST_JSON_UNLIKELY( |
1279 | 90.1k | (d1 | d2 | d3 | d4) == -1)) |
1280 | 53 | { |
1281 | 53 | if(d1 != -1) |
1282 | 15 | ++cs; |
1283 | 53 | if(d2 != -1) |
1284 | 17 | ++cs; |
1285 | 53 | if(d3 != -1) |
1286 | 12 | ++cs; |
1287 | 53 | BOOST_STATIC_CONSTEXPR source_location loc |
1288 | 53 | = BOOST_CURRENT_LOCATION; |
1289 | 53 | return fail(cs.begin(), error::expected_hex_digit, &loc); |
1290 | 53 | } |
1291 | | // 32 bit unicode scalar value |
1292 | 90.1k | unsigned u1 = |
1293 | 90.1k | (d1 << 12) + (d2 << 8) + |
1294 | 90.1k | (d3 << 4) + d4; |
1295 | | // valid unicode scalar values are |
1296 | | // [0, D7FF] and [E000, 10FFFF] |
1297 | | // values within this range are valid utf-8 |
1298 | | // code points and invalid leading surrogates. |
1299 | 90.1k | if(BOOST_JSON_LIKELY( |
1300 | 90.1k | u1 < 0xd800 || u1 > 0xdfff)) |
1301 | 7.45k | { |
1302 | 7.45k | cs += 5; |
1303 | 7.45k | temp.append_utf8(u1); |
1304 | 7.45k | break; |
1305 | 7.45k | } |
1306 | 82.6k | if(BOOST_JSON_UNLIKELY(u1 > 0xdbff)) |
1307 | 19 | { |
1308 | | // If it's an illegal leading surrogate and |
1309 | | // the parser does not allow it, return an error. |
1310 | 19 | if(!allow_bad_utf16) |
1311 | 19 | { |
1312 | 19 | BOOST_STATIC_CONSTEXPR source_location loc |
1313 | 19 | = BOOST_CURRENT_LOCATION; |
1314 | 19 | return fail(cs.begin(), error::illegal_leading_surrogate, |
1315 | 19 | &loc); |
1316 | 19 | } |
1317 | | // Otherwise, append the Unicode replacement character |
1318 | 0 | else |
1319 | 0 | { |
1320 | 0 | cs += 5; |
1321 | 0 | temp.append_utf8(urc); |
1322 | 0 | break; |
1323 | 0 | } |
1324 | 19 | } |
1325 | 82.6k | cs += 5; |
1326 | | // KRYSTIAN TODO: this can be a two byte load |
1327 | | // and a single comparison. We lose error information, |
1328 | | // but it's faster. |
1329 | 82.6k | if(BOOST_JSON_UNLIKELY(*cs != '\\')) |
1330 | 13 | { |
1331 | | // If the next character is not a backslash and |
1332 | | // the parser does not allow it, return a syntax error. |
1333 | 13 | if(!allow_bad_utf16) |
1334 | 13 | { |
1335 | 13 | BOOST_STATIC_CONSTEXPR source_location loc |
1336 | 13 | = BOOST_CURRENT_LOCATION; |
1337 | 13 | return fail(cs.begin(), error::syntax, &loc); |
1338 | 13 | } |
1339 | | // Otherwise, append the Unicode replacement character since |
1340 | | // the first code point is a valid leading surrogate |
1341 | 0 | else |
1342 | 0 | { |
1343 | 0 | temp.append_utf8(urc); |
1344 | 0 | break; |
1345 | 0 | } |
1346 | 13 | } |
1347 | 82.6k | ++cs; |
1348 | 82.6k | if(BOOST_JSON_UNLIKELY(*cs != 'u')) |
1349 | 10 | { |
1350 | 10 | if (!allow_bad_utf16) |
1351 | 10 | { |
1352 | 10 | BOOST_STATIC_CONSTEXPR source_location loc |
1353 | 10 | = BOOST_CURRENT_LOCATION; |
1354 | 10 | return fail(cs.begin(), error::syntax, &loc); |
1355 | 10 | } |
1356 | | // Otherwise, append the Unicode replacement character since |
1357 | | // the first code point is a valid leading surrogate |
1358 | 0 | else |
1359 | 0 | { |
1360 | 0 | temp.append_utf8(urc); |
1361 | 0 | goto do_str3; |
1362 | 0 | } |
1363 | 10 | } |
1364 | 82.6k | ++cs; |
1365 | 82.6k | digit = detail::load_little_endian<4>(cs.begin()); |
1366 | 82.6k | d4 = detail::hex_digit(static_cast< |
1367 | 82.6k | unsigned char>(digit >> 24)); |
1368 | 82.6k | d3 = detail::hex_digit(static_cast< |
1369 | 82.6k | unsigned char>(digit >> 16)); |
1370 | 82.6k | d2 = detail::hex_digit(static_cast< |
1371 | 82.6k | unsigned char>(digit >> 8)); |
1372 | 82.6k | d1 = detail::hex_digit(static_cast< |
1373 | 82.6k | unsigned char>(digit)); |
1374 | 82.6k | if(BOOST_JSON_UNLIKELY( |
1375 | 82.6k | (d1 | d2 | d3 | d4) == -1)) |
1376 | 36 | { |
1377 | 36 | if(d1 != -1) |
1378 | 14 | ++cs; |
1379 | 36 | if(d2 != -1) |
1380 | 19 | ++cs; |
1381 | 36 | if(d3 != -1) |
1382 | 14 | ++cs; |
1383 | 36 | BOOST_STATIC_CONSTEXPR source_location loc |
1384 | 36 | = BOOST_CURRENT_LOCATION; |
1385 | 36 | return fail(cs.begin(), error::expected_hex_digit, &loc); |
1386 | 36 | } |
1387 | 82.6k | unsigned u2 = |
1388 | 82.6k | (d1 << 12) + (d2 << 8) + |
1389 | 82.6k | (d3 << 4) + d4; |
1390 | | // Check if the second code point is a valid trailing surrogate. |
1391 | | // Valid trailing surrogates are [DC00, DFFF] |
1392 | 82.6k | if(BOOST_JSON_UNLIKELY( |
1393 | 82.6k | u2 < 0xdc00 || u2 > 0xdfff)) |
1394 | 29 | { |
1395 | | // If not valid and the parser does not allow it, return an error. |
1396 | 29 | if(!allow_bad_utf16) |
1397 | 29 | { |
1398 | 29 | BOOST_STATIC_CONSTEXPR source_location loc |
1399 | 29 | = BOOST_CURRENT_LOCATION; |
1400 | 29 | return fail(cs.begin(), error::illegal_trailing_surrogate, |
1401 | 29 | &loc); |
1402 | 29 | } |
1403 | | // Append the replacement character for the |
1404 | | // first leading surrogate. |
1405 | 0 | cs += 4; |
1406 | 0 | temp.append_utf8(urc); |
1407 | | // Check if the second code point is a |
1408 | | // valid unicode scalar value (invalid leading |
1409 | | // or trailing surrogate) |
1410 | 0 | if (u2 < 0xd800 || u2 > 0xdbff) |
1411 | 0 | { |
1412 | 0 | temp.append_utf8(u2); |
1413 | 0 | break; |
1414 | 0 | } |
1415 | | // If it is a valid leading surrogate |
1416 | 0 | else |
1417 | 0 | { |
1418 | 0 | u1_ = u2; |
1419 | 0 | goto do_sur1; |
1420 | 0 | } |
1421 | 0 | } |
1422 | 82.5k | cs += 4; |
1423 | | // Calculate the Unicode code point from the surrogate pair and |
1424 | | // append the UTF-8 representation. |
1425 | 82.5k | unsigned cp = |
1426 | 82.5k | ((u1 - 0xd800) << 10) + |
1427 | 82.5k | ((u2 - 0xdc00)) + |
1428 | 82.5k | 0x10000; |
1429 | | // utf-16 surrogate pair |
1430 | 82.5k | temp.append_utf8(cp); |
1431 | 82.5k | break; |
1432 | 82.6k | } |
1433 | | // flush |
1434 | 1.69k | if(BOOST_JSON_LIKELY(! temp.empty())) |
1435 | 1.44k | { |
1436 | 1.44k | BOOST_ASSERT(total <= max_size); |
1437 | 1.44k | if(BOOST_JSON_UNLIKELY( |
1438 | 1.44k | temp.size() > max_size - total)) |
1439 | 0 | { |
1440 | 0 | BOOST_STATIC_CONSTEXPR source_location loc |
1441 | 0 | = BOOST_CURRENT_LOCATION; |
1442 | 0 | return fail(cs.begin(), ev_too_large, &loc); |
1443 | 0 | } |
1444 | 1.44k | total += temp.size(); |
1445 | 1.44k | { |
1446 | 1.44k | bool r = is_key |
1447 | 1.44k | ? h_.on_key_part(temp.get(), total, ec_) |
1448 | 1.44k | : h_.on_string_part(temp.get(), total, ec_); |
1449 | | |
1450 | 1.44k | if(BOOST_JSON_UNLIKELY(!r)) |
1451 | 20 | { |
1452 | 20 | return fail(cs.begin()); |
1453 | 20 | } |
1454 | 1.44k | } |
1455 | 1.42k | temp.clear(); |
1456 | 1.42k | cs.clip(temp.max_size()); |
1457 | 1.42k | } |
1458 | 1.67k | ++cs; |
1459 | | // utf-16 escape |
1460 | 1.67k | do_str4: |
1461 | 1.67k | if(BOOST_JSON_UNLIKELY(! cs)) |
1462 | 19 | return maybe_suspend(cs.begin(), state::str4); |
1463 | 1.65k | digit = detail::hex_digit(*cs); |
1464 | 1.65k | if(BOOST_JSON_UNLIKELY(digit == -1)) |
1465 | 22 | { |
1466 | 22 | BOOST_STATIC_CONSTEXPR source_location loc |
1467 | 22 | = BOOST_CURRENT_LOCATION; |
1468 | 22 | return fail(cs.begin(), error::expected_hex_digit, &loc); |
1469 | 22 | } |
1470 | 1.63k | ++cs; |
1471 | 1.63k | u1_ = digit << 12; |
1472 | 1.63k | do_str5: |
1473 | 1.63k | if(BOOST_JSON_UNLIKELY(! cs)) |
1474 | 8 | return maybe_suspend(cs.begin(), state::str5); |
1475 | 1.62k | digit = detail::hex_digit(*cs); |
1476 | 1.62k | if(BOOST_JSON_UNLIKELY(digit == -1)) |
1477 | 13 | { |
1478 | 13 | BOOST_STATIC_CONSTEXPR source_location loc |
1479 | 13 | = BOOST_CURRENT_LOCATION; |
1480 | 13 | return fail(cs.begin(), error::expected_hex_digit, &loc); |
1481 | 13 | } |
1482 | 1.61k | ++cs; |
1483 | 1.61k | u1_ += digit << 8; |
1484 | 1.61k | do_str6: |
1485 | 1.61k | if(BOOST_JSON_UNLIKELY(! cs)) |
1486 | 9 | return maybe_suspend(cs.begin(), state::str6); |
1487 | 1.60k | digit = detail::hex_digit(*cs); |
1488 | 1.60k | if(BOOST_JSON_UNLIKELY(digit == -1)) |
1489 | 17 | { |
1490 | 17 | BOOST_STATIC_CONSTEXPR source_location loc |
1491 | 17 | = BOOST_CURRENT_LOCATION; |
1492 | 17 | return fail(cs.begin(), error::expected_hex_digit, &loc); |
1493 | 17 | } |
1494 | 1.58k | ++cs; |
1495 | 1.58k | u1_ += digit << 4; |
1496 | 1.58k | do_str7: |
1497 | 1.58k | if(BOOST_JSON_UNLIKELY(! cs)) |
1498 | 18 | return maybe_suspend(cs.begin(), state::str7); |
1499 | 1.57k | digit = detail::hex_digit(*cs); |
1500 | 1.57k | if(BOOST_JSON_UNLIKELY(digit == -1)) |
1501 | 17 | { |
1502 | 17 | BOOST_STATIC_CONSTEXPR source_location loc |
1503 | 17 | = BOOST_CURRENT_LOCATION; |
1504 | 17 | return fail(cs.begin(), error::expected_hex_digit, &loc); |
1505 | 17 | } |
1506 | 1.55k | ++cs; |
1507 | 1.55k | u1_ += digit; |
1508 | 1.55k | if(BOOST_JSON_LIKELY( |
1509 | 1.55k | u1_ < 0xd800 || u1_ > 0xdfff)) |
1510 | 548 | { |
1511 | 548 | BOOST_ASSERT(temp.empty()); |
1512 | | // utf-8 codepoint |
1513 | 548 | temp.append_utf8(u1_); |
1514 | 548 | break; |
1515 | 548 | } |
1516 | 1.00k | if(BOOST_JSON_UNLIKELY(u1_ > 0xdbff)) |
1517 | 16 | { |
1518 | | // If it's an illegal leading surrogate and |
1519 | | // the parser does not allow it, return an error. |
1520 | 16 | if(!allow_bad_utf16) |
1521 | 16 | { |
1522 | 16 | BOOST_STATIC_CONSTEXPR source_location loc |
1523 | 16 | = BOOST_CURRENT_LOCATION; |
1524 | 16 | return fail(cs.begin(), error::illegal_leading_surrogate, &loc); |
1525 | 16 | } |
1526 | | // Otherwise, append the Unicode replacement character |
1527 | 0 | else |
1528 | 0 | { |
1529 | 0 | BOOST_ASSERT(temp.empty()); |
1530 | 0 | temp.append_utf8(urc); |
1531 | 0 | break; |
1532 | 0 | } |
1533 | 16 | } |
1534 | 990 | do_sur1: |
1535 | 990 | if(BOOST_JSON_UNLIKELY(! cs)) |
1536 | 14 | return maybe_suspend(cs.begin(), state::sur1); |
1537 | 976 | if(BOOST_JSON_UNLIKELY(*cs != '\\')) |
1538 | 4 | { |
1539 | | // If the next character is not a backslash and |
1540 | | // the parser does not allow it, return a syntax error. |
1541 | 4 | if(!allow_bad_utf16) |
1542 | 4 | { |
1543 | 4 | BOOST_STATIC_CONSTEXPR source_location loc |
1544 | 4 | = BOOST_CURRENT_LOCATION; |
1545 | 4 | return fail(cs.begin(), error::syntax, &loc); |
1546 | 4 | } |
1547 | | // Otherwise, append the Unicode replacement character since |
1548 | | // the first code point is a valid leading surrogate |
1549 | 0 | else |
1550 | 0 | { |
1551 | 0 | temp.append_utf8(urc); |
1552 | 0 | break; |
1553 | 0 | } |
1554 | 4 | } |
1555 | 972 | ++cs; |
1556 | 972 | do_sur2: |
1557 | 972 | if(BOOST_JSON_UNLIKELY(! cs)) |
1558 | 1 | return maybe_suspend(cs.begin(), state::sur2); |
1559 | 971 | if(BOOST_JSON_UNLIKELY(*cs != 'u')) |
1560 | 4 | { |
1561 | 4 | if (!allow_bad_utf16) |
1562 | 4 | { |
1563 | 4 | BOOST_STATIC_CONSTEXPR source_location loc |
1564 | 4 | = BOOST_CURRENT_LOCATION; |
1565 | 4 | return fail(cs.begin(), error::syntax, &loc); |
1566 | 4 | } |
1567 | | // Otherwise, append the Unicode replacement character since |
1568 | | // the first code point is a valid leading surrogate |
1569 | 0 | else |
1570 | 0 | { |
1571 | 0 | temp.append_utf8(urc); |
1572 | 0 | goto do_str3; |
1573 | 0 | } |
1574 | 4 | } |
1575 | 967 | ++cs; |
1576 | 967 | do_sur3: |
1577 | 967 | if(BOOST_JSON_UNLIKELY(! cs)) |
1578 | 1 | return maybe_suspend(cs.begin(), state::sur3); |
1579 | 966 | digit = detail::hex_digit(*cs); |
1580 | 966 | if(BOOST_JSON_UNLIKELY(digit == -1)) |
1581 | 16 | { |
1582 | 16 | BOOST_STATIC_CONSTEXPR source_location loc |
1583 | 16 | = BOOST_CURRENT_LOCATION; |
1584 | 16 | return fail(cs.begin(), error::expected_hex_digit, &loc); |
1585 | 16 | } |
1586 | 950 | ++cs; |
1587 | 950 | u2_ = digit << 12; |
1588 | 950 | do_sur4: |
1589 | 950 | if(BOOST_JSON_UNLIKELY(! cs)) |
1590 | 7 | return maybe_suspend(cs.begin(), state::sur4); |
1591 | 943 | digit = detail::hex_digit(*cs); |
1592 | 943 | if(BOOST_JSON_UNLIKELY(digit == -1)) |
1593 | 18 | { |
1594 | 18 | BOOST_STATIC_CONSTEXPR source_location loc |
1595 | 18 | = BOOST_CURRENT_LOCATION; |
1596 | 18 | return fail(cs.begin(), error::expected_hex_digit, &loc); |
1597 | 18 | } |
1598 | 925 | ++cs; |
1599 | 925 | u2_ += digit << 8; |
1600 | 925 | do_sur5: |
1601 | 925 | if(BOOST_JSON_UNLIKELY(! cs)) |
1602 | 8 | return maybe_suspend(cs.begin(), state::sur5); |
1603 | 917 | digit = detail::hex_digit(*cs); |
1604 | 917 | if(BOOST_JSON_UNLIKELY(digit == -1)) |
1605 | 10 | { |
1606 | 10 | BOOST_STATIC_CONSTEXPR source_location loc |
1607 | 10 | = BOOST_CURRENT_LOCATION; |
1608 | 10 | return fail(cs.begin(), error::expected_hex_digit, &loc); |
1609 | 10 | } |
1610 | 907 | ++cs; |
1611 | 907 | u2_ += digit << 4; |
1612 | 907 | do_sur6: |
1613 | 907 | if(BOOST_JSON_UNLIKELY(! cs)) |
1614 | 10 | return maybe_suspend(cs.begin(), state::sur6); |
1615 | 897 | digit = detail::hex_digit(*cs); |
1616 | 897 | if(BOOST_JSON_UNLIKELY(digit == -1)) |
1617 | 4 | { |
1618 | 4 | BOOST_STATIC_CONSTEXPR source_location loc |
1619 | 4 | = BOOST_CURRENT_LOCATION; |
1620 | 4 | return fail(cs.begin(), error::expected_hex_digit, &loc); |
1621 | 4 | } |
1622 | 893 | ++cs; |
1623 | 893 | u2_ += digit; |
1624 | | // Check if the second code point is a valid trailing surrogate. |
1625 | | // Valid trailing surrogates are [DC00, DFFF] |
1626 | 893 | if(BOOST_JSON_UNLIKELY( |
1627 | 893 | u2_ < 0xdc00 || u2_ > 0xdfff)) |
1628 | 19 | { |
1629 | | // If not valid and the parser does not allow it, return an error. |
1630 | 19 | if(!allow_bad_utf16) |
1631 | 19 | { |
1632 | 19 | BOOST_STATIC_CONSTEXPR source_location loc |
1633 | 19 | = BOOST_CURRENT_LOCATION; |
1634 | 19 | return fail(cs.begin(), error::illegal_trailing_surrogate, &loc); |
1635 | 19 | } |
1636 | | // Append the replacement character for the |
1637 | | // first leading surrogate. |
1638 | 0 | temp.append_utf8(urc); |
1639 | | // Check if the second code point is a |
1640 | | // valid unicode scalar value (invalid leading |
1641 | | // or trailing surrogate) |
1642 | 0 | if (u2_ < 0xd800 || u2_ > 0xdbff) |
1643 | 0 | { |
1644 | 0 | temp.append_utf8(u2_); |
1645 | 0 | break; |
1646 | 0 | } |
1647 | | // If it is a valid leading surrogate |
1648 | 0 | else |
1649 | 0 | { |
1650 | 0 | u1_ = u2_; |
1651 | 0 | goto do_sur1; |
1652 | 0 | } |
1653 | 0 | } |
1654 | | // Calculate the Unicode code point from the surrogate pair and |
1655 | | // append the UTF-8 representation. |
1656 | 874 | unsigned cp = |
1657 | 874 | ((u1_ - 0xd800) << 10) + |
1658 | 874 | ((u2_ - 0xdc00)) + |
1659 | 874 | 0x10000; |
1660 | | // utf-16 surrogate pair |
1661 | 874 | temp.append_utf8(cp); |
1662 | 4.42M | } |
1663 | | |
1664 | | // flush |
1665 | 4.42M | if(BOOST_JSON_UNLIKELY( !cs ) || *cs != '\\') |
1666 | 14.0k | break; |
1667 | 4.42M | } |
1668 | | |
1669 | 14.0k | if(BOOST_JSON_LIKELY( temp.size() )) |
1670 | 14.0k | { |
1671 | 14.0k | BOOST_ASSERT(total <= max_size); |
1672 | 14.0k | if(BOOST_JSON_UNLIKELY( temp.size() > max_size - total )) |
1673 | 0 | { |
1674 | 0 | BOOST_STATIC_CONSTEXPR source_location loc |
1675 | 0 | = BOOST_CURRENT_LOCATION; |
1676 | 0 | return fail(cs.begin(), ev_too_large, &loc); |
1677 | 0 | } |
1678 | | |
1679 | 14.0k | total += temp.size(); |
1680 | 14.0k | bool const r = is_key |
1681 | 14.0k | ? h_.on_key_part(temp.get(), total, ec_) |
1682 | 14.0k | : h_.on_string_part(temp.get(), total, ec_); |
1683 | 14.0k | if(BOOST_JSON_UNLIKELY( !r )) |
1684 | 212 | return fail( cs.begin() ); |
1685 | 14.0k | } |
1686 | | |
1687 | 13.8k | return cs.begin(); |
1688 | 14.0k | } char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_escaped<true>(char const*, unsigned long&, std::__1::integral_constant<bool, true>, bool, bool) Line | Count | Source | 1132 | 14.6k | { | 1133 | 14.6k | constexpr unsigned urc = 0xFFFD; // Unicode replacement character | 1134 | 14.6k | auto const ev_too_large = is_key? | 1135 | 10.0k | error::key_too_large : error::string_too_large; | 1136 | 14.6k | auto const max_size = is_key? | 1137 | 10.0k | Handler::max_key_size : Handler::max_string_size; | 1138 | 14.6k | int digit; | 1139 | | | 1140 | | //--------------------------------------------------------------- | 1141 | | // | 1142 | | // To handle escapes, a local temporary buffer accumulates | 1143 | | // the unescaped result. The algorithm attempts to fill the | 1144 | | // buffer to capacity before invoking the handler. | 1145 | | // In some cases the temporary buffer needs to be flushed | 1146 | | // before it is full: | 1147 | | // * When the closing double quote is seen | 1148 | | // * When there in no more input (and more is expected later) | 1149 | | // A goal of the algorithm is to call the handler as few times | 1150 | | // as possible. Thus, when the first escape is encountered, | 1151 | | // the algorithm attempts to fill the temporary buffer first. | 1152 | | // | 1153 | 14.6k | detail::buffer<BOOST_JSON_STACK_BUFFER_SIZE> temp; | 1154 | | | 1155 | | // Unescaped JSON is never larger than its escaped version. | 1156 | | // To efficiently process only what will fit in the temporary buffer, | 1157 | | // the size of the input stream is temporarily "clipped" to the size | 1158 | | // of the temporary buffer. | 1159 | | // handle escaped character | 1160 | 14.6k | detail::clipped_const_stream cs(p, end_); | 1161 | 14.6k | cs.clip(temp.max_size()); | 1162 | | | 1163 | 14.6k | if(! stack_empty && ! st_.empty()) | 1164 | 0 | { | 1165 | 0 | state st; | 1166 | 0 | st_.pop(st); | 1167 | 0 | switch(st) | 1168 | 0 | { | 1169 | 0 | default: BOOST_JSON_UNREACHABLE(); | 1170 | 0 | case state::str3: goto do_str3; | 1171 | 0 | case state::str4: goto do_str4; | 1172 | 0 | case state::str5: goto do_str5; | 1173 | 0 | case state::str6: goto do_str6; | 1174 | 0 | case state::str7: goto do_str7; | 1175 | 0 | case state::sur1: goto do_sur1; | 1176 | 0 | case state::sur2: goto do_sur2; | 1177 | 0 | case state::sur3: goto do_sur3; | 1178 | 0 | case state::sur4: goto do_sur4; | 1179 | 0 | case state::sur5: goto do_sur5; | 1180 | 0 | case state::sur6: goto do_sur6; | 1181 | 0 | } | 1182 | 0 | } | 1183 | | | 1184 | 4.42M | while(true) | 1185 | 4.42M | { | 1186 | 4.42M | BOOST_ASSERT( temp.capacity() ); | 1187 | 4.42M | BOOST_ASSERT(*cs == '\\'); | 1188 | 4.42M | ++cs; | 1189 | 4.42M | do_str3: | 1190 | 4.42M | if(BOOST_JSON_UNLIKELY(! cs)) | 1191 | 712 | { | 1192 | 712 | if(BOOST_JSON_LIKELY(! temp.empty())) | 1193 | 673 | { | 1194 | 673 | BOOST_ASSERT(total <= max_size); | 1195 | 673 | if(BOOST_JSON_UNLIKELY( | 1196 | 673 | temp.size() > max_size - total)) | 1197 | 0 | { | 1198 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1199 | 0 | = BOOST_CURRENT_LOCATION; | 1200 | 0 | return fail(cs.begin(), ev_too_large, &loc); | 1201 | 0 | } | 1202 | 673 | total += temp.size(); | 1203 | 673 | { | 1204 | 673 | bool r = is_key | 1205 | 673 | ? h_.on_key_part(temp.get(), total, ec_) | 1206 | 673 | : h_.on_string_part(temp.get(), total, ec_); | 1207 | | | 1208 | 673 | if(BOOST_JSON_UNLIKELY(!r)) | 1209 | 13 | { | 1210 | 13 | return fail(cs.begin()); | 1211 | 13 | } | 1212 | 673 | } | 1213 | 660 | temp.clear(); | 1214 | 660 | } | 1215 | 699 | cs.clip(temp.max_size()); | 1216 | 699 | if(BOOST_JSON_UNLIKELY(! cs)) | 1217 | 84 | return maybe_suspend(cs.begin(), state::str3); | 1218 | 699 | } | 1219 | 4.42M | switch(*cs) | 1220 | 4.42M | { | 1221 | 41 | default: | 1222 | 41 | { | 1223 | 41 | BOOST_STATIC_CONSTEXPR source_location loc | 1224 | 41 | = BOOST_CURRENT_LOCATION; | 1225 | 41 | return fail(cs.begin(), error::syntax, &loc); | 1226 | 0 | } | 1227 | 2.86k | case '\x22': // '"' | 1228 | 2.86k | temp.push_back('\x22'); | 1229 | 2.86k | ++cs; | 1230 | 2.86k | break; | 1231 | 4.31M | case '\\': | 1232 | 4.31M | temp.push_back('\\'); | 1233 | 4.31M | ++cs; | 1234 | 4.31M | break; | 1235 | 3.69k | case '/': | 1236 | 3.69k | temp.push_back('/'); | 1237 | 3.69k | ++cs; | 1238 | 3.69k | break; | 1239 | 960 | case 'b': | 1240 | 960 | temp.push_back('\x08'); | 1241 | 960 | ++cs; | 1242 | 960 | break; | 1243 | 2.43k | case 'f': | 1244 | 2.43k | temp.push_back('\x0c'); | 1245 | 2.43k | ++cs; | 1246 | 2.43k | break; | 1247 | 669 | case 'n': | 1248 | 669 | temp.push_back('\x0a'); | 1249 | 669 | ++cs; | 1250 | 669 | break; | 1251 | 2.38k | case 'r': | 1252 | 2.38k | temp.push_back('\x0d'); | 1253 | 2.38k | ++cs; | 1254 | 2.38k | break; | 1255 | 1.07k | case 't': | 1256 | 1.07k | temp.push_back('\x09'); | 1257 | 1.07k | ++cs; | 1258 | 1.07k | break; | 1259 | 91.8k | case 'u': | 1260 | | // utf16 escape | 1261 | | // | 1262 | | // fast path only when the buffer | 1263 | | // is large enough for 2 surrogates | 1264 | 91.8k | if(BOOST_JSON_LIKELY(cs.remain() > 10)) | 1265 | 90.1k | { | 1266 | | // KRYSTIAN TODO: this could be done | 1267 | | // with fewer instructions | 1268 | 90.1k | digit = detail::load_little_endian<4>( | 1269 | 90.1k | cs.begin() + 1); | 1270 | 90.1k | int d4 = detail::hex_digit(static_cast< | 1271 | 90.1k | unsigned char>(digit >> 24)); | 1272 | 90.1k | int d3 = detail::hex_digit(static_cast< | 1273 | 90.1k | unsigned char>(digit >> 16)); | 1274 | 90.1k | int d2 = detail::hex_digit(static_cast< | 1275 | 90.1k | unsigned char>(digit >> 8)); | 1276 | 90.1k | int d1 = detail::hex_digit(static_cast< | 1277 | 90.1k | unsigned char>(digit)); | 1278 | 90.1k | if(BOOST_JSON_UNLIKELY( | 1279 | 90.1k | (d1 | d2 | d3 | d4) == -1)) | 1280 | 53 | { | 1281 | 53 | if(d1 != -1) | 1282 | 15 | ++cs; | 1283 | 53 | if(d2 != -1) | 1284 | 17 | ++cs; | 1285 | 53 | if(d3 != -1) | 1286 | 12 | ++cs; | 1287 | 53 | BOOST_STATIC_CONSTEXPR source_location loc | 1288 | 53 | = BOOST_CURRENT_LOCATION; | 1289 | 53 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1290 | 53 | } | 1291 | | // 32 bit unicode scalar value | 1292 | 90.1k | unsigned u1 = | 1293 | 90.1k | (d1 << 12) + (d2 << 8) + | 1294 | 90.1k | (d3 << 4) + d4; | 1295 | | // valid unicode scalar values are | 1296 | | // [0, D7FF] and [E000, 10FFFF] | 1297 | | // values within this range are valid utf-8 | 1298 | | // code points and invalid leading surrogates. | 1299 | 90.1k | if(BOOST_JSON_LIKELY( | 1300 | 90.1k | u1 < 0xd800 || u1 > 0xdfff)) | 1301 | 7.45k | { | 1302 | 7.45k | cs += 5; | 1303 | 7.45k | temp.append_utf8(u1); | 1304 | 7.45k | break; | 1305 | 7.45k | } | 1306 | 82.6k | if(BOOST_JSON_UNLIKELY(u1 > 0xdbff)) | 1307 | 19 | { | 1308 | | // If it's an illegal leading surrogate and | 1309 | | // the parser does not allow it, return an error. | 1310 | 19 | if(!allow_bad_utf16) | 1311 | 19 | { | 1312 | 19 | BOOST_STATIC_CONSTEXPR source_location loc | 1313 | 19 | = BOOST_CURRENT_LOCATION; | 1314 | 19 | return fail(cs.begin(), error::illegal_leading_surrogate, | 1315 | 19 | &loc); | 1316 | 19 | } | 1317 | | // Otherwise, append the Unicode replacement character | 1318 | 0 | else | 1319 | 0 | { | 1320 | 0 | cs += 5; | 1321 | 0 | temp.append_utf8(urc); | 1322 | 0 | break; | 1323 | 0 | } | 1324 | 19 | } | 1325 | 82.6k | cs += 5; | 1326 | | // KRYSTIAN TODO: this can be a two byte load | 1327 | | // and a single comparison. We lose error information, | 1328 | | // but it's faster. | 1329 | 82.6k | if(BOOST_JSON_UNLIKELY(*cs != '\\')) | 1330 | 13 | { | 1331 | | // If the next character is not a backslash and | 1332 | | // the parser does not allow it, return a syntax error. | 1333 | 13 | if(!allow_bad_utf16) | 1334 | 13 | { | 1335 | 13 | BOOST_STATIC_CONSTEXPR source_location loc | 1336 | 13 | = BOOST_CURRENT_LOCATION; | 1337 | 13 | return fail(cs.begin(), error::syntax, &loc); | 1338 | 13 | } | 1339 | | // Otherwise, append the Unicode replacement character since | 1340 | | // the first code point is a valid leading surrogate | 1341 | 0 | else | 1342 | 0 | { | 1343 | 0 | temp.append_utf8(urc); | 1344 | 0 | break; | 1345 | 0 | } | 1346 | 13 | } | 1347 | 82.6k | ++cs; | 1348 | 82.6k | if(BOOST_JSON_UNLIKELY(*cs != 'u')) | 1349 | 10 | { | 1350 | 10 | if (!allow_bad_utf16) | 1351 | 10 | { | 1352 | 10 | BOOST_STATIC_CONSTEXPR source_location loc | 1353 | 10 | = BOOST_CURRENT_LOCATION; | 1354 | 10 | return fail(cs.begin(), error::syntax, &loc); | 1355 | 10 | } | 1356 | | // Otherwise, append the Unicode replacement character since | 1357 | | // the first code point is a valid leading surrogate | 1358 | 0 | else | 1359 | 0 | { | 1360 | 0 | temp.append_utf8(urc); | 1361 | 0 | goto do_str3; | 1362 | 0 | } | 1363 | 10 | } | 1364 | 82.6k | ++cs; | 1365 | 82.6k | digit = detail::load_little_endian<4>(cs.begin()); | 1366 | 82.6k | d4 = detail::hex_digit(static_cast< | 1367 | 82.6k | unsigned char>(digit >> 24)); | 1368 | 82.6k | d3 = detail::hex_digit(static_cast< | 1369 | 82.6k | unsigned char>(digit >> 16)); | 1370 | 82.6k | d2 = detail::hex_digit(static_cast< | 1371 | 82.6k | unsigned char>(digit >> 8)); | 1372 | 82.6k | d1 = detail::hex_digit(static_cast< | 1373 | 82.6k | unsigned char>(digit)); | 1374 | 82.6k | if(BOOST_JSON_UNLIKELY( | 1375 | 82.6k | (d1 | d2 | d3 | d4) == -1)) | 1376 | 36 | { | 1377 | 36 | if(d1 != -1) | 1378 | 14 | ++cs; | 1379 | 36 | if(d2 != -1) | 1380 | 19 | ++cs; | 1381 | 36 | if(d3 != -1) | 1382 | 14 | ++cs; | 1383 | 36 | BOOST_STATIC_CONSTEXPR source_location loc | 1384 | 36 | = BOOST_CURRENT_LOCATION; | 1385 | 36 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1386 | 36 | } | 1387 | 82.6k | unsigned u2 = | 1388 | 82.6k | (d1 << 12) + (d2 << 8) + | 1389 | 82.6k | (d3 << 4) + d4; | 1390 | | // Check if the second code point is a valid trailing surrogate. | 1391 | | // Valid trailing surrogates are [DC00, DFFF] | 1392 | 82.6k | if(BOOST_JSON_UNLIKELY( | 1393 | 82.6k | u2 < 0xdc00 || u2 > 0xdfff)) | 1394 | 29 | { | 1395 | | // If not valid and the parser does not allow it, return an error. | 1396 | 29 | if(!allow_bad_utf16) | 1397 | 29 | { | 1398 | 29 | BOOST_STATIC_CONSTEXPR source_location loc | 1399 | 29 | = BOOST_CURRENT_LOCATION; | 1400 | 29 | return fail(cs.begin(), error::illegal_trailing_surrogate, | 1401 | 29 | &loc); | 1402 | 29 | } | 1403 | | // Append the replacement character for the | 1404 | | // first leading surrogate. | 1405 | 0 | cs += 4; | 1406 | 0 | temp.append_utf8(urc); | 1407 | | // Check if the second code point is a | 1408 | | // valid unicode scalar value (invalid leading | 1409 | | // or trailing surrogate) | 1410 | 0 | if (u2 < 0xd800 || u2 > 0xdbff) | 1411 | 0 | { | 1412 | 0 | temp.append_utf8(u2); | 1413 | 0 | break; | 1414 | 0 | } | 1415 | | // If it is a valid leading surrogate | 1416 | 0 | else | 1417 | 0 | { | 1418 | 0 | u1_ = u2; | 1419 | 0 | goto do_sur1; | 1420 | 0 | } | 1421 | 0 | } | 1422 | 82.5k | cs += 4; | 1423 | | // Calculate the Unicode code point from the surrogate pair and | 1424 | | // append the UTF-8 representation. | 1425 | 82.5k | unsigned cp = | 1426 | 82.5k | ((u1 - 0xd800) << 10) + | 1427 | 82.5k | ((u2 - 0xdc00)) + | 1428 | 82.5k | 0x10000; | 1429 | | // utf-16 surrogate pair | 1430 | 82.5k | temp.append_utf8(cp); | 1431 | 82.5k | break; | 1432 | 82.6k | } | 1433 | | // flush | 1434 | 1.69k | if(BOOST_JSON_LIKELY(! temp.empty())) | 1435 | 1.44k | { | 1436 | 1.44k | BOOST_ASSERT(total <= max_size); | 1437 | 1.44k | if(BOOST_JSON_UNLIKELY( | 1438 | 1.44k | temp.size() > max_size - total)) | 1439 | 0 | { | 1440 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1441 | 0 | = BOOST_CURRENT_LOCATION; | 1442 | 0 | return fail(cs.begin(), ev_too_large, &loc); | 1443 | 0 | } | 1444 | 1.44k | total += temp.size(); | 1445 | 1.44k | { | 1446 | 1.44k | bool r = is_key | 1447 | 1.44k | ? h_.on_key_part(temp.get(), total, ec_) | 1448 | 1.44k | : h_.on_string_part(temp.get(), total, ec_); | 1449 | | | 1450 | 1.44k | if(BOOST_JSON_UNLIKELY(!r)) | 1451 | 20 | { | 1452 | 20 | return fail(cs.begin()); | 1453 | 20 | } | 1454 | 1.44k | } | 1455 | 1.42k | temp.clear(); | 1456 | 1.42k | cs.clip(temp.max_size()); | 1457 | 1.42k | } | 1458 | 1.67k | ++cs; | 1459 | | // utf-16 escape | 1460 | 1.67k | do_str4: | 1461 | 1.67k | if(BOOST_JSON_UNLIKELY(! cs)) | 1462 | 19 | return maybe_suspend(cs.begin(), state::str4); | 1463 | 1.65k | digit = detail::hex_digit(*cs); | 1464 | 1.65k | if(BOOST_JSON_UNLIKELY(digit == -1)) | 1465 | 22 | { | 1466 | 22 | BOOST_STATIC_CONSTEXPR source_location loc | 1467 | 22 | = BOOST_CURRENT_LOCATION; | 1468 | 22 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1469 | 22 | } | 1470 | 1.63k | ++cs; | 1471 | 1.63k | u1_ = digit << 12; | 1472 | 1.63k | do_str5: | 1473 | 1.63k | if(BOOST_JSON_UNLIKELY(! cs)) | 1474 | 8 | return maybe_suspend(cs.begin(), state::str5); | 1475 | 1.62k | digit = detail::hex_digit(*cs); | 1476 | 1.62k | if(BOOST_JSON_UNLIKELY(digit == -1)) | 1477 | 13 | { | 1478 | 13 | BOOST_STATIC_CONSTEXPR source_location loc | 1479 | 13 | = BOOST_CURRENT_LOCATION; | 1480 | 13 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1481 | 13 | } | 1482 | 1.61k | ++cs; | 1483 | 1.61k | u1_ += digit << 8; | 1484 | 1.61k | do_str6: | 1485 | 1.61k | if(BOOST_JSON_UNLIKELY(! cs)) | 1486 | 9 | return maybe_suspend(cs.begin(), state::str6); | 1487 | 1.60k | digit = detail::hex_digit(*cs); | 1488 | 1.60k | if(BOOST_JSON_UNLIKELY(digit == -1)) | 1489 | 17 | { | 1490 | 17 | BOOST_STATIC_CONSTEXPR source_location loc | 1491 | 17 | = BOOST_CURRENT_LOCATION; | 1492 | 17 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1493 | 17 | } | 1494 | 1.58k | ++cs; | 1495 | 1.58k | u1_ += digit << 4; | 1496 | 1.58k | do_str7: | 1497 | 1.58k | if(BOOST_JSON_UNLIKELY(! cs)) | 1498 | 18 | return maybe_suspend(cs.begin(), state::str7); | 1499 | 1.57k | digit = detail::hex_digit(*cs); | 1500 | 1.57k | if(BOOST_JSON_UNLIKELY(digit == -1)) | 1501 | 17 | { | 1502 | 17 | BOOST_STATIC_CONSTEXPR source_location loc | 1503 | 17 | = BOOST_CURRENT_LOCATION; | 1504 | 17 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1505 | 17 | } | 1506 | 1.55k | ++cs; | 1507 | 1.55k | u1_ += digit; | 1508 | 1.55k | if(BOOST_JSON_LIKELY( | 1509 | 1.55k | u1_ < 0xd800 || u1_ > 0xdfff)) | 1510 | 548 | { | 1511 | 548 | BOOST_ASSERT(temp.empty()); | 1512 | | // utf-8 codepoint | 1513 | 548 | temp.append_utf8(u1_); | 1514 | 548 | break; | 1515 | 548 | } | 1516 | 1.00k | if(BOOST_JSON_UNLIKELY(u1_ > 0xdbff)) | 1517 | 16 | { | 1518 | | // If it's an illegal leading surrogate and | 1519 | | // the parser does not allow it, return an error. | 1520 | 16 | if(!allow_bad_utf16) | 1521 | 16 | { | 1522 | 16 | BOOST_STATIC_CONSTEXPR source_location loc | 1523 | 16 | = BOOST_CURRENT_LOCATION; | 1524 | 16 | return fail(cs.begin(), error::illegal_leading_surrogate, &loc); | 1525 | 16 | } | 1526 | | // Otherwise, append the Unicode replacement character | 1527 | 0 | else | 1528 | 0 | { | 1529 | 0 | BOOST_ASSERT(temp.empty()); | 1530 | 0 | temp.append_utf8(urc); | 1531 | 0 | break; | 1532 | 0 | } | 1533 | 16 | } | 1534 | 990 | do_sur1: | 1535 | 990 | if(BOOST_JSON_UNLIKELY(! cs)) | 1536 | 14 | return maybe_suspend(cs.begin(), state::sur1); | 1537 | 976 | if(BOOST_JSON_UNLIKELY(*cs != '\\')) | 1538 | 4 | { | 1539 | | // If the next character is not a backslash and | 1540 | | // the parser does not allow it, return a syntax error. | 1541 | 4 | if(!allow_bad_utf16) | 1542 | 4 | { | 1543 | 4 | BOOST_STATIC_CONSTEXPR source_location loc | 1544 | 4 | = BOOST_CURRENT_LOCATION; | 1545 | 4 | return fail(cs.begin(), error::syntax, &loc); | 1546 | 4 | } | 1547 | | // Otherwise, append the Unicode replacement character since | 1548 | | // the first code point is a valid leading surrogate | 1549 | 0 | else | 1550 | 0 | { | 1551 | 0 | temp.append_utf8(urc); | 1552 | 0 | break; | 1553 | 0 | } | 1554 | 4 | } | 1555 | 972 | ++cs; | 1556 | 972 | do_sur2: | 1557 | 972 | if(BOOST_JSON_UNLIKELY(! cs)) | 1558 | 1 | return maybe_suspend(cs.begin(), state::sur2); | 1559 | 971 | if(BOOST_JSON_UNLIKELY(*cs != 'u')) | 1560 | 4 | { | 1561 | 4 | if (!allow_bad_utf16) | 1562 | 4 | { | 1563 | 4 | BOOST_STATIC_CONSTEXPR source_location loc | 1564 | 4 | = BOOST_CURRENT_LOCATION; | 1565 | 4 | return fail(cs.begin(), error::syntax, &loc); | 1566 | 4 | } | 1567 | | // Otherwise, append the Unicode replacement character since | 1568 | | // the first code point is a valid leading surrogate | 1569 | 0 | else | 1570 | 0 | { | 1571 | 0 | temp.append_utf8(urc); | 1572 | 0 | goto do_str3; | 1573 | 0 | } | 1574 | 4 | } | 1575 | 967 | ++cs; | 1576 | 967 | do_sur3: | 1577 | 967 | if(BOOST_JSON_UNLIKELY(! cs)) | 1578 | 1 | return maybe_suspend(cs.begin(), state::sur3); | 1579 | 966 | digit = detail::hex_digit(*cs); | 1580 | 966 | if(BOOST_JSON_UNLIKELY(digit == -1)) | 1581 | 16 | { | 1582 | 16 | BOOST_STATIC_CONSTEXPR source_location loc | 1583 | 16 | = BOOST_CURRENT_LOCATION; | 1584 | 16 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1585 | 16 | } | 1586 | 950 | ++cs; | 1587 | 950 | u2_ = digit << 12; | 1588 | 950 | do_sur4: | 1589 | 950 | if(BOOST_JSON_UNLIKELY(! cs)) | 1590 | 7 | return maybe_suspend(cs.begin(), state::sur4); | 1591 | 943 | digit = detail::hex_digit(*cs); | 1592 | 943 | if(BOOST_JSON_UNLIKELY(digit == -1)) | 1593 | 18 | { | 1594 | 18 | BOOST_STATIC_CONSTEXPR source_location loc | 1595 | 18 | = BOOST_CURRENT_LOCATION; | 1596 | 18 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1597 | 18 | } | 1598 | 925 | ++cs; | 1599 | 925 | u2_ += digit << 8; | 1600 | 925 | do_sur5: | 1601 | 925 | if(BOOST_JSON_UNLIKELY(! cs)) | 1602 | 8 | return maybe_suspend(cs.begin(), state::sur5); | 1603 | 917 | digit = detail::hex_digit(*cs); | 1604 | 917 | if(BOOST_JSON_UNLIKELY(digit == -1)) | 1605 | 10 | { | 1606 | 10 | BOOST_STATIC_CONSTEXPR source_location loc | 1607 | 10 | = BOOST_CURRENT_LOCATION; | 1608 | 10 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1609 | 10 | } | 1610 | 907 | ++cs; | 1611 | 907 | u2_ += digit << 4; | 1612 | 907 | do_sur6: | 1613 | 907 | if(BOOST_JSON_UNLIKELY(! cs)) | 1614 | 10 | return maybe_suspend(cs.begin(), state::sur6); | 1615 | 897 | digit = detail::hex_digit(*cs); | 1616 | 897 | if(BOOST_JSON_UNLIKELY(digit == -1)) | 1617 | 4 | { | 1618 | 4 | BOOST_STATIC_CONSTEXPR source_location loc | 1619 | 4 | = BOOST_CURRENT_LOCATION; | 1620 | 4 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1621 | 4 | } | 1622 | 893 | ++cs; | 1623 | 893 | u2_ += digit; | 1624 | | // Check if the second code point is a valid trailing surrogate. | 1625 | | // Valid trailing surrogates are [DC00, DFFF] | 1626 | 893 | if(BOOST_JSON_UNLIKELY( | 1627 | 893 | u2_ < 0xdc00 || u2_ > 0xdfff)) | 1628 | 19 | { | 1629 | | // If not valid and the parser does not allow it, return an error. | 1630 | 19 | if(!allow_bad_utf16) | 1631 | 19 | { | 1632 | 19 | BOOST_STATIC_CONSTEXPR source_location loc | 1633 | 19 | = BOOST_CURRENT_LOCATION; | 1634 | 19 | return fail(cs.begin(), error::illegal_trailing_surrogate, &loc); | 1635 | 19 | } | 1636 | | // Append the replacement character for the | 1637 | | // first leading surrogate. | 1638 | 0 | temp.append_utf8(urc); | 1639 | | // Check if the second code point is a | 1640 | | // valid unicode scalar value (invalid leading | 1641 | | // or trailing surrogate) | 1642 | 0 | if (u2_ < 0xd800 || u2_ > 0xdbff) | 1643 | 0 | { | 1644 | 0 | temp.append_utf8(u2_); | 1645 | 0 | break; | 1646 | 0 | } | 1647 | | // If it is a valid leading surrogate | 1648 | 0 | else | 1649 | 0 | { | 1650 | 0 | u1_ = u2_; | 1651 | 0 | goto do_sur1; | 1652 | 0 | } | 1653 | 0 | } | 1654 | | // Calculate the Unicode code point from the surrogate pair and | 1655 | | // append the UTF-8 representation. | 1656 | 874 | unsigned cp = | 1657 | 874 | ((u1_ - 0xd800) << 10) + | 1658 | 874 | ((u2_ - 0xdc00)) + | 1659 | 874 | 0x10000; | 1660 | | // utf-16 surrogate pair | 1661 | 874 | temp.append_utf8(cp); | 1662 | 4.42M | } | 1663 | | | 1664 | | // flush | 1665 | 4.42M | if(BOOST_JSON_UNLIKELY( !cs ) || *cs != '\\') | 1666 | 14.0k | break; | 1667 | 4.42M | } | 1668 | | | 1669 | 14.0k | if(BOOST_JSON_LIKELY( temp.size() )) | 1670 | 14.0k | { | 1671 | 14.0k | BOOST_ASSERT(total <= max_size); | 1672 | 14.0k | if(BOOST_JSON_UNLIKELY( temp.size() > max_size - total )) | 1673 | 0 | { | 1674 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1675 | 0 | = BOOST_CURRENT_LOCATION; | 1676 | 0 | return fail(cs.begin(), ev_too_large, &loc); | 1677 | 0 | } | 1678 | | | 1679 | 14.0k | total += temp.size(); | 1680 | 14.0k | bool const r = is_key | 1681 | 14.0k | ? h_.on_key_part(temp.get(), total, ec_) | 1682 | 14.0k | : h_.on_string_part(temp.get(), total, ec_); | 1683 | 14.0k | if(BOOST_JSON_UNLIKELY( !r )) | 1684 | 212 | return fail( cs.begin() ); | 1685 | 14.0k | } | 1686 | | | 1687 | 13.8k | return cs.begin(); | 1688 | 14.0k | } |
Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_escaped<false>(char const*, unsigned long&, std::__1::integral_constant<bool, false>, bool, bool) |
1689 | | |
1690 | | //---------------------------------------------------------- |
1691 | | |
1692 | | template<class Handler> |
1693 | | template< |
1694 | | bool StackEmpty_, |
1695 | | bool AllowComments_/*, |
1696 | | bool AllowTrailing_, |
1697 | | bool AllowBadUTF8_*/> |
1698 | | const char* |
1699 | | basic_parser<Handler>:: |
1700 | | parse_object(const char* p, |
1701 | | std::integral_constant<bool, StackEmpty_> stack_empty, |
1702 | | std::integral_constant<bool, AllowComments_> allow_comments, |
1703 | | /*std::integral_constant<bool, AllowTrailing_>*/ bool allow_trailing, |
1704 | | /*std::integral_constant<bool, AllowBadUTF8_>*/ bool allow_bad_utf8, |
1705 | | bool allow_bad_utf16) |
1706 | 11.1k | { |
1707 | 11.1k | detail::const_stream_wrapper cs(p, end_); |
1708 | 11.1k | std::size_t size; |
1709 | 11.1k | if(! stack_empty && ! st_.empty()) |
1710 | 0 | { |
1711 | | // resume |
1712 | 0 | state st; |
1713 | 0 | st_.pop(st); |
1714 | 0 | st_.pop(size); |
1715 | 0 | switch(st) |
1716 | 0 | { |
1717 | 0 | default: BOOST_JSON_UNREACHABLE(); |
1718 | 0 | case state::obj1: goto do_obj1; |
1719 | 0 | case state::obj2: goto do_obj2; |
1720 | 0 | case state::obj3: goto do_obj3; |
1721 | 0 | case state::obj4: goto do_obj4; |
1722 | 0 | case state::obj5: goto do_obj5; |
1723 | 0 | case state::obj6: goto do_obj6; |
1724 | 0 | case state::obj7: goto do_obj7; |
1725 | 0 | case state::obj8: goto do_obj8; |
1726 | 0 | case state::obj9: goto do_obj9; |
1727 | 0 | case state::obj10: goto do_obj10; |
1728 | 0 | case state::obj11: goto do_obj11; |
1729 | 0 | } |
1730 | 0 | } |
1731 | 11.1k | BOOST_ASSERT(*cs == '{'); |
1732 | 11.1k | size = 0; |
1733 | 11.1k | if(BOOST_JSON_UNLIKELY(! depth_)) |
1734 | 3 | { |
1735 | 3 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; |
1736 | 3 | return fail(cs.begin(), error::too_deep, &loc); |
1737 | 3 | } |
1738 | 11.1k | --depth_; |
1739 | 11.1k | if(BOOST_JSON_UNLIKELY( |
1740 | 11.1k | ! h_.on_object_begin(ec_))) |
1741 | 54 | return fail(cs.begin()); |
1742 | 11.1k | ++cs; |
1743 | | // object: |
1744 | | // '{' *ws '}' |
1745 | | // '{' *ws string *ws ':' *ws value *ws *[ ',' *ws string *ws ':' *ws value *ws ] '}' |
1746 | 11.1k | do_obj1: |
1747 | 11.1k | cs = detail::count_whitespace(cs.begin(), cs.end()); |
1748 | 11.1k | if(BOOST_JSON_UNLIKELY(! cs)) |
1749 | 53 | return maybe_suspend(cs.begin(), state::obj1, size); |
1750 | 11.0k | if(BOOST_JSON_LIKELY(*cs != '}')) |
1751 | 9.57k | { |
1752 | 9.57k | if(BOOST_JSON_UNLIKELY(*cs != '\x22')) |
1753 | 63 | { |
1754 | 63 | if(allow_comments && *cs == '/') |
1755 | 0 | { |
1756 | 0 | do_obj2: |
1757 | 0 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); |
1758 | 0 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) |
1759 | 0 | return suspend_or_fail(state::obj2, size); |
1760 | 0 | goto do_obj1; |
1761 | 0 | } |
1762 | 63 | BOOST_STATIC_CONSTEXPR source_location loc |
1763 | 63 | = BOOST_CURRENT_LOCATION; |
1764 | 63 | return fail(cs.begin(), error::syntax, &loc); |
1765 | 63 | } |
1766 | 266k | loop: |
1767 | 266k | if(BOOST_JSON_UNLIKELY(++size > |
1768 | 266k | Handler::max_object_size)) |
1769 | 0 | { |
1770 | 0 | BOOST_STATIC_CONSTEXPR source_location loc |
1771 | 0 | = BOOST_CURRENT_LOCATION; |
1772 | 0 | return fail(cs.begin(), error::object_too_large, &loc); |
1773 | 0 | } |
1774 | 266k | do_obj3: |
1775 | 266k | cs = parse_string(cs.begin(), stack_empty, std::true_type(), allow_bad_utf8, allow_bad_utf16); |
1776 | 266k | if(BOOST_JSON_UNLIKELY(incomplete(cs))) |
1777 | 521 | return suspend_or_fail(state::obj3, size); |
1778 | 266k | do_obj4: |
1779 | 266k | cs = detail::count_whitespace(cs.begin(), cs.end()); |
1780 | 266k | if(BOOST_JSON_UNLIKELY(! cs)) |
1781 | 408 | return maybe_suspend(cs.begin(), state::obj4, size); |
1782 | 265k | if(BOOST_JSON_UNLIKELY(*cs != ':')) |
1783 | 85 | { |
1784 | 85 | if(allow_comments && *cs == '/') |
1785 | 0 | { |
1786 | 0 | do_obj5: |
1787 | 0 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); |
1788 | 0 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) |
1789 | 0 | return suspend_or_fail(state::obj5, size); |
1790 | 0 | goto do_obj4; |
1791 | 0 | } |
1792 | 85 | BOOST_STATIC_CONSTEXPR source_location loc |
1793 | 85 | = BOOST_CURRENT_LOCATION; |
1794 | 85 | return fail(cs.begin(), error::syntax, &loc); |
1795 | 85 | } |
1796 | 265k | ++cs; |
1797 | 265k | do_obj6: |
1798 | 265k | cs = detail::count_whitespace(cs.begin(), cs.end()); |
1799 | 265k | if(BOOST_JSON_UNLIKELY(! cs)) |
1800 | 42 | return maybe_suspend(cs.begin(), state::obj6, size); |
1801 | 265k | do_obj7: |
1802 | 265k | cs = parse_value(cs.begin(), stack_empty, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); |
1803 | 265k | if(BOOST_JSON_UNLIKELY(incomplete(cs))) |
1804 | 4.90k | return suspend_or_fail(state::obj7, size); |
1805 | 260k | do_obj8: |
1806 | 260k | cs = detail::count_whitespace(cs.begin(), cs.end()); |
1807 | 260k | if(BOOST_JSON_UNLIKELY(! cs)) |
1808 | 1.30k | return maybe_suspend(cs.begin(), state::obj8, size); |
1809 | 259k | if(BOOST_JSON_LIKELY(*cs == ',')) |
1810 | 257k | { |
1811 | 257k | ++cs; |
1812 | 257k | do_obj9: |
1813 | 257k | cs = detail::count_whitespace(cs.begin(), cs.end()); |
1814 | 257k | if(BOOST_JSON_UNLIKELY(! cs)) |
1815 | 51 | return maybe_suspend(cs.begin(), state::obj9, size); |
1816 | | |
1817 | | // loop for next element |
1818 | 257k | if(BOOST_JSON_LIKELY(*cs == '\x22')) |
1819 | 257k | goto loop; |
1820 | 61 | if(! allow_trailing || *cs != '}') |
1821 | 61 | { |
1822 | 61 | if(allow_comments && *cs == '/') |
1823 | 0 | { |
1824 | 0 | do_obj10: |
1825 | 0 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); |
1826 | 0 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) |
1827 | 0 | return suspend_or_fail(state::obj10, size); |
1828 | 0 | goto do_obj9; |
1829 | 0 | } |
1830 | 61 | BOOST_STATIC_CONSTEXPR source_location loc |
1831 | 61 | = BOOST_CURRENT_LOCATION; |
1832 | 61 | return fail(cs.begin(), error::syntax, &loc); |
1833 | 61 | } |
1834 | 61 | } |
1835 | 2.13k | else if(BOOST_JSON_UNLIKELY(*cs != '}')) |
1836 | 113 | { |
1837 | 113 | if(allow_comments && *cs == '/') |
1838 | 0 | { |
1839 | 0 | do_obj11: |
1840 | 0 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); |
1841 | 0 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) |
1842 | 0 | return suspend_or_fail(state::obj11, size); |
1843 | 0 | goto do_obj8; |
1844 | 0 | } |
1845 | 113 | BOOST_STATIC_CONSTEXPR source_location loc |
1846 | 113 | = BOOST_CURRENT_LOCATION; |
1847 | 113 | return fail(cs.begin(), error::syntax, &loc); |
1848 | 113 | } |
1849 | | // got closing brace, fall through |
1850 | 259k | } |
1851 | 3.51k | if(BOOST_JSON_UNLIKELY( |
1852 | 3.51k | ! h_.on_object_end(size, ec_))) |
1853 | 10 | return fail(cs.begin()); |
1854 | 3.50k | ++depth_; |
1855 | 3.50k | ++cs; |
1856 | 3.50k | return cs.begin(); |
1857 | 3.51k | } char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_object<true, false>(char const*, std::__1::integral_constant<bool, true>, std::__1::integral_constant<bool, false>, bool, bool, bool) Line | Count | Source | 1706 | 11.1k | { | 1707 | 11.1k | detail::const_stream_wrapper cs(p, end_); | 1708 | 11.1k | std::size_t size; | 1709 | 11.1k | if(! stack_empty && ! st_.empty()) | 1710 | 0 | { | 1711 | | // resume | 1712 | 0 | state st; | 1713 | 0 | st_.pop(st); | 1714 | 0 | st_.pop(size); | 1715 | 0 | switch(st) | 1716 | 0 | { | 1717 | 0 | default: BOOST_JSON_UNREACHABLE(); | 1718 | 0 | case state::obj1: goto do_obj1; | 1719 | 0 | case state::obj2: goto do_obj2; | 1720 | 0 | case state::obj3: goto do_obj3; | 1721 | 0 | case state::obj4: goto do_obj4; | 1722 | 0 | case state::obj5: goto do_obj5; | 1723 | 0 | case state::obj6: goto do_obj6; | 1724 | 0 | case state::obj7: goto do_obj7; | 1725 | 0 | case state::obj8: goto do_obj8; | 1726 | 0 | case state::obj9: goto do_obj9; | 1727 | 0 | case state::obj10: goto do_obj10; | 1728 | 0 | case state::obj11: goto do_obj11; | 1729 | 0 | } | 1730 | 0 | } | 1731 | 11.1k | BOOST_ASSERT(*cs == '{'); | 1732 | 11.1k | size = 0; | 1733 | 11.1k | if(BOOST_JSON_UNLIKELY(! depth_)) | 1734 | 3 | { | 1735 | 3 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 1736 | 3 | return fail(cs.begin(), error::too_deep, &loc); | 1737 | 3 | } | 1738 | 11.1k | --depth_; | 1739 | 11.1k | if(BOOST_JSON_UNLIKELY( | 1740 | 11.1k | ! h_.on_object_begin(ec_))) | 1741 | 54 | return fail(cs.begin()); | 1742 | 11.1k | ++cs; | 1743 | | // object: | 1744 | | // '{' *ws '}' | 1745 | | // '{' *ws string *ws ':' *ws value *ws *[ ',' *ws string *ws ':' *ws value *ws ] '}' | 1746 | 11.1k | do_obj1: | 1747 | 11.1k | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1748 | 11.1k | if(BOOST_JSON_UNLIKELY(! cs)) | 1749 | 53 | return maybe_suspend(cs.begin(), state::obj1, size); | 1750 | 11.0k | if(BOOST_JSON_LIKELY(*cs != '}')) | 1751 | 9.57k | { | 1752 | 9.57k | if(BOOST_JSON_UNLIKELY(*cs != '\x22')) | 1753 | 63 | { | 1754 | 63 | if(allow_comments && *cs == '/') | 1755 | 0 | { | 1756 | 0 | do_obj2: | 1757 | 0 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); | 1758 | 0 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1759 | 0 | return suspend_or_fail(state::obj2, size); | 1760 | 0 | goto do_obj1; | 1761 | 0 | } | 1762 | 63 | BOOST_STATIC_CONSTEXPR source_location loc | 1763 | 63 | = BOOST_CURRENT_LOCATION; | 1764 | 63 | return fail(cs.begin(), error::syntax, &loc); | 1765 | 63 | } | 1766 | 266k | loop: | 1767 | 266k | if(BOOST_JSON_UNLIKELY(++size > | 1768 | 266k | Handler::max_object_size)) | 1769 | 0 | { | 1770 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1771 | 0 | = BOOST_CURRENT_LOCATION; | 1772 | 0 | return fail(cs.begin(), error::object_too_large, &loc); | 1773 | 0 | } | 1774 | 266k | do_obj3: | 1775 | 266k | cs = parse_string(cs.begin(), stack_empty, std::true_type(), allow_bad_utf8, allow_bad_utf16); | 1776 | 266k | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1777 | 521 | return suspend_or_fail(state::obj3, size); | 1778 | 266k | do_obj4: | 1779 | 266k | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1780 | 266k | if(BOOST_JSON_UNLIKELY(! cs)) | 1781 | 408 | return maybe_suspend(cs.begin(), state::obj4, size); | 1782 | 265k | if(BOOST_JSON_UNLIKELY(*cs != ':')) | 1783 | 85 | { | 1784 | 85 | if(allow_comments && *cs == '/') | 1785 | 0 | { | 1786 | 0 | do_obj5: | 1787 | 0 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); | 1788 | 0 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1789 | 0 | return suspend_or_fail(state::obj5, size); | 1790 | 0 | goto do_obj4; | 1791 | 0 | } | 1792 | 85 | BOOST_STATIC_CONSTEXPR source_location loc | 1793 | 85 | = BOOST_CURRENT_LOCATION; | 1794 | 85 | return fail(cs.begin(), error::syntax, &loc); | 1795 | 85 | } | 1796 | 265k | ++cs; | 1797 | 265k | do_obj6: | 1798 | 265k | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1799 | 265k | if(BOOST_JSON_UNLIKELY(! cs)) | 1800 | 42 | return maybe_suspend(cs.begin(), state::obj6, size); | 1801 | 265k | do_obj7: | 1802 | 265k | cs = parse_value(cs.begin(), stack_empty, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | 1803 | 265k | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1804 | 4.90k | return suspend_or_fail(state::obj7, size); | 1805 | 260k | do_obj8: | 1806 | 260k | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1807 | 260k | if(BOOST_JSON_UNLIKELY(! cs)) | 1808 | 1.30k | return maybe_suspend(cs.begin(), state::obj8, size); | 1809 | 259k | if(BOOST_JSON_LIKELY(*cs == ',')) | 1810 | 257k | { | 1811 | 257k | ++cs; | 1812 | 257k | do_obj9: | 1813 | 257k | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1814 | 257k | if(BOOST_JSON_UNLIKELY(! cs)) | 1815 | 51 | return maybe_suspend(cs.begin(), state::obj9, size); | 1816 | | | 1817 | | // loop for next element | 1818 | 257k | if(BOOST_JSON_LIKELY(*cs == '\x22')) | 1819 | 257k | goto loop; | 1820 | 61 | if(! allow_trailing || *cs != '}') | 1821 | 61 | { | 1822 | 61 | if(allow_comments && *cs == '/') | 1823 | 0 | { | 1824 | 0 | do_obj10: | 1825 | 0 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); | 1826 | 0 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1827 | 0 | return suspend_or_fail(state::obj10, size); | 1828 | 0 | goto do_obj9; | 1829 | 0 | } | 1830 | 61 | BOOST_STATIC_CONSTEXPR source_location loc | 1831 | 61 | = BOOST_CURRENT_LOCATION; | 1832 | 61 | return fail(cs.begin(), error::syntax, &loc); | 1833 | 61 | } | 1834 | 61 | } | 1835 | 2.13k | else if(BOOST_JSON_UNLIKELY(*cs != '}')) | 1836 | 113 | { | 1837 | 113 | if(allow_comments && *cs == '/') | 1838 | 0 | { | 1839 | 0 | do_obj11: | 1840 | 0 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); | 1841 | 0 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1842 | 0 | return suspend_or_fail(state::obj11, size); | 1843 | 0 | goto do_obj8; | 1844 | 0 | } | 1845 | 113 | BOOST_STATIC_CONSTEXPR source_location loc | 1846 | 113 | = BOOST_CURRENT_LOCATION; | 1847 | 113 | return fail(cs.begin(), error::syntax, &loc); | 1848 | 113 | } | 1849 | | // got closing brace, fall through | 1850 | 259k | } | 1851 | 3.51k | if(BOOST_JSON_UNLIKELY( | 1852 | 3.51k | ! h_.on_object_end(size, ec_))) | 1853 | 10 | return fail(cs.begin()); | 1854 | 3.50k | ++depth_; | 1855 | 3.50k | ++cs; | 1856 | 3.50k | return cs.begin(); | 1857 | 3.51k | } |
Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_object<true, true>(char const*, std::__1::integral_constant<bool, true>, std::__1::integral_constant<bool, true>, bool, bool, bool) Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_object<false, false>(char const*, std::__1::integral_constant<bool, false>, std::__1::integral_constant<bool, false>, bool, bool, bool) Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_object<false, true>(char const*, std::__1::integral_constant<bool, false>, std::__1::integral_constant<bool, true>, bool, bool, bool) |
1858 | | |
1859 | | //---------------------------------------------------------- |
1860 | | |
1861 | | template<class Handler> |
1862 | | template< |
1863 | | bool StackEmpty_, |
1864 | | bool AllowComments_/*, |
1865 | | bool AllowTrailing_, |
1866 | | bool AllowBadUTF8_*/> |
1867 | | const char* |
1868 | | basic_parser<Handler>:: |
1869 | | parse_array(const char* p, |
1870 | | std::integral_constant<bool, StackEmpty_> stack_empty, |
1871 | | std::integral_constant<bool, AllowComments_> allow_comments, |
1872 | | /*std::integral_constant<bool, AllowTrailing_>*/ bool allow_trailing, |
1873 | | /*std::integral_constant<bool, AllowBadUTF8_>*/ bool allow_bad_utf8, |
1874 | | bool allow_bad_utf16) |
1875 | 14.5k | { |
1876 | 14.5k | detail::const_stream_wrapper cs(p, end_); |
1877 | 14.5k | std::size_t size; |
1878 | 14.5k | if(! stack_empty && ! st_.empty()) |
1879 | 0 | { |
1880 | | // resume |
1881 | 0 | state st; |
1882 | 0 | st_.pop(st); |
1883 | 0 | st_.pop(size); |
1884 | 0 | switch(st) |
1885 | 0 | { |
1886 | 0 | default: BOOST_JSON_UNREACHABLE(); |
1887 | 0 | case state::arr1: goto do_arr1; |
1888 | 0 | case state::arr2: goto do_arr2; |
1889 | 0 | case state::arr3: goto do_arr3; |
1890 | 0 | case state::arr4: goto do_arr4; |
1891 | 0 | case state::arr5: goto do_arr5; |
1892 | 0 | case state::arr6: goto do_arr6; |
1893 | 0 | } |
1894 | 0 | } |
1895 | 14.5k | BOOST_ASSERT(*cs == '['); |
1896 | 14.5k | size = 0; |
1897 | 14.5k | if(BOOST_JSON_UNLIKELY(! depth_)) |
1898 | 4 | { |
1899 | 4 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; |
1900 | 4 | return fail(cs.begin(), error::too_deep, &loc); |
1901 | 4 | } |
1902 | 14.5k | --depth_; |
1903 | 14.5k | if(BOOST_JSON_UNLIKELY( |
1904 | 14.5k | ! h_.on_array_begin(ec_))) |
1905 | 59 | return fail(cs.begin()); |
1906 | 14.4k | ++cs; |
1907 | | // array: |
1908 | | // '[' *ws ']' |
1909 | | // '[' *ws value *ws *[ ',' *ws value *ws ] ']' |
1910 | 14.4k | do_arr1: |
1911 | 14.4k | cs = detail::count_whitespace(cs.begin(), cs.end()); |
1912 | 14.4k | if(BOOST_JSON_UNLIKELY(! cs)) |
1913 | 147 | return maybe_suspend(cs.begin(), state::arr1, size); |
1914 | 14.3k | if(BOOST_JSON_LIKELY(*cs != ']')) |
1915 | 10.8k | { |
1916 | 1.14M | loop: |
1917 | 1.14M | if(allow_comments && *cs == '/') |
1918 | 0 | { |
1919 | 0 | do_arr2: |
1920 | 0 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); |
1921 | 0 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) |
1922 | 0 | return suspend_or_fail(state::arr2, size); |
1923 | 0 | goto do_arr1; |
1924 | 0 | } |
1925 | 1.14M | if(BOOST_JSON_UNLIKELY(++size > |
1926 | 1.14M | Handler::max_array_size)) |
1927 | 0 | { |
1928 | 0 | BOOST_STATIC_CONSTEXPR source_location loc |
1929 | 0 | = BOOST_CURRENT_LOCATION; |
1930 | 0 | return fail(cs.begin(), error::array_too_large, &loc); |
1931 | 0 | } |
1932 | 1.14M | do_arr3: |
1933 | | // array is not empty, value required |
1934 | 1.14M | cs = parse_value(cs.begin(), stack_empty, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); |
1935 | 1.14M | if(BOOST_JSON_UNLIKELY(incomplete(cs))) |
1936 | 2.45k | return suspend_or_fail(state::arr3, size); |
1937 | 1.14M | do_arr4: |
1938 | 1.14M | cs = detail::count_whitespace(cs.begin(), cs.end()); |
1939 | 1.14M | if(BOOST_JSON_UNLIKELY(! cs)) |
1940 | 893 | return maybe_suspend(cs.begin(), state::arr4, size); |
1941 | 1.13M | if(BOOST_JSON_LIKELY(*cs == ',')) |
1942 | 1.13M | { |
1943 | 1.13M | ++cs; |
1944 | 1.13M | do_arr5: |
1945 | 1.13M | cs = detail::count_whitespace(cs.begin(), cs.end()); |
1946 | 1.13M | if(BOOST_JSON_UNLIKELY(! cs)) |
1947 | 81 | return maybe_suspend(cs.begin(), state::arr5, size); |
1948 | | // loop for next element |
1949 | 1.13M | if(! allow_trailing || *cs != ']') |
1950 | 1.13M | goto loop; |
1951 | 1.13M | } |
1952 | 7.40k | else if(BOOST_JSON_UNLIKELY(*cs != ']')) |
1953 | 322 | { |
1954 | 322 | if(allow_comments && *cs == '/') |
1955 | 0 | { |
1956 | 0 | do_arr6: |
1957 | 0 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); |
1958 | 0 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) |
1959 | 0 | return suspend_or_fail(state::arr6, size); |
1960 | 0 | goto do_arr4; |
1961 | 0 | } |
1962 | 322 | BOOST_STATIC_CONSTEXPR source_location loc |
1963 | 322 | = BOOST_CURRENT_LOCATION; |
1964 | 322 | return fail(cs.begin(), error::syntax, &loc); |
1965 | 322 | } |
1966 | | // got closing bracket; fall through |
1967 | 1.13M | } |
1968 | 10.5k | if(BOOST_JSON_UNLIKELY( |
1969 | 10.5k | ! h_.on_array_end(size, ec_))) |
1970 | 28 | return fail(cs.begin()); |
1971 | 10.5k | ++depth_; |
1972 | 10.5k | ++cs; |
1973 | 10.5k | return cs.begin(); |
1974 | 10.5k | } char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_array<true, false>(char const*, std::__1::integral_constant<bool, true>, std::__1::integral_constant<bool, false>, bool, bool, bool) Line | Count | Source | 1875 | 14.5k | { | 1876 | 14.5k | detail::const_stream_wrapper cs(p, end_); | 1877 | 14.5k | std::size_t size; | 1878 | 14.5k | if(! stack_empty && ! st_.empty()) | 1879 | 0 | { | 1880 | | // resume | 1881 | 0 | state st; | 1882 | 0 | st_.pop(st); | 1883 | 0 | st_.pop(size); | 1884 | 0 | switch(st) | 1885 | 0 | { | 1886 | 0 | default: BOOST_JSON_UNREACHABLE(); | 1887 | 0 | case state::arr1: goto do_arr1; | 1888 | 0 | case state::arr2: goto do_arr2; | 1889 | 0 | case state::arr3: goto do_arr3; | 1890 | 0 | case state::arr4: goto do_arr4; | 1891 | 0 | case state::arr5: goto do_arr5; | 1892 | 0 | case state::arr6: goto do_arr6; | 1893 | 0 | } | 1894 | 0 | } | 1895 | 14.5k | BOOST_ASSERT(*cs == '['); | 1896 | 14.5k | size = 0; | 1897 | 14.5k | if(BOOST_JSON_UNLIKELY(! depth_)) | 1898 | 4 | { | 1899 | 4 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 1900 | 4 | return fail(cs.begin(), error::too_deep, &loc); | 1901 | 4 | } | 1902 | 14.5k | --depth_; | 1903 | 14.5k | if(BOOST_JSON_UNLIKELY( | 1904 | 14.5k | ! h_.on_array_begin(ec_))) | 1905 | 59 | return fail(cs.begin()); | 1906 | 14.4k | ++cs; | 1907 | | // array: | 1908 | | // '[' *ws ']' | 1909 | | // '[' *ws value *ws *[ ',' *ws value *ws ] ']' | 1910 | 14.4k | do_arr1: | 1911 | 14.4k | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1912 | 14.4k | if(BOOST_JSON_UNLIKELY(! cs)) | 1913 | 147 | return maybe_suspend(cs.begin(), state::arr1, size); | 1914 | 14.3k | if(BOOST_JSON_LIKELY(*cs != ']')) | 1915 | 10.8k | { | 1916 | 1.14M | loop: | 1917 | 1.14M | if(allow_comments && *cs == '/') | 1918 | 0 | { | 1919 | 0 | do_arr2: | 1920 | 0 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); | 1921 | 0 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1922 | 0 | return suspend_or_fail(state::arr2, size); | 1923 | 0 | goto do_arr1; | 1924 | 0 | } | 1925 | 1.14M | if(BOOST_JSON_UNLIKELY(++size > | 1926 | 1.14M | Handler::max_array_size)) | 1927 | 0 | { | 1928 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1929 | 0 | = BOOST_CURRENT_LOCATION; | 1930 | 0 | return fail(cs.begin(), error::array_too_large, &loc); | 1931 | 0 | } | 1932 | 1.14M | do_arr3: | 1933 | | // array is not empty, value required | 1934 | 1.14M | cs = parse_value(cs.begin(), stack_empty, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | 1935 | 1.14M | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1936 | 2.45k | return suspend_or_fail(state::arr3, size); | 1937 | 1.14M | do_arr4: | 1938 | 1.14M | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1939 | 1.14M | if(BOOST_JSON_UNLIKELY(! cs)) | 1940 | 893 | return maybe_suspend(cs.begin(), state::arr4, size); | 1941 | 1.13M | if(BOOST_JSON_LIKELY(*cs == ',')) | 1942 | 1.13M | { | 1943 | 1.13M | ++cs; | 1944 | 1.13M | do_arr5: | 1945 | 1.13M | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1946 | 1.13M | if(BOOST_JSON_UNLIKELY(! cs)) | 1947 | 81 | return maybe_suspend(cs.begin(), state::arr5, size); | 1948 | | // loop for next element | 1949 | 1.13M | if(! allow_trailing || *cs != ']') | 1950 | 1.13M | goto loop; | 1951 | 1.13M | } | 1952 | 7.40k | else if(BOOST_JSON_UNLIKELY(*cs != ']')) | 1953 | 322 | { | 1954 | 322 | if(allow_comments && *cs == '/') | 1955 | 0 | { | 1956 | 0 | do_arr6: | 1957 | 0 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); | 1958 | 0 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1959 | 0 | return suspend_or_fail(state::arr6, size); | 1960 | 0 | goto do_arr4; | 1961 | 0 | } | 1962 | 322 | BOOST_STATIC_CONSTEXPR source_location loc | 1963 | 322 | = BOOST_CURRENT_LOCATION; | 1964 | 322 | return fail(cs.begin(), error::syntax, &loc); | 1965 | 322 | } | 1966 | | // got closing bracket; fall through | 1967 | 1.13M | } | 1968 | 10.5k | if(BOOST_JSON_UNLIKELY( | 1969 | 10.5k | ! h_.on_array_end(size, ec_))) | 1970 | 28 | return fail(cs.begin()); | 1971 | 10.5k | ++depth_; | 1972 | 10.5k | ++cs; | 1973 | 10.5k | return cs.begin(); | 1974 | 10.5k | } |
Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_array<true, true>(char const*, std::__1::integral_constant<bool, true>, std::__1::integral_constant<bool, true>, bool, bool, bool) Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_array<false, false>(char const*, std::__1::integral_constant<bool, false>, std::__1::integral_constant<bool, false>, bool, bool, bool) Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_array<false, true>(char const*, std::__1::integral_constant<bool, false>, std::__1::integral_constant<bool, true>, bool, bool, bool) |
1975 | | |
1976 | | //---------------------------------------------------------- |
1977 | | |
1978 | | template<class Handler> |
1979 | | template<bool StackEmpty_, char First_, number_precision Numbers_> |
1980 | | const char* |
1981 | | basic_parser<Handler>:: |
1982 | | parse_number(const char* p, |
1983 | | std::integral_constant<bool, StackEmpty_> stack_empty, |
1984 | | std::integral_constant<char, First_> first, |
1985 | | std::integral_constant<number_precision, Numbers_> mode) |
1986 | 1.17M | { |
1987 | 1.17M | constexpr bool precise_parsing = mode == number_precision::precise; |
1988 | 1.17M | constexpr bool no_parsing = mode == number_precision::none; |
1989 | | |
1990 | | // only one of these will be true if we are not resuming |
1991 | | // if negative then !zero_first && !nonzero_first |
1992 | | // if zero_first then !nonzero_first && !negative |
1993 | | // if nonzero_first then !zero_first && !negative |
1994 | 1.17M | bool const negative = first == '-'; |
1995 | 1.17M | bool const zero_first = first == '0'; |
1996 | 1.17M | bool const nonzero_first = first == '+'; |
1997 | 1.17M | detail::const_stream_wrapper cs(p, end_); |
1998 | 1.17M | number num; |
1999 | 1.17M | const char* begin = cs.begin(); |
2000 | 1.17M | if(stack_empty || st_.empty()) |
2001 | 1.17M | { |
2002 | 1.17M | num.bias = 0; |
2003 | 1.17M | num.exp = 0; |
2004 | 1.17M | num.frac = false; |
2005 | 1.17M | num_buf_.clear(); |
2006 | | |
2007 | | //---------------------------------- |
2008 | | // |
2009 | | // '-' |
2010 | | // leading minus sign |
2011 | | // |
2012 | 1.17M | BOOST_ASSERT(cs); |
2013 | 1.17M | if(negative) |
2014 | 42.8k | ++cs; |
2015 | | |
2016 | 1.17M | num.neg = negative; |
2017 | 1.17M | num.frac = false; |
2018 | 1.17M | num.exp = 0; |
2019 | 1.17M | num.bias = 0; |
2020 | | |
2021 | | // fast path |
2022 | 1.17M | if( cs.remain() >= 16 + 1 + 16 ) // digits . digits |
2023 | 1.16M | { |
2024 | 1.16M | int n1; |
2025 | | |
2026 | 1.16M | if( nonzero_first || |
2027 | 1.16M | (negative && *cs != '0') ) |
2028 | 1.14M | { |
2029 | 1.14M | n1 = detail::count_digits( cs.begin() ); |
2030 | 1.14M | BOOST_ASSERT(n1 >= 0 && n1 <= 16); |
2031 | | |
2032 | 1.14M | if( negative && n1 == 0 && opt_.allow_infinity_and_nan ) |
2033 | 0 | { |
2034 | 0 | return parse_literal( |
2035 | 0 | p - 1, |
2036 | 0 | detail::literals_c<detail::literals::neg_infinity>()); |
2037 | 0 | } |
2038 | | |
2039 | 1.14M | if( ! nonzero_first && n1 == 0 ) |
2040 | 2 | { |
2041 | | // digit required |
2042 | 2 | BOOST_STATIC_CONSTEXPR source_location loc |
2043 | 2 | = BOOST_CURRENT_LOCATION; |
2044 | 2 | return fail(cs.begin(), error::syntax, &loc); |
2045 | 2 | } |
2046 | | |
2047 | 1.14M | BOOST_IF_CONSTEXPR( !no_parsing ) |
2048 | 1.14M | num.mant = detail::parse_unsigned( 0, cs.begin(), n1 ); |
2049 | | else |
2050 | 0 | num.mant = 0; |
2051 | | |
2052 | 1.14M | cs += n1; |
2053 | | |
2054 | | // integer or floating-point with |
2055 | | // >= 16 leading digits |
2056 | 1.14M | if( n1 == 16 ) |
2057 | 14.3k | { |
2058 | 14.3k | goto do_num2; |
2059 | 14.3k | } |
2060 | 1.14M | } |
2061 | 28.3k | else |
2062 | 28.3k | { |
2063 | | // 0. floating-point or 0e integer |
2064 | 28.3k | num.mant = 0; |
2065 | 28.3k | n1 = 0; |
2066 | 28.3k | ++cs; |
2067 | 28.3k | } |
2068 | | |
2069 | 1.15M | { |
2070 | 1.15M | const char c = *cs; |
2071 | 1.15M | if(c != '.') |
2072 | 1.14M | { |
2073 | 1.14M | if((c | 32) == 'e') |
2074 | 7.90k | { |
2075 | 7.90k | ++cs; |
2076 | 7.90k | goto do_exp1; |
2077 | 7.90k | } |
2078 | 1.13M | BOOST_IF_CONSTEXPR( negative && !no_parsing ) |
2079 | 1.13M | num.mant = ~num.mant + 1; |
2080 | 1.13M | goto finish_signed; |
2081 | 1.14M | } |
2082 | 1.15M | } |
2083 | | |
2084 | | // floating-point number |
2085 | | |
2086 | 11.6k | ++cs; |
2087 | | |
2088 | 11.6k | int n2 = detail::count_digits( cs.begin() ); |
2089 | 11.6k | BOOST_ASSERT(n2 >= 0 && n2 <= 16); |
2090 | | |
2091 | 11.6k | if( n2 == 0 ) |
2092 | 6 | { |
2093 | | // digit required |
2094 | 6 | BOOST_STATIC_CONSTEXPR source_location loc |
2095 | 6 | = BOOST_CURRENT_LOCATION; |
2096 | 6 | return fail(cs.begin(), error::syntax, &loc); |
2097 | 6 | } |
2098 | | |
2099 | | // floating-point mantissa overflow |
2100 | 11.6k | if( n1 + n2 >= 19 ) |
2101 | 1.29k | { |
2102 | 1.29k | goto do_num7; |
2103 | 1.29k | } |
2104 | | |
2105 | 10.3k | BOOST_IF_CONSTEXPR( !no_parsing ) |
2106 | 10.3k | num.mant = detail::parse_unsigned( num.mant, cs.begin(), n2 ); |
2107 | | |
2108 | 10.3k | BOOST_ASSERT(num.bias == 0); |
2109 | | |
2110 | 10.3k | num.bias -= n2; |
2111 | | |
2112 | 10.3k | cs += n2; |
2113 | | |
2114 | 10.3k | char ch = *cs; |
2115 | | |
2116 | 10.3k | if( (ch | 32) == 'e' ) |
2117 | 4.05k | { |
2118 | 4.05k | ++cs; |
2119 | 4.05k | goto do_exp1; |
2120 | 4.05k | } |
2121 | 6.31k | else if( ch >= '0' && ch <= '9' ) |
2122 | 1.85k | { |
2123 | 1.85k | goto do_num8; |
2124 | 1.85k | } |
2125 | | |
2126 | 4.45k | goto finish_dub; |
2127 | 10.3k | } |
2128 | 1.17M | } |
2129 | 0 | else |
2130 | 0 | { |
2131 | 0 | num = num_; |
2132 | 0 | state st; |
2133 | 0 | st_.pop(st); |
2134 | 0 | switch(st) |
2135 | 0 | { |
2136 | 0 | default: BOOST_JSON_UNREACHABLE(); |
2137 | 0 | case state::num1: goto do_num1; |
2138 | 0 | case state::num2: goto do_num2; |
2139 | 0 | case state::num3: goto do_num3; |
2140 | 0 | case state::num4: goto do_num4; |
2141 | 0 | case state::num5: goto do_num5; |
2142 | 0 | case state::num6: goto do_num6; |
2143 | 0 | case state::num7: goto do_num7; |
2144 | 0 | case state::num8: goto do_num8; |
2145 | 0 | case state::exp1: goto do_exp1; |
2146 | 0 | case state::exp2: goto do_exp2; |
2147 | 0 | case state::exp3: goto do_exp3; |
2148 | 0 | } |
2149 | 0 | } |
2150 | | |
2151 | | //---------------------------------- |
2152 | | // |
2153 | | // DIGIT |
2154 | | // first digit |
2155 | | // |
2156 | 10.4k | do_num1: |
2157 | 10.4k | if(zero_first || nonzero_first || |
2158 | 10.4k | BOOST_JSON_LIKELY(cs)) |
2159 | 10.3k | { |
2160 | 10.3k | char const c = *cs; |
2161 | 10.3k | if(zero_first) |
2162 | 1.84k | { |
2163 | 1.84k | ++cs; |
2164 | 1.84k | num.mant = 0; |
2165 | 1.84k | goto do_num6; |
2166 | 1.84k | } |
2167 | 8.50k | else if(nonzero_first || BOOST_JSON_LIKELY( |
2168 | 8.50k | c >= '1' && c <= '9')) |
2169 | 8.28k | { |
2170 | 8.28k | ++cs; |
2171 | 8.28k | num.mant = c - '0'; |
2172 | 8.28k | } |
2173 | 217 | else if(BOOST_JSON_UNLIKELY( |
2174 | 217 | c == '0')) |
2175 | 201 | { |
2176 | 201 | ++cs; |
2177 | 201 | num.mant = 0; |
2178 | 201 | goto do_num6; |
2179 | 201 | } |
2180 | 16 | else if( (negative || num.neg) && opt_.allow_infinity_and_nan ) |
2181 | 0 | { |
2182 | 0 | st_.push(state::lit1); |
2183 | 0 | cur_lit_ = literal_index(detail::literals::neg_infinity); |
2184 | 0 | lit_offset_ = 1; |
2185 | 0 | return parse_literal( |
2186 | 0 | cs.begin(), detail::literals_c<detail::literals::resume>() ); |
2187 | 0 | } |
2188 | 16 | else |
2189 | 16 | { |
2190 | 16 | BOOST_STATIC_CONSTEXPR source_location loc |
2191 | 16 | = BOOST_CURRENT_LOCATION; |
2192 | 16 | return fail(cs.begin(), error::syntax, &loc); |
2193 | 16 | } |
2194 | 10.3k | } |
2195 | 64 | else |
2196 | 64 | { |
2197 | 64 | if(BOOST_JSON_UNLIKELY( |
2198 | 64 | ! h_.on_number_part( |
2199 | 64 | {begin, cs.used(begin)}, ec_))) |
2200 | 32 | return fail(cs.begin()); |
2201 | | |
2202 | 32 | BOOST_IF_CONSTEXPR( precise_parsing ) |
2203 | 32 | num_buf_.append( begin, cs.used(begin) ); |
2204 | 32 | return maybe_suspend( |
2205 | 32 | cs.begin(), state::num1, num); |
2206 | 64 | } |
2207 | | |
2208 | | //---------------------------------- |
2209 | | // |
2210 | | // 1*DIGIT |
2211 | | // significant digits left of decimal |
2212 | | // |
2213 | 22.6k | do_num2: |
2214 | 22.6k | if(negative || (!stack_empty && num.neg)) |
2215 | 5.31k | { |
2216 | 5.31k | for(;;) |
2217 | 17.3k | { |
2218 | 17.3k | if(BOOST_JSON_UNLIKELY(! cs)) |
2219 | 465 | { |
2220 | 465 | if(BOOST_JSON_UNLIKELY(more_)) |
2221 | 0 | { |
2222 | 0 | if(BOOST_JSON_UNLIKELY( |
2223 | 0 | ! h_.on_number_part( |
2224 | 0 | {begin, cs.used(begin)}, ec_))) |
2225 | 0 | return fail(cs.begin()); |
2226 | | |
2227 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) |
2228 | 0 | num_buf_.append( begin, cs.used(begin) ); |
2229 | 0 | return suspend(cs.begin(), state::num2, num); |
2230 | 0 | } |
2231 | 465 | goto finish_int; |
2232 | 465 | } |
2233 | 16.9k | char const c = *cs; |
2234 | 16.9k | if(BOOST_JSON_LIKELY( |
2235 | 16.9k | c >= '0' && c <= '9')) |
2236 | 13.8k | { |
2237 | 13.8k | ++cs; |
2238 | | // 9223372036854775808 INT64_MIN |
2239 | 13.8k | if( num.mant > 922337203685477580 || ( |
2240 | 12.3k | num.mant == 922337203685477580 && c > '8')) |
2241 | 1.84k | break; |
2242 | 12.0k | BOOST_IF_CONSTEXPR( !no_parsing ) |
2243 | 12.0k | num.mant = 10 * num.mant + ( c - '0' ); |
2244 | 12.0k | continue; |
2245 | 13.8k | } |
2246 | 3.00k | goto do_num6; // [.eE] |
2247 | 16.9k | } |
2248 | 5.31k | } |
2249 | 17.3k | else |
2250 | 17.3k | { |
2251 | 17.3k | for(;;) |
2252 | 68.6k | { |
2253 | 68.6k | if(BOOST_JSON_UNLIKELY(! cs)) |
2254 | 1.60k | { |
2255 | 1.60k | if(BOOST_JSON_UNLIKELY(more_)) |
2256 | 0 | { |
2257 | 0 | if(BOOST_JSON_UNLIKELY( |
2258 | 0 | ! h_.on_number_part( |
2259 | 0 | {begin, cs.used(begin)}, ec_))) |
2260 | 0 | return fail(cs.begin()); |
2261 | | |
2262 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) |
2263 | 0 | num_buf_.append( begin, cs.used(begin) ); |
2264 | 0 | return suspend(cs.begin(), state::num2, num); |
2265 | 0 | } |
2266 | 1.60k | goto finish_int; |
2267 | 1.60k | } |
2268 | 67.0k | char const c = *cs; |
2269 | 67.0k | if(BOOST_JSON_LIKELY( |
2270 | 67.0k | c >= '0' && c <= '9')) |
2271 | 52.3k | { |
2272 | 52.3k | ++cs; |
2273 | | // 18446744073709551615 UINT64_MAX |
2274 | 52.3k | if( num.mant > 1844674407370955161 || ( |
2275 | 51.3k | num.mant == 1844674407370955161 && c > '5')) |
2276 | 1.11k | break; |
2277 | 51.2k | BOOST_IF_CONSTEXPR( !no_parsing ) |
2278 | 51.2k | num.mant = 10 * num.mant + ( c - '0' ); |
2279 | 51.2k | } |
2280 | 14.6k | else |
2281 | 14.6k | { |
2282 | 14.6k | goto do_num6; // [.eE] |
2283 | 14.6k | } |
2284 | 67.0k | } |
2285 | 17.3k | } |
2286 | 2.96k | ++num.bias; |
2287 | | |
2288 | | //---------------------------------- |
2289 | | // |
2290 | | // 1*DIGIT |
2291 | | // non-significant digits left of decimal |
2292 | | // |
2293 | 2.96k | do_num3: |
2294 | 2.96k | for(;;) |
2295 | 4.93M | { |
2296 | 4.93M | if(BOOST_JSON_UNLIKELY(! cs)) |
2297 | 70 | { |
2298 | 70 | if(BOOST_JSON_UNLIKELY(more_)) |
2299 | 0 | { |
2300 | 0 | if(BOOST_JSON_UNLIKELY( |
2301 | 0 | ! h_.on_number_part( |
2302 | 0 | {begin, cs.used(begin)}, ec_))) |
2303 | 0 | return fail(cs.begin()); |
2304 | | |
2305 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) |
2306 | 0 | num_buf_.append( begin, cs.used(begin) ); |
2307 | 0 | return suspend(cs.begin(), state::num3, num); |
2308 | 0 | } |
2309 | 70 | goto finish_dub; |
2310 | 70 | } |
2311 | 4.93M | char const c = *cs; |
2312 | 4.93M | if(BOOST_JSON_UNLIKELY( |
2313 | 4.93M | c >= '0' && c <= '9')) |
2314 | 4.93M | { |
2315 | 4.93M | if(BOOST_JSON_UNLIKELY( num.bias + 1 == INT_MAX )) |
2316 | 0 | { |
2317 | 0 | BOOST_STATIC_CONSTEXPR source_location loc |
2318 | 0 | = BOOST_CURRENT_LOCATION; |
2319 | 0 | return fail(cs.begin(), error::exponent_overflow, &loc); |
2320 | 0 | } |
2321 | 4.93M | ++cs; |
2322 | 4.93M | ++num.bias; |
2323 | 4.93M | } |
2324 | 2.89k | else if(BOOST_JSON_LIKELY( |
2325 | 2.89k | c == '.')) |
2326 | 347 | { |
2327 | 347 | ++cs; |
2328 | 347 | break; |
2329 | 347 | } |
2330 | 2.54k | else if((c | 32) == 'e') |
2331 | 1.36k | { |
2332 | 1.36k | ++cs; |
2333 | 1.36k | goto do_exp1; |
2334 | 1.36k | } |
2335 | 1.17k | else |
2336 | 1.17k | { |
2337 | 1.17k | goto finish_dub; |
2338 | 1.17k | } |
2339 | 4.93M | } |
2340 | | |
2341 | | //---------------------------------- |
2342 | | // |
2343 | | // DIGIT |
2344 | | // first non-significant digit |
2345 | | // to the right of decimal |
2346 | | // |
2347 | 347 | do_num4: |
2348 | 347 | { |
2349 | 347 | if(BOOST_JSON_UNLIKELY(! cs)) |
2350 | 8 | { |
2351 | 8 | if(BOOST_JSON_UNLIKELY( |
2352 | 8 | ! h_.on_number_part( |
2353 | 8 | {begin, cs.used(begin)}, ec_))) |
2354 | 2 | return fail(cs.begin()); |
2355 | | |
2356 | 6 | BOOST_IF_CONSTEXPR( precise_parsing ) |
2357 | 6 | num_buf_.append( begin, cs.used(begin) ); |
2358 | 6 | return maybe_suspend( |
2359 | 6 | cs.begin(), state::num4, num); |
2360 | 8 | } |
2361 | 339 | char const c = *cs; |
2362 | 339 | if(BOOST_JSON_LIKELY( |
2363 | | //static_cast<unsigned char>(c - '0') < 10)) |
2364 | 339 | c >= '0' && c <= '9')) |
2365 | 330 | { |
2366 | 330 | ++cs; |
2367 | 330 | } |
2368 | 9 | else |
2369 | 9 | { |
2370 | | // digit required |
2371 | 9 | BOOST_STATIC_CONSTEXPR source_location loc |
2372 | 9 | = BOOST_CURRENT_LOCATION; |
2373 | 9 | return fail(cs.begin(), error::syntax, &loc); |
2374 | 9 | } |
2375 | 339 | } |
2376 | | |
2377 | | //---------------------------------- |
2378 | | // |
2379 | | // 1*DIGIT |
2380 | | // non-significant digits |
2381 | | // to the right of decimal |
2382 | | // |
2383 | 3.12k | do_num5: |
2384 | 3.12k | for(;;) |
2385 | 71.4k | { |
2386 | 71.4k | if(BOOST_JSON_UNLIKELY(! cs)) |
2387 | 78 | { |
2388 | 78 | if(BOOST_JSON_UNLIKELY(more_)) |
2389 | 0 | { |
2390 | 0 | if(BOOST_JSON_UNLIKELY( |
2391 | 0 | ! h_.on_number_part( |
2392 | 0 | {begin, cs.used(begin)}, ec_))) |
2393 | 0 | return fail(cs.begin()); |
2394 | | |
2395 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) |
2396 | 0 | num_buf_.append( begin, cs.used(begin) ); |
2397 | 0 | return suspend(cs.begin(), state::num5, num); |
2398 | 0 | } |
2399 | 78 | goto finish_dub; |
2400 | 78 | } |
2401 | 71.4k | char const c = *cs; |
2402 | 71.4k | if(BOOST_JSON_LIKELY( |
2403 | 71.4k | c >= '0' && c <= '9')) |
2404 | 68.3k | { |
2405 | 68.3k | ++cs; |
2406 | 68.3k | } |
2407 | 3.04k | else if((c | 32) == 'e') |
2408 | 935 | { |
2409 | 935 | ++cs; |
2410 | 935 | goto do_exp1; |
2411 | 935 | } |
2412 | 2.11k | else |
2413 | 2.11k | { |
2414 | 2.11k | goto finish_dub; |
2415 | 2.11k | } |
2416 | 71.4k | } |
2417 | | |
2418 | | //---------------------------------- |
2419 | | // |
2420 | | // [.eE] |
2421 | | // |
2422 | 19.6k | do_num6: |
2423 | 19.6k | { |
2424 | 19.6k | if(BOOST_JSON_UNLIKELY(! cs)) |
2425 | 115 | { |
2426 | 115 | if(BOOST_JSON_UNLIKELY(more_)) |
2427 | 0 | { |
2428 | 0 | if(BOOST_JSON_UNLIKELY( |
2429 | 0 | ! h_.on_number_part( |
2430 | 0 | {begin, cs.used(begin)}, ec_))) |
2431 | 0 | return fail(cs.begin()); |
2432 | | |
2433 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) |
2434 | 0 | num_buf_.append( begin, cs.used(begin) ); |
2435 | 0 | return suspend(cs.begin(), state::num6, num); |
2436 | 0 | } |
2437 | 115 | goto finish_int; |
2438 | 115 | } |
2439 | 19.5k | char const c = *cs; |
2440 | 19.5k | if(BOOST_JSON_LIKELY( |
2441 | 19.5k | c == '.')) |
2442 | 2.30k | { |
2443 | 2.30k | ++cs; |
2444 | 2.30k | } |
2445 | 17.2k | else if((c | 32) == 'e') |
2446 | 2.62k | { |
2447 | 2.62k | ++cs; |
2448 | 2.62k | goto do_exp1; |
2449 | 2.62k | } |
2450 | 14.6k | else |
2451 | 14.6k | { |
2452 | 14.6k | goto finish_int; |
2453 | 14.6k | } |
2454 | 19.5k | } |
2455 | | |
2456 | | //---------------------------------- |
2457 | | // |
2458 | | // DIGIT |
2459 | | // first significant digit |
2460 | | // to the right of decimal |
2461 | | // |
2462 | 3.60k | do_num7: |
2463 | 3.60k | { |
2464 | 3.60k | if(BOOST_JSON_UNLIKELY(! cs)) |
2465 | 13 | { |
2466 | 13 | if(BOOST_JSON_UNLIKELY(more_)) |
2467 | 0 | { |
2468 | 0 | if(BOOST_JSON_UNLIKELY( |
2469 | 0 | ! h_.on_number_part( |
2470 | 0 | {begin, cs.used(begin)}, ec_))) |
2471 | 0 | return fail(cs.begin()); |
2472 | | |
2473 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) |
2474 | 0 | num_buf_.append( begin, cs.used(begin) ); |
2475 | 0 | return suspend(cs.begin(), state::num7, num); |
2476 | 0 | } |
2477 | | // digit required |
2478 | 13 | BOOST_STATIC_CONSTEXPR source_location loc |
2479 | 13 | = BOOST_CURRENT_LOCATION; |
2480 | 13 | return fail(cs.begin(), error::syntax, &loc); |
2481 | 13 | } |
2482 | 3.59k | char const c = *cs; |
2483 | 3.59k | if(BOOST_JSON_UNLIKELY( |
2484 | 3.59k | c < '0' || c > '9')) |
2485 | 42 | { |
2486 | | // digit required |
2487 | 42 | BOOST_STATIC_CONSTEXPR source_location loc |
2488 | 42 | = BOOST_CURRENT_LOCATION; |
2489 | 42 | return fail(cs.begin(), error::syntax, &loc); |
2490 | 42 | } |
2491 | 3.59k | } |
2492 | | |
2493 | | //---------------------------------- |
2494 | | // |
2495 | | // 1*DIGIT |
2496 | | // significant digits |
2497 | | // to the right of decimal |
2498 | | // |
2499 | 5.40k | do_num8: |
2500 | 5.40k | for(;;) |
2501 | 6.99M | { |
2502 | 6.99M | if(BOOST_JSON_UNLIKELY(! cs)) |
2503 | 391 | { |
2504 | 391 | if(BOOST_JSON_UNLIKELY(more_)) |
2505 | 0 | { |
2506 | 0 | if(BOOST_JSON_UNLIKELY( |
2507 | 0 | ! h_.on_number_part( |
2508 | 0 | {begin, cs.used(begin)}, ec_))) |
2509 | 0 | return fail(cs.begin()); |
2510 | | |
2511 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) |
2512 | 0 | num_buf_.append( begin, cs.used(begin) ); |
2513 | 0 | return suspend(cs.begin(), state::num8, num); |
2514 | 0 | } |
2515 | 391 | goto finish_dub; |
2516 | 391 | } |
2517 | 6.99M | char const c = *cs; |
2518 | 6.99M | if(BOOST_JSON_LIKELY( |
2519 | 6.99M | c >= '0' && c <= '9')) |
2520 | 6.99M | { |
2521 | 6.99M | ++cs; |
2522 | 6.99M | if(!no_parsing && BOOST_JSON_LIKELY( |
2523 | 6.99M | num.mant <= 9007199254740991)) // 2^53-1 |
2524 | 6.99M | { |
2525 | 6.99M | if(BOOST_JSON_UNLIKELY( num.bias - 1 == INT_MIN )) |
2526 | 0 | { |
2527 | 0 | BOOST_STATIC_CONSTEXPR source_location loc |
2528 | 0 | = BOOST_CURRENT_LOCATION; |
2529 | 0 | return fail(cs.begin(), error::exponent_overflow, &loc); |
2530 | 0 | } |
2531 | 6.99M | --num.bias; |
2532 | 6.99M | num.mant = 10 * num.mant + ( c - '0' ); |
2533 | 6.99M | } |
2534 | 2.79k | else |
2535 | 2.79k | { |
2536 | 2.79k | goto do_num5; |
2537 | 2.79k | } |
2538 | 6.99M | } |
2539 | 2.22k | else if((c | 32) == 'e') |
2540 | 615 | { |
2541 | 615 | ++cs; |
2542 | 615 | goto do_exp1; |
2543 | 615 | } |
2544 | 1.60k | else |
2545 | 1.60k | { |
2546 | 1.60k | goto finish_dub; |
2547 | 1.60k | } |
2548 | 6.99M | } |
2549 | | |
2550 | | //---------------------------------- |
2551 | | // |
2552 | | // *[+-] |
2553 | | // |
2554 | 17.4k | do_exp1: |
2555 | 17.4k | if(BOOST_JSON_UNLIKELY(! cs)) |
2556 | 66 | { |
2557 | 66 | if(BOOST_JSON_UNLIKELY( |
2558 | 66 | ! h_.on_number_part( |
2559 | 66 | {begin, cs.used(begin)}, ec_))) |
2560 | 14 | return fail(cs.begin()); |
2561 | | |
2562 | 52 | BOOST_IF_CONSTEXPR( precise_parsing ) |
2563 | 52 | num_buf_.append( begin, cs.used(begin) ); |
2564 | 52 | return maybe_suspend( |
2565 | 52 | cs.begin(), state::exp1, num); |
2566 | 66 | } |
2567 | 17.4k | if(*cs == '+') |
2568 | 708 | { |
2569 | 708 | ++cs; |
2570 | 708 | } |
2571 | 16.7k | else if(*cs == '-') |
2572 | 5.64k | { |
2573 | 5.64k | ++cs; |
2574 | 5.64k | num.frac = true; |
2575 | 5.64k | } |
2576 | | |
2577 | | //---------------------------------- |
2578 | | // |
2579 | | // DIGIT |
2580 | | // first digit of the exponent |
2581 | | // |
2582 | 17.4k | do_exp2: |
2583 | 17.4k | { |
2584 | 17.4k | if(BOOST_JSON_UNLIKELY(! cs)) |
2585 | 30 | { |
2586 | 30 | if(BOOST_JSON_UNLIKELY(more_)) |
2587 | 0 | { |
2588 | 0 | if(BOOST_JSON_UNLIKELY( |
2589 | 0 | ! h_.on_number_part( |
2590 | 0 | {begin, cs.used(begin)}, ec_))) |
2591 | 0 | return fail(cs.begin()); |
2592 | | |
2593 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) |
2594 | 0 | num_buf_.append( begin, cs.used(begin) ); |
2595 | 0 | return suspend(cs.begin(), state::exp2, num); |
2596 | 0 | } |
2597 | | // digit required |
2598 | 30 | BOOST_STATIC_CONSTEXPR source_location loc |
2599 | 30 | = BOOST_CURRENT_LOCATION; |
2600 | 30 | return fail(cs.begin(), error::syntax, &loc); |
2601 | 30 | } |
2602 | 17.3k | char const c = *cs; |
2603 | 17.3k | if(BOOST_JSON_UNLIKELY( |
2604 | 17.3k | c < '0' || c > '9')) |
2605 | 90 | { |
2606 | | // digit required |
2607 | 90 | BOOST_STATIC_CONSTEXPR source_location loc |
2608 | 90 | = BOOST_CURRENT_LOCATION; |
2609 | 90 | return fail(cs.begin(), error::syntax, &loc); |
2610 | 90 | } |
2611 | 17.3k | ++cs; |
2612 | 17.3k | num.exp = c - '0'; |
2613 | 17.3k | } |
2614 | | |
2615 | | //---------------------------------- |
2616 | | // |
2617 | | // 1*DIGIT |
2618 | | // subsequent digits in the exponent |
2619 | | // |
2620 | 17.3k | do_exp3: |
2621 | 17.3k | for(;;) |
2622 | 87.5k | { |
2623 | 87.5k | if(BOOST_JSON_UNLIKELY(! cs)) |
2624 | 880 | { |
2625 | 880 | if(BOOST_JSON_UNLIKELY(more_)) |
2626 | 0 | { |
2627 | 0 | if(BOOST_JSON_UNLIKELY( |
2628 | 0 | ! h_.on_number_part( |
2629 | 0 | {begin, cs.used(begin)}, ec_))) |
2630 | 0 | return fail(cs.begin()); |
2631 | | |
2632 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) |
2633 | 0 | num_buf_.append( begin, cs.used(begin) ); |
2634 | 0 | return suspend(cs.begin(), state::exp3, num); |
2635 | 0 | } |
2636 | 880 | } |
2637 | 86.6k | else |
2638 | 86.6k | { |
2639 | 86.6k | char const c = *cs; |
2640 | 86.6k | if(BOOST_JSON_LIKELY( c >= '0' && c <= '9' )) |
2641 | 70.2k | { |
2642 | 70.2k | if(BOOST_JSON_UNLIKELY( |
2643 | | // 2147483647 INT_MAX |
2644 | 70.2k | num.exp > 214748364 || |
2645 | 70.2k | (num.exp == 214748364 && c > '7') |
2646 | 70.2k | )) |
2647 | 7.17k | num.exp = INT_MAX; |
2648 | 63.0k | else BOOST_IF_CONSTEXPR( !no_parsing ) |
2649 | 63.0k | num.exp = 10 * num.exp + ( c - '0' ); |
2650 | | |
2651 | 70.2k | ++cs; |
2652 | 70.2k | continue; |
2653 | 70.2k | } |
2654 | 86.6k | } |
2655 | 17.3k | BOOST_ASSERT(num.exp >= 0); |
2656 | 17.3k | if ( num.frac ) |
2657 | 5.62k | { |
2658 | 5.62k | if(BOOST_JSON_UNLIKELY( num.bias < (INT_MIN + num.exp) )) |
2659 | 3.25k | { |
2660 | | // if exponent overflowed, bias is a very large negative |
2661 | | // number, and mantissa isn't zero, then we cannot parse the |
2662 | | // number correctly |
2663 | 3.25k | if(BOOST_JSON_UNLIKELY( |
2664 | 3.25k | (num.exp == INT_MAX) && |
2665 | 3.25k | (num.bias < 0) && |
2666 | 3.25k | (num.exp + num.bias < 308) && |
2667 | 3.25k | num.mant )) |
2668 | 0 | { |
2669 | 0 | BOOST_STATIC_CONSTEXPR source_location loc |
2670 | 0 | = BOOST_CURRENT_LOCATION; |
2671 | 0 | return fail(cs.begin(), error::exponent_overflow, &loc); |
2672 | 0 | } |
2673 | | |
2674 | 3.25k | num.bias = 0; |
2675 | 3.25k | num.exp = INT_MAX; |
2676 | 3.25k | } |
2677 | 5.62k | } |
2678 | 11.6k | else if (BOOST_JSON_UNLIKELY( num.bias > (INT_MAX - num.exp) )) |
2679 | 938 | { |
2680 | | // if exponent overflowed, bias is a very large positive number, |
2681 | | // and mantissa isn't zero, then we cannot parse the |
2682 | | // number correctly |
2683 | 938 | if(BOOST_JSON_UNLIKELY( |
2684 | 938 | (num.exp == INT_MAX) && |
2685 | 938 | (num.bias > 0) && |
2686 | 938 | (num.exp - num.bias < 308) && |
2687 | 938 | num.mant )) |
2688 | 0 | { |
2689 | 0 | BOOST_STATIC_CONSTEXPR source_location loc |
2690 | 0 | = BOOST_CURRENT_LOCATION; |
2691 | 0 | return fail(cs.begin(), error::exponent_overflow, &loc); |
2692 | 0 | } |
2693 | | |
2694 | 938 | num.bias = 0; |
2695 | 938 | num.exp = INT_MAX; |
2696 | 938 | } |
2697 | 17.3k | goto finish_dub; |
2698 | 17.3k | } |
2699 | | |
2700 | 16.7k | finish_int: |
2701 | 16.7k | if(negative || (!stack_empty && num.neg)) |
2702 | 992 | { |
2703 | 992 | if(BOOST_JSON_UNLIKELY( |
2704 | 992 | ! h_.on_int64(static_cast< |
2705 | 992 | int64_t>(~num.mant + 1), {begin, cs.used(begin)}, ec_))) |
2706 | 393 | return fail(cs.begin()); |
2707 | 599 | return cs.begin(); |
2708 | 992 | } |
2709 | 15.8k | if(num.mant <= INT64_MAX) |
2710 | 6.75k | { |
2711 | 1.14M | finish_signed: |
2712 | 1.14M | if(BOOST_JSON_UNLIKELY( |
2713 | 1.14M | ! h_.on_int64(static_cast< |
2714 | 1.14M | int64_t>(num.mant), {begin, cs.used(begin)}, ec_))) |
2715 | 170 | return fail(cs.begin()); |
2716 | 1.14M | return cs.begin(); |
2717 | 1.14M | } |
2718 | 9.04k | if(BOOST_JSON_UNLIKELY( |
2719 | 9.04k | ! h_.on_uint64(num.mant, {begin, cs.used(begin)}, ec_))) |
2720 | 592 | return fail(cs.begin()); |
2721 | 8.45k | return cs.begin(); |
2722 | 27.2k | finish_dub: |
2723 | 27.2k | double d; |
2724 | 27.2k | std::size_t const size = cs.used(begin); |
2725 | 27.2k | BOOST_ASSERT( !num_buf_.size() || precise_parsing ); |
2726 | 27.2k | BOOST_IF_CONSTEXPR( precise_parsing ) |
2727 | 27.2k | { |
2728 | 0 | char const* data = begin; |
2729 | 0 | std::size_t full_size = size; |
2730 | | // if we previously suspended or if the current input ends with the |
2731 | | // number, we need to copy the current part of the number to the |
2732 | | // temporary buffer |
2733 | 0 | if(BOOST_JSON_UNLIKELY( num_buf_.size() )) |
2734 | 0 | { |
2735 | 0 | data = num_buf_.append( begin, size ); |
2736 | 0 | full_size = num_buf_.size(); |
2737 | 0 | } |
2738 | 0 | auto const err = detail::charconv::from_chars( |
2739 | 0 | data, data + full_size, d ); |
2740 | 0 | BOOST_ASSERT( err.ec != std::errc::invalid_argument ); |
2741 | 0 | BOOST_ASSERT( err.ptr == data + full_size ); |
2742 | 0 | (void)err; |
2743 | | } |
2744 | 27.2k | else BOOST_IF_CONSTEXPR( no_parsing ) |
2745 | 27.2k | d = 0; |
2746 | | else |
2747 | 27.2k | d = detail::dec_to_float( |
2748 | 27.2k | num.mant, |
2749 | 27.2k | num.bias + (num.frac ? |
2750 | 21.5k | -num.exp : num.exp), |
2751 | 27.2k | num.neg); |
2752 | 27.2k | if(BOOST_JSON_UNLIKELY( |
2753 | 27.2k | ! h_.on_double(d, {begin, size}, ec_))) |
2754 | 1.31k | return fail(cs.begin()); |
2755 | 25.8k | return cs.begin(); |
2756 | 27.2k | } char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_number<true, (char)48, (boost::json::number_precision)0>(char const*, std::__1::integral_constant<bool, true>, std::__1::integral_constant<char, (char)48>, std::__1::integral_constant<boost::json::number_precision, (boost::json::number_precision)0>) Line | Count | Source | 1986 | 21.5k | { | 1987 | 21.5k | constexpr bool precise_parsing = mode == number_precision::precise; | 1988 | 21.5k | constexpr bool no_parsing = mode == number_precision::none; | 1989 | | | 1990 | | // only one of these will be true if we are not resuming | 1991 | | // if negative then !zero_first && !nonzero_first | 1992 | | // if zero_first then !nonzero_first && !negative | 1993 | | // if nonzero_first then !zero_first && !negative | 1994 | 21.5k | bool const negative = first == '-'; | 1995 | 21.5k | bool const zero_first = first == '0'; | 1996 | 21.5k | bool const nonzero_first = first == '+'; | 1997 | 21.5k | detail::const_stream_wrapper cs(p, end_); | 1998 | 21.5k | number num; | 1999 | 21.5k | const char* begin = cs.begin(); | 2000 | 21.5k | if(stack_empty || st_.empty()) | 2001 | 21.5k | { | 2002 | 21.5k | num.bias = 0; | 2003 | 21.5k | num.exp = 0; | 2004 | 21.5k | num.frac = false; | 2005 | 21.5k | num_buf_.clear(); | 2006 | | | 2007 | | //---------------------------------- | 2008 | | // | 2009 | | // '-' | 2010 | | // leading minus sign | 2011 | | // | 2012 | 21.5k | BOOST_ASSERT(cs); | 2013 | 21.5k | if(negative) | 2014 | 0 | ++cs; | 2015 | | | 2016 | 21.5k | num.neg = negative; | 2017 | 21.5k | num.frac = false; | 2018 | 21.5k | num.exp = 0; | 2019 | 21.5k | num.bias = 0; | 2020 | | | 2021 | | // fast path | 2022 | 21.5k | if( cs.remain() >= 16 + 1 + 16 ) // digits . digits | 2023 | 19.6k | { | 2024 | 19.6k | int n1; | 2025 | | | 2026 | 19.6k | if( nonzero_first || | 2027 | 19.6k | (negative && *cs != '0') ) | 2028 | 0 | { | 2029 | 0 | n1 = detail::count_digits( cs.begin() ); | 2030 | 0 | BOOST_ASSERT(n1 >= 0 && n1 <= 16); | 2031 | | | 2032 | 0 | if( negative && n1 == 0 && opt_.allow_infinity_and_nan ) | 2033 | 0 | { | 2034 | 0 | return parse_literal( | 2035 | 0 | p - 1, | 2036 | 0 | detail::literals_c<detail::literals::neg_infinity>()); | 2037 | 0 | } | 2038 | | | 2039 | 0 | if( ! nonzero_first && n1 == 0 ) | 2040 | 0 | { | 2041 | | // digit required | 2042 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 2043 | 0 | = BOOST_CURRENT_LOCATION; | 2044 | 0 | return fail(cs.begin(), error::syntax, &loc); | 2045 | 0 | } | 2046 | | | 2047 | 0 | BOOST_IF_CONSTEXPR( !no_parsing ) | 2048 | 0 | num.mant = detail::parse_unsigned( 0, cs.begin(), n1 ); | 2049 | | else | 2050 | | num.mant = 0; | 2051 | |
| 2052 | 0 | cs += n1; | 2053 | | | 2054 | | // integer or floating-point with | 2055 | | // >= 16 leading digits | 2056 | 0 | if( n1 == 16 ) | 2057 | 0 | { | 2058 | 0 | goto do_num2; | 2059 | 0 | } | 2060 | 0 | } | 2061 | 19.6k | else | 2062 | 19.6k | { | 2063 | | // 0. floating-point or 0e integer | 2064 | 19.6k | num.mant = 0; | 2065 | 19.6k | n1 = 0; | 2066 | 19.6k | ++cs; | 2067 | 19.6k | } | 2068 | | | 2069 | 19.6k | { | 2070 | 19.6k | const char c = *cs; | 2071 | 19.6k | if(c != '.') | 2072 | 14.7k | { | 2073 | 14.7k | if((c | 32) == 'e') | 2074 | 1.66k | { | 2075 | 1.66k | ++cs; | 2076 | 1.66k | goto do_exp1; | 2077 | 1.66k | } | 2078 | 13.1k | BOOST_IF_CONSTEXPR( negative && !no_parsing ) | 2079 | 13.1k | num.mant = ~num.mant + 1; | 2080 | 13.1k | goto finish_signed; | 2081 | 14.7k | } | 2082 | 19.6k | } | 2083 | | | 2084 | | // floating-point number | 2085 | | | 2086 | 4.89k | ++cs; | 2087 | | | 2088 | 4.89k | int n2 = detail::count_digits( cs.begin() ); | 2089 | 4.89k | BOOST_ASSERT(n2 >= 0 && n2 <= 16); | 2090 | | | 2091 | 4.89k | if( n2 == 0 ) | 2092 | 1 | { | 2093 | | // digit required | 2094 | 1 | BOOST_STATIC_CONSTEXPR source_location loc | 2095 | 1 | = BOOST_CURRENT_LOCATION; | 2096 | 1 | return fail(cs.begin(), error::syntax, &loc); | 2097 | 1 | } | 2098 | | | 2099 | | // floating-point mantissa overflow | 2100 | 4.89k | if( n1 + n2 >= 19 ) | 2101 | 0 | { | 2102 | 0 | goto do_num7; | 2103 | 0 | } | 2104 | | | 2105 | 4.89k | BOOST_IF_CONSTEXPR( !no_parsing ) | 2106 | 4.89k | num.mant = detail::parse_unsigned( num.mant, cs.begin(), n2 ); | 2107 | | | 2108 | 4.89k | BOOST_ASSERT(num.bias == 0); | 2109 | | | 2110 | 4.89k | num.bias -= n2; | 2111 | | | 2112 | 4.89k | cs += n2; | 2113 | | | 2114 | 4.89k | char ch = *cs; | 2115 | | | 2116 | 4.89k | if( (ch | 32) == 'e' ) | 2117 | 2.05k | { | 2118 | 2.05k | ++cs; | 2119 | 2.05k | goto do_exp1; | 2120 | 2.05k | } | 2121 | 2.84k | else if( ch >= '0' && ch <= '9' ) | 2122 | 1.05k | { | 2123 | 1.05k | goto do_num8; | 2124 | 1.05k | } | 2125 | | | 2126 | 1.79k | goto finish_dub; | 2127 | 4.89k | } | 2128 | 21.5k | } | 2129 | 0 | else | 2130 | 0 | { | 2131 | 0 | num = num_; | 2132 | 0 | state st; | 2133 | 0 | st_.pop(st); | 2134 | 0 | switch(st) | 2135 | 0 | { | 2136 | 0 | default: BOOST_JSON_UNREACHABLE(); | 2137 | 0 | case state::num1: goto do_num1; | 2138 | 0 | case state::num2: goto do_num2; | 2139 | 0 | case state::num3: goto do_num3; | 2140 | 0 | case state::num4: goto do_num4; | 2141 | 0 | case state::num5: goto do_num5; | 2142 | 0 | case state::num6: goto do_num6; | 2143 | 0 | case state::num7: goto do_num7; | 2144 | 0 | case state::num8: goto do_num8; | 2145 | 0 | case state::exp1: goto do_exp1; | 2146 | 0 | case state::exp2: goto do_exp2; | 2147 | 0 | case state::exp3: goto do_exp3; | 2148 | 0 | } | 2149 | 0 | } | 2150 | | | 2151 | | //---------------------------------- | 2152 | | // | 2153 | | // DIGIT | 2154 | | // first digit | 2155 | | // | 2156 | 1.84k | do_num1: | 2157 | 1.84k | if(zero_first || nonzero_first || | 2158 | 1.84k | BOOST_JSON_LIKELY(cs)) | 2159 | 1.84k | { | 2160 | 1.84k | char const c = *cs; | 2161 | 1.84k | if(zero_first) | 2162 | 1.84k | { | 2163 | 1.84k | ++cs; | 2164 | 1.84k | num.mant = 0; | 2165 | 1.84k | goto do_num6; | 2166 | 1.84k | } | 2167 | 0 | else if(nonzero_first || BOOST_JSON_LIKELY( | 2168 | 0 | c >= '1' && c <= '9')) | 2169 | 0 | { | 2170 | 0 | ++cs; | 2171 | 0 | num.mant = c - '0'; | 2172 | 0 | } | 2173 | 0 | else if(BOOST_JSON_UNLIKELY( | 2174 | 0 | c == '0')) | 2175 | 0 | { | 2176 | 0 | ++cs; | 2177 | 0 | num.mant = 0; | 2178 | 0 | goto do_num6; | 2179 | 0 | } | 2180 | 0 | else if( (negative || num.neg) && opt_.allow_infinity_and_nan ) | 2181 | 0 | { | 2182 | 0 | st_.push(state::lit1); | 2183 | 0 | cur_lit_ = literal_index(detail::literals::neg_infinity); | 2184 | 0 | lit_offset_ = 1; | 2185 | 0 | return parse_literal( | 2186 | 0 | cs.begin(), detail::literals_c<detail::literals::resume>() ); | 2187 | 0 | } | 2188 | 0 | else | 2189 | 0 | { | 2190 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 2191 | 0 | = BOOST_CURRENT_LOCATION; | 2192 | 0 | return fail(cs.begin(), error::syntax, &loc); | 2193 | 0 | } | 2194 | 1.84k | } | 2195 | 0 | else | 2196 | 0 | { | 2197 | 0 | if(BOOST_JSON_UNLIKELY( | 2198 | 0 | ! h_.on_number_part( | 2199 | 0 | {begin, cs.used(begin)}, ec_))) | 2200 | 0 | return fail(cs.begin()); | 2201 | | | 2202 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2203 | 0 | num_buf_.append( begin, cs.used(begin) ); | 2204 | 0 | return maybe_suspend( | 2205 | 0 | cs.begin(), state::num1, num); | 2206 | 0 | } | 2207 | | | 2208 | | //---------------------------------- | 2209 | | // | 2210 | | // 1*DIGIT | 2211 | | // significant digits left of decimal | 2212 | | // | 2213 | 0 | do_num2: | 2214 | 0 | if(negative || (!stack_empty && num.neg)) | 2215 | 0 | { | 2216 | 0 | for(;;) | 2217 | 0 | { | 2218 | 0 | if(BOOST_JSON_UNLIKELY(! cs)) | 2219 | 0 | { | 2220 | 0 | if(BOOST_JSON_UNLIKELY(more_)) | 2221 | 0 | { | 2222 | 0 | if(BOOST_JSON_UNLIKELY( | 2223 | 0 | ! h_.on_number_part( | 2224 | 0 | {begin, cs.used(begin)}, ec_))) | 2225 | 0 | return fail(cs.begin()); | 2226 | | | 2227 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2228 | 0 | num_buf_.append( begin, cs.used(begin) ); | 2229 | 0 | return suspend(cs.begin(), state::num2, num); | 2230 | 0 | } | 2231 | 0 | goto finish_int; | 2232 | 0 | } | 2233 | 0 | char const c = *cs; | 2234 | 0 | if(BOOST_JSON_LIKELY( | 2235 | 0 | c >= '0' && c <= '9')) | 2236 | 0 | { | 2237 | 0 | ++cs; | 2238 | | // 9223372036854775808 INT64_MIN | 2239 | 0 | if( num.mant > 922337203685477580 || ( | 2240 | 0 | num.mant == 922337203685477580 && c > '8')) | 2241 | 0 | break; | 2242 | 0 | BOOST_IF_CONSTEXPR( !no_parsing ) | 2243 | 0 | num.mant = 10 * num.mant + ( c - '0' ); | 2244 | 0 | continue; | 2245 | 0 | } | 2246 | 0 | goto do_num6; // [.eE] | 2247 | 0 | } | 2248 | 0 | } | 2249 | 0 | else | 2250 | 0 | { | 2251 | 0 | for(;;) | 2252 | 0 | { | 2253 | 0 | if(BOOST_JSON_UNLIKELY(! cs)) | 2254 | 0 | { | 2255 | 0 | if(BOOST_JSON_UNLIKELY(more_)) | 2256 | 0 | { | 2257 | 0 | if(BOOST_JSON_UNLIKELY( | 2258 | 0 | ! h_.on_number_part( | 2259 | 0 | {begin, cs.used(begin)}, ec_))) | 2260 | 0 | return fail(cs.begin()); | 2261 | | | 2262 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2263 | 0 | num_buf_.append( begin, cs.used(begin) ); | 2264 | 0 | return suspend(cs.begin(), state::num2, num); | 2265 | 0 | } | 2266 | 0 | goto finish_int; | 2267 | 0 | } | 2268 | 0 | char const c = *cs; | 2269 | 0 | if(BOOST_JSON_LIKELY( | 2270 | 0 | c >= '0' && c <= '9')) | 2271 | 0 | { | 2272 | 0 | ++cs; | 2273 | | // 18446744073709551615 UINT64_MAX | 2274 | 0 | if( num.mant > 1844674407370955161 || ( | 2275 | 0 | num.mant == 1844674407370955161 && c > '5')) | 2276 | 0 | break; | 2277 | 0 | BOOST_IF_CONSTEXPR( !no_parsing ) | 2278 | 0 | num.mant = 10 * num.mant + ( c - '0' ); | 2279 | 0 | } | 2280 | 0 | else | 2281 | 0 | { | 2282 | 0 | goto do_num6; // [.eE] | 2283 | 0 | } | 2284 | 0 | } | 2285 | 0 | } | 2286 | 0 | ++num.bias; | 2287 | | | 2288 | | //---------------------------------- | 2289 | | // | 2290 | | // 1*DIGIT | 2291 | | // non-significant digits left of decimal | 2292 | | // | 2293 | 0 | do_num3: | 2294 | 0 | for(;;) | 2295 | 0 | { | 2296 | 0 | if(BOOST_JSON_UNLIKELY(! cs)) | 2297 | 0 | { | 2298 | 0 | if(BOOST_JSON_UNLIKELY(more_)) | 2299 | 0 | { | 2300 | 0 | if(BOOST_JSON_UNLIKELY( | 2301 | 0 | ! h_.on_number_part( | 2302 | 0 | {begin, cs.used(begin)}, ec_))) | 2303 | 0 | return fail(cs.begin()); | 2304 | | | 2305 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2306 | 0 | num_buf_.append( begin, cs.used(begin) ); | 2307 | 0 | return suspend(cs.begin(), state::num3, num); | 2308 | 0 | } | 2309 | 0 | goto finish_dub; | 2310 | 0 | } | 2311 | 0 | char const c = *cs; | 2312 | 0 | if(BOOST_JSON_UNLIKELY( | 2313 | 0 | c >= '0' && c <= '9')) | 2314 | 0 | { | 2315 | 0 | if(BOOST_JSON_UNLIKELY( num.bias + 1 == INT_MAX )) | 2316 | 0 | { | 2317 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 2318 | 0 | = BOOST_CURRENT_LOCATION; | 2319 | 0 | return fail(cs.begin(), error::exponent_overflow, &loc); | 2320 | 0 | } | 2321 | 0 | ++cs; | 2322 | 0 | ++num.bias; | 2323 | 0 | } | 2324 | 0 | else if(BOOST_JSON_LIKELY( | 2325 | 0 | c == '.')) | 2326 | 0 | { | 2327 | 0 | ++cs; | 2328 | 0 | break; | 2329 | 0 | } | 2330 | 0 | else if((c | 32) == 'e') | 2331 | 0 | { | 2332 | 0 | ++cs; | 2333 | 0 | goto do_exp1; | 2334 | 0 | } | 2335 | 0 | else | 2336 | 0 | { | 2337 | 0 | goto finish_dub; | 2338 | 0 | } | 2339 | 0 | } | 2340 | | | 2341 | | //---------------------------------- | 2342 | | // | 2343 | | // DIGIT | 2344 | | // first non-significant digit | 2345 | | // to the right of decimal | 2346 | | // | 2347 | 0 | do_num4: | 2348 | 0 | { | 2349 | 0 | if(BOOST_JSON_UNLIKELY(! cs)) | 2350 | 0 | { | 2351 | 0 | if(BOOST_JSON_UNLIKELY( | 2352 | 0 | ! h_.on_number_part( | 2353 | 0 | {begin, cs.used(begin)}, ec_))) | 2354 | 0 | return fail(cs.begin()); | 2355 | | | 2356 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2357 | 0 | num_buf_.append( begin, cs.used(begin) ); | 2358 | 0 | return maybe_suspend( | 2359 | 0 | cs.begin(), state::num4, num); | 2360 | 0 | } | 2361 | 0 | char const c = *cs; | 2362 | 0 | if(BOOST_JSON_LIKELY( | 2363 | | //static_cast<unsigned char>(c - '0') < 10)) | 2364 | 0 | c >= '0' && c <= '9')) | 2365 | 0 | { | 2366 | 0 | ++cs; | 2367 | 0 | } | 2368 | 0 | else | 2369 | 0 | { | 2370 | | // digit required | 2371 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 2372 | 0 | = BOOST_CURRENT_LOCATION; | 2373 | 0 | return fail(cs.begin(), error::syntax, &loc); | 2374 | 0 | } | 2375 | 0 | } | 2376 | | | 2377 | | //---------------------------------- | 2378 | | // | 2379 | | // 1*DIGIT | 2380 | | // non-significant digits | 2381 | | // to the right of decimal | 2382 | | // | 2383 | 529 | do_num5: | 2384 | 529 | for(;;) | 2385 | 53.8k | { | 2386 | 53.8k | if(BOOST_JSON_UNLIKELY(! cs)) | 2387 | 15 | { | 2388 | 15 | if(BOOST_JSON_UNLIKELY(more_)) | 2389 | 0 | { | 2390 | 0 | if(BOOST_JSON_UNLIKELY( | 2391 | 0 | ! h_.on_number_part( | 2392 | 0 | {begin, cs.used(begin)}, ec_))) | 2393 | 0 | return fail(cs.begin()); | 2394 | | | 2395 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2396 | 0 | num_buf_.append( begin, cs.used(begin) ); | 2397 | 0 | return suspend(cs.begin(), state::num5, num); | 2398 | 0 | } | 2399 | 15 | goto finish_dub; | 2400 | 15 | } | 2401 | 53.8k | char const c = *cs; | 2402 | 53.8k | if(BOOST_JSON_LIKELY( | 2403 | 53.8k | c >= '0' && c <= '9')) | 2404 | 53.3k | { | 2405 | 53.3k | ++cs; | 2406 | 53.3k | } | 2407 | 514 | else if((c | 32) == 'e') | 2408 | 239 | { | 2409 | 239 | ++cs; | 2410 | 239 | goto do_exp1; | 2411 | 239 | } | 2412 | 275 | else | 2413 | 275 | { | 2414 | 275 | goto finish_dub; | 2415 | 275 | } | 2416 | 53.8k | } | 2417 | | | 2418 | | //---------------------------------- | 2419 | | // | 2420 | | // [.eE] | 2421 | | // | 2422 | 1.84k | do_num6: | 2423 | 1.84k | { | 2424 | 1.84k | if(BOOST_JSON_UNLIKELY(! cs)) | 2425 | 109 | { | 2426 | 109 | if(BOOST_JSON_UNLIKELY(more_)) | 2427 | 0 | { | 2428 | 0 | if(BOOST_JSON_UNLIKELY( | 2429 | 0 | ! h_.on_number_part( | 2430 | 0 | {begin, cs.used(begin)}, ec_))) | 2431 | 0 | return fail(cs.begin()); | 2432 | | | 2433 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2434 | 0 | num_buf_.append( begin, cs.used(begin) ); | 2435 | 0 | return suspend(cs.begin(), state::num6, num); | 2436 | 0 | } | 2437 | 109 | goto finish_int; | 2438 | 109 | } | 2439 | 1.73k | char const c = *cs; | 2440 | 1.73k | if(BOOST_JSON_LIKELY( | 2441 | 1.73k | c == '.')) | 2442 | 454 | { | 2443 | 454 | ++cs; | 2444 | 454 | } | 2445 | 1.27k | else if((c | 32) == 'e') | 2446 | 469 | { | 2447 | 469 | ++cs; | 2448 | 469 | goto do_exp1; | 2449 | 469 | } | 2450 | 808 | else | 2451 | 808 | { | 2452 | 808 | goto finish_int; | 2453 | 808 | } | 2454 | 1.73k | } | 2455 | | | 2456 | | //---------------------------------- | 2457 | | // | 2458 | | // DIGIT | 2459 | | // first significant digit | 2460 | | // to the right of decimal | 2461 | | // | 2462 | 454 | do_num7: | 2463 | 454 | { | 2464 | 454 | if(BOOST_JSON_UNLIKELY(! cs)) | 2465 | 2 | { | 2466 | 2 | if(BOOST_JSON_UNLIKELY(more_)) | 2467 | 0 | { | 2468 | 0 | if(BOOST_JSON_UNLIKELY( | 2469 | 0 | ! h_.on_number_part( | 2470 | 0 | {begin, cs.used(begin)}, ec_))) | 2471 | 0 | return fail(cs.begin()); | 2472 | | | 2473 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2474 | 0 | num_buf_.append( begin, cs.used(begin) ); | 2475 | 0 | return suspend(cs.begin(), state::num7, num); | 2476 | 0 | } | 2477 | | // digit required | 2478 | 2 | BOOST_STATIC_CONSTEXPR source_location loc | 2479 | 2 | = BOOST_CURRENT_LOCATION; | 2480 | 2 | return fail(cs.begin(), error::syntax, &loc); | 2481 | 2 | } | 2482 | 452 | char const c = *cs; | 2483 | 452 | if(BOOST_JSON_UNLIKELY( | 2484 | 452 | c < '0' || c > '9')) | 2485 | 16 | { | 2486 | | // digit required | 2487 | 16 | BOOST_STATIC_CONSTEXPR source_location loc | 2488 | 16 | = BOOST_CURRENT_LOCATION; | 2489 | 16 | return fail(cs.begin(), error::syntax, &loc); | 2490 | 16 | } | 2491 | 452 | } | 2492 | | | 2493 | | //---------------------------------- | 2494 | | // | 2495 | | // 1*DIGIT | 2496 | | // significant digits | 2497 | | // to the right of decimal | 2498 | | // | 2499 | 1.49k | do_num8: | 2500 | 1.49k | for(;;) | 2501 | 4.13M | { | 2502 | 4.13M | if(BOOST_JSON_UNLIKELY(! cs)) | 2503 | 138 | { | 2504 | 138 | if(BOOST_JSON_UNLIKELY(more_)) | 2505 | 0 | { | 2506 | 0 | if(BOOST_JSON_UNLIKELY( | 2507 | 0 | ! h_.on_number_part( | 2508 | 0 | {begin, cs.used(begin)}, ec_))) | 2509 | 0 | return fail(cs.begin()); | 2510 | | | 2511 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2512 | 0 | num_buf_.append( begin, cs.used(begin) ); | 2513 | 0 | return suspend(cs.begin(), state::num8, num); | 2514 | 0 | } | 2515 | 138 | goto finish_dub; | 2516 | 138 | } | 2517 | 4.12M | char const c = *cs; | 2518 | 4.12M | if(BOOST_JSON_LIKELY( | 2519 | 4.12M | c >= '0' && c <= '9')) | 2520 | 4.12M | { | 2521 | 4.12M | ++cs; | 2522 | 4.12M | if(!no_parsing && BOOST_JSON_LIKELY( | 2523 | 4.12M | num.mant <= 9007199254740991)) // 2^53-1 | 2524 | 4.12M | { | 2525 | 4.12M | if(BOOST_JSON_UNLIKELY( num.bias - 1 == INT_MIN )) | 2526 | 0 | { | 2527 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 2528 | 0 | = BOOST_CURRENT_LOCATION; | 2529 | 0 | return fail(cs.begin(), error::exponent_overflow, &loc); | 2530 | 0 | } | 2531 | 4.12M | --num.bias; | 2532 | 4.12M | num.mant = 10 * num.mant + ( c - '0' ); | 2533 | 4.12M | } | 2534 | 529 | else | 2535 | 529 | { | 2536 | 529 | goto do_num5; | 2537 | 529 | } | 2538 | 4.12M | } | 2539 | 823 | else if((c | 32) == 'e') | 2540 | 285 | { | 2541 | 285 | ++cs; | 2542 | 285 | goto do_exp1; | 2543 | 285 | } | 2544 | 538 | else | 2545 | 538 | { | 2546 | 538 | goto finish_dub; | 2547 | 538 | } | 2548 | 4.12M | } | 2549 | | | 2550 | | //---------------------------------- | 2551 | | // | 2552 | | // *[+-] | 2553 | | // | 2554 | 4.71k | do_exp1: | 2555 | 4.71k | if(BOOST_JSON_UNLIKELY(! cs)) | 2556 | 20 | { | 2557 | 20 | if(BOOST_JSON_UNLIKELY( | 2558 | 20 | ! h_.on_number_part( | 2559 | 20 | {begin, cs.used(begin)}, ec_))) | 2560 | 4 | return fail(cs.begin()); | 2561 | | | 2562 | 16 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2563 | 16 | num_buf_.append( begin, cs.used(begin) ); | 2564 | 16 | return maybe_suspend( | 2565 | 16 | cs.begin(), state::exp1, num); | 2566 | 20 | } | 2567 | 4.69k | if(*cs == '+') | 2568 | 271 | { | 2569 | 271 | ++cs; | 2570 | 271 | } | 2571 | 4.42k | else if(*cs == '-') | 2572 | 2.74k | { | 2573 | 2.74k | ++cs; | 2574 | 2.74k | num.frac = true; | 2575 | 2.74k | } | 2576 | | | 2577 | | //---------------------------------- | 2578 | | // | 2579 | | // DIGIT | 2580 | | // first digit of the exponent | 2581 | | // | 2582 | 4.69k | do_exp2: | 2583 | 4.69k | { | 2584 | 4.69k | if(BOOST_JSON_UNLIKELY(! cs)) | 2585 | 10 | { | 2586 | 10 | if(BOOST_JSON_UNLIKELY(more_)) | 2587 | 0 | { | 2588 | 0 | if(BOOST_JSON_UNLIKELY( | 2589 | 0 | ! h_.on_number_part( | 2590 | 0 | {begin, cs.used(begin)}, ec_))) | 2591 | 0 | return fail(cs.begin()); | 2592 | | | 2593 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2594 | 0 | num_buf_.append( begin, cs.used(begin) ); | 2595 | 0 | return suspend(cs.begin(), state::exp2, num); | 2596 | 0 | } | 2597 | | // digit required | 2598 | 10 | BOOST_STATIC_CONSTEXPR source_location loc | 2599 | 10 | = BOOST_CURRENT_LOCATION; | 2600 | 10 | return fail(cs.begin(), error::syntax, &loc); | 2601 | 10 | } | 2602 | 4.68k | char const c = *cs; | 2603 | 4.68k | if(BOOST_JSON_UNLIKELY( | 2604 | 4.68k | c < '0' || c > '9')) | 2605 | 29 | { | 2606 | | // digit required | 2607 | 29 | BOOST_STATIC_CONSTEXPR source_location loc | 2608 | 29 | = BOOST_CURRENT_LOCATION; | 2609 | 29 | return fail(cs.begin(), error::syntax, &loc); | 2610 | 29 | } | 2611 | 4.65k | ++cs; | 2612 | 4.65k | num.exp = c - '0'; | 2613 | 4.65k | } | 2614 | | | 2615 | | //---------------------------------- | 2616 | | // | 2617 | | // 1*DIGIT | 2618 | | // subsequent digits in the exponent | 2619 | | // | 2620 | 4.65k | do_exp3: | 2621 | 4.65k | for(;;) | 2622 | 26.4k | { | 2623 | 26.4k | if(BOOST_JSON_UNLIKELY(! cs)) | 2624 | 282 | { | 2625 | 282 | if(BOOST_JSON_UNLIKELY(more_)) | 2626 | 0 | { | 2627 | 0 | if(BOOST_JSON_UNLIKELY( | 2628 | 0 | ! h_.on_number_part( | 2629 | 0 | {begin, cs.used(begin)}, ec_))) | 2630 | 0 | return fail(cs.begin()); | 2631 | | | 2632 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2633 | 0 | num_buf_.append( begin, cs.used(begin) ); | 2634 | 0 | return suspend(cs.begin(), state::exp3, num); | 2635 | 0 | } | 2636 | 282 | } | 2637 | 26.1k | else | 2638 | 26.1k | { | 2639 | 26.1k | char const c = *cs; | 2640 | 26.1k | if(BOOST_JSON_LIKELY( c >= '0' && c <= '9' )) | 2641 | 21.8k | { | 2642 | 21.8k | if(BOOST_JSON_UNLIKELY( | 2643 | | // 2147483647 INT_MAX | 2644 | 21.8k | num.exp > 214748364 || | 2645 | 21.8k | (num.exp == 214748364 && c > '7') | 2646 | 21.8k | )) | 2647 | 1.23k | num.exp = INT_MAX; | 2648 | 20.5k | else BOOST_IF_CONSTEXPR( !no_parsing ) | 2649 | 20.5k | num.exp = 10 * num.exp + ( c - '0' ); | 2650 | | | 2651 | 21.8k | ++cs; | 2652 | 21.8k | continue; | 2653 | 21.8k | } | 2654 | 26.1k | } | 2655 | 4.65k | BOOST_ASSERT(num.exp >= 0); | 2656 | 4.65k | if ( num.frac ) | 2657 | 2.74k | { | 2658 | 2.74k | if(BOOST_JSON_UNLIKELY( num.bias < (INT_MIN + num.exp) )) | 2659 | 1.77k | { | 2660 | | // if exponent overflowed, bias is a very large negative | 2661 | | // number, and mantissa isn't zero, then we cannot parse the | 2662 | | // number correctly | 2663 | 1.77k | if(BOOST_JSON_UNLIKELY( | 2664 | 1.77k | (num.exp == INT_MAX) && | 2665 | 1.77k | (num.bias < 0) && | 2666 | 1.77k | (num.exp + num.bias < 308) && | 2667 | 1.77k | num.mant )) | 2668 | 0 | { | 2669 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 2670 | 0 | = BOOST_CURRENT_LOCATION; | 2671 | 0 | return fail(cs.begin(), error::exponent_overflow, &loc); | 2672 | 0 | } | 2673 | | | 2674 | 1.77k | num.bias = 0; | 2675 | 1.77k | num.exp = INT_MAX; | 2676 | 1.77k | } | 2677 | 2.74k | } | 2678 | 1.90k | else if (BOOST_JSON_UNLIKELY( num.bias > (INT_MAX - num.exp) )) | 2679 | 0 | { | 2680 | | // if exponent overflowed, bias is a very large positive number, | 2681 | | // and mantissa isn't zero, then we cannot parse the | 2682 | | // number correctly | 2683 | 0 | if(BOOST_JSON_UNLIKELY( | 2684 | 0 | (num.exp == INT_MAX) && | 2685 | 0 | (num.bias > 0) && | 2686 | 0 | (num.exp - num.bias < 308) && | 2687 | 0 | num.mant )) | 2688 | 0 | { | 2689 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 2690 | 0 | = BOOST_CURRENT_LOCATION; | 2691 | 0 | return fail(cs.begin(), error::exponent_overflow, &loc); | 2692 | 0 | } | 2693 | | | 2694 | 0 | num.bias = 0; | 2695 | 0 | num.exp = INT_MAX; | 2696 | 0 | } | 2697 | 4.65k | goto finish_dub; | 2698 | 4.65k | } | 2699 | | | 2700 | 917 | finish_int: | 2701 | 917 | if(negative || (!stack_empty && num.neg)) | 2702 | 0 | { | 2703 | 0 | if(BOOST_JSON_UNLIKELY( | 2704 | 0 | ! h_.on_int64(static_cast< | 2705 | 0 | int64_t>(~num.mant + 1), {begin, cs.used(begin)}, ec_))) | 2706 | 0 | return fail(cs.begin()); | 2707 | 0 | return cs.begin(); | 2708 | 0 | } | 2709 | 917 | if(num.mant <= INT64_MAX) | 2710 | 917 | { | 2711 | 14.0k | finish_signed: | 2712 | 14.0k | if(BOOST_JSON_UNLIKELY( | 2713 | 14.0k | ! h_.on_int64(static_cast< | 2714 | 14.0k | int64_t>(num.mant), {begin, cs.used(begin)}, ec_))) | 2715 | 23 | return fail(cs.begin()); | 2716 | 14.0k | return cs.begin(); | 2717 | 14.0k | } | 2718 | 0 | if(BOOST_JSON_UNLIKELY( | 2719 | 0 | ! h_.on_uint64(num.mant, {begin, cs.used(begin)}, ec_))) | 2720 | 0 | return fail(cs.begin()); | 2721 | 0 | return cs.begin(); | 2722 | 7.41k | finish_dub: | 2723 | 7.41k | double d; | 2724 | 7.41k | std::size_t const size = cs.used(begin); | 2725 | 7.41k | BOOST_ASSERT( !num_buf_.size() || precise_parsing ); | 2726 | 7.41k | BOOST_IF_CONSTEXPR( precise_parsing ) | 2727 | 7.41k | { | 2728 | 7.41k | char const* data = begin; | 2729 | 7.41k | std::size_t full_size = size; | 2730 | | // if we previously suspended or if the current input ends with the | 2731 | | // number, we need to copy the current part of the number to the | 2732 | | // temporary buffer | 2733 | | if(BOOST_JSON_UNLIKELY( num_buf_.size() )) | 2734 | | { | 2735 | | data = num_buf_.append( begin, size ); | 2736 | | full_size = num_buf_.size(); | 2737 | | } | 2738 | | auto const err = detail::charconv::from_chars( | 2739 | | data, data + full_size, d ); | 2740 | | BOOST_ASSERT( err.ec != std::errc::invalid_argument ); | 2741 | | BOOST_ASSERT( err.ptr == data + full_size ); | 2742 | | (void)err; | 2743 | | } | 2744 | 7.41k | else BOOST_IF_CONSTEXPR( no_parsing ) | 2745 | 7.41k | d = 0; | 2746 | 7.41k | else | 2747 | 7.41k | d = detail::dec_to_float( | 2748 | 7.41k | num.mant, | 2749 | 7.41k | num.bias + (num.frac ? | 2750 | 4.66k | -num.exp : num.exp), | 2751 | 7.41k | num.neg); | 2752 | 7.41k | if(BOOST_JSON_UNLIKELY( | 2753 | 7.41k | ! h_.on_double(d, {begin, size}, ec_))) | 2754 | 404 | return fail(cs.begin()); | 2755 | 7.00k | return cs.begin(); | 2756 | 7.41k | } |
Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_number<true, (char)48, (boost::json::number_precision)1>(char const*, std::__1::integral_constant<bool, true>, std::__1::integral_constant<char, (char)48>, std::__1::integral_constant<boost::json::number_precision, (boost::json::number_precision)1>) Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_number<true, (char)48, (boost::json::number_precision)2>(char const*, std::__1::integral_constant<bool, true>, std::__1::integral_constant<char, (char)48>, std::__1::integral_constant<boost::json::number_precision, (boost::json::number_precision)2>) char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_number<true, (char)45, (boost::json::number_precision)0>(char const*, std::__1::integral_constant<bool, true>, std::__1::integral_constant<char, (char)45>, std::__1::integral_constant<boost::json::number_precision, (boost::json::number_precision)0>) Line | Count | Source | 1986 | 42.8k | { | 1987 | 42.8k | constexpr bool precise_parsing = mode == number_precision::precise; | 1988 | 42.8k | constexpr bool no_parsing = mode == number_precision::none; | 1989 | | | 1990 | | // only one of these will be true if we are not resuming | 1991 | | // if negative then !zero_first && !nonzero_first | 1992 | | // if zero_first then !nonzero_first && !negative | 1993 | | // if nonzero_first then !zero_first && !negative | 1994 | 42.8k | bool const negative = first == '-'; | 1995 | 42.8k | bool const zero_first = first == '0'; | 1996 | 42.8k | bool const nonzero_first = first == '+'; | 1997 | 42.8k | detail::const_stream_wrapper cs(p, end_); | 1998 | 42.8k | number num; | 1999 | 42.8k | const char* begin = cs.begin(); | 2000 | 42.8k | if(stack_empty || st_.empty()) | 2001 | 42.8k | { | 2002 | 42.8k | num.bias = 0; | 2003 | 42.8k | num.exp = 0; | 2004 | 42.8k | num.frac = false; | 2005 | 42.8k | num_buf_.clear(); | 2006 | | | 2007 | | //---------------------------------- | 2008 | | // | 2009 | | // '-' | 2010 | | // leading minus sign | 2011 | | // | 2012 | 42.8k | BOOST_ASSERT(cs); | 2013 | 42.8k | if(negative) | 2014 | 42.8k | ++cs; | 2015 | | | 2016 | 42.8k | num.neg = negative; | 2017 | 42.8k | num.frac = false; | 2018 | 42.8k | num.exp = 0; | 2019 | 42.8k | num.bias = 0; | 2020 | | | 2021 | | // fast path | 2022 | 42.8k | if( cs.remain() >= 16 + 1 + 16 ) // digits . digits | 2023 | 41.3k | { | 2024 | 41.3k | int n1; | 2025 | | | 2026 | 41.3k | if( nonzero_first || | 2027 | 41.3k | (negative && *cs != '0') ) | 2028 | 32.6k | { | 2029 | 32.6k | n1 = detail::count_digits( cs.begin() ); | 2030 | 32.6k | BOOST_ASSERT(n1 >= 0 && n1 <= 16); | 2031 | | | 2032 | 32.6k | if( negative && n1 == 0 && opt_.allow_infinity_and_nan ) | 2033 | 0 | { | 2034 | 0 | return parse_literal( | 2035 | 0 | p - 1, | 2036 | 0 | detail::literals_c<detail::literals::neg_infinity>()); | 2037 | 0 | } | 2038 | | | 2039 | 32.6k | if( ! nonzero_first && n1 == 0 ) | 2040 | 2 | { | 2041 | | // digit required | 2042 | 2 | BOOST_STATIC_CONSTEXPR source_location loc | 2043 | 2 | = BOOST_CURRENT_LOCATION; | 2044 | 2 | return fail(cs.begin(), error::syntax, &loc); | 2045 | 2 | } | 2046 | | | 2047 | 32.6k | BOOST_IF_CONSTEXPR( !no_parsing ) | 2048 | 32.6k | num.mant = detail::parse_unsigned( 0, cs.begin(), n1 ); | 2049 | | else | 2050 | | num.mant = 0; | 2051 | | | 2052 | 32.6k | cs += n1; | 2053 | | | 2054 | | // integer or floating-point with | 2055 | | // >= 16 leading digits | 2056 | 32.6k | if( n1 == 16 ) | 2057 | 4.06k | { | 2058 | 4.06k | goto do_num2; | 2059 | 4.06k | } | 2060 | 32.6k | } | 2061 | 8.65k | else | 2062 | 8.65k | { | 2063 | | // 0. floating-point or 0e integer | 2064 | 8.65k | num.mant = 0; | 2065 | 8.65k | n1 = 0; | 2066 | 8.65k | ++cs; | 2067 | 8.65k | } | 2068 | | | 2069 | 37.2k | { | 2070 | 37.2k | const char c = *cs; | 2071 | 37.2k | if(c != '.') | 2072 | 34.6k | { | 2073 | 34.6k | if((c | 32) == 'e') | 2074 | 4.15k | { | 2075 | 4.15k | ++cs; | 2076 | 4.15k | goto do_exp1; | 2077 | 4.15k | } | 2078 | 30.4k | BOOST_IF_CONSTEXPR( negative && !no_parsing ) | 2079 | 30.4k | num.mant = ~num.mant + 1; | 2080 | 30.4k | goto finish_signed; | 2081 | 34.6k | } | 2082 | 37.2k | } | 2083 | | | 2084 | | // floating-point number | 2085 | | | 2086 | 2.60k | ++cs; | 2087 | | | 2088 | 2.60k | int n2 = detail::count_digits( cs.begin() ); | 2089 | 2.60k | BOOST_ASSERT(n2 >= 0 && n2 <= 16); | 2090 | | | 2091 | 2.60k | if( n2 == 0 ) | 2092 | 4 | { | 2093 | | // digit required | 2094 | 4 | BOOST_STATIC_CONSTEXPR source_location loc | 2095 | 4 | = BOOST_CURRENT_LOCATION; | 2096 | 4 | return fail(cs.begin(), error::syntax, &loc); | 2097 | 4 | } | 2098 | | | 2099 | | // floating-point mantissa overflow | 2100 | 2.59k | if( n1 + n2 >= 19 ) | 2101 | 314 | { | 2102 | 314 | goto do_num7; | 2103 | 314 | } | 2104 | | | 2105 | 2.28k | BOOST_IF_CONSTEXPR( !no_parsing ) | 2106 | 2.28k | num.mant = detail::parse_unsigned( num.mant, cs.begin(), n2 ); | 2107 | | | 2108 | 2.28k | BOOST_ASSERT(num.bias == 0); | 2109 | | | 2110 | 2.28k | num.bias -= n2; | 2111 | | | 2112 | 2.28k | cs += n2; | 2113 | | | 2114 | 2.28k | char ch = *cs; | 2115 | | | 2116 | 2.28k | if( (ch | 32) == 'e' ) | 2117 | 1.20k | { | 2118 | 1.20k | ++cs; | 2119 | 1.20k | goto do_exp1; | 2120 | 1.20k | } | 2121 | 1.08k | else if( ch >= '0' && ch <= '9' ) | 2122 | 415 | { | 2123 | 415 | goto do_num8; | 2124 | 415 | } | 2125 | | | 2126 | 667 | goto finish_dub; | 2127 | 2.28k | } | 2128 | 42.8k | } | 2129 | 0 | else | 2130 | 0 | { | 2131 | 0 | num = num_; | 2132 | 0 | state st; | 2133 | 0 | st_.pop(st); | 2134 | 0 | switch(st) | 2135 | 0 | { | 2136 | 0 | default: BOOST_JSON_UNREACHABLE(); | 2137 | 0 | case state::num1: goto do_num1; | 2138 | 0 | case state::num2: goto do_num2; | 2139 | 0 | case state::num3: goto do_num3; | 2140 | 0 | case state::num4: goto do_num4; | 2141 | 0 | case state::num5: goto do_num5; | 2142 | 0 | case state::num6: goto do_num6; | 2143 | 0 | case state::num7: goto do_num7; | 2144 | 0 | case state::num8: goto do_num8; | 2145 | 0 | case state::exp1: goto do_exp1; | 2146 | 0 | case state::exp2: goto do_exp2; | 2147 | 0 | case state::exp3: goto do_exp3; | 2148 | 0 | } | 2149 | 0 | } | 2150 | | | 2151 | | //---------------------------------- | 2152 | | // | 2153 | | // DIGIT | 2154 | | // first digit | 2155 | | // | 2156 | 1.53k | do_num1: | 2157 | 1.53k | if(zero_first || nonzero_first || | 2158 | 1.53k | BOOST_JSON_LIKELY(cs)) | 2159 | 1.46k | { | 2160 | 1.46k | char const c = *cs; | 2161 | 1.46k | if(zero_first) | 2162 | 0 | { | 2163 | 0 | ++cs; | 2164 | 0 | num.mant = 0; | 2165 | 0 | goto do_num6; | 2166 | 0 | } | 2167 | 1.46k | else if(nonzero_first || BOOST_JSON_LIKELY( | 2168 | 1.46k | c >= '1' && c <= '9')) | 2169 | 1.25k | { | 2170 | 1.25k | ++cs; | 2171 | 1.25k | num.mant = c - '0'; | 2172 | 1.25k | } | 2173 | 217 | else if(BOOST_JSON_UNLIKELY( | 2174 | 217 | c == '0')) | 2175 | 201 | { | 2176 | 201 | ++cs; | 2177 | 201 | num.mant = 0; | 2178 | 201 | goto do_num6; | 2179 | 201 | } | 2180 | 16 | else if( (negative || num.neg) && opt_.allow_infinity_and_nan ) | 2181 | 0 | { | 2182 | 0 | st_.push(state::lit1); | 2183 | 0 | cur_lit_ = literal_index(detail::literals::neg_infinity); | 2184 | 0 | lit_offset_ = 1; | 2185 | 0 | return parse_literal( | 2186 | 0 | cs.begin(), detail::literals_c<detail::literals::resume>() ); | 2187 | 0 | } | 2188 | 16 | else | 2189 | 16 | { | 2190 | 16 | BOOST_STATIC_CONSTEXPR source_location loc | 2191 | 16 | = BOOST_CURRENT_LOCATION; | 2192 | 16 | return fail(cs.begin(), error::syntax, &loc); | 2193 | 16 | } | 2194 | 1.46k | } | 2195 | 64 | else | 2196 | 64 | { | 2197 | 64 | if(BOOST_JSON_UNLIKELY( | 2198 | 64 | ! h_.on_number_part( | 2199 | 64 | {begin, cs.used(begin)}, ec_))) | 2200 | 32 | return fail(cs.begin()); | 2201 | | | 2202 | 32 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2203 | 32 | num_buf_.append( begin, cs.used(begin) ); | 2204 | 32 | return maybe_suspend( | 2205 | 32 | cs.begin(), state::num1, num); | 2206 | 64 | } | 2207 | | | 2208 | | //---------------------------------- | 2209 | | // | 2210 | | // 1*DIGIT | 2211 | | // significant digits left of decimal | 2212 | | // | 2213 | 5.31k | do_num2: | 2214 | 5.31k | if(negative || (!stack_empty && num.neg)) | 2215 | 5.31k | { | 2216 | 5.31k | for(;;) | 2217 | 17.3k | { | 2218 | 17.3k | if(BOOST_JSON_UNLIKELY(! cs)) | 2219 | 465 | { | 2220 | 465 | if(BOOST_JSON_UNLIKELY(more_)) | 2221 | 0 | { | 2222 | 0 | if(BOOST_JSON_UNLIKELY( | 2223 | 0 | ! h_.on_number_part( | 2224 | 0 | {begin, cs.used(begin)}, ec_))) | 2225 | 0 | return fail(cs.begin()); | 2226 | | | 2227 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2228 | 0 | num_buf_.append( begin, cs.used(begin) ); | 2229 | 0 | return suspend(cs.begin(), state::num2, num); | 2230 | 0 | } | 2231 | 465 | goto finish_int; | 2232 | 465 | } | 2233 | 16.9k | char const c = *cs; | 2234 | 16.9k | if(BOOST_JSON_LIKELY( | 2235 | 16.9k | c >= '0' && c <= '9')) | 2236 | 13.8k | { | 2237 | 13.8k | ++cs; | 2238 | | // 9223372036854775808 INT64_MIN | 2239 | 13.8k | if( num.mant > 922337203685477580 || ( | 2240 | 12.3k | num.mant == 922337203685477580 && c > '8')) | 2241 | 1.84k | break; | 2242 | 12.0k | BOOST_IF_CONSTEXPR( !no_parsing ) | 2243 | 12.0k | num.mant = 10 * num.mant + ( c - '0' ); | 2244 | 12.0k | continue; | 2245 | 13.8k | } | 2246 | 3.00k | goto do_num6; // [.eE] | 2247 | 16.9k | } | 2248 | 5.31k | } | 2249 | 0 | else | 2250 | 0 | { | 2251 | 0 | for(;;) | 2252 | 0 | { | 2253 | 0 | if(BOOST_JSON_UNLIKELY(! cs)) | 2254 | 0 | { | 2255 | 0 | if(BOOST_JSON_UNLIKELY(more_)) | 2256 | 0 | { | 2257 | 0 | if(BOOST_JSON_UNLIKELY( | 2258 | 0 | ! h_.on_number_part( | 2259 | 0 | {begin, cs.used(begin)}, ec_))) | 2260 | 0 | return fail(cs.begin()); | 2261 | | | 2262 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2263 | 0 | num_buf_.append( begin, cs.used(begin) ); | 2264 | 0 | return suspend(cs.begin(), state::num2, num); | 2265 | 0 | } | 2266 | 0 | goto finish_int; | 2267 | 0 | } | 2268 | 0 | char const c = *cs; | 2269 | 0 | if(BOOST_JSON_LIKELY( | 2270 | 0 | c >= '0' && c <= '9')) | 2271 | 0 | { | 2272 | 0 | ++cs; | 2273 | | // 18446744073709551615 UINT64_MAX | 2274 | 0 | if( num.mant > 1844674407370955161 || ( | 2275 | 0 | num.mant == 1844674407370955161 && c > '5')) | 2276 | 0 | break; | 2277 | 0 | BOOST_IF_CONSTEXPR( !no_parsing ) | 2278 | 0 | num.mant = 10 * num.mant + ( c - '0' ); | 2279 | 0 | } | 2280 | 0 | else | 2281 | 0 | { | 2282 | 0 | goto do_num6; // [.eE] | 2283 | 0 | } | 2284 | 0 | } | 2285 | 0 | } | 2286 | 1.84k | ++num.bias; | 2287 | | | 2288 | | //---------------------------------- | 2289 | | // | 2290 | | // 1*DIGIT | 2291 | | // non-significant digits left of decimal | 2292 | | // | 2293 | 1.84k | do_num3: | 2294 | 1.84k | for(;;) | 2295 | 3.19M | { | 2296 | 3.19M | if(BOOST_JSON_UNLIKELY(! cs)) | 2297 | 32 | { | 2298 | 32 | if(BOOST_JSON_UNLIKELY(more_)) | 2299 | 0 | { | 2300 | 0 | if(BOOST_JSON_UNLIKELY( | 2301 | 0 | ! h_.on_number_part( | 2302 | 0 | {begin, cs.used(begin)}, ec_))) | 2303 | 0 | return fail(cs.begin()); | 2304 | | | 2305 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2306 | 0 | num_buf_.append( begin, cs.used(begin) ); | 2307 | 0 | return suspend(cs.begin(), state::num3, num); | 2308 | 0 | } | 2309 | 32 | goto finish_dub; | 2310 | 32 | } | 2311 | 3.19M | char const c = *cs; | 2312 | 3.19M | if(BOOST_JSON_UNLIKELY( | 2313 | 3.19M | c >= '0' && c <= '9')) | 2314 | 3.18M | { | 2315 | 3.18M | if(BOOST_JSON_UNLIKELY( num.bias + 1 == INT_MAX )) | 2316 | 0 | { | 2317 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 2318 | 0 | = BOOST_CURRENT_LOCATION; | 2319 | 0 | return fail(cs.begin(), error::exponent_overflow, &loc); | 2320 | 0 | } | 2321 | 3.18M | ++cs; | 2322 | 3.18M | ++num.bias; | 2323 | 3.18M | } | 2324 | 1.81k | else if(BOOST_JSON_LIKELY( | 2325 | 1.81k | c == '.')) | 2326 | 219 | { | 2327 | 219 | ++cs; | 2328 | 219 | break; | 2329 | 219 | } | 2330 | 1.59k | else if((c | 32) == 'e') | 2331 | 782 | { | 2332 | 782 | ++cs; | 2333 | 782 | goto do_exp1; | 2334 | 782 | } | 2335 | 814 | else | 2336 | 814 | { | 2337 | 814 | goto finish_dub; | 2338 | 814 | } | 2339 | 3.19M | } | 2340 | | | 2341 | | //---------------------------------- | 2342 | | // | 2343 | | // DIGIT | 2344 | | // first non-significant digit | 2345 | | // to the right of decimal | 2346 | | // | 2347 | 219 | do_num4: | 2348 | 219 | { | 2349 | 219 | if(BOOST_JSON_UNLIKELY(! cs)) | 2350 | 3 | { | 2351 | 3 | if(BOOST_JSON_UNLIKELY( | 2352 | 3 | ! h_.on_number_part( | 2353 | 3 | {begin, cs.used(begin)}, ec_))) | 2354 | 1 | return fail(cs.begin()); | 2355 | | | 2356 | 2 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2357 | 2 | num_buf_.append( begin, cs.used(begin) ); | 2358 | 2 | return maybe_suspend( | 2359 | 2 | cs.begin(), state::num4, num); | 2360 | 3 | } | 2361 | 216 | char const c = *cs; | 2362 | 216 | if(BOOST_JSON_LIKELY( | 2363 | | //static_cast<unsigned char>(c - '0') < 10)) | 2364 | 216 | c >= '0' && c <= '9')) | 2365 | 211 | { | 2366 | 211 | ++cs; | 2367 | 211 | } | 2368 | 5 | else | 2369 | 5 | { | 2370 | | // digit required | 2371 | 5 | BOOST_STATIC_CONSTEXPR source_location loc | 2372 | 5 | = BOOST_CURRENT_LOCATION; | 2373 | 5 | return fail(cs.begin(), error::syntax, &loc); | 2374 | 5 | } | 2375 | 216 | } | 2376 | | | 2377 | | //---------------------------------- | 2378 | | // | 2379 | | // 1*DIGIT | 2380 | | // non-significant digits | 2381 | | // to the right of decimal | 2382 | | // | 2383 | 1.02k | do_num5: | 2384 | 1.02k | for(;;) | 2385 | 2.41k | { | 2386 | 2.41k | if(BOOST_JSON_UNLIKELY(! cs)) | 2387 | 29 | { | 2388 | 29 | if(BOOST_JSON_UNLIKELY(more_)) | 2389 | 0 | { | 2390 | 0 | if(BOOST_JSON_UNLIKELY( | 2391 | 0 | ! h_.on_number_part( | 2392 | 0 | {begin, cs.used(begin)}, ec_))) | 2393 | 0 | return fail(cs.begin()); | 2394 | | | 2395 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2396 | 0 | num_buf_.append( begin, cs.used(begin) ); | 2397 | 0 | return suspend(cs.begin(), state::num5, num); | 2398 | 0 | } | 2399 | 29 | goto finish_dub; | 2400 | 29 | } | 2401 | 2.39k | char const c = *cs; | 2402 | 2.39k | if(BOOST_JSON_LIKELY( | 2403 | 2.39k | c >= '0' && c <= '9')) | 2404 | 1.39k | { | 2405 | 1.39k | ++cs; | 2406 | 1.39k | } | 2407 | 991 | else if((c | 32) == 'e') | 2408 | 412 | { | 2409 | 412 | ++cs; | 2410 | 412 | goto do_exp1; | 2411 | 412 | } | 2412 | 579 | else | 2413 | 579 | { | 2414 | 579 | goto finish_dub; | 2415 | 579 | } | 2416 | 2.39k | } | 2417 | | | 2418 | | //---------------------------------- | 2419 | | // | 2420 | | // [.eE] | 2421 | | // | 2422 | 3.20k | do_num6: | 2423 | 3.20k | { | 2424 | 3.20k | if(BOOST_JSON_UNLIKELY(! cs)) | 2425 | 6 | { | 2426 | 6 | if(BOOST_JSON_UNLIKELY(more_)) | 2427 | 0 | { | 2428 | 0 | if(BOOST_JSON_UNLIKELY( | 2429 | 0 | ! h_.on_number_part( | 2430 | 0 | {begin, cs.used(begin)}, ec_))) | 2431 | 0 | return fail(cs.begin()); | 2432 | | | 2433 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2434 | 0 | num_buf_.append( begin, cs.used(begin) ); | 2435 | 0 | return suspend(cs.begin(), state::num6, num); | 2436 | 0 | } | 2437 | 6 | goto finish_int; | 2438 | 6 | } | 2439 | 3.20k | char const c = *cs; | 2440 | 3.20k | if(BOOST_JSON_LIKELY( | 2441 | 3.20k | c == '.')) | 2442 | 1.13k | { | 2443 | 1.13k | ++cs; | 2444 | 1.13k | } | 2445 | 2.07k | else if((c | 32) == 'e') | 2446 | 1.54k | { | 2447 | 1.54k | ++cs; | 2448 | 1.54k | goto do_exp1; | 2449 | 1.54k | } | 2450 | 521 | else | 2451 | 521 | { | 2452 | 521 | goto finish_int; | 2453 | 521 | } | 2454 | 3.20k | } | 2455 | | | 2456 | | //---------------------------------- | 2457 | | // | 2458 | | // DIGIT | 2459 | | // first significant digit | 2460 | | // to the right of decimal | 2461 | | // | 2462 | 1.44k | do_num7: | 2463 | 1.44k | { | 2464 | 1.44k | if(BOOST_JSON_UNLIKELY(! cs)) | 2465 | 5 | { | 2466 | 5 | if(BOOST_JSON_UNLIKELY(more_)) | 2467 | 0 | { | 2468 | 0 | if(BOOST_JSON_UNLIKELY( | 2469 | 0 | ! h_.on_number_part( | 2470 | 0 | {begin, cs.used(begin)}, ec_))) | 2471 | 0 | return fail(cs.begin()); | 2472 | | | 2473 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2474 | 0 | num_buf_.append( begin, cs.used(begin) ); | 2475 | 0 | return suspend(cs.begin(), state::num7, num); | 2476 | 0 | } | 2477 | | // digit required | 2478 | 5 | BOOST_STATIC_CONSTEXPR source_location loc | 2479 | 5 | = BOOST_CURRENT_LOCATION; | 2480 | 5 | return fail(cs.begin(), error::syntax, &loc); | 2481 | 5 | } | 2482 | 1.44k | char const c = *cs; | 2483 | 1.44k | if(BOOST_JSON_UNLIKELY( | 2484 | 1.44k | c < '0' || c > '9')) | 2485 | 14 | { | 2486 | | // digit required | 2487 | 14 | BOOST_STATIC_CONSTEXPR source_location loc | 2488 | 14 | = BOOST_CURRENT_LOCATION; | 2489 | 14 | return fail(cs.begin(), error::syntax, &loc); | 2490 | 14 | } | 2491 | 1.44k | } | 2492 | | | 2493 | | //---------------------------------- | 2494 | | // | 2495 | | // 1*DIGIT | 2496 | | // significant digits | 2497 | | // to the right of decimal | 2498 | | // | 2499 | 1.84k | do_num8: | 2500 | 1.84k | for(;;) | 2501 | 2.85M | { | 2502 | 2.85M | if(BOOST_JSON_UNLIKELY(! cs)) | 2503 | 107 | { | 2504 | 107 | if(BOOST_JSON_UNLIKELY(more_)) | 2505 | 0 | { | 2506 | 0 | if(BOOST_JSON_UNLIKELY( | 2507 | 0 | ! h_.on_number_part( | 2508 | 0 | {begin, cs.used(begin)}, ec_))) | 2509 | 0 | return fail(cs.begin()); | 2510 | | | 2511 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2512 | 0 | num_buf_.append( begin, cs.used(begin) ); | 2513 | 0 | return suspend(cs.begin(), state::num8, num); | 2514 | 0 | } | 2515 | 107 | goto finish_dub; | 2516 | 107 | } | 2517 | 2.85M | char const c = *cs; | 2518 | 2.85M | if(BOOST_JSON_LIKELY( | 2519 | 2.85M | c >= '0' && c <= '9')) | 2520 | 2.85M | { | 2521 | 2.85M | ++cs; | 2522 | 2.85M | if(!no_parsing && BOOST_JSON_LIKELY( | 2523 | 2.85M | num.mant <= 9007199254740991)) // 2^53-1 | 2524 | 2.85M | { | 2525 | 2.85M | if(BOOST_JSON_UNLIKELY( num.bias - 1 == INT_MIN )) | 2526 | 0 | { | 2527 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 2528 | 0 | = BOOST_CURRENT_LOCATION; | 2529 | 0 | return fail(cs.begin(), error::exponent_overflow, &loc); | 2530 | 0 | } | 2531 | 2.85M | --num.bias; | 2532 | 2.85M | num.mant = 10 * num.mant + ( c - '0' ); | 2533 | 2.85M | } | 2534 | 809 | else | 2535 | 809 | { | 2536 | 809 | goto do_num5; | 2537 | 809 | } | 2538 | 2.85M | } | 2539 | 926 | else if((c | 32) == 'e') | 2540 | 210 | { | 2541 | 210 | ++cs; | 2542 | 210 | goto do_exp1; | 2543 | 210 | } | 2544 | 716 | else | 2545 | 716 | { | 2546 | 716 | goto finish_dub; | 2547 | 716 | } | 2548 | 2.85M | } | 2549 | | | 2550 | | //---------------------------------- | 2551 | | // | 2552 | | // *[+-] | 2553 | | // | 2554 | 8.31k | do_exp1: | 2555 | 8.31k | if(BOOST_JSON_UNLIKELY(! cs)) | 2556 | 22 | { | 2557 | 22 | if(BOOST_JSON_UNLIKELY( | 2558 | 22 | ! h_.on_number_part( | 2559 | 22 | {begin, cs.used(begin)}, ec_))) | 2560 | 4 | return fail(cs.begin()); | 2561 | | | 2562 | 18 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2563 | 18 | num_buf_.append( begin, cs.used(begin) ); | 2564 | 18 | return maybe_suspend( | 2565 | 18 | cs.begin(), state::exp1, num); | 2566 | 22 | } | 2567 | 8.28k | if(*cs == '+') | 2568 | 88 | { | 2569 | 88 | ++cs; | 2570 | 88 | } | 2571 | 8.20k | else if(*cs == '-') | 2572 | 1.32k | { | 2573 | 1.32k | ++cs; | 2574 | 1.32k | num.frac = true; | 2575 | 1.32k | } | 2576 | | | 2577 | | //---------------------------------- | 2578 | | // | 2579 | | // DIGIT | 2580 | | // first digit of the exponent | 2581 | | // | 2582 | 8.28k | do_exp2: | 2583 | 8.28k | { | 2584 | 8.28k | if(BOOST_JSON_UNLIKELY(! cs)) | 2585 | 11 | { | 2586 | 11 | if(BOOST_JSON_UNLIKELY(more_)) | 2587 | 0 | { | 2588 | 0 | if(BOOST_JSON_UNLIKELY( | 2589 | 0 | ! h_.on_number_part( | 2590 | 0 | {begin, cs.used(begin)}, ec_))) | 2591 | 0 | return fail(cs.begin()); | 2592 | | | 2593 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2594 | 0 | num_buf_.append( begin, cs.used(begin) ); | 2595 | 0 | return suspend(cs.begin(), state::exp2, num); | 2596 | 0 | } | 2597 | | // digit required | 2598 | 11 | BOOST_STATIC_CONSTEXPR source_location loc | 2599 | 11 | = BOOST_CURRENT_LOCATION; | 2600 | 11 | return fail(cs.begin(), error::syntax, &loc); | 2601 | 11 | } | 2602 | 8.27k | char const c = *cs; | 2603 | 8.27k | if(BOOST_JSON_UNLIKELY( | 2604 | 8.27k | c < '0' || c > '9')) | 2605 | 25 | { | 2606 | | // digit required | 2607 | 25 | BOOST_STATIC_CONSTEXPR source_location loc | 2608 | 25 | = BOOST_CURRENT_LOCATION; | 2609 | 25 | return fail(cs.begin(), error::syntax, &loc); | 2610 | 25 | } | 2611 | 8.25k | ++cs; | 2612 | 8.25k | num.exp = c - '0'; | 2613 | 8.25k | } | 2614 | | | 2615 | | //---------------------------------- | 2616 | | // | 2617 | | // 1*DIGIT | 2618 | | // subsequent digits in the exponent | 2619 | | // | 2620 | 8.25k | do_exp3: | 2621 | 8.25k | for(;;) | 2622 | 39.1k | { | 2623 | 39.1k | if(BOOST_JSON_UNLIKELY(! cs)) | 2624 | 288 | { | 2625 | 288 | if(BOOST_JSON_UNLIKELY(more_)) | 2626 | 0 | { | 2627 | 0 | if(BOOST_JSON_UNLIKELY( | 2628 | 0 | ! h_.on_number_part( | 2629 | 0 | {begin, cs.used(begin)}, ec_))) | 2630 | 0 | return fail(cs.begin()); | 2631 | | | 2632 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2633 | 0 | num_buf_.append( begin, cs.used(begin) ); | 2634 | 0 | return suspend(cs.begin(), state::exp3, num); | 2635 | 0 | } | 2636 | 288 | } | 2637 | 38.9k | else | 2638 | 38.9k | { | 2639 | 38.9k | char const c = *cs; | 2640 | 38.9k | if(BOOST_JSON_LIKELY( c >= '0' && c <= '9' )) | 2641 | 30.9k | { | 2642 | 30.9k | if(BOOST_JSON_UNLIKELY( | 2643 | | // 2147483647 INT_MAX | 2644 | 30.9k | num.exp > 214748364 || | 2645 | 30.9k | (num.exp == 214748364 && c > '7') | 2646 | 30.9k | )) | 2647 | 3.17k | num.exp = INT_MAX; | 2648 | 27.7k | else BOOST_IF_CONSTEXPR( !no_parsing ) | 2649 | 27.7k | num.exp = 10 * num.exp + ( c - '0' ); | 2650 | | | 2651 | 30.9k | ++cs; | 2652 | 30.9k | continue; | 2653 | 30.9k | } | 2654 | 38.9k | } | 2655 | 8.25k | BOOST_ASSERT(num.exp >= 0); | 2656 | 8.25k | if ( num.frac ) | 2657 | 1.32k | { | 2658 | 1.32k | if(BOOST_JSON_UNLIKELY( num.bias < (INT_MIN + num.exp) )) | 2659 | 768 | { | 2660 | | // if exponent overflowed, bias is a very large negative | 2661 | | // number, and mantissa isn't zero, then we cannot parse the | 2662 | | // number correctly | 2663 | 768 | if(BOOST_JSON_UNLIKELY( | 2664 | 768 | (num.exp == INT_MAX) && | 2665 | 768 | (num.bias < 0) && | 2666 | 768 | (num.exp + num.bias < 308) && | 2667 | 768 | num.mant )) | 2668 | 0 | { | 2669 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 2670 | 0 | = BOOST_CURRENT_LOCATION; | 2671 | 0 | return fail(cs.begin(), error::exponent_overflow, &loc); | 2672 | 0 | } | 2673 | | | 2674 | 768 | num.bias = 0; | 2675 | 768 | num.exp = INT_MAX; | 2676 | 768 | } | 2677 | 1.32k | } | 2678 | 6.93k | else if (BOOST_JSON_UNLIKELY( num.bias > (INT_MAX - num.exp) )) | 2679 | 524 | { | 2680 | | // if exponent overflowed, bias is a very large positive number, | 2681 | | // and mantissa isn't zero, then we cannot parse the | 2682 | | // number correctly | 2683 | 524 | if(BOOST_JSON_UNLIKELY( | 2684 | 524 | (num.exp == INT_MAX) && | 2685 | 524 | (num.bias > 0) && | 2686 | 524 | (num.exp - num.bias < 308) && | 2687 | 524 | num.mant )) | 2688 | 0 | { | 2689 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 2690 | 0 | = BOOST_CURRENT_LOCATION; | 2691 | 0 | return fail(cs.begin(), error::exponent_overflow, &loc); | 2692 | 0 | } | 2693 | | | 2694 | 524 | num.bias = 0; | 2695 | 524 | num.exp = INT_MAX; | 2696 | 524 | } | 2697 | 8.25k | goto finish_dub; | 2698 | 8.25k | } | 2699 | | | 2700 | 992 | finish_int: | 2701 | 992 | if(negative || (!stack_empty && num.neg)) | 2702 | 992 | { | 2703 | 992 | if(BOOST_JSON_UNLIKELY( | 2704 | 992 | ! h_.on_int64(static_cast< | 2705 | 992 | int64_t>(~num.mant + 1), {begin, cs.used(begin)}, ec_))) | 2706 | 393 | return fail(cs.begin()); | 2707 | 599 | return cs.begin(); | 2708 | 992 | } | 2709 | 0 | if(num.mant <= INT64_MAX) | 2710 | 0 | { | 2711 | 30.4k | finish_signed: | 2712 | 30.4k | if(BOOST_JSON_UNLIKELY( | 2713 | 30.4k | ! h_.on_int64(static_cast< | 2714 | 30.4k | int64_t>(num.mant), {begin, cs.used(begin)}, ec_))) | 2715 | 9 | return fail(cs.begin()); | 2716 | 30.4k | return cs.begin(); | 2717 | 30.4k | } | 2718 | 0 | if(BOOST_JSON_UNLIKELY( | 2719 | 0 | ! h_.on_uint64(num.mant, {begin, cs.used(begin)}, ec_))) | 2720 | 0 | return fail(cs.begin()); | 2721 | 0 | return cs.begin(); | 2722 | 11.1k | finish_dub: | 2723 | 11.1k | double d; | 2724 | 11.1k | std::size_t const size = cs.used(begin); | 2725 | 11.1k | BOOST_ASSERT( !num_buf_.size() || precise_parsing ); | 2726 | 11.1k | BOOST_IF_CONSTEXPR( precise_parsing ) | 2727 | 11.1k | { | 2728 | 11.1k | char const* data = begin; | 2729 | 11.1k | std::size_t full_size = size; | 2730 | | // if we previously suspended or if the current input ends with the | 2731 | | // number, we need to copy the current part of the number to the | 2732 | | // temporary buffer | 2733 | | if(BOOST_JSON_UNLIKELY( num_buf_.size() )) | 2734 | | { | 2735 | | data = num_buf_.append( begin, size ); | 2736 | | full_size = num_buf_.size(); | 2737 | | } | 2738 | | auto const err = detail::charconv::from_chars( | 2739 | | data, data + full_size, d ); | 2740 | | BOOST_ASSERT( err.ec != std::errc::invalid_argument ); | 2741 | | BOOST_ASSERT( err.ptr == data + full_size ); | 2742 | | (void)err; | 2743 | | } | 2744 | 11.1k | else BOOST_IF_CONSTEXPR( no_parsing ) | 2745 | 11.1k | d = 0; | 2746 | 11.1k | else | 2747 | 11.1k | d = detail::dec_to_float( | 2748 | 11.1k | num.mant, | 2749 | 11.1k | num.bias + (num.frac ? | 2750 | 9.87k | -num.exp : num.exp), | 2751 | 11.1k | num.neg); | 2752 | 11.1k | if(BOOST_JSON_UNLIKELY( | 2753 | 11.1k | ! h_.on_double(d, {begin, size}, ec_))) | 2754 | 432 | return fail(cs.begin()); | 2755 | 10.7k | return cs.begin(); | 2756 | 11.1k | } |
Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_number<true, (char)45, (boost::json::number_precision)1>(char const*, std::__1::integral_constant<bool, true>, std::__1::integral_constant<char, (char)45>, std::__1::integral_constant<boost::json::number_precision, (boost::json::number_precision)1>) Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_number<true, (char)45, (boost::json::number_precision)2>(char const*, std::__1::integral_constant<bool, true>, std::__1::integral_constant<char, (char)45>, std::__1::integral_constant<boost::json::number_precision, (boost::json::number_precision)2>) char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_number<true, (char)43, (boost::json::number_precision)0>(char const*, std::__1::integral_constant<bool, true>, std::__1::integral_constant<char, (char)43>, std::__1::integral_constant<boost::json::number_precision, (boost::json::number_precision)0>) Line | Count | Source | 1986 | 1.11M | { | 1987 | 1.11M | constexpr bool precise_parsing = mode == number_precision::precise; | 1988 | 1.11M | constexpr bool no_parsing = mode == number_precision::none; | 1989 | | | 1990 | | // only one of these will be true if we are not resuming | 1991 | | // if negative then !zero_first && !nonzero_first | 1992 | | // if zero_first then !nonzero_first && !negative | 1993 | | // if nonzero_first then !zero_first && !negative | 1994 | 1.11M | bool const negative = first == '-'; | 1995 | 1.11M | bool const zero_first = first == '0'; | 1996 | 1.11M | bool const nonzero_first = first == '+'; | 1997 | 1.11M | detail::const_stream_wrapper cs(p, end_); | 1998 | 1.11M | number num; | 1999 | 1.11M | const char* begin = cs.begin(); | 2000 | 1.11M | if(stack_empty || st_.empty()) | 2001 | 1.11M | { | 2002 | 1.11M | num.bias = 0; | 2003 | 1.11M | num.exp = 0; | 2004 | 1.11M | num.frac = false; | 2005 | 1.11M | num_buf_.clear(); | 2006 | | | 2007 | | //---------------------------------- | 2008 | | // | 2009 | | // '-' | 2010 | | // leading minus sign | 2011 | | // | 2012 | 1.11M | BOOST_ASSERT(cs); | 2013 | 1.11M | if(negative) | 2014 | 0 | ++cs; | 2015 | | | 2016 | 1.11M | num.neg = negative; | 2017 | 1.11M | num.frac = false; | 2018 | 1.11M | num.exp = 0; | 2019 | 1.11M | num.bias = 0; | 2020 | | | 2021 | | // fast path | 2022 | 1.11M | if( cs.remain() >= 16 + 1 + 16 ) // digits . digits | 2023 | 1.10M | { | 2024 | 1.10M | int n1; | 2025 | | | 2026 | 1.10M | if( nonzero_first || | 2027 | 1.10M | (negative && *cs != '0') ) | 2028 | 1.10M | { | 2029 | 1.10M | n1 = detail::count_digits( cs.begin() ); | 2030 | 1.10M | BOOST_ASSERT(n1 >= 0 && n1 <= 16); | 2031 | | | 2032 | 1.10M | if( negative && n1 == 0 && opt_.allow_infinity_and_nan ) | 2033 | 0 | { | 2034 | 0 | return parse_literal( | 2035 | 0 | p - 1, | 2036 | 0 | detail::literals_c<detail::literals::neg_infinity>()); | 2037 | 0 | } | 2038 | | | 2039 | 1.10M | if( ! nonzero_first && n1 == 0 ) | 2040 | 0 | { | 2041 | | // digit required | 2042 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 2043 | 0 | = BOOST_CURRENT_LOCATION; | 2044 | 0 | return fail(cs.begin(), error::syntax, &loc); | 2045 | 0 | } | 2046 | | | 2047 | 1.10M | BOOST_IF_CONSTEXPR( !no_parsing ) | 2048 | 1.10M | num.mant = detail::parse_unsigned( 0, cs.begin(), n1 ); | 2049 | | else | 2050 | | num.mant = 0; | 2051 | | | 2052 | 1.10M | cs += n1; | 2053 | | | 2054 | | // integer or floating-point with | 2055 | | // >= 16 leading digits | 2056 | 1.10M | if( n1 == 16 ) | 2057 | 10.2k | { | 2058 | 10.2k | goto do_num2; | 2059 | 10.2k | } | 2060 | 1.10M | } | 2061 | 0 | else | 2062 | 0 | { | 2063 | | // 0. floating-point or 0e integer | 2064 | 0 | num.mant = 0; | 2065 | 0 | n1 = 0; | 2066 | 0 | ++cs; | 2067 | 0 | } | 2068 | | | 2069 | 1.09M | { | 2070 | 1.09M | const char c = *cs; | 2071 | 1.09M | if(c != '.') | 2072 | 1.09M | { | 2073 | 1.09M | if((c | 32) == 'e') | 2074 | 2.07k | { | 2075 | 2.07k | ++cs; | 2076 | 2.07k | goto do_exp1; | 2077 | 2.07k | } | 2078 | 1.09M | BOOST_IF_CONSTEXPR( negative && !no_parsing ) | 2079 | 1.09M | num.mant = ~num.mant + 1; | 2080 | 1.09M | goto finish_signed; | 2081 | 1.09M | } | 2082 | 1.09M | } | 2083 | | | 2084 | | // floating-point number | 2085 | | | 2086 | 4.17k | ++cs; | 2087 | | | 2088 | 4.17k | int n2 = detail::count_digits( cs.begin() ); | 2089 | 4.17k | BOOST_ASSERT(n2 >= 0 && n2 <= 16); | 2090 | | | 2091 | 4.17k | if( n2 == 0 ) | 2092 | 1 | { | 2093 | | // digit required | 2094 | 1 | BOOST_STATIC_CONSTEXPR source_location loc | 2095 | 1 | = BOOST_CURRENT_LOCATION; | 2096 | 1 | return fail(cs.begin(), error::syntax, &loc); | 2097 | 1 | } | 2098 | | | 2099 | | // floating-point mantissa overflow | 2100 | 4.17k | if( n1 + n2 >= 19 ) | 2101 | 983 | { | 2102 | 983 | goto do_num7; | 2103 | 983 | } | 2104 | | | 2105 | 3.19k | BOOST_IF_CONSTEXPR( !no_parsing ) | 2106 | 3.19k | num.mant = detail::parse_unsigned( num.mant, cs.begin(), n2 ); | 2107 | | | 2108 | 3.19k | BOOST_ASSERT(num.bias == 0); | 2109 | | | 2110 | 3.19k | num.bias -= n2; | 2111 | | | 2112 | 3.19k | cs += n2; | 2113 | | | 2114 | 3.19k | char ch = *cs; | 2115 | | | 2116 | 3.19k | if( (ch | 32) == 'e' ) | 2117 | 803 | { | 2118 | 803 | ++cs; | 2119 | 803 | goto do_exp1; | 2120 | 803 | } | 2121 | 2.38k | else if( ch >= '0' && ch <= '9' ) | 2122 | 390 | { | 2123 | 390 | goto do_num8; | 2124 | 390 | } | 2125 | | | 2126 | 1.99k | goto finish_dub; | 2127 | 3.19k | } | 2128 | 1.11M | } | 2129 | 0 | else | 2130 | 0 | { | 2131 | 0 | num = num_; | 2132 | 0 | state st; | 2133 | 0 | st_.pop(st); | 2134 | 0 | switch(st) | 2135 | 0 | { | 2136 | 0 | default: BOOST_JSON_UNREACHABLE(); | 2137 | 0 | case state::num1: goto do_num1; | 2138 | 0 | case state::num2: goto do_num2; | 2139 | 0 | case state::num3: goto do_num3; | 2140 | 0 | case state::num4: goto do_num4; | 2141 | 0 | case state::num5: goto do_num5; | 2142 | 0 | case state::num6: goto do_num6; | 2143 | 0 | case state::num7: goto do_num7; | 2144 | 0 | case state::num8: goto do_num8; | 2145 | 0 | case state::exp1: goto do_exp1; | 2146 | 0 | case state::exp2: goto do_exp2; | 2147 | 0 | case state::exp3: goto do_exp3; | 2148 | 0 | } | 2149 | 0 | } | 2150 | | | 2151 | | //---------------------------------- | 2152 | | // | 2153 | | // DIGIT | 2154 | | // first digit | 2155 | | // | 2156 | 7.03k | do_num1: | 2157 | 7.03k | if(zero_first || nonzero_first || | 2158 | 7.03k | BOOST_JSON_LIKELY(cs)) | 2159 | 7.03k | { | 2160 | 7.03k | char const c = *cs; | 2161 | 7.03k | if(zero_first) | 2162 | 0 | { | 2163 | 0 | ++cs; | 2164 | 0 | num.mant = 0; | 2165 | 0 | goto do_num6; | 2166 | 0 | } | 2167 | 7.03k | else if(nonzero_first || BOOST_JSON_LIKELY( | 2168 | 7.03k | c >= '1' && c <= '9')) | 2169 | 7.03k | { | 2170 | 7.03k | ++cs; | 2171 | 7.03k | num.mant = c - '0'; | 2172 | 7.03k | } | 2173 | 0 | else if(BOOST_JSON_UNLIKELY( | 2174 | 0 | c == '0')) | 2175 | 0 | { | 2176 | 0 | ++cs; | 2177 | 0 | num.mant = 0; | 2178 | 0 | goto do_num6; | 2179 | 0 | } | 2180 | 0 | else if( (negative || num.neg) && opt_.allow_infinity_and_nan ) | 2181 | 0 | { | 2182 | 0 | st_.push(state::lit1); | 2183 | 0 | cur_lit_ = literal_index(detail::literals::neg_infinity); | 2184 | 0 | lit_offset_ = 1; | 2185 | 0 | return parse_literal( | 2186 | 0 | cs.begin(), detail::literals_c<detail::literals::resume>() ); | 2187 | 0 | } | 2188 | 0 | else | 2189 | 0 | { | 2190 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 2191 | 0 | = BOOST_CURRENT_LOCATION; | 2192 | 0 | return fail(cs.begin(), error::syntax, &loc); | 2193 | 0 | } | 2194 | 7.03k | } | 2195 | 0 | else | 2196 | 0 | { | 2197 | 0 | if(BOOST_JSON_UNLIKELY( | 2198 | 0 | ! h_.on_number_part( | 2199 | 0 | {begin, cs.used(begin)}, ec_))) | 2200 | 0 | return fail(cs.begin()); | 2201 | | | 2202 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2203 | 0 | num_buf_.append( begin, cs.used(begin) ); | 2204 | 0 | return maybe_suspend( | 2205 | 0 | cs.begin(), state::num1, num); | 2206 | 0 | } | 2207 | | | 2208 | | //---------------------------------- | 2209 | | // | 2210 | | // 1*DIGIT | 2211 | | // significant digits left of decimal | 2212 | | // | 2213 | 17.3k | do_num2: | 2214 | 17.3k | if(negative || (!stack_empty && num.neg)) | 2215 | 0 | { | 2216 | 0 | for(;;) | 2217 | 0 | { | 2218 | 0 | if(BOOST_JSON_UNLIKELY(! cs)) | 2219 | 0 | { | 2220 | 0 | if(BOOST_JSON_UNLIKELY(more_)) | 2221 | 0 | { | 2222 | 0 | if(BOOST_JSON_UNLIKELY( | 2223 | 0 | ! h_.on_number_part( | 2224 | 0 | {begin, cs.used(begin)}, ec_))) | 2225 | 0 | return fail(cs.begin()); | 2226 | | | 2227 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2228 | 0 | num_buf_.append( begin, cs.used(begin) ); | 2229 | 0 | return suspend(cs.begin(), state::num2, num); | 2230 | 0 | } | 2231 | 0 | goto finish_int; | 2232 | 0 | } | 2233 | 0 | char const c = *cs; | 2234 | 0 | if(BOOST_JSON_LIKELY( | 2235 | 0 | c >= '0' && c <= '9')) | 2236 | 0 | { | 2237 | 0 | ++cs; | 2238 | | // 9223372036854775808 INT64_MIN | 2239 | 0 | if( num.mant > 922337203685477580 || ( | 2240 | 0 | num.mant == 922337203685477580 && c > '8')) | 2241 | 0 | break; | 2242 | 0 | BOOST_IF_CONSTEXPR( !no_parsing ) | 2243 | 0 | num.mant = 10 * num.mant + ( c - '0' ); | 2244 | 0 | continue; | 2245 | 0 | } | 2246 | 0 | goto do_num6; // [.eE] | 2247 | 0 | } | 2248 | 0 | } | 2249 | 17.3k | else | 2250 | 17.3k | { | 2251 | 17.3k | for(;;) | 2252 | 68.6k | { | 2253 | 68.6k | if(BOOST_JSON_UNLIKELY(! cs)) | 2254 | 1.60k | { | 2255 | 1.60k | if(BOOST_JSON_UNLIKELY(more_)) | 2256 | 0 | { | 2257 | 0 | if(BOOST_JSON_UNLIKELY( | 2258 | 0 | ! h_.on_number_part( | 2259 | 0 | {begin, cs.used(begin)}, ec_))) | 2260 | 0 | return fail(cs.begin()); | 2261 | | | 2262 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2263 | 0 | num_buf_.append( begin, cs.used(begin) ); | 2264 | 0 | return suspend(cs.begin(), state::num2, num); | 2265 | 0 | } | 2266 | 1.60k | goto finish_int; | 2267 | 1.60k | } | 2268 | 67.0k | char const c = *cs; | 2269 | 67.0k | if(BOOST_JSON_LIKELY( | 2270 | 67.0k | c >= '0' && c <= '9')) | 2271 | 52.3k | { | 2272 | 52.3k | ++cs; | 2273 | | // 18446744073709551615 UINT64_MAX | 2274 | 52.3k | if( num.mant > 1844674407370955161 || ( | 2275 | 51.3k | num.mant == 1844674407370955161 && c > '5')) | 2276 | 1.11k | break; | 2277 | 51.2k | BOOST_IF_CONSTEXPR( !no_parsing ) | 2278 | 51.2k | num.mant = 10 * num.mant + ( c - '0' ); | 2279 | 51.2k | } | 2280 | 14.6k | else | 2281 | 14.6k | { | 2282 | 14.6k | goto do_num6; // [.eE] | 2283 | 14.6k | } | 2284 | 67.0k | } | 2285 | 17.3k | } | 2286 | 1.11k | ++num.bias; | 2287 | | | 2288 | | //---------------------------------- | 2289 | | // | 2290 | | // 1*DIGIT | 2291 | | // non-significant digits left of decimal | 2292 | | // | 2293 | 1.11k | do_num3: | 2294 | 1.11k | for(;;) | 2295 | 1.74M | { | 2296 | 1.74M | if(BOOST_JSON_UNLIKELY(! cs)) | 2297 | 38 | { | 2298 | 38 | if(BOOST_JSON_UNLIKELY(more_)) | 2299 | 0 | { | 2300 | 0 | if(BOOST_JSON_UNLIKELY( | 2301 | 0 | ! h_.on_number_part( | 2302 | 0 | {begin, cs.used(begin)}, ec_))) | 2303 | 0 | return fail(cs.begin()); | 2304 | | | 2305 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2306 | 0 | num_buf_.append( begin, cs.used(begin) ); | 2307 | 0 | return suspend(cs.begin(), state::num3, num); | 2308 | 0 | } | 2309 | 38 | goto finish_dub; | 2310 | 38 | } | 2311 | 1.74M | char const c = *cs; | 2312 | 1.74M | if(BOOST_JSON_UNLIKELY( | 2313 | 1.74M | c >= '0' && c <= '9')) | 2314 | 1.74M | { | 2315 | 1.74M | if(BOOST_JSON_UNLIKELY( num.bias + 1 == INT_MAX )) | 2316 | 0 | { | 2317 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 2318 | 0 | = BOOST_CURRENT_LOCATION; | 2319 | 0 | return fail(cs.begin(), error::exponent_overflow, &loc); | 2320 | 0 | } | 2321 | 1.74M | ++cs; | 2322 | 1.74M | ++num.bias; | 2323 | 1.74M | } | 2324 | 1.07k | else if(BOOST_JSON_LIKELY( | 2325 | 1.07k | c == '.')) | 2326 | 128 | { | 2327 | 128 | ++cs; | 2328 | 128 | break; | 2329 | 128 | } | 2330 | 947 | else if((c | 32) == 'e') | 2331 | 583 | { | 2332 | 583 | ++cs; | 2333 | 583 | goto do_exp1; | 2334 | 583 | } | 2335 | 364 | else | 2336 | 364 | { | 2337 | 364 | goto finish_dub; | 2338 | 364 | } | 2339 | 1.74M | } | 2340 | | | 2341 | | //---------------------------------- | 2342 | | // | 2343 | | // DIGIT | 2344 | | // first non-significant digit | 2345 | | // to the right of decimal | 2346 | | // | 2347 | 128 | do_num4: | 2348 | 128 | { | 2349 | 128 | if(BOOST_JSON_UNLIKELY(! cs)) | 2350 | 5 | { | 2351 | 5 | if(BOOST_JSON_UNLIKELY( | 2352 | 5 | ! h_.on_number_part( | 2353 | 5 | {begin, cs.used(begin)}, ec_))) | 2354 | 1 | return fail(cs.begin()); | 2355 | | | 2356 | 4 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2357 | 4 | num_buf_.append( begin, cs.used(begin) ); | 2358 | 4 | return maybe_suspend( | 2359 | 4 | cs.begin(), state::num4, num); | 2360 | 5 | } | 2361 | 123 | char const c = *cs; | 2362 | 123 | if(BOOST_JSON_LIKELY( | 2363 | | //static_cast<unsigned char>(c - '0') < 10)) | 2364 | 123 | c >= '0' && c <= '9')) | 2365 | 119 | { | 2366 | 119 | ++cs; | 2367 | 119 | } | 2368 | 4 | else | 2369 | 4 | { | 2370 | | // digit required | 2371 | 4 | BOOST_STATIC_CONSTEXPR source_location loc | 2372 | 4 | = BOOST_CURRENT_LOCATION; | 2373 | 4 | return fail(cs.begin(), error::syntax, &loc); | 2374 | 4 | } | 2375 | 123 | } | 2376 | | | 2377 | | //---------------------------------- | 2378 | | // | 2379 | | // 1*DIGIT | 2380 | | // non-significant digits | 2381 | | // to the right of decimal | 2382 | | // | 2383 | 1.57k | do_num5: | 2384 | 1.57k | for(;;) | 2385 | 15.2k | { | 2386 | 15.2k | if(BOOST_JSON_UNLIKELY(! cs)) | 2387 | 34 | { | 2388 | 34 | if(BOOST_JSON_UNLIKELY(more_)) | 2389 | 0 | { | 2390 | 0 | if(BOOST_JSON_UNLIKELY( | 2391 | 0 | ! h_.on_number_part( | 2392 | 0 | {begin, cs.used(begin)}, ec_))) | 2393 | 0 | return fail(cs.begin()); | 2394 | | | 2395 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2396 | 0 | num_buf_.append( begin, cs.used(begin) ); | 2397 | 0 | return suspend(cs.begin(), state::num5, num); | 2398 | 0 | } | 2399 | 34 | goto finish_dub; | 2400 | 34 | } | 2401 | 15.1k | char const c = *cs; | 2402 | 15.1k | if(BOOST_JSON_LIKELY( | 2403 | 15.1k | c >= '0' && c <= '9')) | 2404 | 13.6k | { | 2405 | 13.6k | ++cs; | 2406 | 13.6k | } | 2407 | 1.54k | else if((c | 32) == 'e') | 2408 | 284 | { | 2409 | 284 | ++cs; | 2410 | 284 | goto do_exp1; | 2411 | 284 | } | 2412 | 1.25k | else | 2413 | 1.25k | { | 2414 | 1.25k | goto finish_dub; | 2415 | 1.25k | } | 2416 | 15.1k | } | 2417 | | | 2418 | | //---------------------------------- | 2419 | | // | 2420 | | // [.eE] | 2421 | | // | 2422 | 14.6k | do_num6: | 2423 | 14.6k | { | 2424 | 14.6k | if(BOOST_JSON_UNLIKELY(! cs)) | 2425 | 0 | { | 2426 | 0 | if(BOOST_JSON_UNLIKELY(more_)) | 2427 | 0 | { | 2428 | 0 | if(BOOST_JSON_UNLIKELY( | 2429 | 0 | ! h_.on_number_part( | 2430 | 0 | {begin, cs.used(begin)}, ec_))) | 2431 | 0 | return fail(cs.begin()); | 2432 | | | 2433 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2434 | 0 | num_buf_.append( begin, cs.used(begin) ); | 2435 | 0 | return suspend(cs.begin(), state::num6, num); | 2436 | 0 | } | 2437 | 0 | goto finish_int; | 2438 | 0 | } | 2439 | 14.6k | char const c = *cs; | 2440 | 14.6k | if(BOOST_JSON_LIKELY( | 2441 | 14.6k | c == '.')) | 2442 | 721 | { | 2443 | 721 | ++cs; | 2444 | 721 | } | 2445 | 13.8k | else if((c | 32) == 'e') | 2446 | 607 | { | 2447 | 607 | ++cs; | 2448 | 607 | goto do_exp1; | 2449 | 607 | } | 2450 | 13.2k | else | 2451 | 13.2k | { | 2452 | 13.2k | goto finish_int; | 2453 | 13.2k | } | 2454 | 14.6k | } | 2455 | | | 2456 | | //---------------------------------- | 2457 | | // | 2458 | | // DIGIT | 2459 | | // first significant digit | 2460 | | // to the right of decimal | 2461 | | // | 2462 | 1.70k | do_num7: | 2463 | 1.70k | { | 2464 | 1.70k | if(BOOST_JSON_UNLIKELY(! cs)) | 2465 | 6 | { | 2466 | 6 | if(BOOST_JSON_UNLIKELY(more_)) | 2467 | 0 | { | 2468 | 0 | if(BOOST_JSON_UNLIKELY( | 2469 | 0 | ! h_.on_number_part( | 2470 | 0 | {begin, cs.used(begin)}, ec_))) | 2471 | 0 | return fail(cs.begin()); | 2472 | | | 2473 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2474 | 0 | num_buf_.append( begin, cs.used(begin) ); | 2475 | 0 | return suspend(cs.begin(), state::num7, num); | 2476 | 0 | } | 2477 | | // digit required | 2478 | 6 | BOOST_STATIC_CONSTEXPR source_location loc | 2479 | 6 | = BOOST_CURRENT_LOCATION; | 2480 | 6 | return fail(cs.begin(), error::syntax, &loc); | 2481 | 6 | } | 2482 | 1.69k | char const c = *cs; | 2483 | 1.69k | if(BOOST_JSON_UNLIKELY( | 2484 | 1.69k | c < '0' || c > '9')) | 2485 | 12 | { | 2486 | | // digit required | 2487 | 12 | BOOST_STATIC_CONSTEXPR source_location loc | 2488 | 12 | = BOOST_CURRENT_LOCATION; | 2489 | 12 | return fail(cs.begin(), error::syntax, &loc); | 2490 | 12 | } | 2491 | 1.69k | } | 2492 | | | 2493 | | //---------------------------------- | 2494 | | // | 2495 | | // 1*DIGIT | 2496 | | // significant digits | 2497 | | // to the right of decimal | 2498 | | // | 2499 | 2.07k | do_num8: | 2500 | 2.07k | for(;;) | 2501 | 14.3k | { | 2502 | 14.3k | if(BOOST_JSON_UNLIKELY(! cs)) | 2503 | 146 | { | 2504 | 146 | if(BOOST_JSON_UNLIKELY(more_)) | 2505 | 0 | { | 2506 | 0 | if(BOOST_JSON_UNLIKELY( | 2507 | 0 | ! h_.on_number_part( | 2508 | 0 | {begin, cs.used(begin)}, ec_))) | 2509 | 0 | return fail(cs.begin()); | 2510 | | | 2511 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2512 | 0 | num_buf_.append( begin, cs.used(begin) ); | 2513 | 0 | return suspend(cs.begin(), state::num8, num); | 2514 | 0 | } | 2515 | 146 | goto finish_dub; | 2516 | 146 | } | 2517 | 14.2k | char const c = *cs; | 2518 | 14.2k | if(BOOST_JSON_LIKELY( | 2519 | 14.2k | c >= '0' && c <= '9')) | 2520 | 13.7k | { | 2521 | 13.7k | ++cs; | 2522 | 13.7k | if(!no_parsing && BOOST_JSON_LIKELY( | 2523 | 13.7k | num.mant <= 9007199254740991)) // 2^53-1 | 2524 | 12.3k | { | 2525 | 12.3k | if(BOOST_JSON_UNLIKELY( num.bias - 1 == INT_MIN )) | 2526 | 0 | { | 2527 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 2528 | 0 | = BOOST_CURRENT_LOCATION; | 2529 | 0 | return fail(cs.begin(), error::exponent_overflow, &loc); | 2530 | 0 | } | 2531 | 12.3k | --num.bias; | 2532 | 12.3k | num.mant = 10 * num.mant + ( c - '0' ); | 2533 | 12.3k | } | 2534 | 1.45k | else | 2535 | 1.45k | { | 2536 | 1.45k | goto do_num5; | 2537 | 1.45k | } | 2538 | 13.7k | } | 2539 | 475 | else if((c | 32) == 'e') | 2540 | 120 | { | 2541 | 120 | ++cs; | 2542 | 120 | goto do_exp1; | 2543 | 120 | } | 2544 | 355 | else | 2545 | 355 | { | 2546 | 355 | goto finish_dub; | 2547 | 355 | } | 2548 | 14.2k | } | 2549 | | | 2550 | | //---------------------------------- | 2551 | | // | 2552 | | // *[+-] | 2553 | | // | 2554 | 4.47k | do_exp1: | 2555 | 4.47k | if(BOOST_JSON_UNLIKELY(! cs)) | 2556 | 24 | { | 2557 | 24 | if(BOOST_JSON_UNLIKELY( | 2558 | 24 | ! h_.on_number_part( | 2559 | 24 | {begin, cs.used(begin)}, ec_))) | 2560 | 6 | return fail(cs.begin()); | 2561 | | | 2562 | 18 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2563 | 18 | num_buf_.append( begin, cs.used(begin) ); | 2564 | 18 | return maybe_suspend( | 2565 | 18 | cs.begin(), state::exp1, num); | 2566 | 24 | } | 2567 | 4.44k | if(*cs == '+') | 2568 | 349 | { | 2569 | 349 | ++cs; | 2570 | 349 | } | 2571 | 4.09k | else if(*cs == '-') | 2572 | 1.56k | { | 2573 | 1.56k | ++cs; | 2574 | 1.56k | num.frac = true; | 2575 | 1.56k | } | 2576 | | | 2577 | | //---------------------------------- | 2578 | | // | 2579 | | // DIGIT | 2580 | | // first digit of the exponent | 2581 | | // | 2582 | 4.44k | do_exp2: | 2583 | 4.44k | { | 2584 | 4.44k | if(BOOST_JSON_UNLIKELY(! cs)) | 2585 | 9 | { | 2586 | 9 | if(BOOST_JSON_UNLIKELY(more_)) | 2587 | 0 | { | 2588 | 0 | if(BOOST_JSON_UNLIKELY( | 2589 | 0 | ! h_.on_number_part( | 2590 | 0 | {begin, cs.used(begin)}, ec_))) | 2591 | 0 | return fail(cs.begin()); | 2592 | | | 2593 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2594 | 0 | num_buf_.append( begin, cs.used(begin) ); | 2595 | 0 | return suspend(cs.begin(), state::exp2, num); | 2596 | 0 | } | 2597 | | // digit required | 2598 | 9 | BOOST_STATIC_CONSTEXPR source_location loc | 2599 | 9 | = BOOST_CURRENT_LOCATION; | 2600 | 9 | return fail(cs.begin(), error::syntax, &loc); | 2601 | 9 | } | 2602 | 4.43k | char const c = *cs; | 2603 | 4.43k | if(BOOST_JSON_UNLIKELY( | 2604 | 4.43k | c < '0' || c > '9')) | 2605 | 36 | { | 2606 | | // digit required | 2607 | 36 | BOOST_STATIC_CONSTEXPR source_location loc | 2608 | 36 | = BOOST_CURRENT_LOCATION; | 2609 | 36 | return fail(cs.begin(), error::syntax, &loc); | 2610 | 36 | } | 2611 | 4.40k | ++cs; | 2612 | 4.40k | num.exp = c - '0'; | 2613 | 4.40k | } | 2614 | | | 2615 | | //---------------------------------- | 2616 | | // | 2617 | | // 1*DIGIT | 2618 | | // subsequent digits in the exponent | 2619 | | // | 2620 | 4.40k | do_exp3: | 2621 | 4.40k | for(;;) | 2622 | 21.8k | { | 2623 | 21.8k | if(BOOST_JSON_UNLIKELY(! cs)) | 2624 | 310 | { | 2625 | 310 | if(BOOST_JSON_UNLIKELY(more_)) | 2626 | 0 | { | 2627 | 0 | if(BOOST_JSON_UNLIKELY( | 2628 | 0 | ! h_.on_number_part( | 2629 | 0 | {begin, cs.used(begin)}, ec_))) | 2630 | 0 | return fail(cs.begin()); | 2631 | | | 2632 | 0 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2633 | 0 | num_buf_.append( begin, cs.used(begin) ); | 2634 | 0 | return suspend(cs.begin(), state::exp3, num); | 2635 | 0 | } | 2636 | 310 | } | 2637 | 21.5k | else | 2638 | 21.5k | { | 2639 | 21.5k | char const c = *cs; | 2640 | 21.5k | if(BOOST_JSON_LIKELY( c >= '0' && c <= '9' )) | 2641 | 17.4k | { | 2642 | 17.4k | if(BOOST_JSON_UNLIKELY( | 2643 | | // 2147483647 INT_MAX | 2644 | 17.4k | num.exp > 214748364 || | 2645 | 17.4k | (num.exp == 214748364 && c > '7') | 2646 | 17.4k | )) | 2647 | 2.76k | num.exp = INT_MAX; | 2648 | 14.7k | else BOOST_IF_CONSTEXPR( !no_parsing ) | 2649 | 14.7k | num.exp = 10 * num.exp + ( c - '0' ); | 2650 | | | 2651 | 17.4k | ++cs; | 2652 | 17.4k | continue; | 2653 | 17.4k | } | 2654 | 21.5k | } | 2655 | 4.40k | BOOST_ASSERT(num.exp >= 0); | 2656 | 4.40k | if ( num.frac ) | 2657 | 1.56k | { | 2658 | 1.56k | if(BOOST_JSON_UNLIKELY( num.bias < (INT_MIN + num.exp) )) | 2659 | 709 | { | 2660 | | // if exponent overflowed, bias is a very large negative | 2661 | | // number, and mantissa isn't zero, then we cannot parse the | 2662 | | // number correctly | 2663 | 709 | if(BOOST_JSON_UNLIKELY( | 2664 | 709 | (num.exp == INT_MAX) && | 2665 | 709 | (num.bias < 0) && | 2666 | 709 | (num.exp + num.bias < 308) && | 2667 | 709 | num.mant )) | 2668 | 0 | { | 2669 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 2670 | 0 | = BOOST_CURRENT_LOCATION; | 2671 | 0 | return fail(cs.begin(), error::exponent_overflow, &loc); | 2672 | 0 | } | 2673 | | | 2674 | 709 | num.bias = 0; | 2675 | 709 | num.exp = INT_MAX; | 2676 | 709 | } | 2677 | 1.56k | } | 2678 | 2.84k | else if (BOOST_JSON_UNLIKELY( num.bias > (INT_MAX - num.exp) )) | 2679 | 414 | { | 2680 | | // if exponent overflowed, bias is a very large positive number, | 2681 | | // and mantissa isn't zero, then we cannot parse the | 2682 | | // number correctly | 2683 | 414 | if(BOOST_JSON_UNLIKELY( | 2684 | 414 | (num.exp == INT_MAX) && | 2685 | 414 | (num.bias > 0) && | 2686 | 414 | (num.exp - num.bias < 308) && | 2687 | 414 | num.mant )) | 2688 | 0 | { | 2689 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 2690 | 0 | = BOOST_CURRENT_LOCATION; | 2691 | 0 | return fail(cs.begin(), error::exponent_overflow, &loc); | 2692 | 0 | } | 2693 | | | 2694 | 414 | num.bias = 0; | 2695 | 414 | num.exp = INT_MAX; | 2696 | 414 | } | 2697 | 4.40k | goto finish_dub; | 2698 | 4.40k | } | 2699 | | | 2700 | 14.8k | finish_int: | 2701 | 14.8k | if(negative || (!stack_empty && num.neg)) | 2702 | 0 | { | 2703 | 0 | if(BOOST_JSON_UNLIKELY( | 2704 | 0 | ! h_.on_int64(static_cast< | 2705 | 0 | int64_t>(~num.mant + 1), {begin, cs.used(begin)}, ec_))) | 2706 | 0 | return fail(cs.begin()); | 2707 | 0 | return cs.begin(); | 2708 | 0 | } | 2709 | 14.8k | if(num.mant <= INT64_MAX) | 2710 | 5.83k | { | 2711 | 1.09M | finish_signed: | 2712 | 1.09M | if(BOOST_JSON_UNLIKELY( | 2713 | 1.09M | ! h_.on_int64(static_cast< | 2714 | 1.09M | int64_t>(num.mant), {begin, cs.used(begin)}, ec_))) | 2715 | 138 | return fail(cs.begin()); | 2716 | 1.09M | return cs.begin(); | 2717 | 1.09M | } | 2718 | 9.04k | if(BOOST_JSON_UNLIKELY( | 2719 | 9.04k | ! h_.on_uint64(num.mant, {begin, cs.used(begin)}, ec_))) | 2720 | 592 | return fail(cs.begin()); | 2721 | 8.45k | return cs.begin(); | 2722 | 8.59k | finish_dub: | 2723 | 8.59k | double d; | 2724 | 8.59k | std::size_t const size = cs.used(begin); | 2725 | 8.59k | BOOST_ASSERT( !num_buf_.size() || precise_parsing ); | 2726 | 8.59k | BOOST_IF_CONSTEXPR( precise_parsing ) | 2727 | 8.59k | { | 2728 | 8.59k | char const* data = begin; | 2729 | 8.59k | std::size_t full_size = size; | 2730 | | // if we previously suspended or if the current input ends with the | 2731 | | // number, we need to copy the current part of the number to the | 2732 | | // temporary buffer | 2733 | | if(BOOST_JSON_UNLIKELY( num_buf_.size() )) | 2734 | | { | 2735 | | data = num_buf_.append( begin, size ); | 2736 | | full_size = num_buf_.size(); | 2737 | | } | 2738 | | auto const err = detail::charconv::from_chars( | 2739 | | data, data + full_size, d ); | 2740 | | BOOST_ASSERT( err.ec != std::errc::invalid_argument ); | 2741 | | BOOST_ASSERT( err.ptr == data + full_size ); | 2742 | | (void)err; | 2743 | | } | 2744 | 8.59k | else BOOST_IF_CONSTEXPR( no_parsing ) | 2745 | 8.59k | d = 0; | 2746 | 8.59k | else | 2747 | 8.59k | d = detail::dec_to_float( | 2748 | 8.59k | num.mant, | 2749 | 8.59k | num.bias + (num.frac ? | 2750 | 7.03k | -num.exp : num.exp), | 2751 | 8.59k | num.neg); | 2752 | 8.59k | if(BOOST_JSON_UNLIKELY( | 2753 | 8.59k | ! h_.on_double(d, {begin, size}, ec_))) | 2754 | 480 | return fail(cs.begin()); | 2755 | 8.11k | return cs.begin(); | 2756 | 8.59k | } |
Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_number<true, (char)43, (boost::json::number_precision)1>(char const*, std::__1::integral_constant<bool, true>, std::__1::integral_constant<char, (char)43>, std::__1::integral_constant<boost::json::number_precision, (boost::json::number_precision)1>) Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_number<true, (char)43, (boost::json::number_precision)2>(char const*, std::__1::integral_constant<bool, true>, std::__1::integral_constant<char, (char)43>, std::__1::integral_constant<boost::json::number_precision, (boost::json::number_precision)2>) Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_number<false, (char)0, (boost::json::number_precision)0>(char const*, std::__1::integral_constant<bool, false>, std::__1::integral_constant<char, (char)0>, std::__1::integral_constant<boost::json::number_precision, (boost::json::number_precision)0>) Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_number<false, (char)0, (boost::json::number_precision)1>(char const*, std::__1::integral_constant<bool, false>, std::__1::integral_constant<char, (char)0>, std::__1::integral_constant<boost::json::number_precision, (boost::json::number_precision)1>) Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::into_handler<Object> >::parse_number<false, (char)0, (boost::json::number_precision)2>(char const*, std::__1::integral_constant<bool, false>, std::__1::integral_constant<char, (char)0>, std::__1::integral_constant<boost::json::number_precision, (boost::json::number_precision)2>) |
2757 | | |
2758 | | //---------------------------------------------------------- |
2759 | | |
2760 | | template<class Handler> |
2761 | | template<class... Args> |
2762 | | basic_parser<Handler>:: |
2763 | | basic_parser( |
2764 | | parse_options const& opt, |
2765 | | Args&&... args) |
2766 | 8.84k | : h_(std::forward<Args>(args)...) |
2767 | 8.84k | , opt_(opt) |
2768 | 8.84k | { |
2769 | 8.84k | } |
2770 | | |
2771 | | //---------------------------------------------------------- |
2772 | | |
2773 | | template<class Handler> |
2774 | | void |
2775 | | basic_parser<Handler>:: |
2776 | | reset() noexcept |
2777 | | { |
2778 | | ec_ = {}; |
2779 | | st_.clear(); |
2780 | | more_ = true; |
2781 | | done_ = false; |
2782 | | clean_ = true; |
2783 | | num_buf_.clear(); |
2784 | | } |
2785 | | |
2786 | | template<class Handler> |
2787 | | void |
2788 | | basic_parser<Handler>:: |
2789 | | fail(system::error_code ec) noexcept |
2790 | | { |
2791 | | if(! ec) |
2792 | | { |
2793 | | // assign an arbitrary |
2794 | | // error code to prevent UB |
2795 | | BOOST_JSON_FAIL(ec_, error::incomplete); |
2796 | | } |
2797 | | else |
2798 | | { |
2799 | | ec_ = ec; |
2800 | | } |
2801 | | done_ = false; |
2802 | | } |
2803 | | |
2804 | | //---------------------------------------------------------- |
2805 | | |
2806 | | template<class Handler> |
2807 | | std::size_t |
2808 | | basic_parser<Handler>:: |
2809 | | write_some( |
2810 | | bool more, |
2811 | | char const* data, |
2812 | | std::size_t size, |
2813 | | system::error_code& ec) |
2814 | 8.84k | { |
2815 | | // see if we exited via exception |
2816 | | // on the last call to write_some |
2817 | 8.84k | if(! clean_) |
2818 | 0 | { |
2819 | | // prevent UB |
2820 | 0 | if(! ec_) |
2821 | 0 | { |
2822 | 0 | BOOST_JSON_FAIL(ec_, error::exception); |
2823 | 0 | } |
2824 | 0 | } |
2825 | 8.84k | if(ec_) |
2826 | 0 | { |
2827 | | // error is sticky |
2828 | 0 | ec = ec_; |
2829 | 0 | return 0; |
2830 | 0 | } |
2831 | 8.84k | clean_ = false; |
2832 | 8.84k | more_ = more; |
2833 | 8.84k | end_ = data + size; |
2834 | 8.84k | const char* p; |
2835 | 8.84k | if(BOOST_JSON_LIKELY(st_.empty())) |
2836 | 8.84k | { |
2837 | | // first time |
2838 | 8.84k | depth_ = opt_.max_depth; |
2839 | 8.84k | if(BOOST_JSON_UNLIKELY( |
2840 | 8.84k | ! h_.on_document_begin(ec_))) |
2841 | 0 | { |
2842 | 0 | ec = ec_; |
2843 | 0 | return 0; |
2844 | 0 | } |
2845 | 8.84k | p = parse_document(data, std::true_type()); |
2846 | 8.84k | } |
2847 | 0 | else |
2848 | 0 | { |
2849 | 0 | p = parse_document(data, std::false_type()); |
2850 | 0 | } |
2851 | | |
2852 | 8.84k | if(BOOST_JSON_LIKELY(p != sentinel())) |
2853 | 73 | { |
2854 | 73 | BOOST_ASSERT(! ec_); |
2855 | 73 | if(! done_) |
2856 | 73 | { |
2857 | 73 | done_ = true; |
2858 | 73 | h_.on_document_end(ec_); |
2859 | 73 | } |
2860 | 73 | } |
2861 | 8.77k | else |
2862 | 8.77k | { |
2863 | 8.77k | if(! ec_) |
2864 | 3.74k | { |
2865 | 3.74k | if(! more_) |
2866 | 3.74k | { |
2867 | 3.74k | BOOST_JSON_FAIL(ec_, error::incomplete); |
2868 | 3.74k | } |
2869 | 0 | else if(! st_.empty()) |
2870 | 0 | { |
2871 | | // consume as much trailing whitespace in |
2872 | | // the JSON document as possible, but still |
2873 | | // consider the parse complete |
2874 | 0 | state st; |
2875 | 0 | st_.peek(st); |
2876 | 0 | if( st == state::doc3 && |
2877 | 0 | ! done_) |
2878 | 0 | { |
2879 | 0 | done_ = true; |
2880 | 0 | h_.on_document_end(ec_); |
2881 | 0 | } |
2882 | 0 | } |
2883 | 3.74k | } |
2884 | 8.77k | p = end_; |
2885 | 8.77k | } |
2886 | 8.84k | ec = ec_; |
2887 | 8.84k | clean_ = true; |
2888 | 8.84k | return p - data; |
2889 | 8.84k | } |
2890 | | |
2891 | | template<class Handler> |
2892 | | std::size_t |
2893 | | basic_parser<Handler>:: |
2894 | | write_some( |
2895 | | bool more, |
2896 | | char const* data, |
2897 | | std::size_t size, |
2898 | | std::error_code& ec) |
2899 | | { |
2900 | | system::error_code jec; |
2901 | | std::size_t const result = write_some(more, data, size, jec); |
2902 | | ec = jec; |
2903 | | return result; |
2904 | | } |
2905 | | |
2906 | | #endif |
2907 | | |
2908 | | } // namespace json |
2909 | | } // namespace boost |
2910 | | |
2911 | | #ifdef _MSC_VER |
2912 | | #pragma warning(pop) |
2913 | | #endif |
2914 | | |
2915 | | #endif |