/src/boost/boost/json/basic_parser_impl.hpp
Line | Count | Source |
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 | 4.09M | { |
57 | 4.09M | static double const tab[618] = { |
58 | 4.09M | 1e-308, 1e-307, 1e-306, 1e-305, 1e-304, 1e-303, 1e-302, 1e-301, |
59 | | |
60 | 4.09M | 1e-300, 1e-299, 1e-298, 1e-297, 1e-296, 1e-295, 1e-294, 1e-293, 1e-292, 1e-291, |
61 | 4.09M | 1e-290, 1e-289, 1e-288, 1e-287, 1e-286, 1e-285, 1e-284, 1e-283, 1e-282, 1e-281, |
62 | 4.09M | 1e-280, 1e-279, 1e-278, 1e-277, 1e-276, 1e-275, 1e-274, 1e-273, 1e-272, 1e-271, |
63 | 4.09M | 1e-270, 1e-269, 1e-268, 1e-267, 1e-266, 1e-265, 1e-264, 1e-263, 1e-262, 1e-261, |
64 | 4.09M | 1e-260, 1e-259, 1e-258, 1e-257, 1e-256, 1e-255, 1e-254, 1e-253, 1e-252, 1e-251, |
65 | 4.09M | 1e-250, 1e-249, 1e-248, 1e-247, 1e-246, 1e-245, 1e-244, 1e-243, 1e-242, 1e-241, |
66 | 4.09M | 1e-240, 1e-239, 1e-238, 1e-237, 1e-236, 1e-235, 1e-234, 1e-233, 1e-232, 1e-231, |
67 | 4.09M | 1e-230, 1e-229, 1e-228, 1e-227, 1e-226, 1e-225, 1e-224, 1e-223, 1e-222, 1e-221, |
68 | 4.09M | 1e-220, 1e-219, 1e-218, 1e-217, 1e-216, 1e-215, 1e-214, 1e-213, 1e-212, 1e-211, |
69 | 4.09M | 1e-210, 1e-209, 1e-208, 1e-207, 1e-206, 1e-205, 1e-204, 1e-203, 1e-202, 1e-201, |
70 | | |
71 | 4.09M | 1e-200, 1e-199, 1e-198, 1e-197, 1e-196, 1e-195, 1e-194, 1e-193, 1e-192, 1e-191, |
72 | 4.09M | 1e-190, 1e-189, 1e-188, 1e-187, 1e-186, 1e-185, 1e-184, 1e-183, 1e-182, 1e-181, |
73 | 4.09M | 1e-180, 1e-179, 1e-178, 1e-177, 1e-176, 1e-175, 1e-174, 1e-173, 1e-172, 1e-171, |
74 | 4.09M | 1e-170, 1e-169, 1e-168, 1e-167, 1e-166, 1e-165, 1e-164, 1e-163, 1e-162, 1e-161, |
75 | 4.09M | 1e-160, 1e-159, 1e-158, 1e-157, 1e-156, 1e-155, 1e-154, 1e-153, 1e-152, 1e-151, |
76 | 4.09M | 1e-150, 1e-149, 1e-148, 1e-147, 1e-146, 1e-145, 1e-144, 1e-143, 1e-142, 1e-141, |
77 | 4.09M | 1e-140, 1e-139, 1e-138, 1e-137, 1e-136, 1e-135, 1e-134, 1e-133, 1e-132, 1e-131, |
78 | 4.09M | 1e-130, 1e-129, 1e-128, 1e-127, 1e-126, 1e-125, 1e-124, 1e-123, 1e-122, 1e-121, |
79 | 4.09M | 1e-120, 1e-119, 1e-118, 1e-117, 1e-116, 1e-115, 1e-114, 1e-113, 1e-112, 1e-111, |
80 | 4.09M | 1e-110, 1e-109, 1e-108, 1e-107, 1e-106, 1e-105, 1e-104, 1e-103, 1e-102, 1e-101, |
81 | | |
82 | 4.09M | 1e-100, 1e-099, 1e-098, 1e-097, 1e-096, 1e-095, 1e-094, 1e-093, 1e-092, 1e-091, |
83 | 4.09M | 1e-090, 1e-089, 1e-088, 1e-087, 1e-086, 1e-085, 1e-084, 1e-083, 1e-082, 1e-081, |
84 | 4.09M | 1e-080, 1e-079, 1e-078, 1e-077, 1e-076, 1e-075, 1e-074, 1e-073, 1e-072, 1e-071, |
85 | 4.09M | 1e-070, 1e-069, 1e-068, 1e-067, 1e-066, 1e-065, 1e-064, 1e-063, 1e-062, 1e-061, |
86 | 4.09M | 1e-060, 1e-059, 1e-058, 1e-057, 1e-056, 1e-055, 1e-054, 1e-053, 1e-052, 1e-051, |
87 | 4.09M | 1e-050, 1e-049, 1e-048, 1e-047, 1e-046, 1e-045, 1e-044, 1e-043, 1e-042, 1e-041, |
88 | 4.09M | 1e-040, 1e-039, 1e-038, 1e-037, 1e-036, 1e-035, 1e-034, 1e-033, 1e-032, 1e-031, |
89 | 4.09M | 1e-030, 1e-029, 1e-028, 1e-027, 1e-026, 1e-025, 1e-024, 1e-023, 1e-022, 1e-021, |
90 | 4.09M | 1e-020, 1e-019, 1e-018, 1e-017, 1e-016, 1e-015, 1e-014, 1e-013, 1e-012, 1e-011, |
91 | 4.09M | 1e-010, 1e-009, 1e-008, 1e-007, 1e-006, 1e-005, 1e-004, 1e-003, 1e-002, 1e-001, |
92 | | |
93 | 4.09M | 1e+000, 1e+001, 1e+002, 1e+003, 1e+004, 1e+005, 1e+006, 1e+007, 1e+008, 1e+009, |
94 | 4.09M | 1e+010, 1e+011, 1e+012, 1e+013, 1e+014, 1e+015, 1e+016, 1e+017, 1e+018, 1e+019, |
95 | 4.09M | 1e+020, 1e+021, 1e+022, 1e+023, 1e+024, 1e+025, 1e+026, 1e+027, 1e+028, 1e+029, |
96 | 4.09M | 1e+030, 1e+031, 1e+032, 1e+033, 1e+034, 1e+035, 1e+036, 1e+037, 1e+038, 1e+039, |
97 | 4.09M | 1e+040, 1e+041, 1e+042, 1e+043, 1e+044, 1e+045, 1e+046, 1e+047, 1e+048, 1e+049, |
98 | 4.09M | 1e+050, 1e+051, 1e+052, 1e+053, 1e+054, 1e+055, 1e+056, 1e+057, 1e+058, 1e+059, |
99 | 4.09M | 1e+060, 1e+061, 1e+062, 1e+063, 1e+064, 1e+065, 1e+066, 1e+067, 1e+068, 1e+069, |
100 | 4.09M | 1e+070, 1e+071, 1e+072, 1e+073, 1e+074, 1e+075, 1e+076, 1e+077, 1e+078, 1e+079, |
101 | 4.09M | 1e+080, 1e+081, 1e+082, 1e+083, 1e+084, 1e+085, 1e+086, 1e+087, 1e+088, 1e+089, |
102 | 4.09M | 1e+090, 1e+091, 1e+092, 1e+093, 1e+094, 1e+095, 1e+096, 1e+097, 1e+098, 1e+099, |
103 | | |
104 | 4.09M | 1e+100, 1e+101, 1e+102, 1e+103, 1e+104, 1e+105, 1e+106, 1e+107, 1e+108, 1e+109, |
105 | 4.09M | 1e+110, 1e+111, 1e+112, 1e+113, 1e+114, 1e+115, 1e+116, 1e+117, 1e+118, 1e+119, |
106 | 4.09M | 1e+120, 1e+121, 1e+122, 1e+123, 1e+124, 1e+125, 1e+126, 1e+127, 1e+128, 1e+129, |
107 | 4.09M | 1e+130, 1e+131, 1e+132, 1e+133, 1e+134, 1e+135, 1e+136, 1e+137, 1e+138, 1e+139, |
108 | 4.09M | 1e+140, 1e+141, 1e+142, 1e+143, 1e+144, 1e+145, 1e+146, 1e+147, 1e+148, 1e+149, |
109 | 4.09M | 1e+150, 1e+151, 1e+152, 1e+153, 1e+154, 1e+155, 1e+156, 1e+157, 1e+158, 1e+159, |
110 | 4.09M | 1e+160, 1e+161, 1e+162, 1e+163, 1e+164, 1e+165, 1e+166, 1e+167, 1e+168, 1e+169, |
111 | 4.09M | 1e+170, 1e+171, 1e+172, 1e+173, 1e+174, 1e+175, 1e+176, 1e+177, 1e+178, 1e+179, |
112 | 4.09M | 1e+180, 1e+181, 1e+182, 1e+183, 1e+184, 1e+185, 1e+186, 1e+187, 1e+188, 1e+189, |
113 | 4.09M | 1e+190, 1e+191, 1e+192, 1e+193, 1e+194, 1e+195, 1e+196, 1e+197, 1e+198, 1e+199, |
114 | | |
115 | 4.09M | 1e+200, 1e+201, 1e+202, 1e+203, 1e+204, 1e+205, 1e+206, 1e+207, 1e+208, 1e+209, |
116 | 4.09M | 1e+210, 1e+211, 1e+212, 1e+213, 1e+214, 1e+215, 1e+216, 1e+217, 1e+218, 1e+219, |
117 | 4.09M | 1e+220, 1e+221, 1e+222, 1e+223, 1e+224, 1e+225, 1e+226, 1e+227, 1e+228, 1e+229, |
118 | 4.09M | 1e+230, 1e+231, 1e+232, 1e+233, 1e+234, 1e+235, 1e+236, 1e+237, 1e+238, 1e+239, |
119 | 4.09M | 1e+240, 1e+241, 1e+242, 1e+243, 1e+244, 1e+245, 1e+246, 1e+247, 1e+248, 1e+249, |
120 | 4.09M | 1e+250, 1e+251, 1e+252, 1e+253, 1e+254, 1e+255, 1e+256, 1e+257, 1e+258, 1e+259, |
121 | 4.09M | 1e+260, 1e+261, 1e+262, 1e+263, 1e+264, 1e+265, 1e+266, 1e+267, 1e+268, 1e+269, |
122 | 4.09M | 1e+270, 1e+271, 1e+272, 1e+273, 1e+274, 1e+275, 1e+276, 1e+277, 1e+278, 1e+279, |
123 | 4.09M | 1e+280, 1e+281, 1e+282, 1e+283, 1e+284, 1e+285, 1e+286, 1e+287, 1e+288, 1e+289, |
124 | 4.09M | 1e+290, 1e+291, 1e+292, 1e+293, 1e+294, 1e+295, 1e+296, 1e+297, 1e+298, 1e+299, |
125 | | |
126 | 4.09M | 1e+300, 1e+301, 1e+302, 1e+303, 1e+304, 1e+305, 1e+306, 1e+307, 1e+308 }; |
127 | | |
128 | 4.09M | if( exp > 308 ) |
129 | 28.6k | { |
130 | 28.6k | return std::numeric_limits<double>::infinity(); |
131 | 28.6k | } |
132 | 4.06M | else if( exp < -308 ) |
133 | 5.01k | { |
134 | | // due to the way pow10 is used by dec_to_float, |
135 | | // we can afford to return 0.0 here |
136 | 5.01k | return 0.0; |
137 | 5.01k | } |
138 | 4.06M | else |
139 | 4.06M | { |
140 | 4.06M | exp += 308; |
141 | 4.06M | BOOST_ASSERT(exp >= 0 && exp < 618); |
142 | 4.06M | return tab[exp]; |
143 | 4.06M | } |
144 | 4.09M | } |
145 | | |
146 | | inline |
147 | | double |
148 | | dec_to_float( |
149 | | std::uint64_t m, |
150 | | std::int32_t e, |
151 | | bool neg) noexcept |
152 | 4.18M | { |
153 | | // convert to double explicitly to silence warnings |
154 | 4.18M | double x = static_cast<double>(m); |
155 | 4.18M | if(neg) |
156 | 45.1k | x = -x; |
157 | | |
158 | 4.18M | if(e < -305) |
159 | 12.9k | { |
160 | 12.9k | x *= 1e-305 ; |
161 | 12.9k | e += 305; |
162 | 12.9k | } |
163 | | |
164 | 4.18M | if(e >= -22 && e < 0) |
165 | 56.0k | return x / pow10(-e); |
166 | | |
167 | 4.12M | return x * pow10(e); |
168 | 4.18M | } |
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 | 3.31M | { |
181 | | // by Peter Dimov |
182 | 3.31M | if( c >= '0' && c <= '9' ) |
183 | 1.82M | return c - '0'; |
184 | 1.49M | c &= ~0x20; |
185 | 1.49M | if( c >= 'A' && c <= 'F' ) |
186 | 1.49M | return 10 + c - 'A'; |
187 | 3.10k | return -1; |
188 | 1.49M | } |
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 | 10.4M | { |
206 | 10.4M | return parser->parse_number( |
207 | 10.4M | p, |
208 | 10.4M | std::integral_constant<bool, StackEmpty_>(), |
209 | 10.4M | std::integral_constant<char, First_>(), |
210 | 10.4M | std::integral_constant< |
211 | 10.4M | number_precision, static_cast<number_precision>(N)>() ); |
212 | 10.4M | } char const* boost::json::basic_parser<boost::json::detail::handler>::parse_number_helper<true, (char)48>::operator()<0ul>(std::__1::integral_constant<unsigned long, 0ul>) const Line | Count | Source | 205 | 189k | { | 206 | 189k | return parser->parse_number( | 207 | 189k | p, | 208 | 189k | std::integral_constant<bool, StackEmpty_>(), | 209 | 189k | std::integral_constant<char, First_>(), | 210 | 189k | std::integral_constant< | 211 | 189k | number_precision, static_cast<number_precision>(N)>() ); | 212 | 189k | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::parse_number_helper<true, (char)48>::operator()<1ul>(std::__1::integral_constant<unsigned long, 1ul>) const Line | Count | Source | 205 | 518k | { | 206 | 518k | return parser->parse_number( | 207 | 518k | p, | 208 | 518k | std::integral_constant<bool, StackEmpty_>(), | 209 | 518k | std::integral_constant<char, First_>(), | 210 | 518k | std::integral_constant< | 211 | 518k | number_precision, static_cast<number_precision>(N)>() ); | 212 | 518k | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::parse_number_helper<true, (char)48>::operator()<2ul>(std::__1::integral_constant<unsigned long, 2ul>) const Line | Count | Source | 205 | 20.0k | { | 206 | 20.0k | return parser->parse_number( | 207 | 20.0k | p, | 208 | 20.0k | std::integral_constant<bool, StackEmpty_>(), | 209 | 20.0k | std::integral_constant<char, First_>(), | 210 | 20.0k | std::integral_constant< | 211 | 20.0k | number_precision, static_cast<number_precision>(N)>() ); | 212 | 20.0k | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::parse_number_helper<true, (char)45>::operator()<0ul>(std::__1::integral_constant<unsigned long, 0ul>) const Line | Count | Source | 205 | 46.7k | { | 206 | 46.7k | return parser->parse_number( | 207 | 46.7k | p, | 208 | 46.7k | std::integral_constant<bool, StackEmpty_>(), | 209 | 46.7k | std::integral_constant<char, First_>(), | 210 | 46.7k | std::integral_constant< | 211 | 46.7k | number_precision, static_cast<number_precision>(N)>() ); | 212 | 46.7k | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::parse_number_helper<true, (char)45>::operator()<1ul>(std::__1::integral_constant<unsigned long, 1ul>) const Line | Count | Source | 205 | 20.2k | { | 206 | 20.2k | return parser->parse_number( | 207 | 20.2k | p, | 208 | 20.2k | std::integral_constant<bool, StackEmpty_>(), | 209 | 20.2k | std::integral_constant<char, First_>(), | 210 | 20.2k | std::integral_constant< | 211 | 20.2k | number_precision, static_cast<number_precision>(N)>() ); | 212 | 20.2k | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::parse_number_helper<true, (char)45>::operator()<2ul>(std::__1::integral_constant<unsigned long, 2ul>) const Line | Count | Source | 205 | 4.28k | { | 206 | 4.28k | return parser->parse_number( | 207 | 4.28k | p, | 208 | 4.28k | std::integral_constant<bool, StackEmpty_>(), | 209 | 4.28k | std::integral_constant<char, First_>(), | 210 | 4.28k | std::integral_constant< | 211 | 4.28k | number_precision, static_cast<number_precision>(N)>() ); | 212 | 4.28k | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::parse_number_helper<true, (char)43>::operator()<0ul>(std::__1::integral_constant<unsigned long, 0ul>) const Line | Count | Source | 205 | 9.02M | { | 206 | 9.02M | return parser->parse_number( | 207 | 9.02M | p, | 208 | 9.02M | std::integral_constant<bool, StackEmpty_>(), | 209 | 9.02M | std::integral_constant<char, First_>(), | 210 | 9.02M | std::integral_constant< | 211 | 9.02M | number_precision, static_cast<number_precision>(N)>() ); | 212 | 9.02M | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::parse_number_helper<true, (char)43>::operator()<1ul>(std::__1::integral_constant<unsigned long, 1ul>) const Line | Count | Source | 205 | 90.9k | { | 206 | 90.9k | return parser->parse_number( | 207 | 90.9k | p, | 208 | 90.9k | std::integral_constant<bool, StackEmpty_>(), | 209 | 90.9k | std::integral_constant<char, First_>(), | 210 | 90.9k | std::integral_constant< | 211 | 90.9k | number_precision, static_cast<number_precision>(N)>() ); | 212 | 90.9k | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::parse_number_helper<true, (char)43>::operator()<2ul>(std::__1::integral_constant<unsigned long, 2ul>) const Line | Count | Source | 205 | 533k | { | 206 | 533k | return parser->parse_number( | 207 | 533k | p, | 208 | 533k | std::integral_constant<bool, StackEmpty_>(), | 209 | 533k | std::integral_constant<char, First_>(), | 210 | 533k | std::integral_constant< | 211 | 533k | number_precision, static_cast<number_precision>(N)>() ); | 212 | 533k | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::parse_number_helper<false, (char)0>::operator()<0ul>(std::__1::integral_constant<unsigned long, 0ul>) const Line | Count | Source | 205 | 2.16k | { | 206 | 2.16k | return parser->parse_number( | 207 | 2.16k | p, | 208 | 2.16k | std::integral_constant<bool, StackEmpty_>(), | 209 | 2.16k | std::integral_constant<char, First_>(), | 210 | 2.16k | std::integral_constant< | 211 | 2.16k | number_precision, static_cast<number_precision>(N)>() ); | 212 | 2.16k | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::parse_number_helper<false, (char)0>::operator()<1ul>(std::__1::integral_constant<unsigned long, 1ul>) const Line | Count | Source | 205 | 4.04k | { | 206 | 4.04k | return parser->parse_number( | 207 | 4.04k | p, | 208 | 4.04k | std::integral_constant<bool, StackEmpty_>(), | 209 | 4.04k | std::integral_constant<char, First_>(), | 210 | 4.04k | std::integral_constant< | 211 | 4.04k | number_precision, static_cast<number_precision>(N)>() ); | 212 | 4.04k | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::parse_number_helper<false, (char)0>::operator()<2ul>(std::__1::integral_constant<unsigned long, 2ul>) const Line | Count | Source | 205 | 361 | { | 206 | 361 | return parser->parse_number( | 207 | 361 | p, | 208 | 361 | std::integral_constant<bool, StackEmpty_>(), | 209 | 361 | std::integral_constant<char, First_>(), | 210 | 361 | std::integral_constant< | 211 | 361 | number_precision, static_cast<number_precision>(N)>() ); | 212 | 361 | } |
|
213 | | }; |
214 | | |
215 | | //---------------------------------------------------------- |
216 | | |
217 | | template<class Handler> |
218 | | void |
219 | | basic_parser<Handler>:: |
220 | | reserve() |
221 | 13.4k | { |
222 | 13.4k | if(BOOST_JSON_LIKELY( |
223 | 13.4k | ! st_.empty())) |
224 | 3.06k | return; |
225 | | // Reserve the largest stack we need, |
226 | | // to avoid reallocation during suspend. |
227 | 10.3k | st_.reserve( |
228 | 10.3k | sizeof(state) + // document parsing state |
229 | 10.3k | (sizeof(state) + |
230 | 10.3k | sizeof(std::size_t)) * depth() + // array and object state + size |
231 | 10.3k | sizeof(state) + // value parsing state |
232 | 10.3k | sizeof(std::size_t) + // string size |
233 | 10.3k | sizeof(state)); // comment state |
234 | 10.3k | } |
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 | 12.6M | { |
248 | | // the "+1" ensures that the returned pointer is unique even if |
249 | | // the given input buffer borders on this object |
250 | 12.6M | return reinterpret_cast< |
251 | 12.6M | const char*>(this) + 1; |
252 | 12.6M | } |
253 | | |
254 | | template<class Handler> |
255 | | bool |
256 | | basic_parser<Handler>:: |
257 | | incomplete( |
258 | | const detail::const_stream_wrapper& cs) |
259 | 12.5M | { |
260 | 12.5M | return cs.begin() == sentinel(); |
261 | 12.5M | } |
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 | 10.3k | { |
292 | 10.3k | if(BOOST_JSON_LIKELY( |
293 | 10.3k | ! ec_ && more_)) |
294 | 3.03k | { |
295 | | // suspend |
296 | 3.03k | reserve(); |
297 | 3.03k | st_.push_unchecked(n); |
298 | 3.03k | st_.push_unchecked(st); |
299 | 3.03k | } |
300 | 10.3k | return sentinel(); |
301 | 10.3k | } |
302 | | |
303 | | |
304 | | template<class Handler> |
305 | | const char* |
306 | | basic_parser<Handler>:: |
307 | | fail(const char* p) noexcept |
308 | 0 | { |
309 | 0 | BOOST_ASSERT( p != sentinel() ); |
310 | 0 | end_ = p; |
311 | 0 | return sentinel(); |
312 | 0 | } |
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 | 5.53k | { |
322 | 5.53k | BOOST_ASSERT( p != sentinel() ); |
323 | 5.53k | end_ = p; |
324 | 5.53k | ec_.assign(ev, loc); |
325 | 5.53k | return sentinel(); |
326 | 5.53k | } |
327 | | |
328 | | template<class Handler> |
329 | | const char* |
330 | | basic_parser<Handler>:: |
331 | | maybe_suspend( |
332 | | const char* p, |
333 | | state st) |
334 | 1.19k | { |
335 | 1.19k | if( p != sentinel() ) |
336 | 1.11k | end_ = p; |
337 | 1.19k | if(BOOST_JSON_LIKELY(more_)) |
338 | 460 | { |
339 | | // suspend |
340 | 460 | reserve(); |
341 | 460 | st_.push_unchecked(st); |
342 | 460 | } |
343 | 1.19k | return sentinel(); |
344 | 1.19k | } |
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 | 5.41k | { |
354 | 5.41k | BOOST_ASSERT( p != sentinel() ); |
355 | 5.41k | end_ = p; |
356 | 5.41k | if(BOOST_JSON_LIKELY(more_)) |
357 | 1.44k | { |
358 | | // suspend |
359 | 1.44k | reserve(); |
360 | 1.44k | st_.push_unchecked(n); |
361 | 1.44k | st_.push_unchecked(st); |
362 | 1.44k | } |
363 | 5.41k | return sentinel(); |
364 | 5.41k | } |
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 | 615 | { |
374 | 615 | BOOST_ASSERT( p != sentinel() ); |
375 | 615 | end_ = p; |
376 | 615 | if(BOOST_JSON_LIKELY(more_)) |
377 | 258 | { |
378 | | // suspend |
379 | 258 | num_ = num; |
380 | 258 | reserve(); |
381 | 258 | st_.push_unchecked(st);; |
382 | 258 | } |
383 | 615 | return sentinel(); |
384 | 615 | } |
385 | | |
386 | | template<class Handler> |
387 | | const char* |
388 | | basic_parser<Handler>:: |
389 | | suspend( |
390 | | const char* p, |
391 | | state st) |
392 | 1.93k | { |
393 | 1.93k | BOOST_ASSERT( p != sentinel() ); |
394 | 1.93k | end_ = p; |
395 | | // suspend |
396 | 1.93k | reserve(); |
397 | 1.93k | st_.push_unchecked(st); |
398 | 1.93k | return sentinel(); |
399 | 1.93k | } |
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 | 6.31k | { |
409 | 6.31k | BOOST_ASSERT( p != sentinel() ); |
410 | 6.31k | end_ = p; |
411 | | // suspend |
412 | 6.31k | num_ = num; |
413 | 6.31k | reserve(); |
414 | 6.31k | st_.push_unchecked(st); |
415 | 6.31k | return sentinel(); |
416 | 6.31k | } |
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 | 5.53k | { |
428 | 5.53k | detail::const_stream_wrapper cs(p, end_); |
429 | 5.53k | const char* start = cs.begin(); |
430 | 5.53k | std::size_t remain; |
431 | 5.53k | if(! stack_empty && ! st_.empty()) |
432 | 104 | { |
433 | 104 | state st; |
434 | 104 | st_.pop(st); |
435 | 104 | switch(st) |
436 | 104 | { |
437 | 0 | default: BOOST_JSON_UNREACHABLE(); |
438 | 72 | case state::com1: goto do_com1; |
439 | 12 | case state::com2: goto do_com2; |
440 | 18 | case state::com3: goto do_com3; |
441 | 2 | case state::com4: goto do_com4; |
442 | 104 | } |
443 | 104 | } |
444 | 5.43k | BOOST_ASSERT(*cs == '/'); |
445 | 5.43k | ++cs; |
446 | 5.50k | do_com1: |
447 | 5.50k | if(BOOST_JSON_UNLIKELY(! cs)) |
448 | 144 | return maybe_suspend(cs.begin(), state::com1); |
449 | 5.36k | switch(*cs) |
450 | 5.36k | { |
451 | 24 | default: |
452 | 24 | { |
453 | 24 | BOOST_STATIC_CONSTEXPR source_location loc |
454 | 24 | = BOOST_CURRENT_LOCATION; |
455 | 24 | return fail(cs.begin(), error::syntax, &loc); |
456 | 0 | } |
457 | 5.12k | case '/': |
458 | 5.12k | ++cs; |
459 | 5.13k | do_com2: |
460 | | // KRYSTIAN TODO: this is a mess, we have to fix this |
461 | 5.13k | remain = cs.remain(); |
462 | 5.13k | cs = remain ? static_cast<const char*>( |
463 | 5.11k | std::memchr(cs.begin(), '\n', remain)) : sentinel(); |
464 | 5.13k | if(! cs.begin()) |
465 | 3 | cs = sentinel(); |
466 | 5.13k | if(BOOST_JSON_UNLIKELY(incomplete(cs))) |
467 | 24 | { |
468 | | // if the doc does not terminate |
469 | | // with a newline, treat it as the |
470 | | // end of the comment |
471 | 24 | if(terminal && ! more_) |
472 | 1 | { |
473 | 1 | if(BOOST_JSON_UNLIKELY(! h_.on_comment( |
474 | 1 | {start, cs.remain(start)}, ec_))) |
475 | 0 | return fail(cs.end()); |
476 | 1 | return cs.end(); |
477 | 1 | } |
478 | 23 | if(BOOST_JSON_UNLIKELY(! h_.on_comment_part( |
479 | 23 | {start, cs.remain(start)}, ec_))) |
480 | 0 | return fail(cs.end()); |
481 | 23 | if(terminal) |
482 | 1 | return suspend(cs.end(), state::com2); |
483 | 22 | return maybe_suspend(cs.end(), state::com2); |
484 | 23 | } |
485 | 5.11k | break; |
486 | 5.11k | case '*': |
487 | 214 | do |
488 | 451 | { |
489 | 451 | ++cs; |
490 | 469 | do_com3: |
491 | | // KRYSTIAN TODO: this is a mess, we have to fix this |
492 | 469 | remain = cs.remain(); |
493 | 469 | cs = remain ? static_cast<const char*>( |
494 | 439 | std::memchr(cs.begin(), '*', remain)) : sentinel(); |
495 | 469 | if(! cs.begin()) |
496 | 6 | cs = sentinel(); |
497 | | // stopped inside a c comment |
498 | 469 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) |
499 | 36 | { |
500 | 36 | if(BOOST_JSON_UNLIKELY(! h_.on_comment_part( |
501 | 36 | {start, cs.remain(start)}, ec_))) |
502 | 0 | return fail(cs.end()); |
503 | 36 | return maybe_suspend(cs.end(), state::com3); |
504 | 36 | } |
505 | | // found a asterisk, check if the next char is a slash |
506 | 433 | ++cs; |
507 | 435 | do_com4: |
508 | 435 | if(BOOST_JSON_UNLIKELY(! cs)) |
509 | 4 | { |
510 | 4 | if(BOOST_JSON_UNLIKELY(! h_.on_comment_part( |
511 | 4 | {start, cs.used(start)}, ec_))) |
512 | 0 | return fail(cs.begin()); |
513 | 4 | return maybe_suspend(cs.begin(), state::com4); |
514 | 4 | } |
515 | 435 | } |
516 | 431 | while(*cs != '/'); |
517 | 5.36k | } |
518 | 5.30k | ++cs; |
519 | 5.30k | if(BOOST_JSON_UNLIKELY(! h_.on_comment( |
520 | 5.30k | {start, cs.used(start)}, ec_))) |
521 | 0 | return fail(cs.begin()); |
522 | 5.30k | return cs.begin(); |
523 | 5.30k | } char const* boost::json::basic_parser<boost::json::detail::handler>::parse_comment<true>(char const*, std::__1::integral_constant<bool, true>, bool) Line | Count | Source | 427 | 5.43k | { | 428 | 5.43k | detail::const_stream_wrapper cs(p, end_); | 429 | 5.43k | const char* start = cs.begin(); | 430 | 5.43k | std::size_t remain; | 431 | 5.43k | 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 | 5.43k | BOOST_ASSERT(*cs == '/'); | 445 | 5.43k | ++cs; | 446 | 5.43k | do_com1: | 447 | 5.43k | if(BOOST_JSON_UNLIKELY(! cs)) | 448 | 72 | return maybe_suspend(cs.begin(), state::com1); | 449 | 5.36k | switch(*cs) | 450 | 5.36k | { | 451 | 24 | default: | 452 | 24 | { | 453 | 24 | BOOST_STATIC_CONSTEXPR source_location loc | 454 | 24 | = BOOST_CURRENT_LOCATION; | 455 | 24 | return fail(cs.begin(), error::syntax, &loc); | 456 | 0 | } | 457 | 5.12k | case '/': | 458 | 5.12k | ++cs; | 459 | 5.12k | do_com2: | 460 | | // KRYSTIAN TODO: this is a mess, we have to fix this | 461 | 5.12k | remain = cs.remain(); | 462 | 5.12k | cs = remain ? static_cast<const char*>( | 463 | 5.11k | std::memchr(cs.begin(), '\n', remain)) : sentinel(); | 464 | 5.12k | if(! cs.begin()) | 465 | 3 | cs = sentinel(); | 466 | 5.12k | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 467 | 12 | { | 468 | | // if the doc does not terminate | 469 | | // with a newline, treat it as the | 470 | | // end of the comment | 471 | 12 | 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 | 12 | if(BOOST_JSON_UNLIKELY(! h_.on_comment_part( | 479 | 12 | {start, cs.remain(start)}, ec_))) | 480 | 0 | return fail(cs.end()); | 481 | 12 | if(terminal) | 482 | 1 | return suspend(cs.end(), state::com2); | 483 | 11 | return maybe_suspend(cs.end(), state::com2); | 484 | 12 | } | 485 | 5.11k | break; | 486 | 5.11k | case '*': | 487 | 214 | do | 488 | 451 | { | 489 | 451 | ++cs; | 490 | 451 | do_com3: | 491 | | // KRYSTIAN TODO: this is a mess, we have to fix this | 492 | 451 | remain = cs.remain(); | 493 | 451 | cs = remain ? static_cast<const char*>( | 494 | 439 | std::memchr(cs.begin(), '*', remain)) : sentinel(); | 495 | 451 | if(! cs.begin()) | 496 | 6 | cs = sentinel(); | 497 | | // stopped inside a c comment | 498 | 451 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 499 | 18 | { | 500 | 18 | if(BOOST_JSON_UNLIKELY(! h_.on_comment_part( | 501 | 18 | {start, cs.remain(start)}, ec_))) | 502 | 0 | return fail(cs.end()); | 503 | 18 | return maybe_suspend(cs.end(), state::com3); | 504 | 18 | } | 505 | | // found a asterisk, check if the next char is a slash | 506 | 433 | ++cs; | 507 | 433 | do_com4: | 508 | 433 | if(BOOST_JSON_UNLIKELY(! cs)) | 509 | 2 | { | 510 | 2 | if(BOOST_JSON_UNLIKELY(! h_.on_comment_part( | 511 | 2 | {start, cs.used(start)}, ec_))) | 512 | 0 | return fail(cs.begin()); | 513 | 2 | return maybe_suspend(cs.begin(), state::com4); | 514 | 2 | } | 515 | 433 | } | 516 | 431 | while(*cs != '/'); | 517 | 5.36k | } | 518 | 5.30k | ++cs; | 519 | 5.30k | if(BOOST_JSON_UNLIKELY(! h_.on_comment( | 520 | 5.30k | {start, cs.used(start)}, ec_))) | 521 | 0 | return fail(cs.begin()); | 522 | 5.30k | return cs.begin(); | 523 | 5.30k | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::parse_comment<false>(char const*, std::__1::integral_constant<bool, false>, bool) Line | Count | Source | 427 | 104 | { | 428 | 104 | detail::const_stream_wrapper cs(p, end_); | 429 | 104 | const char* start = cs.begin(); | 430 | 104 | std::size_t remain; | 431 | 104 | if(! stack_empty && ! st_.empty()) | 432 | 104 | { | 433 | 104 | state st; | 434 | 104 | st_.pop(st); | 435 | 104 | switch(st) | 436 | 104 | { | 437 | 0 | default: BOOST_JSON_UNREACHABLE(); | 438 | 72 | case state::com1: goto do_com1; | 439 | 12 | case state::com2: goto do_com2; | 440 | 18 | case state::com3: goto do_com3; | 441 | 2 | case state::com4: goto do_com4; | 442 | 104 | } | 443 | 104 | } | 444 | 0 | BOOST_ASSERT(*cs == '/'); | 445 | 0 | ++cs; | 446 | 72 | do_com1: | 447 | 72 | if(BOOST_JSON_UNLIKELY(! cs)) | 448 | 72 | 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 | 12 | do_com2: | 460 | | // KRYSTIAN TODO: this is a mess, we have to fix this | 461 | 12 | remain = cs.remain(); | 462 | 12 | cs = remain ? static_cast<const char*>( | 463 | 12 | std::memchr(cs.begin(), '\n', remain)) : sentinel(); | 464 | 12 | if(! cs.begin()) | 465 | 0 | cs = sentinel(); | 466 | 12 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 467 | 12 | { | 468 | | // if the doc does not terminate | 469 | | // with a newline, treat it as the | 470 | | // end of the comment | 471 | 12 | if(terminal && ! more_) | 472 | 1 | { | 473 | 1 | if(BOOST_JSON_UNLIKELY(! h_.on_comment( | 474 | 1 | {start, cs.remain(start)}, ec_))) | 475 | 0 | return fail(cs.end()); | 476 | 1 | return cs.end(); | 477 | 1 | } | 478 | 11 | if(BOOST_JSON_UNLIKELY(! h_.on_comment_part( | 479 | 11 | {start, cs.remain(start)}, ec_))) | 480 | 0 | return fail(cs.end()); | 481 | 11 | if(terminal) | 482 | 0 | return suspend(cs.end(), state::com2); | 483 | 11 | return maybe_suspend(cs.end(), state::com2); | 484 | 11 | } | 485 | 0 | break; | 486 | 0 | case '*': | 487 | 0 | do | 488 | 0 | { | 489 | 0 | ++cs; | 490 | 18 | do_com3: | 491 | | // KRYSTIAN TODO: this is a mess, we have to fix this | 492 | 18 | remain = cs.remain(); | 493 | 18 | cs = remain ? static_cast<const char*>( | 494 | 18 | std::memchr(cs.begin(), '*', remain)) : sentinel(); | 495 | 18 | if(! cs.begin()) | 496 | 0 | cs = sentinel(); | 497 | | // stopped inside a c comment | 498 | 18 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 499 | 18 | { | 500 | 18 | if(BOOST_JSON_UNLIKELY(! h_.on_comment_part( | 501 | 18 | {start, cs.remain(start)}, ec_))) | 502 | 0 | return fail(cs.end()); | 503 | 18 | return maybe_suspend(cs.end(), state::com3); | 504 | 18 | } | 505 | | // found a asterisk, check if the next char is a slash | 506 | 0 | ++cs; | 507 | 2 | do_com4: | 508 | 2 | if(BOOST_JSON_UNLIKELY(! cs)) | 509 | 2 | { | 510 | 2 | if(BOOST_JSON_UNLIKELY(! h_.on_comment_part( | 511 | 2 | {start, cs.used(start)}, ec_))) | 512 | 0 | return fail(cs.begin()); | 513 | 2 | return maybe_suspend(cs.begin(), state::com4); | 514 | 2 | } | 515 | 2 | } | 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 | } |
|
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 | 32.4k | { |
532 | 32.4k | detail::const_stream_wrapper cs(p, end_); |
533 | 32.4k | if(! stack_empty && ! st_.empty()) |
534 | 10.3k | { |
535 | 10.3k | state st; |
536 | 10.3k | st_.peek(st); |
537 | 10.3k | switch(st) |
538 | 10.3k | { |
539 | 8.36k | default: goto do_doc2; |
540 | 8.36k | case state::doc1: |
541 | 46 | st_.pop(st); |
542 | 46 | goto do_doc1; |
543 | 1.93k | case state::doc3: |
544 | 1.93k | st_.pop(st); |
545 | 1.93k | goto do_doc3; |
546 | 20 | case state::com1: case state::com2: |
547 | 22 | case state::com3: case state::com4: |
548 | 22 | goto do_doc4; |
549 | 10.3k | } |
550 | 10.3k | } |
551 | 22.1k | do_doc1: |
552 | 22.1k | cs = detail::count_whitespace(cs.begin(), cs.end()); |
553 | 22.1k | if(BOOST_JSON_UNLIKELY(! cs)) |
554 | 117 | return maybe_suspend(cs.begin(), state::doc1); |
555 | 30.4k | do_doc2: |
556 | 30.4k | switch(+opt_.allow_comments | |
557 | 30.4k | (opt_.allow_trailing_commas << 1) | |
558 | 30.4k | (opt_.allow_invalid_utf8 << 2)) |
559 | 30.4k | { |
560 | | // no extensions |
561 | 9.45k | default: |
562 | 9.45k | cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::false_type(), std::false_type(), opt_.allow_invalid_utf16); |
563 | 9.45k | break; |
564 | | // comments |
565 | 2.41k | case 1: |
566 | 2.41k | cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::false_type(), std::false_type(), opt_.allow_invalid_utf16); |
567 | 2.41k | break; |
568 | | // trailing |
569 | 2.17k | case 2: |
570 | 2.17k | cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::true_type(), std::false_type(), opt_.allow_invalid_utf16); |
571 | 2.17k | break; |
572 | | // comments & trailing |
573 | 3.06k | case 3: |
574 | 3.06k | cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::true_type(), std::false_type(), opt_.allow_invalid_utf16); |
575 | 3.06k | break; |
576 | | // skip validation |
577 | 1.84k | case 4: |
578 | 1.84k | cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::false_type(), std::true_type(), opt_.allow_invalid_utf16); |
579 | 1.84k | break; |
580 | | // comments & skip validation |
581 | 2.86k | case 5: |
582 | 2.86k | cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::false_type(), std::true_type(), opt_.allow_invalid_utf16); |
583 | 2.86k | break; |
584 | | // trailing & skip validation |
585 | 4.54k | case 6: |
586 | 4.54k | cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::true_type(), std::true_type(), opt_.allow_invalid_utf16); |
587 | 4.54k | break; |
588 | | // comments & trailing & skip validation |
589 | 4.05k | case 7: |
590 | 4.05k | cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::true_type(), std::true_type(), opt_.allow_invalid_utf16); |
591 | 4.05k | break; |
592 | 30.4k | } |
593 | 30.2k | if(BOOST_JSON_UNLIKELY(incomplete(cs))) |
594 | | // the appropriate state has already been pushed into stack |
595 | 18.8k | return sentinel(); |
596 | 13.8k | do_doc3: |
597 | 13.8k | cs = detail::count_whitespace(cs.begin(), cs.end()); |
598 | 13.8k | if(BOOST_JSON_UNLIKELY(! cs)) |
599 | 10.9k | { |
600 | 10.9k | if(more_) |
601 | 1.93k | return suspend(cs.begin(), state::doc3); |
602 | 10.9k | } |
603 | 2.88k | else if(opt_.allow_comments && *cs == '/') |
604 | 560 | { |
605 | 582 | do_doc4: |
606 | 582 | cs = parse_comment(cs.begin(), stack_empty, std::true_type()); |
607 | 582 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) |
608 | 49 | return sentinel(); |
609 | 533 | goto do_doc3; |
610 | 582 | } |
611 | 11.3k | return cs.begin(); |
612 | 13.8k | } char const* boost::json::basic_parser<boost::json::detail::handler>::parse_document<true>(char const*, std::__1::integral_constant<bool, true>) Line | Count | Source | 531 | 22.1k | { | 532 | 22.1k | detail::const_stream_wrapper cs(p, end_); | 533 | 22.1k | 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 | 22.1k | do_doc1: | 552 | 22.1k | cs = detail::count_whitespace(cs.begin(), cs.end()); | 553 | 22.1k | if(BOOST_JSON_UNLIKELY(! cs)) | 554 | 71 | return maybe_suspend(cs.begin(), state::doc1); | 555 | 22.0k | do_doc2: | 556 | 22.0k | switch(+opt_.allow_comments | | 557 | 22.0k | (opt_.allow_trailing_commas << 1) | | 558 | 22.0k | (opt_.allow_invalid_utf8 << 2)) | 559 | 22.0k | { | 560 | | // no extensions | 561 | 8.35k | default: | 562 | 8.35k | cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::false_type(), std::false_type(), opt_.allow_invalid_utf16); | 563 | 8.35k | break; | 564 | | // comments | 565 | 1.49k | case 1: | 566 | 1.49k | cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::false_type(), std::false_type(), opt_.allow_invalid_utf16); | 567 | 1.49k | break; | 568 | | // trailing | 569 | 1.38k | case 2: | 570 | 1.38k | cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::true_type(), std::false_type(), opt_.allow_invalid_utf16); | 571 | 1.38k | break; | 572 | | // comments & trailing | 573 | 1.96k | case 3: | 574 | 1.96k | cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::true_type(), std::false_type(), opt_.allow_invalid_utf16); | 575 | 1.96k | break; | 576 | | // skip validation | 577 | 1.18k | case 4: | 578 | 1.18k | cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::false_type(), std::true_type(), opt_.allow_invalid_utf16); | 579 | 1.18k | break; | 580 | | // comments & skip validation | 581 | 1.93k | case 5: | 582 | 1.93k | cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::false_type(), std::true_type(), opt_.allow_invalid_utf16); | 583 | 1.93k | break; | 584 | | // trailing & skip validation | 585 | 3.04k | case 6: | 586 | 3.04k | cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::true_type(), std::true_type(), opt_.allow_invalid_utf16); | 587 | 3.04k | break; | 588 | | // comments & trailing & skip validation | 589 | 2.69k | case 7: | 590 | 2.69k | cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::true_type(), std::true_type(), opt_.allow_invalid_utf16); | 591 | 2.69k | break; | 592 | 22.0k | } | 593 | 21.9k | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 594 | | // the appropriate state has already been pushed into stack | 595 | 15.5k | return sentinel(); | 596 | 6.91k | do_doc3: | 597 | 6.91k | cs = detail::count_whitespace(cs.begin(), cs.end()); | 598 | 6.91k | if(BOOST_JSON_UNLIKELY(! cs)) | 599 | 4.03k | { | 600 | 4.03k | if(more_) | 601 | 1.93k | return suspend(cs.begin(), state::doc3); | 602 | 4.03k | } | 603 | 2.88k | else if(opt_.allow_comments && *cs == '/') | 604 | 560 | { | 605 | 560 | do_doc4: | 606 | 560 | cs = parse_comment(cs.begin(), stack_empty, std::true_type()); | 607 | 560 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 608 | 28 | return sentinel(); | 609 | 532 | goto do_doc3; | 610 | 560 | } | 611 | 4.42k | return cs.begin(); | 612 | 6.91k | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::parse_document<false>(char const*, std::__1::integral_constant<bool, false>) Line | Count | Source | 531 | 10.3k | { | 532 | 10.3k | detail::const_stream_wrapper cs(p, end_); | 533 | 10.3k | if(! stack_empty && ! st_.empty()) | 534 | 10.3k | { | 535 | 10.3k | state st; | 536 | 10.3k | st_.peek(st); | 537 | 10.3k | switch(st) | 538 | 10.3k | { | 539 | 8.36k | default: goto do_doc2; | 540 | 8.36k | case state::doc1: | 541 | 46 | st_.pop(st); | 542 | 46 | goto do_doc1; | 543 | 1.93k | case state::doc3: | 544 | 1.93k | st_.pop(st); | 545 | 1.93k | goto do_doc3; | 546 | 20 | case state::com1: case state::com2: | 547 | 22 | case state::com3: case state::com4: | 548 | 22 | goto do_doc4; | 549 | 10.3k | } | 550 | 10.3k | } | 551 | 46 | do_doc1: | 552 | 46 | cs = detail::count_whitespace(cs.begin(), cs.end()); | 553 | 46 | if(BOOST_JSON_UNLIKELY(! cs)) | 554 | 46 | return maybe_suspend(cs.begin(), state::doc1); | 555 | 8.36k | do_doc2: | 556 | 8.36k | switch(+opt_.allow_comments | | 557 | 8.36k | (opt_.allow_trailing_commas << 1) | | 558 | 8.36k | (opt_.allow_invalid_utf8 << 2)) | 559 | 8.36k | { | 560 | | // no extensions | 561 | 1.10k | default: | 562 | 1.10k | cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::false_type(), std::false_type(), opt_.allow_invalid_utf16); | 563 | 1.10k | break; | 564 | | // comments | 565 | 926 | case 1: | 566 | 926 | cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::false_type(), std::false_type(), opt_.allow_invalid_utf16); | 567 | 926 | break; | 568 | | // trailing | 569 | 797 | case 2: | 570 | 797 | cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::true_type(), std::false_type(), opt_.allow_invalid_utf16); | 571 | 797 | break; | 572 | | // comments & trailing | 573 | 1.09k | case 3: | 574 | 1.09k | cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::true_type(), std::false_type(), opt_.allow_invalid_utf16); | 575 | 1.09k | break; | 576 | | // skip validation | 577 | 661 | case 4: | 578 | 661 | cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::false_type(), std::true_type(), opt_.allow_invalid_utf16); | 579 | 661 | break; | 580 | | // comments & skip validation | 581 | 929 | case 5: | 582 | 929 | cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::false_type(), std::true_type(), opt_.allow_invalid_utf16); | 583 | 929 | break; | 584 | | // trailing & skip validation | 585 | 1.50k | case 6: | 586 | 1.50k | cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::true_type(), std::true_type(), opt_.allow_invalid_utf16); | 587 | 1.50k | break; | 588 | | // comments & trailing & skip validation | 589 | 1.35k | case 7: | 590 | 1.35k | cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::true_type(), std::true_type(), opt_.allow_invalid_utf16); | 591 | 1.35k | break; | 592 | 8.36k | } | 593 | 8.28k | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 594 | | // the appropriate state has already been pushed into stack | 595 | 3.26k | return sentinel(); | 596 | 6.96k | do_doc3: | 597 | 6.96k | cs = detail::count_whitespace(cs.begin(), cs.end()); | 598 | 6.96k | if(BOOST_JSON_UNLIKELY(! cs)) | 599 | 6.96k | { | 600 | 6.96k | if(more_) | 601 | 0 | return suspend(cs.begin(), state::doc3); | 602 | 6.96k | } | 603 | 0 | else if(opt_.allow_comments && *cs == '/') | 604 | 0 | { | 605 | 22 | do_doc4: | 606 | 22 | cs = parse_comment(cs.begin(), stack_empty, std::true_type()); | 607 | 22 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 608 | 21 | return sentinel(); | 609 | 1 | goto do_doc3; | 610 | 22 | } | 611 | 6.96k | return cs.begin(); | 612 | 6.96k | } |
|
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 | 10.6M | { |
629 | 10.6M | if(stack_empty || st_.empty()) |
630 | 10.6M | { |
631 | 10.6M | loop: |
632 | 10.6M | switch(*p) |
633 | 10.6M | { |
634 | 728k | case '0': |
635 | 728k | return mp11::mp_with_index<3>( |
636 | 728k | static_cast<unsigned char>(opt_.numbers), |
637 | 728k | parse_number_helper<true, '0'>{ this, p }); |
638 | 71.3k | case '-': |
639 | 71.3k | return mp11::mp_with_index<3>( |
640 | 71.3k | static_cast<unsigned char>(opt_.numbers), |
641 | 71.3k | parse_number_helper<true, '-'>{ this, p }); |
642 | 4.99M | case '1': case '2': case '3': |
643 | 5.37M | case '4': case '5': case '6': |
644 | 9.64M | case '7': case '8': case '9': |
645 | 9.64M | return mp11::mp_with_index<3>( |
646 | 9.64M | static_cast<unsigned char>(opt_.numbers), |
647 | 9.64M | parse_number_helper<true, '+'>{ this, p }); |
648 | 14.3k | case 'n': |
649 | 14.3k | return parse_literal( p, detail::literals_c<detail::literals::null>() ); |
650 | 46.4k | case 't': |
651 | 46.4k | return parse_literal( p, detail::literals_c<detail::literals::true_>() ); |
652 | 10.3k | case 'f': |
653 | 10.3k | return parse_literal( p, detail::literals_c<detail::literals::false_>() ); |
654 | 6 | case 'I': |
655 | 6 | if( !opt_.allow_infinity_and_nan ) |
656 | 6 | { |
657 | 6 | BOOST_STATIC_CONSTEXPR source_location loc |
658 | 6 | = BOOST_CURRENT_LOCATION; |
659 | 6 | return fail(p, error::syntax, &loc); |
660 | 6 | } |
661 | 0 | return parse_literal( p, detail::literals_c<detail::literals::infinity>() ); |
662 | 6 | case 'N': |
663 | 6 | if( !opt_.allow_infinity_and_nan ) |
664 | 6 | { |
665 | 6 | BOOST_STATIC_CONSTEXPR source_location loc |
666 | 6 | = BOOST_CURRENT_LOCATION; |
667 | 6 | return fail(p, error::syntax, &loc); |
668 | 6 | } |
669 | 0 | return parse_literal(p, detail::literals_c<detail::literals::nan>() ); |
670 | 54.3k | case '"': |
671 | 54.3k | return parse_string(p, std::true_type(), std::false_type(), allow_bad_utf8, allow_bad_utf16); |
672 | 31.1k | case '[': |
673 | 31.1k | return parse_array(p, std::true_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); |
674 | 30.9k | case '{': |
675 | 30.9k | return parse_object(p, std::true_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); |
676 | 2.08k | case '/': |
677 | 2.08k | if(! allow_comments) |
678 | 7 | { |
679 | 7 | BOOST_STATIC_CONSTEXPR source_location loc |
680 | 7 | = BOOST_CURRENT_LOCATION; |
681 | 7 | return fail(p, error::syntax, &loc); |
682 | 7 | } |
683 | 2.08k | 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 | 2.08k | if(BOOST_JSON_UNLIKELY(p == sentinel())) |
688 | 40 | return maybe_suspend(p, state::val2); |
689 | 2.04k | BOOST_FALLTHROUGH; |
690 | 2.04k | case ' ': |
691 | 2.04k | case '\t': |
692 | 2.04k | case '\n': |
693 | 2.04k | case '\r': |
694 | 2.04k | p = detail::count_whitespace(p, end_); |
695 | 2.04k | if(BOOST_JSON_UNLIKELY(p == end_)) |
696 | 37 | return maybe_suspend(p, state::val1); |
697 | 2.00k | goto loop; |
698 | 2.00k | default: |
699 | 673 | { |
700 | 673 | BOOST_STATIC_CONSTEXPR source_location loc |
701 | 673 | = BOOST_CURRENT_LOCATION; |
702 | 673 | return fail(p, error::syntax, &loc); |
703 | 2.04k | } |
704 | 10.6M | } |
705 | 10.6M | } |
706 | 10.9k | return resume_value(p, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); |
707 | 10.6M | } char const* boost::json::basic_parser<boost::json::detail::handler>::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 | 6.09M | { | 629 | 6.09M | if(stack_empty || st_.empty()) | 630 | 6.09M | { | 631 | 6.09M | loop: | 632 | 6.09M | switch(*p) | 633 | 6.09M | { | 634 | 694k | case '0': | 635 | 694k | return mp11::mp_with_index<3>( | 636 | 694k | static_cast<unsigned char>(opt_.numbers), | 637 | 694k | parse_number_helper<true, '0'>{ this, p }); | 638 | 52.0k | case '-': | 639 | 52.0k | return mp11::mp_with_index<3>( | 640 | 52.0k | static_cast<unsigned char>(opt_.numbers), | 641 | 52.0k | parse_number_helper<true, '-'>{ this, p }); | 642 | 1.33M | case '1': case '2': case '3': | 643 | 1.65M | case '4': case '5': case '6': | 644 | 5.20M | case '7': case '8': case '9': | 645 | 5.20M | return mp11::mp_with_index<3>( | 646 | 5.20M | static_cast<unsigned char>(opt_.numbers), | 647 | 5.20M | parse_number_helper<true, '+'>{ this, p }); | 648 | 8.19k | case 'n': | 649 | 8.19k | return parse_literal( p, detail::literals_c<detail::literals::null>() ); | 650 | 38.3k | case 't': | 651 | 38.3k | return parse_literal( p, detail::literals_c<detail::literals::true_>() ); | 652 | 5.85k | case 'f': | 653 | 5.85k | return parse_literal( p, detail::literals_c<detail::literals::false_>() ); | 654 | 3 | case 'I': | 655 | 3 | if( !opt_.allow_infinity_and_nan ) | 656 | 3 | { | 657 | 3 | BOOST_STATIC_CONSTEXPR source_location loc | 658 | 3 | = BOOST_CURRENT_LOCATION; | 659 | 3 | return fail(p, error::syntax, &loc); | 660 | 3 | } | 661 | 0 | return parse_literal( p, detail::literals_c<detail::literals::infinity>() ); | 662 | 4 | case 'N': | 663 | 4 | if( !opt_.allow_infinity_and_nan ) | 664 | 4 | { | 665 | 4 | BOOST_STATIC_CONSTEXPR source_location loc | 666 | 4 | = BOOST_CURRENT_LOCATION; | 667 | 4 | return fail(p, error::syntax, &loc); | 668 | 4 | } | 669 | 0 | return parse_literal(p, detail::literals_c<detail::literals::nan>() ); | 670 | 45.9k | case '"': | 671 | 45.9k | return parse_string(p, std::true_type(), std::false_type(), allow_bad_utf8, allow_bad_utf16); | 672 | 19.6k | case '[': | 673 | 19.6k | return parse_array(p, std::true_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | 674 | 26.6k | case '{': | 675 | 26.6k | return parse_object(p, std::true_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | 676 | 7 | case '/': | 677 | 7 | if(! allow_comments) | 678 | 7 | { | 679 | 7 | BOOST_STATIC_CONSTEXPR source_location loc | 680 | 7 | = BOOST_CURRENT_LOCATION; | 681 | 7 | return fail(p, error::syntax, &loc); | 682 | 7 | } | 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 | 456 | default: | 699 | 456 | { | 700 | 456 | BOOST_STATIC_CONSTEXPR source_location loc | 701 | 456 | = BOOST_CURRENT_LOCATION; | 702 | 456 | return fail(p, error::syntax, &loc); | 703 | 0 | } | 704 | 6.09M | } | 705 | 6.09M | } | 706 | 0 | return resume_value(p, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | 707 | 6.09M | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::parse_value<true, true>(char const*, std::__1::integral_constant<bool, true>, std::__1::integral_constant<bool, true>, bool, bool, bool) Line | Count | Source | 628 | 4.53M | { | 629 | 4.53M | if(stack_empty || st_.empty()) | 630 | 4.53M | { | 631 | 4.53M | loop: | 632 | 4.53M | switch(*p) | 633 | 4.53M | { | 634 | 33.6k | case '0': | 635 | 33.6k | return mp11::mp_with_index<3>( | 636 | 33.6k | static_cast<unsigned char>(opt_.numbers), | 637 | 33.6k | parse_number_helper<true, '0'>{ this, p }); | 638 | 19.2k | case '-': | 639 | 19.2k | return mp11::mp_with_index<3>( | 640 | 19.2k | static_cast<unsigned char>(opt_.numbers), | 641 | 19.2k | parse_number_helper<true, '-'>{ this, p }); | 642 | 3.66M | case '1': case '2': case '3': | 643 | 3.72M | case '4': case '5': case '6': | 644 | 4.43M | case '7': case '8': case '9': | 645 | 4.43M | return mp11::mp_with_index<3>( | 646 | 4.43M | static_cast<unsigned char>(opt_.numbers), | 647 | 4.43M | parse_number_helper<true, '+'>{ this, p }); | 648 | 6.12k | case 'n': | 649 | 6.12k | return parse_literal( p, detail::literals_c<detail::literals::null>() ); | 650 | 8.03k | case 't': | 651 | 8.03k | return parse_literal( p, detail::literals_c<detail::literals::true_>() ); | 652 | 4.50k | case 'f': | 653 | 4.50k | return parse_literal( p, detail::literals_c<detail::literals::false_>() ); | 654 | 3 | case 'I': | 655 | 3 | if( !opt_.allow_infinity_and_nan ) | 656 | 3 | { | 657 | 3 | BOOST_STATIC_CONSTEXPR source_location loc | 658 | 3 | = BOOST_CURRENT_LOCATION; | 659 | 3 | return fail(p, error::syntax, &loc); | 660 | 3 | } | 661 | 0 | return parse_literal( p, detail::literals_c<detail::literals::infinity>() ); | 662 | 2 | case 'N': | 663 | 2 | if( !opt_.allow_infinity_and_nan ) | 664 | 2 | { | 665 | 2 | BOOST_STATIC_CONSTEXPR source_location loc | 666 | 2 | = BOOST_CURRENT_LOCATION; | 667 | 2 | return fail(p, error::syntax, &loc); | 668 | 2 | } | 669 | 0 | return parse_literal(p, detail::literals_c<detail::literals::nan>() ); | 670 | 8.40k | case '"': | 671 | 8.40k | return parse_string(p, std::true_type(), std::false_type(), allow_bad_utf8, allow_bad_utf16); | 672 | 11.5k | case '[': | 673 | 11.5k | return parse_array(p, std::true_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | 674 | 4.37k | case '{': | 675 | 4.37k | return parse_object(p, std::true_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | 676 | 2.08k | case '/': | 677 | 2.08k | if(! allow_comments) | 678 | 0 | { | 679 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 680 | 0 | = BOOST_CURRENT_LOCATION; | 681 | 0 | return fail(p, error::syntax, &loc); | 682 | 0 | } | 683 | 2.08k | 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 | 2.08k | if(BOOST_JSON_UNLIKELY(p == sentinel())) | 688 | 40 | return maybe_suspend(p, state::val2); | 689 | 2.04k | BOOST_FALLTHROUGH; | 690 | 2.04k | case ' ': | 691 | 2.04k | case '\t': | 692 | 2.04k | case '\n': | 693 | 2.04k | case '\r': | 694 | 2.04k | p = detail::count_whitespace(p, end_); | 695 | 2.04k | if(BOOST_JSON_UNLIKELY(p == end_)) | 696 | 37 | return maybe_suspend(p, state::val1); | 697 | 2.00k | goto loop; | 698 | 2.00k | default: | 699 | 217 | { | 700 | 217 | BOOST_STATIC_CONSTEXPR source_location loc | 701 | 217 | = BOOST_CURRENT_LOCATION; | 702 | 217 | return fail(p, error::syntax, &loc); | 703 | 2.04k | } | 704 | 4.53M | } | 705 | 4.53M | } | 706 | 0 | return resume_value(p, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | 707 | 4.53M | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::parse_value<false, false>(char const*, std::__1::integral_constant<bool, false>, std::__1::integral_constant<bool, false>, bool, bool, bool) Line | Count | Source | 628 | 5.10k | { | 629 | 5.10k | if(stack_empty || st_.empty()) | 630 | 0 | { | 631 | 0 | loop: | 632 | 0 | switch(*p) | 633 | 0 | { | 634 | 0 | case '0': | 635 | 0 | return mp11::mp_with_index<3>( | 636 | 0 | static_cast<unsigned char>(opt_.numbers), | 637 | 0 | parse_number_helper<true, '0'>{ this, p }); | 638 | 0 | case '-': | 639 | 0 | return mp11::mp_with_index<3>( | 640 | 0 | static_cast<unsigned char>(opt_.numbers), | 641 | 0 | parse_number_helper<true, '-'>{ this, p }); | 642 | 0 | case '1': case '2': case '3': | 643 | 0 | case '4': case '5': case '6': | 644 | 0 | case '7': case '8': case '9': | 645 | 0 | return mp11::mp_with_index<3>( | 646 | 0 | static_cast<unsigned char>(opt_.numbers), | 647 | 0 | parse_number_helper<true, '+'>{ this, p }); | 648 | 0 | case 'n': | 649 | 0 | return parse_literal( p, detail::literals_c<detail::literals::null>() ); | 650 | 0 | case 't': | 651 | 0 | return parse_literal( p, detail::literals_c<detail::literals::true_>() ); | 652 | 0 | case 'f': | 653 | 0 | return parse_literal( p, detail::literals_c<detail::literals::false_>() ); | 654 | 0 | case 'I': | 655 | 0 | if( !opt_.allow_infinity_and_nan ) | 656 | 0 | { | 657 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 658 | 0 | = BOOST_CURRENT_LOCATION; | 659 | 0 | return fail(p, error::syntax, &loc); | 660 | 0 | } | 661 | 0 | return parse_literal( p, detail::literals_c<detail::literals::infinity>() ); | 662 | 0 | case 'N': | 663 | 0 | if( !opt_.allow_infinity_and_nan ) | 664 | 0 | { | 665 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 666 | 0 | = BOOST_CURRENT_LOCATION; | 667 | 0 | return fail(p, error::syntax, &loc); | 668 | 0 | } | 669 | 0 | return parse_literal(p, detail::literals_c<detail::literals::nan>() ); | 670 | 0 | case '"': | 671 | 0 | return parse_string(p, std::true_type(), std::false_type(), allow_bad_utf8, allow_bad_utf16); | 672 | 0 | case '[': | 673 | 0 | return parse_array(p, std::true_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | 674 | 0 | case '{': | 675 | 0 | return parse_object(p, std::true_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | 676 | 0 | case '/': | 677 | 0 | if(! allow_comments) | 678 | 0 | { | 679 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 680 | 0 | = BOOST_CURRENT_LOCATION; | 681 | 0 | return fail(p, error::syntax, &loc); | 682 | 0 | } | 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 | 0 | default: | 699 | 0 | { | 700 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 701 | 0 | = BOOST_CURRENT_LOCATION; | 702 | 0 | return fail(p, error::syntax, &loc); | 703 | 0 | } | 704 | 0 | } | 705 | 0 | } | 706 | 5.10k | return resume_value(p, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | 707 | 5.10k | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::parse_value<false, true>(char const*, std::__1::integral_constant<bool, false>, std::__1::integral_constant<bool, true>, bool, bool, bool) Line | Count | Source | 628 | 5.88k | { | 629 | 5.88k | if(stack_empty || st_.empty()) | 630 | 0 | { | 631 | 0 | loop: | 632 | 0 | switch(*p) | 633 | 0 | { | 634 | 0 | case '0': | 635 | 0 | return mp11::mp_with_index<3>( | 636 | 0 | static_cast<unsigned char>(opt_.numbers), | 637 | 0 | parse_number_helper<true, '0'>{ this, p }); | 638 | 0 | case '-': | 639 | 0 | return mp11::mp_with_index<3>( | 640 | 0 | static_cast<unsigned char>(opt_.numbers), | 641 | 0 | parse_number_helper<true, '-'>{ this, p }); | 642 | 0 | case '1': case '2': case '3': | 643 | 0 | case '4': case '5': case '6': | 644 | 0 | case '7': case '8': case '9': | 645 | 0 | return mp11::mp_with_index<3>( | 646 | 0 | static_cast<unsigned char>(opt_.numbers), | 647 | 0 | parse_number_helper<true, '+'>{ this, p }); | 648 | 0 | case 'n': | 649 | 0 | return parse_literal( p, detail::literals_c<detail::literals::null>() ); | 650 | 0 | case 't': | 651 | 0 | return parse_literal( p, detail::literals_c<detail::literals::true_>() ); | 652 | 0 | case 'f': | 653 | 0 | return parse_literal( p, detail::literals_c<detail::literals::false_>() ); | 654 | 0 | case 'I': | 655 | 0 | if( !opt_.allow_infinity_and_nan ) | 656 | 0 | { | 657 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 658 | 0 | = BOOST_CURRENT_LOCATION; | 659 | 0 | return fail(p, error::syntax, &loc); | 660 | 0 | } | 661 | 0 | return parse_literal( p, detail::literals_c<detail::literals::infinity>() ); | 662 | 0 | case 'N': | 663 | 0 | if( !opt_.allow_infinity_and_nan ) | 664 | 0 | { | 665 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 666 | 0 | = BOOST_CURRENT_LOCATION; | 667 | 0 | return fail(p, error::syntax, &loc); | 668 | 0 | } | 669 | 0 | return parse_literal(p, detail::literals_c<detail::literals::nan>() ); | 670 | 0 | case '"': | 671 | 0 | return parse_string(p, std::true_type(), std::false_type(), allow_bad_utf8, allow_bad_utf16); | 672 | 0 | case '[': | 673 | 0 | return parse_array(p, std::true_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | 674 | 0 | case '{': | 675 | 0 | return parse_object(p, std::true_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | 676 | 0 | case '/': | 677 | 0 | if(! allow_comments) | 678 | 0 | { | 679 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 680 | 0 | = BOOST_CURRENT_LOCATION; | 681 | 0 | return fail(p, error::syntax, &loc); | 682 | 0 | } | 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 | 0 | default: | 699 | 0 | { | 700 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 701 | 0 | = BOOST_CURRENT_LOCATION; | 702 | 0 | return fail(p, error::syntax, &loc); | 703 | 0 | } | 704 | 0 | } | 705 | 0 | } | 706 | 5.88k | return resume_value(p, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | 707 | 5.88k | } |
|
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 | 10.9k | { |
722 | 10.9k | state st; |
723 | 10.9k | st_.peek(st); |
724 | 10.9k | switch(st) |
725 | 10.9k | { |
726 | 0 | default: BOOST_JSON_UNREACHABLE(); |
727 | 59 | case state::lit1: |
728 | 59 | return parse_literal(p, detail::literals_c<detail::literals::resume>() ); |
729 | | |
730 | 475 | case state::str1: case state::str2: |
731 | 486 | case state::str8: |
732 | 486 | return parse_string(p, std::false_type(), std::false_type(), allow_bad_utf8, allow_bad_utf16); |
733 | | |
734 | 109 | case state::arr1: case state::arr2: |
735 | 2.58k | case state::arr3: case state::arr4: |
736 | 2.85k | case state::arr5: case state::arr6: |
737 | 2.85k | return parse_array(p, std::false_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); |
738 | | |
739 | 83 | case state::obj1: case state::obj2: |
740 | 364 | case state::obj3: case state::obj4: |
741 | 435 | case state::obj5: case state::obj6: |
742 | 885 | case state::obj7: case state::obj8: |
743 | 957 | case state::obj9: case state::obj10: |
744 | 960 | case state::obj11: |
745 | 960 | return parse_object(p, std::false_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); |
746 | | |
747 | 1.14k | case state::num1: case state::num2: |
748 | 1.69k | case state::num3: case state::num4: |
749 | 2.81k | case state::num5: case state::num6: |
750 | 4.15k | case state::num7: case state::num8: |
751 | 4.44k | case state::exp1: case state::exp2: |
752 | 6.56k | case state::exp3: |
753 | 6.56k | return mp11::mp_with_index<3>( |
754 | 6.56k | static_cast<unsigned char>(opt_.numbers), |
755 | 6.56k | parse_number_helper<false, 0>{ this, p }); |
756 | | |
757 | | // KRYSTIAN NOTE: these are special cases |
758 | 37 | case state::val1: |
759 | 37 | { |
760 | 37 | st_.pop(st); |
761 | 37 | BOOST_ASSERT(st_.empty()); |
762 | 37 | p = detail::count_whitespace(p, end_); |
763 | 37 | if(BOOST_JSON_UNLIKELY(p == end_)) |
764 | 37 | 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 | 37 | } |
767 | | |
768 | 35 | case state::val2: |
769 | 35 | { |
770 | 35 | st_.pop(st); |
771 | 35 | p = parse_comment(p, std::false_type(), std::false_type()); |
772 | 35 | if(BOOST_JSON_UNLIKELY(p == sentinel())) |
773 | 35 | 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 | 10.9k | } |
786 | 10.9k | } char const* boost::json::basic_parser<boost::json::detail::handler>::resume_value<false>(char const*, std::__1::integral_constant<bool, false>, bool, bool, bool) Line | Count | Source | 721 | 5.10k | { | 722 | 5.10k | state st; | 723 | 5.10k | st_.peek(st); | 724 | 5.10k | switch(st) | 725 | 5.10k | { | 726 | 0 | default: BOOST_JSON_UNREACHABLE(); | 727 | 28 | case state::lit1: | 728 | 28 | return parse_literal(p, detail::literals_c<detail::literals::resume>() ); | 729 | | | 730 | 189 | case state::str1: case state::str2: | 731 | 195 | case state::str8: | 732 | 195 | return parse_string(p, std::false_type(), std::false_type(), allow_bad_utf8, allow_bad_utf16); | 733 | | | 734 | 40 | case state::arr1: case state::arr2: | 735 | 1.08k | case state::arr3: case state::arr4: | 736 | 1.19k | case state::arr5: case state::arr6: | 737 | 1.19k | return parse_array(p, std::false_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | 738 | | | 739 | 33 | case state::obj1: case state::obj2: | 740 | 173 | case state::obj3: case state::obj4: | 741 | 205 | case state::obj5: case state::obj6: | 742 | 342 | case state::obj7: case state::obj8: | 743 | 368 | case state::obj9: case state::obj10: | 744 | 368 | case state::obj11: | 745 | 368 | return parse_object(p, std::false_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | 746 | | | 747 | 574 | case state::num1: case state::num2: | 748 | 877 | case state::num3: case state::num4: | 749 | 1.45k | case state::num5: case state::num6: | 750 | 2.13k | case state::num7: case state::num8: | 751 | 2.26k | case state::exp1: case state::exp2: | 752 | 3.31k | case state::exp3: | 753 | 3.31k | return mp11::mp_with_index<3>( | 754 | 3.31k | static_cast<unsigned char>(opt_.numbers), | 755 | 3.31k | 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 | 5.10k | } | 786 | 5.10k | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::resume_value<true>(char const*, std::__1::integral_constant<bool, true>, bool, bool, bool) Line | Count | Source | 721 | 5.88k | { | 722 | 5.88k | state st; | 723 | 5.88k | st_.peek(st); | 724 | 5.88k | switch(st) | 725 | 5.88k | { | 726 | 0 | default: BOOST_JSON_UNREACHABLE(); | 727 | 31 | case state::lit1: | 728 | 31 | return parse_literal(p, detail::literals_c<detail::literals::resume>() ); | 729 | | | 730 | 286 | case state::str1: case state::str2: | 731 | 291 | case state::str8: | 732 | 291 | return parse_string(p, std::false_type(), std::false_type(), allow_bad_utf8, allow_bad_utf16); | 733 | | | 734 | 69 | case state::arr1: case state::arr2: | 735 | 1.50k | case state::arr3: case state::arr4: | 736 | 1.65k | case state::arr5: case state::arr6: | 737 | 1.65k | return parse_array(p, std::false_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | 738 | | | 739 | 50 | case state::obj1: case state::obj2: | 740 | 191 | case state::obj3: case state::obj4: | 741 | 230 | case state::obj5: case state::obj6: | 742 | 543 | case state::obj7: case state::obj8: | 743 | 589 | case state::obj9: case state::obj10: | 744 | 592 | case state::obj11: | 745 | 592 | return parse_object(p, std::false_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | 746 | | | 747 | 567 | case state::num1: case state::num2: | 748 | 820 | case state::num3: case state::num4: | 749 | 1.36k | case state::num5: case state::num6: | 750 | 2.02k | case state::num7: case state::num8: | 751 | 2.17k | case state::exp1: case state::exp2: | 752 | 3.24k | case state::exp3: | 753 | 3.24k | return mp11::mp_with_index<3>( | 754 | 3.24k | static_cast<unsigned char>(opt_.numbers), | 755 | 3.24k | parse_number_helper<false, 0>{ this, p }); | 756 | | | 757 | | // KRYSTIAN NOTE: these are special cases | 758 | 37 | case state::val1: | 759 | 37 | { | 760 | 37 | st_.pop(st); | 761 | 37 | BOOST_ASSERT(st_.empty()); | 762 | 37 | p = detail::count_whitespace(p, end_); | 763 | 37 | if(BOOST_JSON_UNLIKELY(p == end_)) | 764 | 37 | 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 | 37 | } | 767 | | | 768 | 35 | case state::val2: | 769 | 35 | { | 770 | 35 | st_.pop(st); | 771 | 35 | p = parse_comment(p, std::false_type(), std::false_type()); | 772 | 35 | if(BOOST_JSON_UNLIKELY(p == sentinel())) | 773 | 35 | 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 | 5.88k | } | 786 | 5.88k | } |
|
787 | | |
788 | | template<class Handler> |
789 | | template<class Literal> |
790 | | const char* |
791 | | basic_parser<Handler>:: |
792 | | parse_literal(const char* p, Literal) |
793 | 71.1k | { |
794 | 71.1k | using L = detail::literals; |
795 | | |
796 | 71.1k | std::size_t cur_lit; |
797 | 71.1k | std::size_t offset; |
798 | | |
799 | 71.1k | detail::const_stream_wrapper cs(p, end_); |
800 | | BOOST_IF_CONSTEXPR( Literal::value != L::resume ) |
801 | 71.0k | { |
802 | 71.0k | constexpr std::size_t index = literal_index(Literal::value); |
803 | 71.0k | constexpr char const* literal = detail::literal_strings[index]; |
804 | 71.0k | constexpr std::size_t sz = detail::literal_sizes[index]; |
805 | | |
806 | 71.0k | if(BOOST_JSON_LIKELY( cs.remain() >= sz )) |
807 | 70.7k | { |
808 | 70.7k | int const cmp = std::memcmp(cs.begin(), literal, sz); |
809 | 70.7k | if( cmp != 0 ) |
810 | 105 | { |
811 | 105 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; |
812 | 105 | return fail(cs.begin(), error::syntax, &loc); |
813 | 105 | } |
814 | | |
815 | 70.6k | BOOST_IF_CONSTEXPR( Literal::value == L::null ) |
816 | 70.6k | { |
817 | 14.1k | if(BOOST_JSON_UNLIKELY( |
818 | 14.1k | ! h_.on_null(ec_))) |
819 | 0 | return fail(cs.begin()); |
820 | | } |
821 | 56.4k | else BOOST_IF_CONSTEXPR( Literal::value == L::true_ ) |
822 | 56.4k | { |
823 | 46.2k | if(BOOST_JSON_UNLIKELY( |
824 | 46.2k | ! h_.on_bool(true, ec_))) |
825 | 0 | return fail(cs.begin()); |
826 | | } |
827 | 10.2k | else BOOST_IF_CONSTEXPR( Literal::value == L::false_ ) |
828 | 10.2k | { |
829 | 10.2k | if(BOOST_JSON_UNLIKELY( |
830 | 10.2k | ! h_.on_bool(false, ec_))) |
831 | 0 | 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 | 70.6k | cs += sz; |
866 | 70.6k | return cs.begin(); |
867 | 70.7k | } |
868 | | |
869 | 337 | offset = 0; |
870 | 337 | cur_lit = index; |
871 | | } |
872 | | else |
873 | 59 | { |
874 | 59 | state st; |
875 | 59 | st_.pop(st); |
876 | 59 | BOOST_ASSERT( st == state::lit1 ); |
877 | | |
878 | 59 | cur_lit = cur_lit_; |
879 | 59 | offset = lit_offset_; |
880 | 59 | } |
881 | | |
882 | 0 | std::size_t const lit_size = detail::literal_sizes[cur_lit]; |
883 | 71.1k | std::size_t const size = (std::min)( lit_size - offset, cs.remain() ); |
884 | 71.1k | int cmp = 0; |
885 | 71.1k | if(BOOST_JSON_LIKELY( cs.begin() )) |
886 | 337 | cmp = std::memcmp( |
887 | 337 | cs.begin(), detail::literal_strings[cur_lit] + offset, size ); |
888 | 71.1k | if( cmp != 0 ) |
889 | 250 | { |
890 | 250 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; |
891 | 250 | return fail(cs.begin(), error::syntax, &loc); |
892 | 250 | } |
893 | | |
894 | 70.9k | if(BOOST_JSON_UNLIKELY( offset + size < lit_size )) |
895 | 146 | { |
896 | 146 | BOOST_ASSERT( cur_lit < 256 ); |
897 | 146 | cur_lit_ = static_cast<unsigned char>( cur_lit ); |
898 | 146 | BOOST_ASSERT( offset + size < 256 ); |
899 | 146 | lit_offset_ = static_cast<unsigned char>( offset + size ); |
900 | 146 | return maybe_suspend(cs.begin() + size, state::lit1); |
901 | 146 | } |
902 | | |
903 | 70.7k | switch( static_cast<L>(cur_lit) ) |
904 | 70.7k | { |
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 | 70.7k | } |
952 | | |
953 | 0 | cs += size; |
954 | 0 | return cs.begin(); |
955 | 70.7k | } Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::handler>::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>) char const* boost::json::basic_parser<boost::json::detail::handler>::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>) Line | Count | Source | 793 | 59 | { | 794 | 59 | using L = detail::literals; | 795 | | | 796 | 59 | std::size_t cur_lit; | 797 | 59 | std::size_t offset; | 798 | | | 799 | 59 | detail::const_stream_wrapper cs(p, end_); | 800 | | BOOST_IF_CONSTEXPR( Literal::value != L::resume ) | 801 | | { | 802 | | constexpr std::size_t index = literal_index(Literal::value); | 803 | | constexpr char const* literal = detail::literal_strings[index]; | 804 | | constexpr std::size_t sz = detail::literal_sizes[index]; | 805 | | | 806 | | if(BOOST_JSON_LIKELY( cs.remain() >= sz )) | 807 | | { | 808 | | int const cmp = std::memcmp(cs.begin(), literal, sz); | 809 | | if( cmp != 0 ) | 810 | | { | 811 | | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 812 | | return fail(cs.begin(), error::syntax, &loc); | 813 | | } | 814 | | | 815 | | BOOST_IF_CONSTEXPR( Literal::value == L::null ) | 816 | | { | 817 | | if(BOOST_JSON_UNLIKELY( | 818 | | ! h_.on_null(ec_))) | 819 | | 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 | | cs += sz; | 866 | | return cs.begin(); | 867 | | } | 868 | | | 869 | | offset = 0; | 870 | | cur_lit = index; | 871 | | } | 872 | | else | 873 | 59 | { | 874 | 59 | state st; | 875 | 59 | st_.pop(st); | 876 | 59 | BOOST_ASSERT( st == state::lit1 ); | 877 | | | 878 | 59 | cur_lit = cur_lit_; | 879 | 59 | offset = lit_offset_; | 880 | 59 | } | 881 | | | 882 | 59 | std::size_t const lit_size = detail::literal_sizes[cur_lit]; | 883 | 59 | std::size_t const size = (std::min)( lit_size - offset, cs.remain() ); | 884 | 59 | int cmp = 0; | 885 | 59 | if(BOOST_JSON_LIKELY( cs.begin() )) | 886 | 0 | cmp = std::memcmp( | 887 | 0 | cs.begin(), detail::literal_strings[cur_lit] + offset, size ); | 888 | 59 | if( cmp != 0 ) | 889 | 0 | { | 890 | 0 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 891 | 0 | return fail(cs.begin(), error::syntax, &loc); | 892 | 0 | } | 893 | | | 894 | 59 | if(BOOST_JSON_UNLIKELY( offset + size < lit_size )) | 895 | 59 | { | 896 | 59 | BOOST_ASSERT( cur_lit < 256 ); | 897 | 59 | cur_lit_ = static_cast<unsigned char>( cur_lit ); | 898 | 59 | BOOST_ASSERT( offset + size < 256 ); | 899 | 59 | lit_offset_ = static_cast<unsigned char>( offset + size ); | 900 | 59 | return maybe_suspend(cs.begin() + size, state::lit1); | 901 | 59 | } | 902 | | | 903 | 0 | switch( static_cast<L>(cur_lit) ) | 904 | 0 | { | 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 | 0 | } | 952 | | | 953 | 0 | cs += size; | 954 | 0 | return cs.begin(); | 955 | 0 | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::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 | 14.3k | { | 794 | 14.3k | using L = detail::literals; | 795 | | | 796 | 14.3k | std::size_t cur_lit; | 797 | 14.3k | std::size_t offset; | 798 | | | 799 | 14.3k | detail::const_stream_wrapper cs(p, end_); | 800 | | BOOST_IF_CONSTEXPR( Literal::value != L::resume ) | 801 | 14.3k | { | 802 | 14.3k | constexpr std::size_t index = literal_index(Literal::value); | 803 | 14.3k | constexpr char const* literal = detail::literal_strings[index]; | 804 | 14.3k | constexpr std::size_t sz = detail::literal_sizes[index]; | 805 | | | 806 | 14.3k | if(BOOST_JSON_LIKELY( cs.remain() >= sz )) | 807 | 14.2k | { | 808 | 14.2k | int const cmp = std::memcmp(cs.begin(), literal, sz); | 809 | 14.2k | if( cmp != 0 ) | 810 | 29 | { | 811 | 29 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 812 | 29 | return fail(cs.begin(), error::syntax, &loc); | 813 | 29 | } | 814 | | | 815 | 14.1k | BOOST_IF_CONSTEXPR( Literal::value == L::null ) | 816 | 14.1k | { | 817 | 14.1k | if(BOOST_JSON_UNLIKELY( | 818 | 14.1k | ! h_.on_null(ec_))) | 819 | 0 | 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 | 14.1k | cs += sz; | 866 | 14.1k | return cs.begin(); | 867 | 14.2k | } | 868 | | | 869 | 106 | offset = 0; | 870 | 106 | 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 | 14.3k | std::size_t const size = (std::min)( lit_size - offset, cs.remain() ); | 884 | 14.3k | int cmp = 0; | 885 | 14.3k | if(BOOST_JSON_LIKELY( cs.begin() )) | 886 | 106 | cmp = std::memcmp( | 887 | 106 | cs.begin(), detail::literal_strings[cur_lit] + offset, size ); | 888 | 14.3k | if( cmp != 0 ) | 889 | 80 | { | 890 | 80 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 891 | 80 | return fail(cs.begin(), error::syntax, &loc); | 892 | 80 | } | 893 | | | 894 | 14.2k | 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 | 14.2k | switch( static_cast<L>(cur_lit) ) | 904 | 14.2k | { | 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 | 14.2k | } | 952 | | | 953 | 0 | cs += size; | 954 | 0 | return cs.begin(); | 955 | 14.2k | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::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 | 46.4k | { | 794 | 46.4k | using L = detail::literals; | 795 | | | 796 | 46.4k | std::size_t cur_lit; | 797 | 46.4k | std::size_t offset; | 798 | | | 799 | 46.4k | detail::const_stream_wrapper cs(p, end_); | 800 | | BOOST_IF_CONSTEXPR( Literal::value != L::resume ) | 801 | 46.4k | { | 802 | 46.4k | constexpr std::size_t index = literal_index(Literal::value); | 803 | 46.4k | constexpr char const* literal = detail::literal_strings[index]; | 804 | 46.4k | constexpr std::size_t sz = detail::literal_sizes[index]; | 805 | | | 806 | 46.4k | if(BOOST_JSON_LIKELY( cs.remain() >= sz )) | 807 | 46.3k | { | 808 | 46.3k | int const cmp = std::memcmp(cs.begin(), literal, sz); | 809 | 46.3k | if( cmp != 0 ) | 810 | 31 | { | 811 | 31 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 812 | 31 | return fail(cs.begin(), error::syntax, &loc); | 813 | 31 | } | 814 | | | 815 | 46.2k | BOOST_IF_CONSTEXPR( Literal::value == L::null ) | 816 | 46.2k | { | 817 | 46.2k | if(BOOST_JSON_UNLIKELY( | 818 | 46.2k | ! h_.on_null(ec_))) | 819 | 46.2k | return fail(cs.begin()); | 820 | 46.2k | } | 821 | 46.2k | else BOOST_IF_CONSTEXPR( Literal::value == L::true_ ) | 822 | 46.2k | { | 823 | 46.2k | if(BOOST_JSON_UNLIKELY( | 824 | 46.2k | ! h_.on_bool(true, ec_))) | 825 | 0 | 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 | 46.2k | cs += sz; | 866 | 46.2k | return cs.begin(); | 867 | 46.3k | } | 868 | | | 869 | 115 | offset = 0; | 870 | 115 | 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 | 46.4k | std::size_t const size = (std::min)( lit_size - offset, cs.remain() ); | 884 | 46.4k | int cmp = 0; | 885 | 46.4k | if(BOOST_JSON_LIKELY( cs.begin() )) | 886 | 115 | cmp = std::memcmp( | 887 | 115 | cs.begin(), detail::literal_strings[cur_lit] + offset, size ); | 888 | 46.4k | if( cmp != 0 ) | 889 | 85 | { | 890 | 85 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 891 | 85 | return fail(cs.begin(), error::syntax, &loc); | 892 | 85 | } | 893 | | | 894 | 46.3k | if(BOOST_JSON_UNLIKELY( offset + size < lit_size )) | 895 | 30 | { | 896 | 30 | BOOST_ASSERT( cur_lit < 256 ); | 897 | 30 | cur_lit_ = static_cast<unsigned char>( cur_lit ); | 898 | 30 | BOOST_ASSERT( offset + size < 256 ); | 899 | 30 | lit_offset_ = static_cast<unsigned char>( offset + size ); | 900 | 30 | return maybe_suspend(cs.begin() + size, state::lit1); | 901 | 30 | } | 902 | | | 903 | 46.3k | switch( static_cast<L>(cur_lit) ) | 904 | 46.3k | { | 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 | 46.3k | } | 952 | | | 953 | 0 | cs += size; | 954 | 0 | return cs.begin(); | 955 | 46.3k | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::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 | 10.3k | { | 794 | 10.3k | using L = detail::literals; | 795 | | | 796 | 10.3k | std::size_t cur_lit; | 797 | 10.3k | std::size_t offset; | 798 | | | 799 | 10.3k | detail::const_stream_wrapper cs(p, end_); | 800 | | BOOST_IF_CONSTEXPR( Literal::value != L::resume ) | 801 | 10.3k | { | 802 | 10.3k | constexpr std::size_t index = literal_index(Literal::value); | 803 | 10.3k | constexpr char const* literal = detail::literal_strings[index]; | 804 | 10.3k | constexpr std::size_t sz = detail::literal_sizes[index]; | 805 | | | 806 | 10.3k | if(BOOST_JSON_LIKELY( cs.remain() >= sz )) | 807 | 10.2k | { | 808 | 10.2k | int const cmp = std::memcmp(cs.begin(), literal, sz); | 809 | 10.2k | if( cmp != 0 ) | 810 | 45 | { | 811 | 45 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 812 | 45 | return fail(cs.begin(), error::syntax, &loc); | 813 | 45 | } | 814 | | | 815 | 10.2k | BOOST_IF_CONSTEXPR( Literal::value == L::null ) | 816 | 10.2k | { | 817 | 10.2k | if(BOOST_JSON_UNLIKELY( | 818 | 10.2k | ! h_.on_null(ec_))) | 819 | 10.2k | return fail(cs.begin()); | 820 | 10.2k | } | 821 | 10.2k | else BOOST_IF_CONSTEXPR( Literal::value == L::true_ ) | 822 | 10.2k | { | 823 | 10.2k | if(BOOST_JSON_UNLIKELY( | 824 | 10.2k | ! h_.on_bool(true, ec_))) | 825 | 10.2k | return fail(cs.begin()); | 826 | 10.2k | } | 827 | 10.2k | else BOOST_IF_CONSTEXPR( Literal::value == L::false_ ) | 828 | 10.2k | { | 829 | 10.2k | if(BOOST_JSON_UNLIKELY( | 830 | 10.2k | ! h_.on_bool(false, ec_))) | 831 | 0 | 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 | 10.2k | cs += sz; | 866 | 10.2k | return cs.begin(); | 867 | 10.2k | } | 868 | | | 869 | 116 | offset = 0; | 870 | 116 | 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 | 10.3k | std::size_t const size = (std::min)( lit_size - offset, cs.remain() ); | 884 | 10.3k | int cmp = 0; | 885 | 10.3k | if(BOOST_JSON_LIKELY( cs.begin() )) | 886 | 116 | cmp = std::memcmp( | 887 | 116 | cs.begin(), detail::literal_strings[cur_lit] + offset, size ); | 888 | 10.3k | if( cmp != 0 ) | 889 | 85 | { | 890 | 85 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 891 | 85 | return fail(cs.begin(), error::syntax, &loc); | 892 | 85 | } | 893 | | | 894 | 10.2k | if(BOOST_JSON_UNLIKELY( offset + size < lit_size )) | 895 | 31 | { | 896 | 31 | BOOST_ASSERT( cur_lit < 256 ); | 897 | 31 | cur_lit_ = static_cast<unsigned char>( cur_lit ); | 898 | 31 | BOOST_ASSERT( offset + size < 256 ); | 899 | 31 | lit_offset_ = static_cast<unsigned char>( offset + size ); | 900 | 31 | return maybe_suspend(cs.begin() + size, state::lit1); | 901 | 31 | } | 902 | | | 903 | 10.2k | switch( static_cast<L>(cur_lit) ) | 904 | 10.2k | { | 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 | 10.2k | } | 952 | | | 953 | 0 | cs += size; | 954 | 0 | return cs.begin(); | 955 | 10.2k | } |
Unexecuted instantiation: char const* boost::json::basic_parser<boost::json::detail::handler>::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::handler>::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 | 1.88M | { |
969 | 1.88M | detail::const_stream_wrapper cs(p, end_); |
970 | 1.88M | std::size_t total; |
971 | 1.88M | char const* start; |
972 | 1.88M | std::size_t size; |
973 | 1.88M | if(! stack_empty && ! st_.empty()) |
974 | 671 | { |
975 | 671 | state st; |
976 | 671 | st_.pop(st); |
977 | 671 | st_.pop(total); |
978 | 671 | switch(st) |
979 | 671 | { |
980 | 0 | default: BOOST_JSON_UNREACHABLE(); |
981 | 175 | case state::str2: goto do_str2; |
982 | 19 | case state::str8: goto do_str8; |
983 | 477 | case state::str1: break; |
984 | 671 | } |
985 | 671 | } |
986 | 1.88M | else |
987 | 1.88M | { |
988 | 1.88M | BOOST_ASSERT(*cs == '\x22'); // '"' |
989 | 1.88M | ++cs; |
990 | 1.88M | total = 0; |
991 | 1.88M | } |
992 | | |
993 | 1.97M | do_str1: |
994 | 1.97M | start = cs.begin(); |
995 | 1.97M | cs = allow_bad_utf8? |
996 | 715k | detail::count_valid<true>(cs.begin(), cs.end()): |
997 | 1.97M | detail::count_valid<false>(cs.begin(), cs.end()); |
998 | 1.97M | size = cs.used(start); |
999 | 1.97M | if(is_key) |
1000 | 1.84M | { |
1001 | 1.84M | BOOST_ASSERT(total <= Handler::max_key_size); |
1002 | 1.84M | if(BOOST_JSON_UNLIKELY(size > |
1003 | 1.84M | 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 | 1.84M | } |
1010 | 129k | else |
1011 | 129k | { |
1012 | 129k | BOOST_ASSERT(total <= Handler::max_string_size); |
1013 | 129k | if(BOOST_JSON_UNLIKELY(size > |
1014 | 129k | 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 | 129k | } |
1021 | 1.97M | total += size; |
1022 | 1.97M | if(BOOST_JSON_UNLIKELY(! cs)) |
1023 | 1.50k | { |
1024 | | // call handler if the string isn't empty |
1025 | 1.50k | if(BOOST_JSON_LIKELY(size)) |
1026 | 483 | { |
1027 | 483 | { |
1028 | 483 | bool r = is_key? |
1029 | 197 | h_.on_key_part( {start, size}, total, ec_ ): |
1030 | 483 | h_.on_string_part( {start, size}, total, ec_ ); |
1031 | | |
1032 | 483 | if(BOOST_JSON_UNLIKELY(!r)) |
1033 | 0 | { |
1034 | 0 | return fail(cs.begin()); |
1035 | 0 | } |
1036 | 483 | } |
1037 | 483 | } |
1038 | 1.50k | return maybe_suspend(cs.begin(), state::str1, total); |
1039 | 1.50k | } |
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 | 1.97M | if(BOOST_JSON_UNLIKELY(*cs != '\x22')) // '"' |
1044 | 94.3k | { |
1045 | | // sequence is invalid or incomplete |
1046 | 94.3k | if((*cs & 0x80) && !allow_bad_utf8) |
1047 | 534 | { |
1048 | 534 | seq_.save(cs.begin(), cs.remain()); |
1049 | 534 | if(BOOST_JSON_UNLIKELY(seq_.complete())) |
1050 | 495 | { |
1051 | 495 | BOOST_STATIC_CONSTEXPR source_location loc |
1052 | 495 | = BOOST_CURRENT_LOCATION; |
1053 | 495 | return fail(cs.begin(), error::syntax, &loc); |
1054 | 495 | } |
1055 | 39 | if(BOOST_JSON_LIKELY(size)) |
1056 | 10 | { |
1057 | 10 | bool const r = is_key? |
1058 | 4 | 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 | 0 | return fail( cs.begin() ); |
1062 | 10 | } |
1063 | 39 | return maybe_suspend(cs.end(), state::str8, total); |
1064 | 39 | } |
1065 | 93.8k | else if(BOOST_JSON_LIKELY(*cs == '\\')) |
1066 | 93.6k | { |
1067 | | // flush unescaped run from input |
1068 | 93.6k | if(BOOST_JSON_LIKELY(size)) |
1069 | 82.0k | { |
1070 | 82.0k | bool const r = is_key? |
1071 | 12.3k | h_.on_key_part( {start, size}, total, ec_ ): |
1072 | 82.0k | h_.on_string_part( {start, size}, total, ec_ ); |
1073 | 82.0k | if(BOOST_JSON_UNLIKELY( !r )) |
1074 | 0 | return fail( cs.begin() ); |
1075 | 82.0k | } |
1076 | 93.8k | do_str2: |
1077 | 93.8k | cs = parse_escaped(cs.begin(), total, stack_empty, is_key, allow_bad_utf16); |
1078 | 93.8k | if(BOOST_JSON_UNLIKELY( incomplete(cs) )) |
1079 | 1.58k | return suspend_or_fail(state::str2, total); |
1080 | | |
1081 | 92.2k | goto do_str1; |
1082 | 93.8k | } |
1083 | | // illegal control |
1084 | 94.3k | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; |
1085 | 150 | return fail(cs.begin(), error::syntax, &loc); |
1086 | 94.3k | } |
1087 | | |
1088 | 1.88M | { |
1089 | 1.88M | bool r = is_key? |
1090 | 1.82M | h_.on_key( {start, size}, total, ec_ ): |
1091 | 1.88M | h_.on_string( {start, size}, total, ec_ ); |
1092 | | |
1093 | 1.88M | if(BOOST_JSON_UNLIKELY(!r)) |
1094 | 0 | { |
1095 | 0 | return fail(cs.begin()); |
1096 | 0 | } |
1097 | 1.88M | } |
1098 | | |
1099 | 1.88M | ++cs; |
1100 | 1.88M | return cs.begin(); |
1101 | | |
1102 | 19 | do_str8: |
1103 | 19 | uint8_t needed = seq_.needed(); |
1104 | 19 | if(BOOST_JSON_UNLIKELY( !seq_.append(cs.begin(), cs.remain()) )) |
1105 | 19 | 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::handler>::parse_string<true, false>(char const*, std::__1::integral_constant<bool, true>, std::__1::integral_constant<bool, false>, bool, bool) Line | Count | Source | 968 | 54.3k | { | 969 | 54.3k | detail::const_stream_wrapper cs(p, end_); | 970 | 54.3k | std::size_t total; | 971 | 54.3k | char const* start; | 972 | 54.3k | std::size_t size; | 973 | 54.3k | 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 | 54.3k | else | 987 | 54.3k | { | 988 | 54.3k | BOOST_ASSERT(*cs == '\x22'); // '"' | 989 | 54.3k | ++cs; | 990 | 54.3k | total = 0; | 991 | 54.3k | } | 992 | | | 993 | 129k | do_str1: | 994 | 129k | start = cs.begin(); | 995 | 129k | cs = allow_bad_utf8? | 996 | 73.1k | detail::count_valid<true>(cs.begin(), cs.end()): | 997 | 129k | detail::count_valid<false>(cs.begin(), cs.end()); | 998 | 129k | size = cs.used(start); | 999 | 129k | 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 | 129k | else | 1011 | 129k | { | 1012 | 129k | BOOST_ASSERT(total <= Handler::max_string_size); | 1013 | 129k | if(BOOST_JSON_UNLIKELY(size > | 1014 | 129k | 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 | 129k | } | 1021 | 129k | total += size; | 1022 | 129k | if(BOOST_JSON_UNLIKELY(! cs)) | 1023 | 745 | { | 1024 | | // call handler if the string isn't empty | 1025 | 745 | if(BOOST_JSON_LIKELY(size)) | 1026 | 286 | { | 1027 | 286 | { | 1028 | 286 | bool r = is_key? | 1029 | 0 | h_.on_key_part( {start, size}, total, ec_ ): | 1030 | 286 | h_.on_string_part( {start, size}, total, ec_ ); | 1031 | | | 1032 | 286 | if(BOOST_JSON_UNLIKELY(!r)) | 1033 | 0 | { | 1034 | 0 | return fail(cs.begin()); | 1035 | 0 | } | 1036 | 286 | } | 1037 | 286 | } | 1038 | 745 | return maybe_suspend(cs.begin(), state::str1, total); | 1039 | 745 | } | 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 | 128k | if(BOOST_JSON_UNLIKELY(*cs != '\x22')) // '"' | 1044 | 76.3k | { | 1045 | | // sequence is invalid or incomplete | 1046 | 76.3k | if((*cs & 0x80) && !allow_bad_utf8) | 1047 | 286 | { | 1048 | 286 | seq_.save(cs.begin(), cs.remain()); | 1049 | 286 | if(BOOST_JSON_UNLIKELY(seq_.complete())) | 1050 | 265 | { | 1051 | 265 | BOOST_STATIC_CONSTEXPR source_location loc | 1052 | 265 | = BOOST_CURRENT_LOCATION; | 1053 | 265 | return fail(cs.begin(), error::syntax, &loc); | 1054 | 265 | } | 1055 | 21 | if(BOOST_JSON_LIKELY(size)) | 1056 | 6 | { | 1057 | 6 | bool const r = is_key? | 1058 | 0 | h_.on_key_part( {start, size}, total, ec_ ): | 1059 | 6 | h_.on_string_part( {start, size}, total, ec_ ); | 1060 | 6 | if(BOOST_JSON_UNLIKELY( !r )) | 1061 | 0 | return fail( cs.begin() ); | 1062 | 6 | } | 1063 | 21 | return maybe_suspend(cs.end(), state::str8, total); | 1064 | 21 | } | 1065 | 76.0k | else if(BOOST_JSON_LIKELY(*cs == '\\')) | 1066 | 75.9k | { | 1067 | | // flush unescaped run from input | 1068 | 75.9k | if(BOOST_JSON_LIKELY(size)) | 1069 | 69.7k | { | 1070 | 69.7k | bool const r = is_key? | 1071 | 0 | h_.on_key_part( {start, size}, total, ec_ ): | 1072 | 69.7k | h_.on_string_part( {start, size}, total, ec_ ); | 1073 | 69.7k | if(BOOST_JSON_UNLIKELY( !r )) | 1074 | 0 | return fail( cs.begin() ); | 1075 | 69.7k | } | 1076 | 75.9k | do_str2: | 1077 | 75.9k | cs = parse_escaped(cs.begin(), total, stack_empty, is_key, allow_bad_utf16); | 1078 | 75.9k | if(BOOST_JSON_UNLIKELY( incomplete(cs) )) | 1079 | 1.27k | return suspend_or_fail(state::str2, total); | 1080 | | | 1081 | 74.7k | goto do_str1; | 1082 | 75.9k | } | 1083 | | // illegal control | 1084 | 76.3k | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 1085 | 91 | return fail(cs.begin(), error::syntax, &loc); | 1086 | 76.3k | } | 1087 | | | 1088 | 51.9k | { | 1089 | 51.9k | bool r = is_key? | 1090 | 0 | h_.on_key( {start, size}, total, ec_ ): | 1091 | 51.9k | h_.on_string( {start, size}, total, ec_ ); | 1092 | | | 1093 | 51.9k | if(BOOST_JSON_UNLIKELY(!r)) | 1094 | 0 | { | 1095 | 0 | return fail(cs.begin()); | 1096 | 0 | } | 1097 | 51.9k | } | 1098 | | | 1099 | 51.9k | ++cs; | 1100 | 51.9k | 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::handler>::parse_string<true, true>(char const*, std::__1::integral_constant<bool, true>, std::__1::integral_constant<bool, true>, bool, bool) Line | Count | Source | 968 | 1.83M | { | 969 | 1.83M | detail::const_stream_wrapper cs(p, end_); | 970 | 1.83M | std::size_t total; | 971 | 1.83M | char const* start; | 972 | 1.83M | std::size_t size; | 973 | 1.83M | 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 | 1.83M | else | 987 | 1.83M | { | 988 | 1.83M | BOOST_ASSERT(*cs == '\x22'); // '"' | 989 | 1.83M | ++cs; | 990 | 1.83M | total = 0; | 991 | 1.83M | } | 992 | | | 993 | 1.84M | do_str1: | 994 | 1.84M | start = cs.begin(); | 995 | 1.84M | cs = allow_bad_utf8? | 996 | 642k | detail::count_valid<true>(cs.begin(), cs.end()): | 997 | 1.84M | detail::count_valid<false>(cs.begin(), cs.end()); | 998 | 1.84M | size = cs.used(start); | 999 | 1.84M | if(is_key) | 1000 | 1.84M | { | 1001 | 1.84M | BOOST_ASSERT(total <= Handler::max_key_size); | 1002 | 1.84M | if(BOOST_JSON_UNLIKELY(size > | 1003 | 1.84M | 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 | 1.84M | } | 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 | 1.84M | total += size; | 1022 | 1.84M | if(BOOST_JSON_UNLIKELY(! cs)) | 1023 | 281 | { | 1024 | | // call handler if the string isn't empty | 1025 | 281 | if(BOOST_JSON_LIKELY(size)) | 1026 | 197 | { | 1027 | 197 | { | 1028 | 197 | bool r = is_key? | 1029 | 197 | h_.on_key_part( {start, size}, total, ec_ ): | 1030 | 197 | h_.on_string_part( {start, size}, total, ec_ ); | 1031 | | | 1032 | 197 | if(BOOST_JSON_UNLIKELY(!r)) | 1033 | 0 | { | 1034 | 0 | return fail(cs.begin()); | 1035 | 0 | } | 1036 | 197 | } | 1037 | 197 | } | 1038 | 281 | return maybe_suspend(cs.begin(), state::str1, total); | 1039 | 281 | } | 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 | 1.84M | if(BOOST_JSON_UNLIKELY(*cs != '\x22')) // '"' | 1044 | 18.0k | { | 1045 | | // sequence is invalid or incomplete | 1046 | 18.0k | if((*cs & 0x80) && !allow_bad_utf8) | 1047 | 248 | { | 1048 | 248 | seq_.save(cs.begin(), cs.remain()); | 1049 | 248 | if(BOOST_JSON_UNLIKELY(seq_.complete())) | 1050 | 230 | { | 1051 | 230 | BOOST_STATIC_CONSTEXPR source_location loc | 1052 | 230 | = BOOST_CURRENT_LOCATION; | 1053 | 230 | return fail(cs.begin(), error::syntax, &loc); | 1054 | 230 | } | 1055 | 18 | if(BOOST_JSON_LIKELY(size)) | 1056 | 4 | { | 1057 | 4 | bool const r = is_key? | 1058 | 4 | h_.on_key_part( {start, size}, total, ec_ ): | 1059 | 4 | h_.on_string_part( {start, size}, total, ec_ ); | 1060 | 4 | if(BOOST_JSON_UNLIKELY( !r )) | 1061 | 0 | return fail( cs.begin() ); | 1062 | 4 | } | 1063 | 18 | return maybe_suspend(cs.end(), state::str8, total); | 1064 | 18 | } | 1065 | 17.7k | else if(BOOST_JSON_LIKELY(*cs == '\\')) | 1066 | 17.7k | { | 1067 | | // flush unescaped run from input | 1068 | 17.7k | if(BOOST_JSON_LIKELY(size)) | 1069 | 12.3k | { | 1070 | 12.3k | bool const r = is_key? | 1071 | 12.3k | h_.on_key_part( {start, size}, total, ec_ ): | 1072 | 12.3k | h_.on_string_part( {start, size}, total, ec_ ); | 1073 | 12.3k | if(BOOST_JSON_UNLIKELY( !r )) | 1074 | 0 | return fail( cs.begin() ); | 1075 | 12.3k | } | 1076 | 17.7k | do_str2: | 1077 | 17.7k | cs = parse_escaped(cs.begin(), total, stack_empty, is_key, allow_bad_utf16); | 1078 | 17.7k | if(BOOST_JSON_UNLIKELY( incomplete(cs) )) | 1079 | 133 | return suspend_or_fail(state::str2, total); | 1080 | | | 1081 | 17.5k | goto do_str1; | 1082 | 17.7k | } | 1083 | | // illegal control | 1084 | 18.0k | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 1085 | 59 | return fail(cs.begin(), error::syntax, &loc); | 1086 | 18.0k | } | 1087 | | | 1088 | 1.82M | { | 1089 | 1.82M | bool r = is_key? | 1090 | 1.82M | h_.on_key( {start, size}, total, ec_ ): | 1091 | 1.82M | h_.on_string( {start, size}, total, ec_ ); | 1092 | | | 1093 | 1.82M | if(BOOST_JSON_UNLIKELY(!r)) | 1094 | 0 | { | 1095 | 0 | return fail(cs.begin()); | 1096 | 0 | } | 1097 | 1.82M | } | 1098 | | | 1099 | 1.82M | ++cs; | 1100 | 1.82M | 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::handler>::parse_string<false, false>(char const*, std::__1::integral_constant<bool, false>, std::__1::integral_constant<bool, false>, bool, bool) Line | Count | Source | 968 | 486 | { | 969 | 486 | detail::const_stream_wrapper cs(p, end_); | 970 | 486 | std::size_t total; | 971 | 486 | char const* start; | 972 | 486 | std::size_t size; | 973 | 486 | if(! stack_empty && ! st_.empty()) | 974 | 486 | { | 975 | 486 | state st; | 976 | 486 | st_.pop(st); | 977 | 486 | st_.pop(total); | 978 | 486 | switch(st) | 979 | 486 | { | 980 | 0 | default: BOOST_JSON_UNREACHABLE(); | 981 | 129 | case state::str2: goto do_str2; | 982 | 11 | case state::str8: goto do_str8; | 983 | 346 | case state::str1: break; | 984 | 486 | } | 985 | 486 | } | 986 | 0 | else | 987 | 0 | { | 988 | 0 | BOOST_ASSERT(*cs == '\x22'); // '"' | 989 | 0 | ++cs; | 990 | 0 | total = 0; | 991 | 0 | } | 992 | | | 993 | 346 | do_str1: | 994 | 346 | start = cs.begin(); | 995 | 346 | cs = allow_bad_utf8? | 996 | 202 | detail::count_valid<true>(cs.begin(), cs.end()): | 997 | 346 | detail::count_valid<false>(cs.begin(), cs.end()); | 998 | 346 | size = cs.used(start); | 999 | 346 | 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 | 346 | else | 1011 | 346 | { | 1012 | 346 | BOOST_ASSERT(total <= Handler::max_string_size); | 1013 | 346 | if(BOOST_JSON_UNLIKELY(size > | 1014 | 346 | 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 | 346 | } | 1021 | 346 | total += size; | 1022 | 346 | if(BOOST_JSON_UNLIKELY(! cs)) | 1023 | 346 | { | 1024 | | // call handler if the string isn't empty | 1025 | 346 | if(BOOST_JSON_LIKELY(size)) | 1026 | 0 | { | 1027 | 0 | { | 1028 | 0 | bool r = is_key? | 1029 | 0 | h_.on_key_part( {start, size}, total, ec_ ): | 1030 | 0 | h_.on_string_part( {start, size}, total, ec_ ); | 1031 | |
| 1032 | 0 | if(BOOST_JSON_UNLIKELY(!r)) | 1033 | 0 | { | 1034 | 0 | return fail(cs.begin()); | 1035 | 0 | } | 1036 | 0 | } | 1037 | 0 | } | 1038 | 346 | return maybe_suspend(cs.begin(), state::str1, total); | 1039 | 346 | } | 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 | 0 | if(BOOST_JSON_UNLIKELY(*cs != '\x22')) // '"' | 1044 | 0 | { | 1045 | | // sequence is invalid or incomplete | 1046 | 0 | if((*cs & 0x80) && !allow_bad_utf8) | 1047 | 0 | { | 1048 | 0 | seq_.save(cs.begin(), cs.remain()); | 1049 | 0 | if(BOOST_JSON_UNLIKELY(seq_.complete())) | 1050 | 0 | { | 1051 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1052 | 0 | = BOOST_CURRENT_LOCATION; | 1053 | 0 | return fail(cs.begin(), error::syntax, &loc); | 1054 | 0 | } | 1055 | 0 | if(BOOST_JSON_LIKELY(size)) | 1056 | 0 | { | 1057 | 0 | bool const r = is_key? | 1058 | 0 | h_.on_key_part( {start, size}, total, ec_ ): | 1059 | 0 | h_.on_string_part( {start, size}, total, ec_ ); | 1060 | 0 | if(BOOST_JSON_UNLIKELY( !r )) | 1061 | 0 | return fail( cs.begin() ); | 1062 | 0 | } | 1063 | 0 | return maybe_suspend(cs.end(), state::str8, total); | 1064 | 0 | } | 1065 | 0 | else if(BOOST_JSON_LIKELY(*cs == '\\')) | 1066 | 0 | { | 1067 | | // flush unescaped run from input | 1068 | 0 | if(BOOST_JSON_LIKELY(size)) | 1069 | 0 | { | 1070 | 0 | bool const r = is_key? | 1071 | 0 | h_.on_key_part( {start, size}, total, ec_ ): | 1072 | 0 | h_.on_string_part( {start, size}, total, ec_ ); | 1073 | 0 | if(BOOST_JSON_UNLIKELY( !r )) | 1074 | 0 | return fail( cs.begin() ); | 1075 | 0 | } | 1076 | 129 | do_str2: | 1077 | 129 | cs = parse_escaped(cs.begin(), total, stack_empty, is_key, allow_bad_utf16); | 1078 | 129 | if(BOOST_JSON_UNLIKELY( incomplete(cs) )) | 1079 | 129 | return suspend_or_fail(state::str2, total); | 1080 | | | 1081 | 0 | goto do_str1; | 1082 | 129 | } | 1083 | | // illegal control | 1084 | 0 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 1085 | 0 | return fail(cs.begin(), error::syntax, &loc); | 1086 | 0 | } | 1087 | | | 1088 | 0 | { | 1089 | 0 | bool r = is_key? | 1090 | 0 | h_.on_key( {start, size}, total, ec_ ): | 1091 | 0 | h_.on_string( {start, size}, total, ec_ ); | 1092 | |
| 1093 | 0 | if(BOOST_JSON_UNLIKELY(!r)) | 1094 | 0 | { | 1095 | 0 | return fail(cs.begin()); | 1096 | 0 | } | 1097 | 0 | } | 1098 | | | 1099 | 0 | ++cs; | 1100 | 0 | return cs.begin(); | 1101 | | | 1102 | 11 | do_str8: | 1103 | 11 | uint8_t needed = seq_.needed(); | 1104 | 11 | if(BOOST_JSON_UNLIKELY( !seq_.append(cs.begin(), cs.remain()) )) | 1105 | 11 | 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::handler>::parse_string<false, true>(char const*, std::__1::integral_constant<bool, false>, std::__1::integral_constant<bool, true>, bool, bool) Line | Count | Source | 968 | 185 | { | 969 | 185 | detail::const_stream_wrapper cs(p, end_); | 970 | 185 | std::size_t total; | 971 | 185 | char const* start; | 972 | 185 | std::size_t size; | 973 | 185 | if(! stack_empty && ! st_.empty()) | 974 | 185 | { | 975 | 185 | state st; | 976 | 185 | st_.pop(st); | 977 | 185 | st_.pop(total); | 978 | 185 | switch(st) | 979 | 185 | { | 980 | 0 | default: BOOST_JSON_UNREACHABLE(); | 981 | 46 | case state::str2: goto do_str2; | 982 | 8 | case state::str8: goto do_str8; | 983 | 131 | case state::str1: break; | 984 | 185 | } | 985 | 185 | } | 986 | 0 | else | 987 | 0 | { | 988 | 0 | BOOST_ASSERT(*cs == '\x22'); // '"' | 989 | 0 | ++cs; | 990 | 0 | total = 0; | 991 | 0 | } | 992 | | | 993 | 131 | do_str1: | 994 | 131 | start = cs.begin(); | 995 | 131 | cs = allow_bad_utf8? | 996 | 62 | detail::count_valid<true>(cs.begin(), cs.end()): | 997 | 131 | detail::count_valid<false>(cs.begin(), cs.end()); | 998 | 131 | size = cs.used(start); | 999 | 131 | if(is_key) | 1000 | 131 | { | 1001 | 131 | BOOST_ASSERT(total <= Handler::max_key_size); | 1002 | 131 | if(BOOST_JSON_UNLIKELY(size > | 1003 | 131 | 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 | 131 | } | 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 | 131 | total += size; | 1022 | 131 | if(BOOST_JSON_UNLIKELY(! cs)) | 1023 | 131 | { | 1024 | | // call handler if the string isn't empty | 1025 | 131 | if(BOOST_JSON_LIKELY(size)) | 1026 | 0 | { | 1027 | 0 | { | 1028 | 0 | bool r = is_key? | 1029 | 0 | h_.on_key_part( {start, size}, total, ec_ ): | 1030 | 0 | h_.on_string_part( {start, size}, total, ec_ ); | 1031 | |
| 1032 | 0 | if(BOOST_JSON_UNLIKELY(!r)) | 1033 | 0 | { | 1034 | 0 | return fail(cs.begin()); | 1035 | 0 | } | 1036 | 0 | } | 1037 | 0 | } | 1038 | 131 | return maybe_suspend(cs.begin(), state::str1, total); | 1039 | 131 | } | 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 | 0 | if(BOOST_JSON_UNLIKELY(*cs != '\x22')) // '"' | 1044 | 0 | { | 1045 | | // sequence is invalid or incomplete | 1046 | 0 | if((*cs & 0x80) && !allow_bad_utf8) | 1047 | 0 | { | 1048 | 0 | seq_.save(cs.begin(), cs.remain()); | 1049 | 0 | if(BOOST_JSON_UNLIKELY(seq_.complete())) | 1050 | 0 | { | 1051 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1052 | 0 | = BOOST_CURRENT_LOCATION; | 1053 | 0 | return fail(cs.begin(), error::syntax, &loc); | 1054 | 0 | } | 1055 | 0 | if(BOOST_JSON_LIKELY(size)) | 1056 | 0 | { | 1057 | 0 | bool const r = is_key? | 1058 | 0 | h_.on_key_part( {start, size}, total, ec_ ): | 1059 | 0 | h_.on_string_part( {start, size}, total, ec_ ); | 1060 | 0 | if(BOOST_JSON_UNLIKELY( !r )) | 1061 | 0 | return fail( cs.begin() ); | 1062 | 0 | } | 1063 | 0 | return maybe_suspend(cs.end(), state::str8, total); | 1064 | 0 | } | 1065 | 0 | else if(BOOST_JSON_LIKELY(*cs == '\\')) | 1066 | 0 | { | 1067 | | // flush unescaped run from input | 1068 | 0 | if(BOOST_JSON_LIKELY(size)) | 1069 | 0 | { | 1070 | 0 | bool const r = is_key? | 1071 | 0 | h_.on_key_part( {start, size}, total, ec_ ): | 1072 | 0 | h_.on_string_part( {start, size}, total, ec_ ); | 1073 | 0 | if(BOOST_JSON_UNLIKELY( !r )) | 1074 | 0 | return fail( cs.begin() ); | 1075 | 0 | } | 1076 | 46 | do_str2: | 1077 | 46 | cs = parse_escaped(cs.begin(), total, stack_empty, is_key, allow_bad_utf16); | 1078 | 46 | if(BOOST_JSON_UNLIKELY( incomplete(cs) )) | 1079 | 46 | return suspend_or_fail(state::str2, total); | 1080 | | | 1081 | 0 | goto do_str1; | 1082 | 46 | } | 1083 | | // illegal control | 1084 | 0 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 1085 | 0 | return fail(cs.begin(), error::syntax, &loc); | 1086 | 0 | } | 1087 | | | 1088 | 0 | { | 1089 | 0 | bool r = is_key? | 1090 | 0 | h_.on_key( {start, size}, total, ec_ ): | 1091 | 0 | h_.on_string( {start, size}, total, ec_ ); | 1092 | |
| 1093 | 0 | if(BOOST_JSON_UNLIKELY(!r)) | 1094 | 0 | { | 1095 | 0 | return fail(cs.begin()); | 1096 | 0 | } | 1097 | 0 | } | 1098 | | | 1099 | 0 | ++cs; | 1100 | 0 | return cs.begin(); | 1101 | | | 1102 | 8 | do_str8: | 1103 | 8 | uint8_t needed = seq_.needed(); | 1104 | 8 | if(BOOST_JSON_UNLIKELY( !seq_.append(cs.begin(), cs.remain()) )) | 1105 | 8 | 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 | } |
|
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 | 93.8k | { |
1133 | 93.8k | constexpr unsigned urc = 0xFFFD; // Unicode replacement character |
1134 | 93.8k | auto const ev_too_large = is_key? |
1135 | 76.1k | error::key_too_large : error::string_too_large; |
1136 | 93.8k | auto const max_size = is_key? |
1137 | 76.1k | Handler::max_key_size : Handler::max_string_size; |
1138 | 93.8k | 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 | 93.8k | 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 | 93.8k | detail::clipped_const_stream cs(p, end_); |
1161 | 93.8k | cs.clip(temp.max_size()); |
1162 | | |
1163 | 93.8k | if(! stack_empty && ! st_.empty()) |
1164 | 175 | { |
1165 | 175 | state st; |
1166 | 175 | st_.pop(st); |
1167 | 175 | switch(st) |
1168 | 175 | { |
1169 | 0 | default: BOOST_JSON_UNREACHABLE(); |
1170 | 90 | case state::str3: goto do_str3; |
1171 | 15 | case state::str4: goto do_str4; |
1172 | 13 | case state::str5: goto do_str5; |
1173 | 10 | case state::str6: goto do_str6; |
1174 | 17 | case state::str7: goto do_str7; |
1175 | 7 | case state::sur1: goto do_sur1; |
1176 | 1 | case state::sur2: goto do_sur2; |
1177 | 1 | case state::sur3: goto do_sur3; |
1178 | 5 | case state::sur4: goto do_sur4; |
1179 | 6 | case state::sur5: goto do_sur5; |
1180 | 10 | case state::sur6: goto do_sur6; |
1181 | 175 | } |
1182 | 175 | } |
1183 | | |
1184 | 9.95M | while(true) |
1185 | 9.95M | { |
1186 | 9.95M | BOOST_ASSERT( temp.capacity() ); |
1187 | 9.95M | BOOST_ASSERT(*cs == '\\'); |
1188 | 9.95M | ++cs; |
1189 | 9.95M | do_str3: |
1190 | 9.95M | if(BOOST_JSON_UNLIKELY(! cs)) |
1191 | 1.50k | { |
1192 | 1.50k | if(BOOST_JSON_LIKELY(! temp.empty())) |
1193 | 1.29k | { |
1194 | 1.29k | BOOST_ASSERT(total <= max_size); |
1195 | 1.29k | if(BOOST_JSON_UNLIKELY( |
1196 | 1.29k | 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 | 1.29k | total += temp.size(); |
1203 | 1.29k | { |
1204 | 1.29k | bool r = is_key |
1205 | 1.29k | ? h_.on_key_part(temp.get(), total, ec_) |
1206 | 1.29k | : h_.on_string_part(temp.get(), total, ec_); |
1207 | | |
1208 | 1.29k | if(BOOST_JSON_UNLIKELY(!r)) |
1209 | 0 | { |
1210 | 0 | return fail(cs.begin()); |
1211 | 0 | } |
1212 | 1.29k | } |
1213 | 1.29k | temp.clear(); |
1214 | 1.29k | } |
1215 | 1.50k | cs.clip(temp.max_size()); |
1216 | 1.50k | if(BOOST_JSON_UNLIKELY(! cs)) |
1217 | 288 | return maybe_suspend(cs.begin(), state::str3); |
1218 | 1.50k | } |
1219 | 9.95M | switch(*cs) |
1220 | 9.95M | { |
1221 | 93 | default: |
1222 | 93 | { |
1223 | 93 | BOOST_STATIC_CONSTEXPR source_location loc |
1224 | 93 | = BOOST_CURRENT_LOCATION; |
1225 | 93 | return fail(cs.begin(), error::syntax, &loc); |
1226 | 0 | } |
1227 | 5.55k | case '\x22': // '"' |
1228 | 5.55k | temp.push_back('\x22'); |
1229 | 5.55k | ++cs; |
1230 | 5.55k | break; |
1231 | 9.19M | case '\\': |
1232 | 9.19M | temp.push_back('\\'); |
1233 | 9.19M | ++cs; |
1234 | 9.19M | break; |
1235 | 2.80k | case '/': |
1236 | 2.80k | temp.push_back('/'); |
1237 | 2.80k | ++cs; |
1238 | 2.80k | break; |
1239 | 409k | case 'b': |
1240 | 409k | temp.push_back('\x08'); |
1241 | 409k | ++cs; |
1242 | 409k | break; |
1243 | 3.27k | case 'f': |
1244 | 3.27k | temp.push_back('\x0c'); |
1245 | 3.27k | ++cs; |
1246 | 3.27k | break; |
1247 | 17.2k | case 'n': |
1248 | 17.2k | temp.push_back('\x0a'); |
1249 | 17.2k | ++cs; |
1250 | 17.2k | break; |
1251 | 1.98k | case 'r': |
1252 | 1.98k | temp.push_back('\x0d'); |
1253 | 1.98k | ++cs; |
1254 | 1.98k | break; |
1255 | 2.72k | case 't': |
1256 | 2.72k | temp.push_back('\x09'); |
1257 | 2.72k | ++cs; |
1258 | 2.72k | break; |
1259 | 319k | case 'u': |
1260 | | // utf16 escape |
1261 | | // |
1262 | | // fast path only when the buffer |
1263 | | // is large enough for 2 surrogates |
1264 | 319k | if(BOOST_JSON_LIKELY(cs.remain() > 10)) |
1265 | 316k | { |
1266 | | // KRYSTIAN TODO: this could be done |
1267 | | // with fewer instructions |
1268 | 316k | digit = detail::load_little_endian<4>( |
1269 | 316k | cs.begin() + 1); |
1270 | 316k | int d4 = detail::hex_digit(static_cast< |
1271 | 316k | unsigned char>(digit >> 24)); |
1272 | 316k | int d3 = detail::hex_digit(static_cast< |
1273 | 316k | unsigned char>(digit >> 16)); |
1274 | 316k | int d2 = detail::hex_digit(static_cast< |
1275 | 316k | unsigned char>(digit >> 8)); |
1276 | 316k | int d1 = detail::hex_digit(static_cast< |
1277 | 316k | unsigned char>(digit)); |
1278 | 316k | if(BOOST_JSON_UNLIKELY( |
1279 | 316k | (d1 | d2 | d3 | d4) == -1)) |
1280 | 215 | { |
1281 | 215 | if(d1 != -1) |
1282 | 80 | ++cs; |
1283 | 215 | if(d2 != -1) |
1284 | 49 | ++cs; |
1285 | 215 | if(d3 != -1) |
1286 | 38 | ++cs; |
1287 | 215 | BOOST_STATIC_CONSTEXPR source_location loc |
1288 | 215 | = BOOST_CURRENT_LOCATION; |
1289 | 215 | return fail(cs.begin(), error::expected_hex_digit, &loc); |
1290 | 215 | } |
1291 | | // 32 bit unicode scalar value |
1292 | 315k | unsigned u1 = |
1293 | 315k | (d1 << 12) + (d2 << 8) + |
1294 | 315k | (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 | 315k | if(BOOST_JSON_LIKELY( |
1300 | 315k | u1 < 0xd800 || u1 > 0xdfff)) |
1301 | 264k | { |
1302 | 264k | cs += 5; |
1303 | 264k | temp.append_utf8(u1); |
1304 | 264k | break; |
1305 | 264k | } |
1306 | 51.5k | if(BOOST_JSON_UNLIKELY(u1 > 0xdbff)) |
1307 | 21 | { |
1308 | | // If it's an illegal leading surrogate and |
1309 | | // the parser does not allow it, return an error. |
1310 | 21 | if(!allow_bad_utf16) |
1311 | 21 | { |
1312 | 21 | BOOST_STATIC_CONSTEXPR source_location loc |
1313 | 21 | = BOOST_CURRENT_LOCATION; |
1314 | 21 | return fail(cs.begin(), error::illegal_leading_surrogate, |
1315 | 21 | &loc); |
1316 | 21 | } |
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 | 21 | } |
1325 | 51.5k | 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 | 51.5k | if(BOOST_JSON_UNLIKELY(*cs != '\\')) |
1330 | 25 | { |
1331 | | // If the next character is not a backslash and |
1332 | | // the parser does not allow it, return a syntax error. |
1333 | 25 | if(!allow_bad_utf16) |
1334 | 25 | { |
1335 | 25 | BOOST_STATIC_CONSTEXPR source_location loc |
1336 | 25 | = BOOST_CURRENT_LOCATION; |
1337 | 25 | return fail(cs.begin(), error::syntax, &loc); |
1338 | 25 | } |
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 | 25 | } |
1347 | 51.5k | ++cs; |
1348 | 51.5k | if(BOOST_JSON_UNLIKELY(*cs != 'u')) |
1349 | 26 | { |
1350 | 26 | if (!allow_bad_utf16) |
1351 | 26 | { |
1352 | 26 | BOOST_STATIC_CONSTEXPR source_location loc |
1353 | 26 | = BOOST_CURRENT_LOCATION; |
1354 | 26 | return fail(cs.begin(), error::syntax, &loc); |
1355 | 26 | } |
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 | 26 | } |
1364 | 51.4k | ++cs; |
1365 | 51.4k | digit = detail::load_little_endian<4>(cs.begin()); |
1366 | 51.4k | d4 = detail::hex_digit(static_cast< |
1367 | 51.4k | unsigned char>(digit >> 24)); |
1368 | 51.4k | d3 = detail::hex_digit(static_cast< |
1369 | 51.4k | unsigned char>(digit >> 16)); |
1370 | 51.4k | d2 = detail::hex_digit(static_cast< |
1371 | 51.4k | unsigned char>(digit >> 8)); |
1372 | 51.4k | d1 = detail::hex_digit(static_cast< |
1373 | 51.4k | unsigned char>(digit)); |
1374 | 51.4k | if(BOOST_JSON_UNLIKELY( |
1375 | 51.4k | (d1 | d2 | d3 | d4) == -1)) |
1376 | 199 | { |
1377 | 199 | if(d1 != -1) |
1378 | 59 | ++cs; |
1379 | 199 | if(d2 != -1) |
1380 | 43 | ++cs; |
1381 | 199 | if(d3 != -1) |
1382 | 34 | ++cs; |
1383 | 199 | BOOST_STATIC_CONSTEXPR source_location loc |
1384 | 199 | = BOOST_CURRENT_LOCATION; |
1385 | 199 | return fail(cs.begin(), error::expected_hex_digit, &loc); |
1386 | 199 | } |
1387 | 51.2k | unsigned u2 = |
1388 | 51.2k | (d1 << 12) + (d2 << 8) + |
1389 | 51.2k | (d3 << 4) + d4; |
1390 | | // Check if the second code point is a valid trailing surrogate. |
1391 | | // Valid trailing surrogates are [DC00, DFFF] |
1392 | 51.2k | if(BOOST_JSON_UNLIKELY( |
1393 | 51.2k | u2 < 0xdc00 || u2 > 0xdfff)) |
1394 | 50 | { |
1395 | | // If not valid and the parser does not allow it, return an error. |
1396 | 50 | if(!allow_bad_utf16) |
1397 | 50 | { |
1398 | 50 | BOOST_STATIC_CONSTEXPR source_location loc |
1399 | 50 | = BOOST_CURRENT_LOCATION; |
1400 | 50 | return fail(cs.begin(), error::illegal_trailing_surrogate, |
1401 | 50 | &loc); |
1402 | 50 | } |
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 | 51.2k | cs += 4; |
1423 | | // Calculate the Unicode code point from the surrogate pair and |
1424 | | // append the UTF-8 representation. |
1425 | 51.2k | unsigned cp = |
1426 | 51.2k | ((u1 - 0xd800) << 10) + |
1427 | 51.2k | ((u2 - 0xdc00)) + |
1428 | 51.2k | 0x10000; |
1429 | | // utf-16 surrogate pair |
1430 | 51.2k | temp.append_utf8(cp); |
1431 | 51.2k | break; |
1432 | 51.2k | } |
1433 | | // flush |
1434 | 3.41k | if(BOOST_JSON_LIKELY(! temp.empty())) |
1435 | 2.82k | { |
1436 | 2.82k | BOOST_ASSERT(total <= max_size); |
1437 | 2.82k | if(BOOST_JSON_UNLIKELY( |
1438 | 2.82k | 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 | 2.82k | total += temp.size(); |
1445 | 2.82k | { |
1446 | 2.82k | bool r = is_key |
1447 | 2.82k | ? h_.on_key_part(temp.get(), total, ec_) |
1448 | 2.82k | : h_.on_string_part(temp.get(), total, ec_); |
1449 | | |
1450 | 2.82k | if(BOOST_JSON_UNLIKELY(!r)) |
1451 | 0 | { |
1452 | 0 | return fail(cs.begin()); |
1453 | 0 | } |
1454 | 2.82k | } |
1455 | 2.82k | temp.clear(); |
1456 | 2.82k | cs.clip(temp.max_size()); |
1457 | 2.82k | } |
1458 | 3.41k | ++cs; |
1459 | | // utf-16 escape |
1460 | 3.43k | do_str4: |
1461 | 3.43k | if(BOOST_JSON_UNLIKELY(! cs)) |
1462 | 49 | return maybe_suspend(cs.begin(), state::str4); |
1463 | 3.38k | digit = detail::hex_digit(*cs); |
1464 | 3.38k | if(BOOST_JSON_UNLIKELY(digit == -1)) |
1465 | 52 | { |
1466 | 52 | BOOST_STATIC_CONSTEXPR source_location loc |
1467 | 52 | = BOOST_CURRENT_LOCATION; |
1468 | 52 | return fail(cs.begin(), error::expected_hex_digit, &loc); |
1469 | 52 | } |
1470 | 3.33k | ++cs; |
1471 | 3.33k | u1_ = digit << 12; |
1472 | 3.34k | do_str5: |
1473 | 3.34k | if(BOOST_JSON_UNLIKELY(! cs)) |
1474 | 46 | return maybe_suspend(cs.begin(), state::str5); |
1475 | 3.29k | digit = detail::hex_digit(*cs); |
1476 | 3.29k | if(BOOST_JSON_UNLIKELY(digit == -1)) |
1477 | 51 | { |
1478 | 51 | BOOST_STATIC_CONSTEXPR source_location loc |
1479 | 51 | = BOOST_CURRENT_LOCATION; |
1480 | 51 | return fail(cs.begin(), error::expected_hex_digit, &loc); |
1481 | 51 | } |
1482 | 3.24k | ++cs; |
1483 | 3.24k | u1_ += digit << 8; |
1484 | 3.25k | do_str6: |
1485 | 3.25k | if(BOOST_JSON_UNLIKELY(! cs)) |
1486 | 31 | return maybe_suspend(cs.begin(), state::str6); |
1487 | 3.22k | digit = detail::hex_digit(*cs); |
1488 | 3.22k | if(BOOST_JSON_UNLIKELY(digit == -1)) |
1489 | 30 | { |
1490 | 30 | BOOST_STATIC_CONSTEXPR source_location loc |
1491 | 30 | = BOOST_CURRENT_LOCATION; |
1492 | 30 | return fail(cs.begin(), error::expected_hex_digit, &loc); |
1493 | 30 | } |
1494 | 3.19k | ++cs; |
1495 | 3.19k | u1_ += digit << 4; |
1496 | 3.21k | do_str7: |
1497 | 3.21k | if(BOOST_JSON_UNLIKELY(! cs)) |
1498 | 50 | return maybe_suspend(cs.begin(), state::str7); |
1499 | 3.16k | digit = detail::hex_digit(*cs); |
1500 | 3.16k | if(BOOST_JSON_UNLIKELY(digit == -1)) |
1501 | 42 | { |
1502 | 42 | BOOST_STATIC_CONSTEXPR source_location loc |
1503 | 42 | = BOOST_CURRENT_LOCATION; |
1504 | 42 | return fail(cs.begin(), error::expected_hex_digit, &loc); |
1505 | 42 | } |
1506 | 3.12k | ++cs; |
1507 | 3.12k | u1_ += digit; |
1508 | 3.12k | if(BOOST_JSON_LIKELY( |
1509 | 3.12k | u1_ < 0xd800 || u1_ > 0xdfff)) |
1510 | 1.66k | { |
1511 | 1.66k | BOOST_ASSERT(temp.empty()); |
1512 | | // utf-8 codepoint |
1513 | 1.66k | temp.append_utf8(u1_); |
1514 | 1.66k | break; |
1515 | 1.66k | } |
1516 | 1.45k | if(BOOST_JSON_UNLIKELY(u1_ > 0xdbff)) |
1517 | 27 | { |
1518 | | // If it's an illegal leading surrogate and |
1519 | | // the parser does not allow it, return an error. |
1520 | 27 | if(!allow_bad_utf16) |
1521 | 27 | { |
1522 | 27 | BOOST_STATIC_CONSTEXPR source_location loc |
1523 | 27 | = BOOST_CURRENT_LOCATION; |
1524 | 27 | return fail(cs.begin(), error::illegal_leading_surrogate, &loc); |
1525 | 27 | } |
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 | 27 | } |
1534 | 1.43k | do_sur1: |
1535 | 1.43k | if(BOOST_JSON_UNLIKELY(! cs)) |
1536 | 28 | return maybe_suspend(cs.begin(), state::sur1); |
1537 | 1.41k | if(BOOST_JSON_UNLIKELY(*cs != '\\')) |
1538 | 18 | { |
1539 | | // If the next character is not a backslash and |
1540 | | // the parser does not allow it, return a syntax error. |
1541 | 18 | if(!allow_bad_utf16) |
1542 | 18 | { |
1543 | 18 | BOOST_STATIC_CONSTEXPR source_location loc |
1544 | 18 | = BOOST_CURRENT_LOCATION; |
1545 | 18 | return fail(cs.begin(), error::syntax, &loc); |
1546 | 18 | } |
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 | 18 | } |
1555 | 1.39k | ++cs; |
1556 | 1.39k | do_sur2: |
1557 | 1.39k | if(BOOST_JSON_UNLIKELY(! cs)) |
1558 | 4 | return maybe_suspend(cs.begin(), state::sur2); |
1559 | 1.39k | if(BOOST_JSON_UNLIKELY(*cs != 'u')) |
1560 | 21 | { |
1561 | 21 | if (!allow_bad_utf16) |
1562 | 21 | { |
1563 | 21 | BOOST_STATIC_CONSTEXPR source_location loc |
1564 | 21 | = BOOST_CURRENT_LOCATION; |
1565 | 21 | return fail(cs.begin(), error::syntax, &loc); |
1566 | 21 | } |
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 | 21 | } |
1575 | 1.36k | ++cs; |
1576 | 1.37k | do_sur3: |
1577 | 1.37k | if(BOOST_JSON_UNLIKELY(! cs)) |
1578 | 7 | return maybe_suspend(cs.begin(), state::sur3); |
1579 | 1.36k | digit = detail::hex_digit(*cs); |
1580 | 1.36k | if(BOOST_JSON_UNLIKELY(digit == -1)) |
1581 | 26 | { |
1582 | 26 | BOOST_STATIC_CONSTEXPR source_location loc |
1583 | 26 | = BOOST_CURRENT_LOCATION; |
1584 | 26 | return fail(cs.begin(), error::expected_hex_digit, &loc); |
1585 | 26 | } |
1586 | 1.33k | ++cs; |
1587 | 1.33k | u2_ = digit << 12; |
1588 | 1.34k | do_sur4: |
1589 | 1.34k | if(BOOST_JSON_UNLIKELY(! cs)) |
1590 | 18 | return maybe_suspend(cs.begin(), state::sur4); |
1591 | 1.32k | digit = detail::hex_digit(*cs); |
1592 | 1.32k | if(BOOST_JSON_UNLIKELY(digit == -1)) |
1593 | 24 | { |
1594 | 24 | BOOST_STATIC_CONSTEXPR source_location loc |
1595 | 24 | = BOOST_CURRENT_LOCATION; |
1596 | 24 | return fail(cs.begin(), error::expected_hex_digit, &loc); |
1597 | 24 | } |
1598 | 1.30k | ++cs; |
1599 | 1.30k | u2_ += digit << 8; |
1600 | 1.30k | do_sur5: |
1601 | 1.30k | if(BOOST_JSON_UNLIKELY(! cs)) |
1602 | 19 | return maybe_suspend(cs.begin(), state::sur5); |
1603 | 1.28k | digit = detail::hex_digit(*cs); |
1604 | 1.28k | if(BOOST_JSON_UNLIKELY(digit == -1)) |
1605 | 36 | { |
1606 | 36 | BOOST_STATIC_CONSTEXPR source_location loc |
1607 | 36 | = BOOST_CURRENT_LOCATION; |
1608 | 36 | return fail(cs.begin(), error::expected_hex_digit, &loc); |
1609 | 36 | } |
1610 | 1.25k | ++cs; |
1611 | 1.25k | u2_ += digit << 4; |
1612 | 1.26k | do_sur6: |
1613 | 1.26k | if(BOOST_JSON_UNLIKELY(! cs)) |
1614 | 34 | return maybe_suspend(cs.begin(), state::sur6); |
1615 | 1.22k | digit = detail::hex_digit(*cs); |
1616 | 1.22k | if(BOOST_JSON_UNLIKELY(digit == -1)) |
1617 | 18 | { |
1618 | 18 | BOOST_STATIC_CONSTEXPR source_location loc |
1619 | 18 | = BOOST_CURRENT_LOCATION; |
1620 | 18 | return fail(cs.begin(), error::expected_hex_digit, &loc); |
1621 | 18 | } |
1622 | 1.20k | ++cs; |
1623 | 1.20k | u2_ += digit; |
1624 | | // Check if the second code point is a valid trailing surrogate. |
1625 | | // Valid trailing surrogates are [DC00, DFFF] |
1626 | 1.20k | if(BOOST_JSON_UNLIKELY( |
1627 | 1.20k | u2_ < 0xdc00 || u2_ > 0xdfff)) |
1628 | 33 | { |
1629 | | // If not valid and the parser does not allow it, return an error. |
1630 | 33 | if(!allow_bad_utf16) |
1631 | 33 | { |
1632 | 33 | BOOST_STATIC_CONSTEXPR source_location loc |
1633 | 33 | = BOOST_CURRENT_LOCATION; |
1634 | 33 | return fail(cs.begin(), error::illegal_trailing_surrogate, &loc); |
1635 | 33 | } |
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 | 1.17k | unsigned cp = |
1657 | 1.17k | ((u1_ - 0xd800) << 10) + |
1658 | 1.17k | ((u2_ - 0xdc00)) + |
1659 | 1.17k | 0x10000; |
1660 | | // utf-16 surrogate pair |
1661 | 1.17k | temp.append_utf8(cp); |
1662 | 9.95M | } |
1663 | | |
1664 | | // flush |
1665 | 9.95M | if(BOOST_JSON_UNLIKELY( !cs ) || *cs != '\\') |
1666 | 92.2k | break; |
1667 | 9.95M | } |
1668 | | |
1669 | 92.2k | if(BOOST_JSON_LIKELY( temp.size() )) |
1670 | 92.2k | { |
1671 | 92.2k | BOOST_ASSERT(total <= max_size); |
1672 | 92.2k | 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 | 92.2k | total += temp.size(); |
1680 | 92.2k | bool const r = is_key |
1681 | 92.2k | ? h_.on_key_part(temp.get(), total, ec_) |
1682 | 92.2k | : h_.on_string_part(temp.get(), total, ec_); |
1683 | 92.2k | if(BOOST_JSON_UNLIKELY( !r )) |
1684 | 0 | return fail( cs.begin() ); |
1685 | 92.2k | } |
1686 | | |
1687 | 92.2k | return cs.begin(); |
1688 | 92.2k | } char const* boost::json::basic_parser<boost::json::detail::handler>::parse_escaped<true>(char const*, unsigned long&, std::__1::integral_constant<bool, true>, bool, bool) Line | Count | Source | 1132 | 93.6k | { | 1133 | 93.6k | constexpr unsigned urc = 0xFFFD; // Unicode replacement character | 1134 | 93.6k | auto const ev_too_large = is_key? | 1135 | 75.9k | error::key_too_large : error::string_too_large; | 1136 | 93.6k | auto const max_size = is_key? | 1137 | 75.9k | Handler::max_key_size : Handler::max_string_size; | 1138 | 93.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 | 93.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 | 93.6k | detail::clipped_const_stream cs(p, end_); | 1161 | 93.6k | cs.clip(temp.max_size()); | 1162 | | | 1163 | 93.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 | 9.95M | while(true) | 1185 | 9.95M | { | 1186 | 9.95M | BOOST_ASSERT( temp.capacity() ); | 1187 | 9.95M | BOOST_ASSERT(*cs == '\\'); | 1188 | 9.95M | ++cs; | 1189 | 9.95M | do_str3: | 1190 | 9.95M | if(BOOST_JSON_UNLIKELY(! cs)) | 1191 | 1.41k | { | 1192 | 1.41k | if(BOOST_JSON_LIKELY(! temp.empty())) | 1193 | 1.29k | { | 1194 | 1.29k | BOOST_ASSERT(total <= max_size); | 1195 | 1.29k | if(BOOST_JSON_UNLIKELY( | 1196 | 1.29k | 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 | 1.29k | total += temp.size(); | 1203 | 1.29k | { | 1204 | 1.29k | bool r = is_key | 1205 | 1.29k | ? h_.on_key_part(temp.get(), total, ec_) | 1206 | 1.29k | : h_.on_string_part(temp.get(), total, ec_); | 1207 | | | 1208 | 1.29k | if(BOOST_JSON_UNLIKELY(!r)) | 1209 | 0 | { | 1210 | 0 | return fail(cs.begin()); | 1211 | 0 | } | 1212 | 1.29k | } | 1213 | 1.29k | temp.clear(); | 1214 | 1.29k | } | 1215 | 1.41k | cs.clip(temp.max_size()); | 1216 | 1.41k | if(BOOST_JSON_UNLIKELY(! cs)) | 1217 | 198 | return maybe_suspend(cs.begin(), state::str3); | 1218 | 1.41k | } | 1219 | 9.95M | switch(*cs) | 1220 | 9.95M | { | 1221 | 93 | default: | 1222 | 93 | { | 1223 | 93 | BOOST_STATIC_CONSTEXPR source_location loc | 1224 | 93 | = BOOST_CURRENT_LOCATION; | 1225 | 93 | return fail(cs.begin(), error::syntax, &loc); | 1226 | 0 | } | 1227 | 5.55k | case '\x22': // '"' | 1228 | 5.55k | temp.push_back('\x22'); | 1229 | 5.55k | ++cs; | 1230 | 5.55k | break; | 1231 | 9.19M | case '\\': | 1232 | 9.19M | temp.push_back('\\'); | 1233 | 9.19M | ++cs; | 1234 | 9.19M | break; | 1235 | 2.80k | case '/': | 1236 | 2.80k | temp.push_back('/'); | 1237 | 2.80k | ++cs; | 1238 | 2.80k | break; | 1239 | 409k | case 'b': | 1240 | 409k | temp.push_back('\x08'); | 1241 | 409k | ++cs; | 1242 | 409k | break; | 1243 | 3.27k | case 'f': | 1244 | 3.27k | temp.push_back('\x0c'); | 1245 | 3.27k | ++cs; | 1246 | 3.27k | break; | 1247 | 17.2k | case 'n': | 1248 | 17.2k | temp.push_back('\x0a'); | 1249 | 17.2k | ++cs; | 1250 | 17.2k | break; | 1251 | 1.98k | case 'r': | 1252 | 1.98k | temp.push_back('\x0d'); | 1253 | 1.98k | ++cs; | 1254 | 1.98k | break; | 1255 | 2.72k | case 't': | 1256 | 2.72k | temp.push_back('\x09'); | 1257 | 2.72k | ++cs; | 1258 | 2.72k | break; | 1259 | 319k | case 'u': | 1260 | | // utf16 escape | 1261 | | // | 1262 | | // fast path only when the buffer | 1263 | | // is large enough for 2 surrogates | 1264 | 319k | if(BOOST_JSON_LIKELY(cs.remain() > 10)) | 1265 | 316k | { | 1266 | | // KRYSTIAN TODO: this could be done | 1267 | | // with fewer instructions | 1268 | 316k | digit = detail::load_little_endian<4>( | 1269 | 316k | cs.begin() + 1); | 1270 | 316k | int d4 = detail::hex_digit(static_cast< | 1271 | 316k | unsigned char>(digit >> 24)); | 1272 | 316k | int d3 = detail::hex_digit(static_cast< | 1273 | 316k | unsigned char>(digit >> 16)); | 1274 | 316k | int d2 = detail::hex_digit(static_cast< | 1275 | 316k | unsigned char>(digit >> 8)); | 1276 | 316k | int d1 = detail::hex_digit(static_cast< | 1277 | 316k | unsigned char>(digit)); | 1278 | 316k | if(BOOST_JSON_UNLIKELY( | 1279 | 316k | (d1 | d2 | d3 | d4) == -1)) | 1280 | 215 | { | 1281 | 215 | if(d1 != -1) | 1282 | 80 | ++cs; | 1283 | 215 | if(d2 != -1) | 1284 | 49 | ++cs; | 1285 | 215 | if(d3 != -1) | 1286 | 38 | ++cs; | 1287 | 215 | BOOST_STATIC_CONSTEXPR source_location loc | 1288 | 215 | = BOOST_CURRENT_LOCATION; | 1289 | 215 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1290 | 215 | } | 1291 | | // 32 bit unicode scalar value | 1292 | 315k | unsigned u1 = | 1293 | 315k | (d1 << 12) + (d2 << 8) + | 1294 | 315k | (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 | 315k | if(BOOST_JSON_LIKELY( | 1300 | 315k | u1 < 0xd800 || u1 > 0xdfff)) | 1301 | 264k | { | 1302 | 264k | cs += 5; | 1303 | 264k | temp.append_utf8(u1); | 1304 | 264k | break; | 1305 | 264k | } | 1306 | 51.5k | if(BOOST_JSON_UNLIKELY(u1 > 0xdbff)) | 1307 | 21 | { | 1308 | | // If it's an illegal leading surrogate and | 1309 | | // the parser does not allow it, return an error. | 1310 | 21 | if(!allow_bad_utf16) | 1311 | 21 | { | 1312 | 21 | BOOST_STATIC_CONSTEXPR source_location loc | 1313 | 21 | = BOOST_CURRENT_LOCATION; | 1314 | 21 | return fail(cs.begin(), error::illegal_leading_surrogate, | 1315 | 21 | &loc); | 1316 | 21 | } | 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 | 21 | } | 1325 | 51.5k | 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 | 51.5k | if(BOOST_JSON_UNLIKELY(*cs != '\\')) | 1330 | 25 | { | 1331 | | // If the next character is not a backslash and | 1332 | | // the parser does not allow it, return a syntax error. | 1333 | 25 | if(!allow_bad_utf16) | 1334 | 25 | { | 1335 | 25 | BOOST_STATIC_CONSTEXPR source_location loc | 1336 | 25 | = BOOST_CURRENT_LOCATION; | 1337 | 25 | return fail(cs.begin(), error::syntax, &loc); | 1338 | 25 | } | 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 | 25 | } | 1347 | 51.5k | ++cs; | 1348 | 51.5k | if(BOOST_JSON_UNLIKELY(*cs != 'u')) | 1349 | 26 | { | 1350 | 26 | if (!allow_bad_utf16) | 1351 | 26 | { | 1352 | 26 | BOOST_STATIC_CONSTEXPR source_location loc | 1353 | 26 | = BOOST_CURRENT_LOCATION; | 1354 | 26 | return fail(cs.begin(), error::syntax, &loc); | 1355 | 26 | } | 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 | 26 | } | 1364 | 51.4k | ++cs; | 1365 | 51.4k | digit = detail::load_little_endian<4>(cs.begin()); | 1366 | 51.4k | d4 = detail::hex_digit(static_cast< | 1367 | 51.4k | unsigned char>(digit >> 24)); | 1368 | 51.4k | d3 = detail::hex_digit(static_cast< | 1369 | 51.4k | unsigned char>(digit >> 16)); | 1370 | 51.4k | d2 = detail::hex_digit(static_cast< | 1371 | 51.4k | unsigned char>(digit >> 8)); | 1372 | 51.4k | d1 = detail::hex_digit(static_cast< | 1373 | 51.4k | unsigned char>(digit)); | 1374 | 51.4k | if(BOOST_JSON_UNLIKELY( | 1375 | 51.4k | (d1 | d2 | d3 | d4) == -1)) | 1376 | 199 | { | 1377 | 199 | if(d1 != -1) | 1378 | 59 | ++cs; | 1379 | 199 | if(d2 != -1) | 1380 | 43 | ++cs; | 1381 | 199 | if(d3 != -1) | 1382 | 34 | ++cs; | 1383 | 199 | BOOST_STATIC_CONSTEXPR source_location loc | 1384 | 199 | = BOOST_CURRENT_LOCATION; | 1385 | 199 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1386 | 199 | } | 1387 | 51.2k | unsigned u2 = | 1388 | 51.2k | (d1 << 12) + (d2 << 8) + | 1389 | 51.2k | (d3 << 4) + d4; | 1390 | | // Check if the second code point is a valid trailing surrogate. | 1391 | | // Valid trailing surrogates are [DC00, DFFF] | 1392 | 51.2k | if(BOOST_JSON_UNLIKELY( | 1393 | 51.2k | u2 < 0xdc00 || u2 > 0xdfff)) | 1394 | 50 | { | 1395 | | // If not valid and the parser does not allow it, return an error. | 1396 | 50 | if(!allow_bad_utf16) | 1397 | 50 | { | 1398 | 50 | BOOST_STATIC_CONSTEXPR source_location loc | 1399 | 50 | = BOOST_CURRENT_LOCATION; | 1400 | 50 | return fail(cs.begin(), error::illegal_trailing_surrogate, | 1401 | 50 | &loc); | 1402 | 50 | } | 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 | 51.2k | cs += 4; | 1423 | | // Calculate the Unicode code point from the surrogate pair and | 1424 | | // append the UTF-8 representation. | 1425 | 51.2k | unsigned cp = | 1426 | 51.2k | ((u1 - 0xd800) << 10) + | 1427 | 51.2k | ((u2 - 0xdc00)) + | 1428 | 51.2k | 0x10000; | 1429 | | // utf-16 surrogate pair | 1430 | 51.2k | temp.append_utf8(cp); | 1431 | 51.2k | break; | 1432 | 51.2k | } | 1433 | | // flush | 1434 | 3.41k | if(BOOST_JSON_LIKELY(! temp.empty())) | 1435 | 2.82k | { | 1436 | 2.82k | BOOST_ASSERT(total <= max_size); | 1437 | 2.82k | if(BOOST_JSON_UNLIKELY( | 1438 | 2.82k | 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 | 2.82k | total += temp.size(); | 1445 | 2.82k | { | 1446 | 2.82k | bool r = is_key | 1447 | 2.82k | ? h_.on_key_part(temp.get(), total, ec_) | 1448 | 2.82k | : h_.on_string_part(temp.get(), total, ec_); | 1449 | | | 1450 | 2.82k | if(BOOST_JSON_UNLIKELY(!r)) | 1451 | 0 | { | 1452 | 0 | return fail(cs.begin()); | 1453 | 0 | } | 1454 | 2.82k | } | 1455 | 2.82k | temp.clear(); | 1456 | 2.82k | cs.clip(temp.max_size()); | 1457 | 2.82k | } | 1458 | 3.41k | ++cs; | 1459 | | // utf-16 escape | 1460 | 3.41k | do_str4: | 1461 | 3.41k | if(BOOST_JSON_UNLIKELY(! cs)) | 1462 | 34 | return maybe_suspend(cs.begin(), state::str4); | 1463 | 3.38k | digit = detail::hex_digit(*cs); | 1464 | 3.38k | if(BOOST_JSON_UNLIKELY(digit == -1)) | 1465 | 52 | { | 1466 | 52 | BOOST_STATIC_CONSTEXPR source_location loc | 1467 | 52 | = BOOST_CURRENT_LOCATION; | 1468 | 52 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1469 | 52 | } | 1470 | 3.33k | ++cs; | 1471 | 3.33k | u1_ = digit << 12; | 1472 | 3.33k | do_str5: | 1473 | 3.33k | if(BOOST_JSON_UNLIKELY(! cs)) | 1474 | 33 | return maybe_suspend(cs.begin(), state::str5); | 1475 | 3.29k | digit = detail::hex_digit(*cs); | 1476 | 3.29k | if(BOOST_JSON_UNLIKELY(digit == -1)) | 1477 | 51 | { | 1478 | 51 | BOOST_STATIC_CONSTEXPR source_location loc | 1479 | 51 | = BOOST_CURRENT_LOCATION; | 1480 | 51 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1481 | 51 | } | 1482 | 3.24k | ++cs; | 1483 | 3.24k | u1_ += digit << 8; | 1484 | 3.24k | do_str6: | 1485 | 3.24k | if(BOOST_JSON_UNLIKELY(! cs)) | 1486 | 21 | return maybe_suspend(cs.begin(), state::str6); | 1487 | 3.22k | digit = detail::hex_digit(*cs); | 1488 | 3.22k | if(BOOST_JSON_UNLIKELY(digit == -1)) | 1489 | 30 | { | 1490 | 30 | BOOST_STATIC_CONSTEXPR source_location loc | 1491 | 30 | = BOOST_CURRENT_LOCATION; | 1492 | 30 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1493 | 30 | } | 1494 | 3.19k | ++cs; | 1495 | 3.19k | u1_ += digit << 4; | 1496 | 3.19k | do_str7: | 1497 | 3.19k | if(BOOST_JSON_UNLIKELY(! cs)) | 1498 | 33 | return maybe_suspend(cs.begin(), state::str7); | 1499 | 3.16k | digit = detail::hex_digit(*cs); | 1500 | 3.16k | if(BOOST_JSON_UNLIKELY(digit == -1)) | 1501 | 42 | { | 1502 | 42 | BOOST_STATIC_CONSTEXPR source_location loc | 1503 | 42 | = BOOST_CURRENT_LOCATION; | 1504 | 42 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1505 | 42 | } | 1506 | 3.12k | ++cs; | 1507 | 3.12k | u1_ += digit; | 1508 | 3.12k | if(BOOST_JSON_LIKELY( | 1509 | 3.12k | u1_ < 0xd800 || u1_ > 0xdfff)) | 1510 | 1.66k | { | 1511 | 1.66k | BOOST_ASSERT(temp.empty()); | 1512 | | // utf-8 codepoint | 1513 | 1.66k | temp.append_utf8(u1_); | 1514 | 1.66k | break; | 1515 | 1.66k | } | 1516 | 1.45k | if(BOOST_JSON_UNLIKELY(u1_ > 0xdbff)) | 1517 | 27 | { | 1518 | | // If it's an illegal leading surrogate and | 1519 | | // the parser does not allow it, return an error. | 1520 | 27 | if(!allow_bad_utf16) | 1521 | 27 | { | 1522 | 27 | BOOST_STATIC_CONSTEXPR source_location loc | 1523 | 27 | = BOOST_CURRENT_LOCATION; | 1524 | 27 | return fail(cs.begin(), error::illegal_leading_surrogate, &loc); | 1525 | 27 | } | 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 | 27 | } | 1534 | 1.43k | do_sur1: | 1535 | 1.43k | if(BOOST_JSON_UNLIKELY(! cs)) | 1536 | 21 | return maybe_suspend(cs.begin(), state::sur1); | 1537 | 1.41k | if(BOOST_JSON_UNLIKELY(*cs != '\\')) | 1538 | 18 | { | 1539 | | // If the next character is not a backslash and | 1540 | | // the parser does not allow it, return a syntax error. | 1541 | 18 | if(!allow_bad_utf16) | 1542 | 18 | { | 1543 | 18 | BOOST_STATIC_CONSTEXPR source_location loc | 1544 | 18 | = BOOST_CURRENT_LOCATION; | 1545 | 18 | return fail(cs.begin(), error::syntax, &loc); | 1546 | 18 | } | 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 | 18 | } | 1555 | 1.39k | ++cs; | 1556 | 1.39k | do_sur2: | 1557 | 1.39k | if(BOOST_JSON_UNLIKELY(! cs)) | 1558 | 3 | return maybe_suspend(cs.begin(), state::sur2); | 1559 | 1.39k | if(BOOST_JSON_UNLIKELY(*cs != 'u')) | 1560 | 21 | { | 1561 | 21 | if (!allow_bad_utf16) | 1562 | 21 | { | 1563 | 21 | BOOST_STATIC_CONSTEXPR source_location loc | 1564 | 21 | = BOOST_CURRENT_LOCATION; | 1565 | 21 | return fail(cs.begin(), error::syntax, &loc); | 1566 | 21 | } | 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 | 21 | } | 1575 | 1.36k | ++cs; | 1576 | 1.36k | do_sur3: | 1577 | 1.36k | if(BOOST_JSON_UNLIKELY(! cs)) | 1578 | 6 | return maybe_suspend(cs.begin(), state::sur3); | 1579 | 1.36k | digit = detail::hex_digit(*cs); | 1580 | 1.36k | if(BOOST_JSON_UNLIKELY(digit == -1)) | 1581 | 26 | { | 1582 | 26 | BOOST_STATIC_CONSTEXPR source_location loc | 1583 | 26 | = BOOST_CURRENT_LOCATION; | 1584 | 26 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1585 | 26 | } | 1586 | 1.33k | ++cs; | 1587 | 1.33k | u2_ = digit << 12; | 1588 | 1.33k | do_sur4: | 1589 | 1.33k | if(BOOST_JSON_UNLIKELY(! cs)) | 1590 | 13 | return maybe_suspend(cs.begin(), state::sur4); | 1591 | 1.32k | digit = detail::hex_digit(*cs); | 1592 | 1.32k | if(BOOST_JSON_UNLIKELY(digit == -1)) | 1593 | 24 | { | 1594 | 24 | BOOST_STATIC_CONSTEXPR source_location loc | 1595 | 24 | = BOOST_CURRENT_LOCATION; | 1596 | 24 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1597 | 24 | } | 1598 | 1.30k | ++cs; | 1599 | 1.30k | u2_ += digit << 8; | 1600 | 1.30k | do_sur5: | 1601 | 1.30k | if(BOOST_JSON_UNLIKELY(! cs)) | 1602 | 13 | return maybe_suspend(cs.begin(), state::sur5); | 1603 | 1.28k | digit = detail::hex_digit(*cs); | 1604 | 1.28k | if(BOOST_JSON_UNLIKELY(digit == -1)) | 1605 | 36 | { | 1606 | 36 | BOOST_STATIC_CONSTEXPR source_location loc | 1607 | 36 | = BOOST_CURRENT_LOCATION; | 1608 | 36 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1609 | 36 | } | 1610 | 1.25k | ++cs; | 1611 | 1.25k | u2_ += digit << 4; | 1612 | 1.25k | do_sur6: | 1613 | 1.25k | if(BOOST_JSON_UNLIKELY(! cs)) | 1614 | 24 | return maybe_suspend(cs.begin(), state::sur6); | 1615 | 1.22k | digit = detail::hex_digit(*cs); | 1616 | 1.22k | if(BOOST_JSON_UNLIKELY(digit == -1)) | 1617 | 18 | { | 1618 | 18 | BOOST_STATIC_CONSTEXPR source_location loc | 1619 | 18 | = BOOST_CURRENT_LOCATION; | 1620 | 18 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1621 | 18 | } | 1622 | 1.20k | ++cs; | 1623 | 1.20k | u2_ += digit; | 1624 | | // Check if the second code point is a valid trailing surrogate. | 1625 | | // Valid trailing surrogates are [DC00, DFFF] | 1626 | 1.20k | if(BOOST_JSON_UNLIKELY( | 1627 | 1.20k | u2_ < 0xdc00 || u2_ > 0xdfff)) | 1628 | 33 | { | 1629 | | // If not valid and the parser does not allow it, return an error. | 1630 | 33 | if(!allow_bad_utf16) | 1631 | 33 | { | 1632 | 33 | BOOST_STATIC_CONSTEXPR source_location loc | 1633 | 33 | = BOOST_CURRENT_LOCATION; | 1634 | 33 | return fail(cs.begin(), error::illegal_trailing_surrogate, &loc); | 1635 | 33 | } | 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 | 1.17k | unsigned cp = | 1657 | 1.17k | ((u1_ - 0xd800) << 10) + | 1658 | 1.17k | ((u2_ - 0xdc00)) + | 1659 | 1.17k | 0x10000; | 1660 | | // utf-16 surrogate pair | 1661 | 1.17k | temp.append_utf8(cp); | 1662 | 9.95M | } | 1663 | | | 1664 | | // flush | 1665 | 9.95M | if(BOOST_JSON_UNLIKELY( !cs ) || *cs != '\\') | 1666 | 92.2k | break; | 1667 | 9.95M | } | 1668 | | | 1669 | 92.2k | if(BOOST_JSON_LIKELY( temp.size() )) | 1670 | 92.2k | { | 1671 | 92.2k | BOOST_ASSERT(total <= max_size); | 1672 | 92.2k | 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 | 92.2k | total += temp.size(); | 1680 | 92.2k | bool const r = is_key | 1681 | 92.2k | ? h_.on_key_part(temp.get(), total, ec_) | 1682 | 92.2k | : h_.on_string_part(temp.get(), total, ec_); | 1683 | 92.2k | if(BOOST_JSON_UNLIKELY( !r )) | 1684 | 0 | return fail( cs.begin() ); | 1685 | 92.2k | } | 1686 | | | 1687 | 92.2k | return cs.begin(); | 1688 | 92.2k | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::parse_escaped<false>(char const*, unsigned long&, std::__1::integral_constant<bool, false>, bool, bool) Line | Count | Source | 1132 | 175 | { | 1133 | 175 | constexpr unsigned urc = 0xFFFD; // Unicode replacement character | 1134 | 175 | auto const ev_too_large = is_key? | 1135 | 129 | error::key_too_large : error::string_too_large; | 1136 | 175 | auto const max_size = is_key? | 1137 | 129 | Handler::max_key_size : Handler::max_string_size; | 1138 | 175 | 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 | 175 | 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 | 175 | detail::clipped_const_stream cs(p, end_); | 1161 | 175 | cs.clip(temp.max_size()); | 1162 | | | 1163 | 175 | if(! stack_empty && ! st_.empty()) | 1164 | 175 | { | 1165 | 175 | state st; | 1166 | 175 | st_.pop(st); | 1167 | 175 | switch(st) | 1168 | 175 | { | 1169 | 0 | default: BOOST_JSON_UNREACHABLE(); | 1170 | 90 | case state::str3: goto do_str3; | 1171 | 15 | case state::str4: goto do_str4; | 1172 | 13 | case state::str5: goto do_str5; | 1173 | 10 | case state::str6: goto do_str6; | 1174 | 17 | case state::str7: goto do_str7; | 1175 | 7 | case state::sur1: goto do_sur1; | 1176 | 1 | case state::sur2: goto do_sur2; | 1177 | 1 | case state::sur3: goto do_sur3; | 1178 | 5 | case state::sur4: goto do_sur4; | 1179 | 6 | case state::sur5: goto do_sur5; | 1180 | 10 | case state::sur6: goto do_sur6; | 1181 | 175 | } | 1182 | 175 | } | 1183 | | | 1184 | 0 | while(true) | 1185 | 0 | { | 1186 | 0 | BOOST_ASSERT( temp.capacity() ); | 1187 | 0 | BOOST_ASSERT(*cs == '\\'); | 1188 | 0 | ++cs; | 1189 | 90 | do_str3: | 1190 | 90 | if(BOOST_JSON_UNLIKELY(! cs)) | 1191 | 90 | { | 1192 | 90 | if(BOOST_JSON_LIKELY(! temp.empty())) | 1193 | 0 | { | 1194 | 0 | BOOST_ASSERT(total <= max_size); | 1195 | 0 | if(BOOST_JSON_UNLIKELY( | 1196 | 0 | 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 | 0 | total += temp.size(); | 1203 | 0 | { | 1204 | 0 | bool r = is_key | 1205 | 0 | ? h_.on_key_part(temp.get(), total, ec_) | 1206 | 0 | : h_.on_string_part(temp.get(), total, ec_); | 1207 | |
| 1208 | 0 | if(BOOST_JSON_UNLIKELY(!r)) | 1209 | 0 | { | 1210 | 0 | return fail(cs.begin()); | 1211 | 0 | } | 1212 | 0 | } | 1213 | 0 | temp.clear(); | 1214 | 0 | } | 1215 | 90 | cs.clip(temp.max_size()); | 1216 | 90 | if(BOOST_JSON_UNLIKELY(! cs)) | 1217 | 90 | return maybe_suspend(cs.begin(), state::str3); | 1218 | 90 | } | 1219 | 0 | switch(*cs) | 1220 | 0 | { | 1221 | 0 | default: | 1222 | 0 | { | 1223 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1224 | 0 | = BOOST_CURRENT_LOCATION; | 1225 | 0 | return fail(cs.begin(), error::syntax, &loc); | 1226 | 0 | } | 1227 | 0 | case '\x22': // '"' | 1228 | 0 | temp.push_back('\x22'); | 1229 | 0 | ++cs; | 1230 | 0 | break; | 1231 | 0 | case '\\': | 1232 | 0 | temp.push_back('\\'); | 1233 | 0 | ++cs; | 1234 | 0 | break; | 1235 | 0 | case '/': | 1236 | 0 | temp.push_back('/'); | 1237 | 0 | ++cs; | 1238 | 0 | break; | 1239 | 0 | case 'b': | 1240 | 0 | temp.push_back('\x08'); | 1241 | 0 | ++cs; | 1242 | 0 | break; | 1243 | 0 | case 'f': | 1244 | 0 | temp.push_back('\x0c'); | 1245 | 0 | ++cs; | 1246 | 0 | break; | 1247 | 0 | case 'n': | 1248 | 0 | temp.push_back('\x0a'); | 1249 | 0 | ++cs; | 1250 | 0 | break; | 1251 | 0 | case 'r': | 1252 | 0 | temp.push_back('\x0d'); | 1253 | 0 | ++cs; | 1254 | 0 | break; | 1255 | 0 | case 't': | 1256 | 0 | temp.push_back('\x09'); | 1257 | 0 | ++cs; | 1258 | 0 | break; | 1259 | 0 | case 'u': | 1260 | | // utf16 escape | 1261 | | // | 1262 | | // fast path only when the buffer | 1263 | | // is large enough for 2 surrogates | 1264 | 0 | if(BOOST_JSON_LIKELY(cs.remain() > 10)) | 1265 | 0 | { | 1266 | | // KRYSTIAN TODO: this could be done | 1267 | | // with fewer instructions | 1268 | 0 | digit = detail::load_little_endian<4>( | 1269 | 0 | cs.begin() + 1); | 1270 | 0 | int d4 = detail::hex_digit(static_cast< | 1271 | 0 | unsigned char>(digit >> 24)); | 1272 | 0 | int d3 = detail::hex_digit(static_cast< | 1273 | 0 | unsigned char>(digit >> 16)); | 1274 | 0 | int d2 = detail::hex_digit(static_cast< | 1275 | 0 | unsigned char>(digit >> 8)); | 1276 | 0 | int d1 = detail::hex_digit(static_cast< | 1277 | 0 | unsigned char>(digit)); | 1278 | 0 | if(BOOST_JSON_UNLIKELY( | 1279 | 0 | (d1 | d2 | d3 | d4) == -1)) | 1280 | 0 | { | 1281 | 0 | if(d1 != -1) | 1282 | 0 | ++cs; | 1283 | 0 | if(d2 != -1) | 1284 | 0 | ++cs; | 1285 | 0 | if(d3 != -1) | 1286 | 0 | ++cs; | 1287 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1288 | 0 | = BOOST_CURRENT_LOCATION; | 1289 | 0 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1290 | 0 | } | 1291 | | // 32 bit unicode scalar value | 1292 | 0 | unsigned u1 = | 1293 | 0 | (d1 << 12) + (d2 << 8) + | 1294 | 0 | (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 | 0 | if(BOOST_JSON_LIKELY( | 1300 | 0 | u1 < 0xd800 || u1 > 0xdfff)) | 1301 | 0 | { | 1302 | 0 | cs += 5; | 1303 | 0 | temp.append_utf8(u1); | 1304 | 0 | break; | 1305 | 0 | } | 1306 | 0 | if(BOOST_JSON_UNLIKELY(u1 > 0xdbff)) | 1307 | 0 | { | 1308 | | // If it's an illegal leading surrogate and | 1309 | | // the parser does not allow it, return an error. | 1310 | 0 | if(!allow_bad_utf16) | 1311 | 0 | { | 1312 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1313 | 0 | = BOOST_CURRENT_LOCATION; | 1314 | 0 | return fail(cs.begin(), error::illegal_leading_surrogate, | 1315 | 0 | &loc); | 1316 | 0 | } | 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 | 0 | } | 1325 | 0 | 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 | 0 | if(BOOST_JSON_UNLIKELY(*cs != '\\')) | 1330 | 0 | { | 1331 | | // If the next character is not a backslash and | 1332 | | // the parser does not allow it, return a syntax error. | 1333 | 0 | if(!allow_bad_utf16) | 1334 | 0 | { | 1335 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1336 | 0 | = BOOST_CURRENT_LOCATION; | 1337 | 0 | return fail(cs.begin(), error::syntax, &loc); | 1338 | 0 | } | 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 | 0 | } | 1347 | 0 | ++cs; | 1348 | 0 | if(BOOST_JSON_UNLIKELY(*cs != 'u')) | 1349 | 0 | { | 1350 | 0 | if (!allow_bad_utf16) | 1351 | 0 | { | 1352 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1353 | 0 | = BOOST_CURRENT_LOCATION; | 1354 | 0 | return fail(cs.begin(), error::syntax, &loc); | 1355 | 0 | } | 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 | 0 | } | 1364 | 0 | ++cs; | 1365 | 0 | digit = detail::load_little_endian<4>(cs.begin()); | 1366 | 0 | d4 = detail::hex_digit(static_cast< | 1367 | 0 | unsigned char>(digit >> 24)); | 1368 | 0 | d3 = detail::hex_digit(static_cast< | 1369 | 0 | unsigned char>(digit >> 16)); | 1370 | 0 | d2 = detail::hex_digit(static_cast< | 1371 | 0 | unsigned char>(digit >> 8)); | 1372 | 0 | d1 = detail::hex_digit(static_cast< | 1373 | 0 | unsigned char>(digit)); | 1374 | 0 | if(BOOST_JSON_UNLIKELY( | 1375 | 0 | (d1 | d2 | d3 | d4) == -1)) | 1376 | 0 | { | 1377 | 0 | if(d1 != -1) | 1378 | 0 | ++cs; | 1379 | 0 | if(d2 != -1) | 1380 | 0 | ++cs; | 1381 | 0 | if(d3 != -1) | 1382 | 0 | ++cs; | 1383 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1384 | 0 | = BOOST_CURRENT_LOCATION; | 1385 | 0 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1386 | 0 | } | 1387 | 0 | unsigned u2 = | 1388 | 0 | (d1 << 12) + (d2 << 8) + | 1389 | 0 | (d3 << 4) + d4; | 1390 | | // Check if the second code point is a valid trailing surrogate. | 1391 | | // Valid trailing surrogates are [DC00, DFFF] | 1392 | 0 | if(BOOST_JSON_UNLIKELY( | 1393 | 0 | u2 < 0xdc00 || u2 > 0xdfff)) | 1394 | 0 | { | 1395 | | // If not valid and the parser does not allow it, return an error. | 1396 | 0 | if(!allow_bad_utf16) | 1397 | 0 | { | 1398 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1399 | 0 | = BOOST_CURRENT_LOCATION; | 1400 | 0 | return fail(cs.begin(), error::illegal_trailing_surrogate, | 1401 | 0 | &loc); | 1402 | 0 | } | 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 | 0 | cs += 4; | 1423 | | // Calculate the Unicode code point from the surrogate pair and | 1424 | | // append the UTF-8 representation. | 1425 | 0 | unsigned cp = | 1426 | 0 | ((u1 - 0xd800) << 10) + | 1427 | 0 | ((u2 - 0xdc00)) + | 1428 | 0 | 0x10000; | 1429 | | // utf-16 surrogate pair | 1430 | 0 | temp.append_utf8(cp); | 1431 | 0 | break; | 1432 | 0 | } | 1433 | | // flush | 1434 | 0 | if(BOOST_JSON_LIKELY(! temp.empty())) | 1435 | 0 | { | 1436 | 0 | BOOST_ASSERT(total <= max_size); | 1437 | 0 | if(BOOST_JSON_UNLIKELY( | 1438 | 0 | 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 | 0 | total += temp.size(); | 1445 | 0 | { | 1446 | 0 | bool r = is_key | 1447 | 0 | ? h_.on_key_part(temp.get(), total, ec_) | 1448 | 0 | : h_.on_string_part(temp.get(), total, ec_); | 1449 | |
| 1450 | 0 | if(BOOST_JSON_UNLIKELY(!r)) | 1451 | 0 | { | 1452 | 0 | return fail(cs.begin()); | 1453 | 0 | } | 1454 | 0 | } | 1455 | 0 | temp.clear(); | 1456 | 0 | cs.clip(temp.max_size()); | 1457 | 0 | } | 1458 | 0 | ++cs; | 1459 | | // utf-16 escape | 1460 | 15 | do_str4: | 1461 | 15 | if(BOOST_JSON_UNLIKELY(! cs)) | 1462 | 15 | return maybe_suspend(cs.begin(), state::str4); | 1463 | 0 | digit = detail::hex_digit(*cs); | 1464 | 0 | if(BOOST_JSON_UNLIKELY(digit == -1)) | 1465 | 0 | { | 1466 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1467 | 0 | = BOOST_CURRENT_LOCATION; | 1468 | 0 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1469 | 0 | } | 1470 | 0 | ++cs; | 1471 | 0 | u1_ = digit << 12; | 1472 | 13 | do_str5: | 1473 | 13 | if(BOOST_JSON_UNLIKELY(! cs)) | 1474 | 13 | return maybe_suspend(cs.begin(), state::str5); | 1475 | 0 | digit = detail::hex_digit(*cs); | 1476 | 0 | if(BOOST_JSON_UNLIKELY(digit == -1)) | 1477 | 0 | { | 1478 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1479 | 0 | = BOOST_CURRENT_LOCATION; | 1480 | 0 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1481 | 0 | } | 1482 | 0 | ++cs; | 1483 | 0 | u1_ += digit << 8; | 1484 | 10 | do_str6: | 1485 | 10 | if(BOOST_JSON_UNLIKELY(! cs)) | 1486 | 10 | return maybe_suspend(cs.begin(), state::str6); | 1487 | 0 | digit = detail::hex_digit(*cs); | 1488 | 0 | if(BOOST_JSON_UNLIKELY(digit == -1)) | 1489 | 0 | { | 1490 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1491 | 0 | = BOOST_CURRENT_LOCATION; | 1492 | 0 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1493 | 0 | } | 1494 | 0 | ++cs; | 1495 | 0 | u1_ += digit << 4; | 1496 | 17 | do_str7: | 1497 | 17 | if(BOOST_JSON_UNLIKELY(! cs)) | 1498 | 17 | return maybe_suspend(cs.begin(), state::str7); | 1499 | 0 | digit = detail::hex_digit(*cs); | 1500 | 0 | if(BOOST_JSON_UNLIKELY(digit == -1)) | 1501 | 0 | { | 1502 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1503 | 0 | = BOOST_CURRENT_LOCATION; | 1504 | 0 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1505 | 0 | } | 1506 | 0 | ++cs; | 1507 | 0 | u1_ += digit; | 1508 | 0 | if(BOOST_JSON_LIKELY( | 1509 | 0 | u1_ < 0xd800 || u1_ > 0xdfff)) | 1510 | 0 | { | 1511 | 0 | BOOST_ASSERT(temp.empty()); | 1512 | | // utf-8 codepoint | 1513 | 0 | temp.append_utf8(u1_); | 1514 | 0 | break; | 1515 | 0 | } | 1516 | 0 | if(BOOST_JSON_UNLIKELY(u1_ > 0xdbff)) | 1517 | 0 | { | 1518 | | // If it's an illegal leading surrogate and | 1519 | | // the parser does not allow it, return an error. | 1520 | 0 | if(!allow_bad_utf16) | 1521 | 0 | { | 1522 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1523 | 0 | = BOOST_CURRENT_LOCATION; | 1524 | 0 | return fail(cs.begin(), error::illegal_leading_surrogate, &loc); | 1525 | 0 | } | 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 | 0 | } | 1534 | 7 | do_sur1: | 1535 | 7 | if(BOOST_JSON_UNLIKELY(! cs)) | 1536 | 7 | return maybe_suspend(cs.begin(), state::sur1); | 1537 | 0 | if(BOOST_JSON_UNLIKELY(*cs != '\\')) | 1538 | 0 | { | 1539 | | // If the next character is not a backslash and | 1540 | | // the parser does not allow it, return a syntax error. | 1541 | 0 | if(!allow_bad_utf16) | 1542 | 0 | { | 1543 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1544 | 0 | = BOOST_CURRENT_LOCATION; | 1545 | 0 | return fail(cs.begin(), error::syntax, &loc); | 1546 | 0 | } | 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 | 0 | } | 1555 | 0 | ++cs; | 1556 | 1 | do_sur2: | 1557 | 1 | if(BOOST_JSON_UNLIKELY(! cs)) | 1558 | 1 | return maybe_suspend(cs.begin(), state::sur2); | 1559 | 0 | if(BOOST_JSON_UNLIKELY(*cs != 'u')) | 1560 | 0 | { | 1561 | 0 | if (!allow_bad_utf16) | 1562 | 0 | { | 1563 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1564 | 0 | = BOOST_CURRENT_LOCATION; | 1565 | 0 | return fail(cs.begin(), error::syntax, &loc); | 1566 | 0 | } | 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 | 0 | } | 1575 | 0 | ++cs; | 1576 | 1 | do_sur3: | 1577 | 1 | if(BOOST_JSON_UNLIKELY(! cs)) | 1578 | 1 | return maybe_suspend(cs.begin(), state::sur3); | 1579 | 0 | digit = detail::hex_digit(*cs); | 1580 | 0 | if(BOOST_JSON_UNLIKELY(digit == -1)) | 1581 | 0 | { | 1582 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1583 | 0 | = BOOST_CURRENT_LOCATION; | 1584 | 0 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1585 | 0 | } | 1586 | 0 | ++cs; | 1587 | 0 | u2_ = digit << 12; | 1588 | 5 | do_sur4: | 1589 | 5 | if(BOOST_JSON_UNLIKELY(! cs)) | 1590 | 5 | return maybe_suspend(cs.begin(), state::sur4); | 1591 | 0 | digit = detail::hex_digit(*cs); | 1592 | 0 | if(BOOST_JSON_UNLIKELY(digit == -1)) | 1593 | 0 | { | 1594 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1595 | 0 | = BOOST_CURRENT_LOCATION; | 1596 | 0 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1597 | 0 | } | 1598 | 0 | ++cs; | 1599 | 0 | u2_ += digit << 8; | 1600 | 6 | do_sur5: | 1601 | 6 | if(BOOST_JSON_UNLIKELY(! cs)) | 1602 | 6 | return maybe_suspend(cs.begin(), state::sur5); | 1603 | 0 | digit = detail::hex_digit(*cs); | 1604 | 0 | if(BOOST_JSON_UNLIKELY(digit == -1)) | 1605 | 0 | { | 1606 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1607 | 0 | = BOOST_CURRENT_LOCATION; | 1608 | 0 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1609 | 0 | } | 1610 | 0 | ++cs; | 1611 | 0 | u2_ += digit << 4; | 1612 | 10 | do_sur6: | 1613 | 10 | if(BOOST_JSON_UNLIKELY(! cs)) | 1614 | 10 | return maybe_suspend(cs.begin(), state::sur6); | 1615 | 0 | digit = detail::hex_digit(*cs); | 1616 | 0 | if(BOOST_JSON_UNLIKELY(digit == -1)) | 1617 | 0 | { | 1618 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1619 | 0 | = BOOST_CURRENT_LOCATION; | 1620 | 0 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1621 | 0 | } | 1622 | 0 | ++cs; | 1623 | 0 | u2_ += digit; | 1624 | | // Check if the second code point is a valid trailing surrogate. | 1625 | | // Valid trailing surrogates are [DC00, DFFF] | 1626 | 0 | if(BOOST_JSON_UNLIKELY( | 1627 | 0 | u2_ < 0xdc00 || u2_ > 0xdfff)) | 1628 | 0 | { | 1629 | | // If not valid and the parser does not allow it, return an error. | 1630 | 0 | if(!allow_bad_utf16) | 1631 | 0 | { | 1632 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1633 | 0 | = BOOST_CURRENT_LOCATION; | 1634 | 0 | return fail(cs.begin(), error::illegal_trailing_surrogate, &loc); | 1635 | 0 | } | 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 | 0 | unsigned cp = | 1657 | 0 | ((u1_ - 0xd800) << 10) + | 1658 | 0 | ((u2_ - 0xdc00)) + | 1659 | 0 | 0x10000; | 1660 | | // utf-16 surrogate pair | 1661 | 0 | temp.append_utf8(cp); | 1662 | 0 | } | 1663 | | | 1664 | | // flush | 1665 | 0 | if(BOOST_JSON_UNLIKELY( !cs ) || *cs != '\\') | 1666 | 0 | break; | 1667 | 0 | } | 1668 | | | 1669 | 0 | if(BOOST_JSON_LIKELY( temp.size() )) | 1670 | 0 | { | 1671 | 0 | BOOST_ASSERT(total <= max_size); | 1672 | 0 | 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 | 0 | total += temp.size(); | 1680 | 0 | bool const r = is_key | 1681 | 0 | ? h_.on_key_part(temp.get(), total, ec_) | 1682 | 0 | : h_.on_string_part(temp.get(), total, ec_); | 1683 | 0 | if(BOOST_JSON_UNLIKELY( !r )) | 1684 | 0 | return fail( cs.begin() ); | 1685 | 0 | } | 1686 | | | 1687 | 0 | return cs.begin(); | 1688 | 0 | } |
|
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 | 31.9k | { |
1707 | 31.9k | detail::const_stream_wrapper cs(p, end_); |
1708 | 31.9k | std::size_t size; |
1709 | 31.9k | if(! stack_empty && ! st_.empty()) |
1710 | 960 | { |
1711 | | // resume |
1712 | 960 | state st; |
1713 | 960 | st_.pop(st); |
1714 | 960 | st_.pop(size); |
1715 | 960 | switch(st) |
1716 | 960 | { |
1717 | 0 | default: BOOST_JSON_UNREACHABLE(); |
1718 | 78 | case state::obj1: goto do_obj1; |
1719 | 5 | case state::obj2: goto do_obj2; |
1720 | 185 | case state::obj3: goto do_obj3; |
1721 | 96 | case state::obj4: goto do_obj4; |
1722 | 4 | case state::obj5: goto do_obj5; |
1723 | 67 | case state::obj6: goto do_obj6; |
1724 | 383 | case state::obj7: goto do_obj7; |
1725 | 67 | case state::obj8: goto do_obj8; |
1726 | 62 | case state::obj9: goto do_obj9; |
1727 | 10 | case state::obj10: goto do_obj10; |
1728 | 3 | case state::obj11: goto do_obj11; |
1729 | 960 | } |
1730 | 960 | } |
1731 | 30.9k | BOOST_ASSERT(*cs == '{'); |
1732 | 30.9k | size = 0; |
1733 | 30.9k | if(BOOST_JSON_UNLIKELY(! depth_)) |
1734 | 14 | { |
1735 | 14 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; |
1736 | 14 | return fail(cs.begin(), error::too_deep, &loc); |
1737 | 14 | } |
1738 | 30.9k | --depth_; |
1739 | 30.9k | if(BOOST_JSON_UNLIKELY( |
1740 | 30.9k | ! h_.on_object_begin(ec_))) |
1741 | 0 | return fail(cs.begin()); |
1742 | 30.9k | ++cs; |
1743 | | // object: |
1744 | | // '{' *ws '}' |
1745 | | // '{' *ws string *ws ':' *ws value *ws *[ ',' *ws string *ws ':' *ws value *ws ] '}' |
1746 | 31.4k | do_obj1: |
1747 | 31.4k | cs = detail::count_whitespace(cs.begin(), cs.end()); |
1748 | 31.4k | if(BOOST_JSON_UNLIKELY(! cs)) |
1749 | 192 | return maybe_suspend(cs.begin(), state::obj1, size); |
1750 | 31.2k | if(BOOST_JSON_LIKELY(*cs != '}')) |
1751 | 13.3k | { |
1752 | 13.3k | if(BOOST_JSON_UNLIKELY(*cs != '\x22')) |
1753 | 585 | { |
1754 | 585 | if(allow_comments && *cs == '/') |
1755 | 417 | { |
1756 | 422 | do_obj2: |
1757 | 422 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); |
1758 | 422 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) |
1759 | 11 | return suspend_or_fail(state::obj2, size); |
1760 | 411 | goto do_obj1; |
1761 | 422 | } |
1762 | 585 | BOOST_STATIC_CONSTEXPR source_location loc |
1763 | 168 | = BOOST_CURRENT_LOCATION; |
1764 | 168 | return fail(cs.begin(), error::syntax, &loc); |
1765 | 585 | } |
1766 | 1.83M | loop: |
1767 | 1.83M | if(BOOST_JSON_UNLIKELY(++size > |
1768 | 1.83M | 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 | 1.83M | do_obj3: |
1775 | 1.83M | cs = parse_string(cs.begin(), stack_empty, std::true_type(), allow_bad_utf8, allow_bad_utf16); |
1776 | 1.83M | if(BOOST_JSON_UNLIKELY(incomplete(cs))) |
1777 | 901 | return suspend_or_fail(state::obj3, size); |
1778 | 1.83M | do_obj4: |
1779 | 1.83M | cs = detail::count_whitespace(cs.begin(), cs.end()); |
1780 | 1.83M | if(BOOST_JSON_UNLIKELY(! cs)) |
1781 | 247 | return maybe_suspend(cs.begin(), state::obj4, size); |
1782 | 1.82M | if(BOOST_JSON_UNLIKELY(*cs != ':')) |
1783 | 608 | { |
1784 | 608 | if(allow_comments && *cs == '/') |
1785 | 424 | { |
1786 | 428 | do_obj5: |
1787 | 428 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); |
1788 | 428 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) |
1789 | 8 | return suspend_or_fail(state::obj5, size); |
1790 | 420 | goto do_obj4; |
1791 | 428 | } |
1792 | 608 | BOOST_STATIC_CONSTEXPR source_location loc |
1793 | 184 | = BOOST_CURRENT_LOCATION; |
1794 | 184 | return fail(cs.begin(), error::syntax, &loc); |
1795 | 608 | } |
1796 | 1.82M | ++cs; |
1797 | 1.82M | do_obj6: |
1798 | 1.82M | cs = detail::count_whitespace(cs.begin(), cs.end()); |
1799 | 1.82M | if(BOOST_JSON_UNLIKELY(! cs)) |
1800 | 171 | return maybe_suspend(cs.begin(), state::obj6, size); |
1801 | 1.82M | do_obj7: |
1802 | 1.82M | cs = parse_value(cs.begin(), stack_empty, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); |
1803 | 1.82M | if(BOOST_JSON_UNLIKELY(incomplete(cs))) |
1804 | 2.07k | return suspend_or_fail(state::obj7, size); |
1805 | 1.82M | do_obj8: |
1806 | 1.82M | cs = detail::count_whitespace(cs.begin(), cs.end()); |
1807 | 1.82M | if(BOOST_JSON_UNLIKELY(! cs)) |
1808 | 173 | return maybe_suspend(cs.begin(), state::obj8, size); |
1809 | 1.82M | if(BOOST_JSON_LIKELY(*cs == ',')) |
1810 | 1.81M | { |
1811 | 1.81M | ++cs; |
1812 | 1.81M | do_obj9: |
1813 | 1.81M | cs = detail::count_whitespace(cs.begin(), cs.end()); |
1814 | 1.81M | if(BOOST_JSON_UNLIKELY(! cs)) |
1815 | 157 | return maybe_suspend(cs.begin(), state::obj9, size); |
1816 | | |
1817 | | // loop for next element |
1818 | 1.81M | if(BOOST_JSON_LIKELY(*cs == '\x22')) |
1819 | 1.81M | goto loop; |
1820 | 1.42k | if(! allow_trailing || *cs != '}') |
1821 | 904 | { |
1822 | 904 | if(allow_comments && *cs == '/') |
1823 | 747 | { |
1824 | 757 | do_obj10: |
1825 | 757 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); |
1826 | 757 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) |
1827 | 22 | return suspend_or_fail(state::obj10, size); |
1828 | 735 | goto do_obj9; |
1829 | 757 | } |
1830 | 904 | BOOST_STATIC_CONSTEXPR source_location loc |
1831 | 157 | = BOOST_CURRENT_LOCATION; |
1832 | 157 | return fail(cs.begin(), error::syntax, &loc); |
1833 | 904 | } |
1834 | 1.42k | } |
1835 | 9.47k | else if(BOOST_JSON_UNLIKELY(*cs != '}')) |
1836 | 661 | { |
1837 | 661 | if(allow_comments && *cs == '/') |
1838 | 433 | { |
1839 | 436 | do_obj11: |
1840 | 436 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); |
1841 | 436 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) |
1842 | 9 | return suspend_or_fail(state::obj11, size); |
1843 | 427 | goto do_obj8; |
1844 | 436 | } |
1845 | 661 | BOOST_STATIC_CONSTEXPR source_location loc |
1846 | 228 | = BOOST_CURRENT_LOCATION; |
1847 | 228 | return fail(cs.begin(), error::syntax, &loc); |
1848 | 661 | } |
1849 | | // got closing brace, fall through |
1850 | 1.82M | } |
1851 | 27.2k | if(BOOST_JSON_UNLIKELY( |
1852 | 27.2k | ! h_.on_object_end(size, ec_))) |
1853 | 0 | return fail(cs.begin()); |
1854 | 27.2k | ++depth_; |
1855 | 27.2k | ++cs; |
1856 | 27.2k | return cs.begin(); |
1857 | 27.2k | } char const* boost::json::basic_parser<boost::json::detail::handler>::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 | 26.6k | { | 1707 | 26.6k | detail::const_stream_wrapper cs(p, end_); | 1708 | 26.6k | std::size_t size; | 1709 | 26.6k | 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 | 26.6k | BOOST_ASSERT(*cs == '{'); | 1732 | 26.6k | size = 0; | 1733 | 26.6k | if(BOOST_JSON_UNLIKELY(! depth_)) | 1734 | 10 | { | 1735 | 10 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 1736 | 10 | return fail(cs.begin(), error::too_deep, &loc); | 1737 | 10 | } | 1738 | 26.5k | --depth_; | 1739 | 26.5k | if(BOOST_JSON_UNLIKELY( | 1740 | 26.5k | ! h_.on_object_begin(ec_))) | 1741 | 0 | return fail(cs.begin()); | 1742 | 26.5k | ++cs; | 1743 | | // object: | 1744 | | // '{' *ws '}' | 1745 | | // '{' *ws string *ws ':' *ws value *ws *[ ',' *ws string *ws ':' *ws value *ws ] '}' | 1746 | 26.5k | do_obj1: | 1747 | 26.5k | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1748 | 26.5k | if(BOOST_JSON_UNLIKELY(! cs)) | 1749 | 69 | return maybe_suspend(cs.begin(), state::obj1, size); | 1750 | 26.5k | if(BOOST_JSON_LIKELY(*cs != '}')) | 1751 | 9.31k | { | 1752 | 9.31k | if(BOOST_JSON_UNLIKELY(*cs != '\x22')) | 1753 | 104 | { | 1754 | 104 | 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 | 104 | BOOST_STATIC_CONSTEXPR source_location loc | 1763 | 104 | = BOOST_CURRENT_LOCATION; | 1764 | 104 | return fail(cs.begin(), error::syntax, &loc); | 1765 | 104 | } | 1766 | 1.80M | loop: | 1767 | 1.80M | if(BOOST_JSON_UNLIKELY(++size > | 1768 | 1.80M | 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 | 1.80M | do_obj3: | 1775 | 1.80M | cs = parse_string(cs.begin(), stack_empty, std::true_type(), allow_bad_utf8, allow_bad_utf16); | 1776 | 1.80M | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1777 | 540 | return suspend_or_fail(state::obj3, size); | 1778 | 1.80M | do_obj4: | 1779 | 1.80M | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1780 | 1.80M | if(BOOST_JSON_UNLIKELY(! cs)) | 1781 | 97 | return maybe_suspend(cs.begin(), state::obj4, size); | 1782 | 1.80M | if(BOOST_JSON_UNLIKELY(*cs != ':')) | 1783 | 122 | { | 1784 | 122 | 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 | 122 | BOOST_STATIC_CONSTEXPR source_location loc | 1793 | 122 | = BOOST_CURRENT_LOCATION; | 1794 | 122 | return fail(cs.begin(), error::syntax, &loc); | 1795 | 122 | } | 1796 | 1.80M | ++cs; | 1797 | 1.80M | do_obj6: | 1798 | 1.80M | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1799 | 1.80M | if(BOOST_JSON_UNLIKELY(! cs)) | 1800 | 69 | return maybe_suspend(cs.begin(), state::obj6, size); | 1801 | 1.80M | do_obj7: | 1802 | 1.80M | cs = parse_value(cs.begin(), stack_empty, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | 1803 | 1.80M | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1804 | 1.19k | return suspend_or_fail(state::obj7, size); | 1805 | 1.80M | do_obj8: | 1806 | 1.80M | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1807 | 1.80M | if(BOOST_JSON_UNLIKELY(! cs)) | 1808 | 67 | return maybe_suspend(cs.begin(), state::obj8, size); | 1809 | 1.80M | if(BOOST_JSON_LIKELY(*cs == ',')) | 1810 | 1.79M | { | 1811 | 1.79M | ++cs; | 1812 | 1.79M | do_obj9: | 1813 | 1.79M | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1814 | 1.79M | if(BOOST_JSON_UNLIKELY(! cs)) | 1815 | 59 | return maybe_suspend(cs.begin(), state::obj9, size); | 1816 | | | 1817 | | // loop for next element | 1818 | 1.79M | if(BOOST_JSON_LIKELY(*cs == '\x22')) | 1819 | 1.79M | goto loop; | 1820 | 307 | if(! allow_trailing || *cs != '}') | 1821 | 96 | { | 1822 | 96 | 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 | 96 | BOOST_STATIC_CONSTEXPR source_location loc | 1831 | 96 | = BOOST_CURRENT_LOCATION; | 1832 | 96 | return fail(cs.begin(), error::syntax, &loc); | 1833 | 96 | } | 1834 | 307 | } | 1835 | 6.74k | else if(BOOST_JSON_UNLIKELY(*cs != '}')) | 1836 | 156 | { | 1837 | 156 | 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 | 156 | BOOST_STATIC_CONSTEXPR source_location loc | 1846 | 156 | = BOOST_CURRENT_LOCATION; | 1847 | 156 | return fail(cs.begin(), error::syntax, &loc); | 1848 | 156 | } | 1849 | | // got closing brace, fall through | 1850 | 1.80M | } | 1851 | 24.0k | if(BOOST_JSON_UNLIKELY( | 1852 | 24.0k | ! h_.on_object_end(size, ec_))) | 1853 | 0 | return fail(cs.begin()); | 1854 | 24.0k | ++depth_; | 1855 | 24.0k | ++cs; | 1856 | 24.0k | return cs.begin(); | 1857 | 24.0k | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::parse_object<true, true>(char const*, std::__1::integral_constant<bool, true>, std::__1::integral_constant<bool, true>, bool, bool, bool) Line | Count | Source | 1706 | 4.37k | { | 1707 | 4.37k | detail::const_stream_wrapper cs(p, end_); | 1708 | 4.37k | std::size_t size; | 1709 | 4.37k | 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 | 4.37k | BOOST_ASSERT(*cs == '{'); | 1732 | 4.37k | size = 0; | 1733 | 4.37k | if(BOOST_JSON_UNLIKELY(! depth_)) | 1734 | 4 | { | 1735 | 4 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 1736 | 4 | return fail(cs.begin(), error::too_deep, &loc); | 1737 | 4 | } | 1738 | 4.37k | --depth_; | 1739 | 4.37k | if(BOOST_JSON_UNLIKELY( | 1740 | 4.37k | ! h_.on_object_begin(ec_))) | 1741 | 0 | return fail(cs.begin()); | 1742 | 4.37k | ++cs; | 1743 | | // object: | 1744 | | // '{' *ws '}' | 1745 | | // '{' *ws string *ws ':' *ws value *ws *[ ',' *ws string *ws ':' *ws value *ws ] '}' | 1746 | 4.78k | do_obj1: | 1747 | 4.78k | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1748 | 4.78k | if(BOOST_JSON_UNLIKELY(! cs)) | 1749 | 45 | return maybe_suspend(cs.begin(), state::obj1, size); | 1750 | 4.73k | if(BOOST_JSON_LIKELY(*cs != '}')) | 1751 | 4.07k | { | 1752 | 4.07k | if(BOOST_JSON_UNLIKELY(*cs != '\x22')) | 1753 | 481 | { | 1754 | 481 | if(allow_comments && *cs == '/') | 1755 | 417 | { | 1756 | 417 | do_obj2: | 1757 | 417 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); | 1758 | 417 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1759 | 6 | return suspend_or_fail(state::obj2, size); | 1760 | 411 | goto do_obj1; | 1761 | 417 | } | 1762 | 481 | BOOST_STATIC_CONSTEXPR source_location loc | 1763 | 64 | = BOOST_CURRENT_LOCATION; | 1764 | 64 | return fail(cs.begin(), error::syntax, &loc); | 1765 | 481 | } | 1766 | 23.6k | loop: | 1767 | 23.6k | if(BOOST_JSON_UNLIKELY(++size > | 1768 | 23.6k | 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 | 23.6k | do_obj3: | 1775 | 23.6k | cs = parse_string(cs.begin(), stack_empty, std::true_type(), allow_bad_utf8, allow_bad_utf16); | 1776 | 23.6k | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1777 | 176 | return suspend_or_fail(state::obj3, size); | 1778 | 23.8k | do_obj4: | 1779 | 23.8k | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1780 | 23.8k | if(BOOST_JSON_UNLIKELY(! cs)) | 1781 | 54 | return maybe_suspend(cs.begin(), state::obj4, size); | 1782 | 23.8k | if(BOOST_JSON_UNLIKELY(*cs != ':')) | 1783 | 486 | { | 1784 | 486 | if(allow_comments && *cs == '/') | 1785 | 424 | { | 1786 | 424 | do_obj5: | 1787 | 424 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); | 1788 | 424 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1789 | 4 | return suspend_or_fail(state::obj5, size); | 1790 | 420 | goto do_obj4; | 1791 | 424 | } | 1792 | 486 | BOOST_STATIC_CONSTEXPR source_location loc | 1793 | 62 | = BOOST_CURRENT_LOCATION; | 1794 | 62 | return fail(cs.begin(), error::syntax, &loc); | 1795 | 486 | } | 1796 | 23.3k | ++cs; | 1797 | 23.3k | do_obj6: | 1798 | 23.3k | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1799 | 23.3k | if(BOOST_JSON_UNLIKELY(! cs)) | 1800 | 35 | return maybe_suspend(cs.begin(), state::obj6, size); | 1801 | 23.3k | do_obj7: | 1802 | 23.3k | cs = parse_value(cs.begin(), stack_empty, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | 1803 | 23.3k | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1804 | 502 | return suspend_or_fail(state::obj7, size); | 1805 | 23.2k | do_obj8: | 1806 | 23.2k | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1807 | 23.2k | if(BOOST_JSON_UNLIKELY(! cs)) | 1808 | 34 | return maybe_suspend(cs.begin(), state::obj8, size); | 1809 | 23.2k | if(BOOST_JSON_LIKELY(*cs == ',')) | 1810 | 20.4k | { | 1811 | 20.4k | ++cs; | 1812 | 21.2k | do_obj9: | 1813 | 21.2k | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1814 | 21.2k | if(BOOST_JSON_UNLIKELY(! cs)) | 1815 | 36 | return maybe_suspend(cs.begin(), state::obj9, size); | 1816 | | | 1817 | | // loop for next element | 1818 | 21.1k | if(BOOST_JSON_LIKELY(*cs == '\x22')) | 1819 | 20.0k | goto loop; | 1820 | 1.11k | if(! allow_trailing || *cs != '}') | 1821 | 808 | { | 1822 | 808 | if(allow_comments && *cs == '/') | 1823 | 747 | { | 1824 | 747 | do_obj10: | 1825 | 747 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); | 1826 | 747 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1827 | 12 | return suspend_or_fail(state::obj10, size); | 1828 | 735 | goto do_obj9; | 1829 | 747 | } | 1830 | 808 | BOOST_STATIC_CONSTEXPR source_location loc | 1831 | 61 | = BOOST_CURRENT_LOCATION; | 1832 | 61 | return fail(cs.begin(), error::syntax, &loc); | 1833 | 808 | } | 1834 | 1.11k | } | 1835 | 2.73k | else if(BOOST_JSON_UNLIKELY(*cs != '}')) | 1836 | 505 | { | 1837 | 505 | if(allow_comments && *cs == '/') | 1838 | 433 | { | 1839 | 433 | do_obj11: | 1840 | 433 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); | 1841 | 433 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1842 | 6 | return suspend_or_fail(state::obj11, size); | 1843 | 427 | goto do_obj8; | 1844 | 433 | } | 1845 | 505 | BOOST_STATIC_CONSTEXPR source_location loc | 1846 | 72 | = BOOST_CURRENT_LOCATION; | 1847 | 72 | return fail(cs.begin(), error::syntax, &loc); | 1848 | 505 | } | 1849 | | // got closing brace, fall through | 1850 | 23.2k | } | 1851 | 3.19k | if(BOOST_JSON_UNLIKELY( | 1852 | 3.19k | ! h_.on_object_end(size, ec_))) | 1853 | 0 | return fail(cs.begin()); | 1854 | 3.19k | ++depth_; | 1855 | 3.19k | ++cs; | 1856 | 3.19k | return cs.begin(); | 1857 | 3.19k | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::parse_object<false, false>(char const*, std::__1::integral_constant<bool, false>, std::__1::integral_constant<bool, false>, bool, bool, bool) Line | Count | Source | 1706 | 368 | { | 1707 | 368 | detail::const_stream_wrapper cs(p, end_); | 1708 | 368 | std::size_t size; | 1709 | 368 | if(! stack_empty && ! st_.empty()) | 1710 | 368 | { | 1711 | | // resume | 1712 | 368 | state st; | 1713 | 368 | st_.pop(st); | 1714 | 368 | st_.pop(size); | 1715 | 368 | switch(st) | 1716 | 368 | { | 1717 | 0 | default: BOOST_JSON_UNREACHABLE(); | 1718 | 33 | case state::obj1: goto do_obj1; | 1719 | 0 | case state::obj2: goto do_obj2; | 1720 | 98 | case state::obj3: goto do_obj3; | 1721 | 42 | case state::obj4: goto do_obj4; | 1722 | 0 | case state::obj5: goto do_obj5; | 1723 | 32 | case state::obj6: goto do_obj6; | 1724 | 104 | case state::obj7: goto do_obj7; | 1725 | 33 | case state::obj8: goto do_obj8; | 1726 | 26 | case state::obj9: goto do_obj9; | 1727 | 0 | case state::obj10: goto do_obj10; | 1728 | 0 | case state::obj11: goto do_obj11; | 1729 | 368 | } | 1730 | 368 | } | 1731 | 0 | BOOST_ASSERT(*cs == '{'); | 1732 | 0 | size = 0; | 1733 | 0 | if(BOOST_JSON_UNLIKELY(! depth_)) | 1734 | 0 | { | 1735 | 0 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 1736 | 0 | return fail(cs.begin(), error::too_deep, &loc); | 1737 | 0 | } | 1738 | 0 | --depth_; | 1739 | 0 | if(BOOST_JSON_UNLIKELY( | 1740 | 0 | ! h_.on_object_begin(ec_))) | 1741 | 0 | return fail(cs.begin()); | 1742 | 0 | ++cs; | 1743 | | // object: | 1744 | | // '{' *ws '}' | 1745 | | // '{' *ws string *ws ':' *ws value *ws *[ ',' *ws string *ws ':' *ws value *ws ] '}' | 1746 | 33 | do_obj1: | 1747 | 33 | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1748 | 33 | if(BOOST_JSON_UNLIKELY(! cs)) | 1749 | 33 | return maybe_suspend(cs.begin(), state::obj1, size); | 1750 | 0 | if(BOOST_JSON_LIKELY(*cs != '}')) | 1751 | 0 | { | 1752 | 0 | if(BOOST_JSON_UNLIKELY(*cs != '\x22')) | 1753 | 0 | { | 1754 | 0 | 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 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1763 | 0 | = BOOST_CURRENT_LOCATION; | 1764 | 0 | return fail(cs.begin(), error::syntax, &loc); | 1765 | 0 | } | 1766 | 0 | loop: | 1767 | 0 | if(BOOST_JSON_UNLIKELY(++size > | 1768 | 0 | 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 | 98 | do_obj3: | 1775 | 98 | cs = parse_string(cs.begin(), stack_empty, std::true_type(), allow_bad_utf8, allow_bad_utf16); | 1776 | 98 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1777 | 98 | return suspend_or_fail(state::obj3, size); | 1778 | 42 | do_obj4: | 1779 | 42 | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1780 | 42 | if(BOOST_JSON_UNLIKELY(! cs)) | 1781 | 42 | return maybe_suspend(cs.begin(), state::obj4, size); | 1782 | 0 | if(BOOST_JSON_UNLIKELY(*cs != ':')) | 1783 | 0 | { | 1784 | 0 | 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 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1793 | 0 | = BOOST_CURRENT_LOCATION; | 1794 | 0 | return fail(cs.begin(), error::syntax, &loc); | 1795 | 0 | } | 1796 | 0 | ++cs; | 1797 | 32 | do_obj6: | 1798 | 32 | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1799 | 32 | if(BOOST_JSON_UNLIKELY(! cs)) | 1800 | 32 | return maybe_suspend(cs.begin(), state::obj6, size); | 1801 | 104 | do_obj7: | 1802 | 104 | cs = parse_value(cs.begin(), stack_empty, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | 1803 | 104 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1804 | 102 | return suspend_or_fail(state::obj7, size); | 1805 | 35 | do_obj8: | 1806 | 35 | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1807 | 35 | if(BOOST_JSON_UNLIKELY(! cs)) | 1808 | 35 | return maybe_suspend(cs.begin(), state::obj8, size); | 1809 | 0 | if(BOOST_JSON_LIKELY(*cs == ',')) | 1810 | 0 | { | 1811 | 0 | ++cs; | 1812 | 26 | do_obj9: | 1813 | 26 | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1814 | 26 | if(BOOST_JSON_UNLIKELY(! cs)) | 1815 | 26 | return maybe_suspend(cs.begin(), state::obj9, size); | 1816 | | | 1817 | | // loop for next element | 1818 | 0 | if(BOOST_JSON_LIKELY(*cs == '\x22')) | 1819 | 0 | goto loop; | 1820 | 0 | if(! allow_trailing || *cs != '}') | 1821 | 0 | { | 1822 | 0 | 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 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1831 | 0 | = BOOST_CURRENT_LOCATION; | 1832 | 0 | return fail(cs.begin(), error::syntax, &loc); | 1833 | 0 | } | 1834 | 0 | } | 1835 | 0 | else if(BOOST_JSON_UNLIKELY(*cs != '}')) | 1836 | 0 | { | 1837 | 0 | 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 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1846 | 0 | = BOOST_CURRENT_LOCATION; | 1847 | 0 | return fail(cs.begin(), error::syntax, &loc); | 1848 | 0 | } | 1849 | | // got closing brace, fall through | 1850 | 0 | } | 1851 | 0 | if(BOOST_JSON_UNLIKELY( | 1852 | 0 | ! h_.on_object_end(size, ec_))) | 1853 | 0 | return fail(cs.begin()); | 1854 | 0 | ++depth_; | 1855 | 0 | ++cs; | 1856 | 0 | return cs.begin(); | 1857 | 0 | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::parse_object<false, true>(char const*, std::__1::integral_constant<bool, false>, std::__1::integral_constant<bool, true>, bool, bool, bool) Line | Count | Source | 1706 | 592 | { | 1707 | 592 | detail::const_stream_wrapper cs(p, end_); | 1708 | 592 | std::size_t size; | 1709 | 592 | if(! stack_empty && ! st_.empty()) | 1710 | 592 | { | 1711 | | // resume | 1712 | 592 | state st; | 1713 | 592 | st_.pop(st); | 1714 | 592 | st_.pop(size); | 1715 | 592 | switch(st) | 1716 | 592 | { | 1717 | 0 | default: BOOST_JSON_UNREACHABLE(); | 1718 | 45 | case state::obj1: goto do_obj1; | 1719 | 5 | case state::obj2: goto do_obj2; | 1720 | 87 | case state::obj3: goto do_obj3; | 1721 | 54 | case state::obj4: goto do_obj4; | 1722 | 4 | case state::obj5: goto do_obj5; | 1723 | 35 | case state::obj6: goto do_obj6; | 1724 | 279 | case state::obj7: goto do_obj7; | 1725 | 34 | case state::obj8: goto do_obj8; | 1726 | 36 | case state::obj9: goto do_obj9; | 1727 | 10 | case state::obj10: goto do_obj10; | 1728 | 3 | case state::obj11: goto do_obj11; | 1729 | 592 | } | 1730 | 592 | } | 1731 | 0 | BOOST_ASSERT(*cs == '{'); | 1732 | 0 | size = 0; | 1733 | 0 | if(BOOST_JSON_UNLIKELY(! depth_)) | 1734 | 0 | { | 1735 | 0 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 1736 | 0 | return fail(cs.begin(), error::too_deep, &loc); | 1737 | 0 | } | 1738 | 0 | --depth_; | 1739 | 0 | if(BOOST_JSON_UNLIKELY( | 1740 | 0 | ! h_.on_object_begin(ec_))) | 1741 | 0 | return fail(cs.begin()); | 1742 | 0 | ++cs; | 1743 | | // object: | 1744 | | // '{' *ws '}' | 1745 | | // '{' *ws string *ws ':' *ws value *ws *[ ',' *ws string *ws ':' *ws value *ws ] '}' | 1746 | 45 | do_obj1: | 1747 | 45 | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1748 | 45 | if(BOOST_JSON_UNLIKELY(! cs)) | 1749 | 45 | return maybe_suspend(cs.begin(), state::obj1, size); | 1750 | 0 | if(BOOST_JSON_LIKELY(*cs != '}')) | 1751 | 0 | { | 1752 | 0 | if(BOOST_JSON_UNLIKELY(*cs != '\x22')) | 1753 | 0 | { | 1754 | 0 | if(allow_comments && *cs == '/') | 1755 | 0 | { | 1756 | 5 | do_obj2: | 1757 | 5 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); | 1758 | 5 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1759 | 5 | return suspend_or_fail(state::obj2, size); | 1760 | 0 | goto do_obj1; | 1761 | 5 | } | 1762 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1763 | 0 | = BOOST_CURRENT_LOCATION; | 1764 | 0 | return fail(cs.begin(), error::syntax, &loc); | 1765 | 0 | } | 1766 | 0 | loop: | 1767 | 0 | if(BOOST_JSON_UNLIKELY(++size > | 1768 | 0 | 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 | 87 | do_obj3: | 1775 | 87 | cs = parse_string(cs.begin(), stack_empty, std::true_type(), allow_bad_utf8, allow_bad_utf16); | 1776 | 87 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1777 | 87 | return suspend_or_fail(state::obj3, size); | 1778 | 54 | do_obj4: | 1779 | 54 | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1780 | 54 | if(BOOST_JSON_UNLIKELY(! cs)) | 1781 | 54 | return maybe_suspend(cs.begin(), state::obj4, size); | 1782 | 0 | if(BOOST_JSON_UNLIKELY(*cs != ':')) | 1783 | 0 | { | 1784 | 0 | if(allow_comments && *cs == '/') | 1785 | 0 | { | 1786 | 4 | do_obj5: | 1787 | 4 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); | 1788 | 4 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1789 | 4 | return suspend_or_fail(state::obj5, size); | 1790 | 0 | goto do_obj4; | 1791 | 4 | } | 1792 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1793 | 0 | = BOOST_CURRENT_LOCATION; | 1794 | 0 | return fail(cs.begin(), error::syntax, &loc); | 1795 | 0 | } | 1796 | 0 | ++cs; | 1797 | 35 | do_obj6: | 1798 | 35 | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1799 | 35 | if(BOOST_JSON_UNLIKELY(! cs)) | 1800 | 35 | return maybe_suspend(cs.begin(), state::obj6, size); | 1801 | 279 | do_obj7: | 1802 | 279 | cs = parse_value(cs.begin(), stack_empty, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | 1803 | 279 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1804 | 276 | return suspend_or_fail(state::obj7, size); | 1805 | 37 | do_obj8: | 1806 | 37 | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1807 | 37 | if(BOOST_JSON_UNLIKELY(! cs)) | 1808 | 37 | return maybe_suspend(cs.begin(), state::obj8, size); | 1809 | 0 | if(BOOST_JSON_LIKELY(*cs == ',')) | 1810 | 0 | { | 1811 | 0 | ++cs; | 1812 | 36 | do_obj9: | 1813 | 36 | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1814 | 36 | if(BOOST_JSON_UNLIKELY(! cs)) | 1815 | 36 | return maybe_suspend(cs.begin(), state::obj9, size); | 1816 | | | 1817 | | // loop for next element | 1818 | 0 | if(BOOST_JSON_LIKELY(*cs == '\x22')) | 1819 | 0 | goto loop; | 1820 | 0 | if(! allow_trailing || *cs != '}') | 1821 | 0 | { | 1822 | 0 | if(allow_comments && *cs == '/') | 1823 | 0 | { | 1824 | 10 | do_obj10: | 1825 | 10 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); | 1826 | 10 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1827 | 10 | return suspend_or_fail(state::obj10, size); | 1828 | 0 | goto do_obj9; | 1829 | 10 | } | 1830 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1831 | 0 | = BOOST_CURRENT_LOCATION; | 1832 | 0 | return fail(cs.begin(), error::syntax, &loc); | 1833 | 0 | } | 1834 | 0 | } | 1835 | 0 | else if(BOOST_JSON_UNLIKELY(*cs != '}')) | 1836 | 0 | { | 1837 | 0 | if(allow_comments && *cs == '/') | 1838 | 0 | { | 1839 | 3 | do_obj11: | 1840 | 3 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); | 1841 | 3 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1842 | 3 | return suspend_or_fail(state::obj11, size); | 1843 | 0 | goto do_obj8; | 1844 | 3 | } | 1845 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1846 | 0 | = BOOST_CURRENT_LOCATION; | 1847 | 0 | return fail(cs.begin(), error::syntax, &loc); | 1848 | 0 | } | 1849 | | // got closing brace, fall through | 1850 | 0 | } | 1851 | 0 | if(BOOST_JSON_UNLIKELY( | 1852 | 0 | ! h_.on_object_end(size, ec_))) | 1853 | 0 | return fail(cs.begin()); | 1854 | 0 | ++depth_; | 1855 | 0 | ++cs; | 1856 | 0 | return cs.begin(); | 1857 | 0 | } |
|
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 | 33.9k | { |
1876 | 33.9k | detail::const_stream_wrapper cs(p, end_); |
1877 | 33.9k | std::size_t size; |
1878 | 33.9k | if(! stack_empty && ! st_.empty()) |
1879 | 2.85k | { |
1880 | | // resume |
1881 | 2.85k | state st; |
1882 | 2.85k | st_.pop(st); |
1883 | 2.85k | st_.pop(size); |
1884 | 2.85k | switch(st) |
1885 | 2.85k | { |
1886 | 0 | default: BOOST_JSON_UNREACHABLE(); |
1887 | 92 | case state::arr1: goto do_arr1; |
1888 | 17 | case state::arr2: goto do_arr2; |
1889 | 2.24k | case state::arr3: goto do_arr3; |
1890 | 236 | case state::arr4: goto do_arr4; |
1891 | 253 | case state::arr5: goto do_arr5; |
1892 | 8 | case state::arr6: goto do_arr6; |
1893 | 2.85k | } |
1894 | 2.85k | } |
1895 | 31.1k | BOOST_ASSERT(*cs == '['); |
1896 | 31.1k | size = 0; |
1897 | 31.1k | if(BOOST_JSON_UNLIKELY(! depth_)) |
1898 | 16 | { |
1899 | 16 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; |
1900 | 16 | return fail(cs.begin(), error::too_deep, &loc); |
1901 | 16 | } |
1902 | 31.1k | --depth_; |
1903 | 31.1k | if(BOOST_JSON_UNLIKELY( |
1904 | 31.1k | ! h_.on_array_begin(ec_))) |
1905 | 0 | return fail(cs.begin()); |
1906 | 31.1k | ++cs; |
1907 | | // array: |
1908 | | // '[' *ws ']' |
1909 | | // '[' *ws value *ws *[ ',' *ws value *ws ] ']' |
1910 | 31.7k | do_arr1: |
1911 | 31.7k | cs = detail::count_whitespace(cs.begin(), cs.end()); |
1912 | 31.7k | if(BOOST_JSON_UNLIKELY(! cs)) |
1913 | 219 | return maybe_suspend(cs.begin(), state::arr1, size); |
1914 | 31.5k | if(BOOST_JSON_LIKELY(*cs != ']')) |
1915 | 27.6k | { |
1916 | 8.78M | loop: |
1917 | 8.78M | if(allow_comments && *cs == '/') |
1918 | 543 | { |
1919 | 560 | do_arr2: |
1920 | 560 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); |
1921 | 560 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) |
1922 | 36 | return suspend_or_fail(state::arr2, size); |
1923 | 524 | goto do_arr1; |
1924 | 560 | } |
1925 | 8.78M | if(BOOST_JSON_UNLIKELY(++size > |
1926 | 8.78M | 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 | 8.78M | do_arr3: |
1933 | | // array is not empty, value required |
1934 | 8.78M | cs = parse_value(cs.begin(), stack_empty, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); |
1935 | 8.78M | if(BOOST_JSON_UNLIKELY(incomplete(cs))) |
1936 | 5.71k | return suspend_or_fail(state::arr3, size); |
1937 | 8.77M | do_arr4: |
1938 | 8.77M | cs = detail::count_whitespace(cs.begin(), cs.end()); |
1939 | 8.77M | if(BOOST_JSON_UNLIKELY(! cs)) |
1940 | 2.13k | return maybe_suspend(cs.begin(), state::arr4, size); |
1941 | 8.77M | if(BOOST_JSON_LIKELY(*cs == ',')) |
1942 | 8.75M | { |
1943 | 8.75M | ++cs; |
1944 | 8.75M | do_arr5: |
1945 | 8.75M | cs = detail::count_whitespace(cs.begin(), cs.end()); |
1946 | 8.75M | if(BOOST_JSON_UNLIKELY(! cs)) |
1947 | 580 | return maybe_suspend(cs.begin(), state::arr5, size); |
1948 | | // loop for next element |
1949 | 8.75M | if(! allow_trailing || *cs != ']') |
1950 | 8.75M | goto loop; |
1951 | 8.75M | } |
1952 | 20.4k | else if(BOOST_JSON_UNLIKELY(*cs != ']')) |
1953 | 1.50k | { |
1954 | 1.50k | if(allow_comments && *cs == '/') |
1955 | 226 | { |
1956 | 234 | do_arr6: |
1957 | 234 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); |
1958 | 234 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) |
1959 | 21 | return suspend_or_fail(state::arr6, size); |
1960 | 213 | goto do_arr4; |
1961 | 234 | } |
1962 | 1.50k | BOOST_STATIC_CONSTEXPR source_location loc |
1963 | 1.28k | = BOOST_CURRENT_LOCATION; |
1964 | 1.28k | return fail(cs.begin(), error::syntax, &loc); |
1965 | 1.50k | } |
1966 | | // got closing bracket; fall through |
1967 | 8.77M | } |
1968 | 23.9k | if(BOOST_JSON_UNLIKELY( |
1969 | 23.9k | ! h_.on_array_end(size, ec_))) |
1970 | 0 | return fail(cs.begin()); |
1971 | 23.9k | ++depth_; |
1972 | 23.9k | ++cs; |
1973 | 23.9k | return cs.begin(); |
1974 | 23.9k | } char const* boost::json::basic_parser<boost::json::detail::handler>::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 | 19.6k | { | 1876 | 19.6k | detail::const_stream_wrapper cs(p, end_); | 1877 | 19.6k | std::size_t size; | 1878 | 19.6k | 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 | 19.6k | BOOST_ASSERT(*cs == '['); | 1896 | 19.6k | size = 0; | 1897 | 19.6k | if(BOOST_JSON_UNLIKELY(! depth_)) | 1898 | 11 | { | 1899 | 11 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 1900 | 11 | return fail(cs.begin(), error::too_deep, &loc); | 1901 | 11 | } | 1902 | 19.6k | --depth_; | 1903 | 19.6k | if(BOOST_JSON_UNLIKELY( | 1904 | 19.6k | ! h_.on_array_begin(ec_))) | 1905 | 0 | return fail(cs.begin()); | 1906 | 19.6k | ++cs; | 1907 | | // array: | 1908 | | // '[' *ws ']' | 1909 | | // '[' *ws value *ws *[ ',' *ws value *ws ] ']' | 1910 | 19.6k | do_arr1: | 1911 | 19.6k | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1912 | 19.6k | if(BOOST_JSON_UNLIKELY(! cs)) | 1913 | 75 | return maybe_suspend(cs.begin(), state::arr1, size); | 1914 | 19.5k | if(BOOST_JSON_LIKELY(*cs != ']')) | 1915 | 17.3k | { | 1916 | 4.27M | loop: | 1917 | 4.27M | 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 | 4.27M | if(BOOST_JSON_UNLIKELY(++size > | 1926 | 4.27M | 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 | 4.27M | do_arr3: | 1933 | | // array is not empty, value required | 1934 | 4.27M | cs = parse_value(cs.begin(), stack_empty, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | 1935 | 4.27M | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1936 | 2.80k | return suspend_or_fail(state::arr3, size); | 1937 | 4.27M | do_arr4: | 1938 | 4.27M | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1939 | 4.27M | if(BOOST_JSON_UNLIKELY(! cs)) | 1940 | 702 | return maybe_suspend(cs.begin(), state::arr4, size); | 1941 | 4.27M | if(BOOST_JSON_LIKELY(*cs == ',')) | 1942 | 4.26M | { | 1943 | 4.26M | ++cs; | 1944 | 4.26M | do_arr5: | 1945 | 4.26M | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1946 | 4.26M | if(BOOST_JSON_UNLIKELY(! cs)) | 1947 | 182 | return maybe_suspend(cs.begin(), state::arr5, size); | 1948 | | // loop for next element | 1949 | 4.26M | if(! allow_trailing || *cs != ']') | 1950 | 4.26M | goto loop; | 1951 | 4.26M | } | 1952 | 13.1k | else if(BOOST_JSON_UNLIKELY(*cs != ']')) | 1953 | 785 | { | 1954 | 785 | 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 | 785 | BOOST_STATIC_CONSTEXPR source_location loc | 1963 | 785 | = BOOST_CURRENT_LOCATION; | 1964 | 785 | return fail(cs.begin(), error::syntax, &loc); | 1965 | 785 | } | 1966 | | // got closing bracket; fall through | 1967 | 4.27M | } | 1968 | 15.0k | if(BOOST_JSON_UNLIKELY( | 1969 | 15.0k | ! h_.on_array_end(size, ec_))) | 1970 | 0 | return fail(cs.begin()); | 1971 | 15.0k | ++depth_; | 1972 | 15.0k | ++cs; | 1973 | 15.0k | return cs.begin(); | 1974 | 15.0k | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::parse_array<true, true>(char const*, std::__1::integral_constant<bool, true>, std::__1::integral_constant<bool, true>, bool, bool, bool) Line | Count | Source | 1875 | 11.5k | { | 1876 | 11.5k | detail::const_stream_wrapper cs(p, end_); | 1877 | 11.5k | std::size_t size; | 1878 | 11.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 | 11.5k | BOOST_ASSERT(*cs == '['); | 1896 | 11.5k | size = 0; | 1897 | 11.5k | if(BOOST_JSON_UNLIKELY(! depth_)) | 1898 | 5 | { | 1899 | 5 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 1900 | 5 | return fail(cs.begin(), error::too_deep, &loc); | 1901 | 5 | } | 1902 | 11.5k | --depth_; | 1903 | 11.5k | if(BOOST_JSON_UNLIKELY( | 1904 | 11.5k | ! h_.on_array_begin(ec_))) | 1905 | 0 | return fail(cs.begin()); | 1906 | 11.5k | ++cs; | 1907 | | // array: | 1908 | | // '[' *ws ']' | 1909 | | // '[' *ws value *ws *[ ',' *ws value *ws ] ']' | 1910 | 12.0k | do_arr1: | 1911 | 12.0k | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1912 | 12.0k | if(BOOST_JSON_UNLIKELY(! cs)) | 1913 | 52 | return maybe_suspend(cs.begin(), state::arr1, size); | 1914 | 11.9k | if(BOOST_JSON_LIKELY(*cs != ']')) | 1915 | 10.3k | { | 1916 | 4.50M | loop: | 1917 | 4.50M | if(allow_comments && *cs == '/') | 1918 | 543 | { | 1919 | 543 | do_arr2: | 1920 | 543 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); | 1921 | 543 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1922 | 19 | return suspend_or_fail(state::arr2, size); | 1923 | 524 | goto do_arr1; | 1924 | 543 | } | 1925 | 4.50M | if(BOOST_JSON_UNLIKELY(++size > | 1926 | 4.50M | 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 | 4.50M | do_arr3: | 1933 | | // array is not empty, value required | 1934 | 4.50M | cs = parse_value(cs.begin(), stack_empty, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | 1935 | 4.50M | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1936 | 1.73k | return suspend_or_fail(state::arr3, size); | 1937 | 4.50M | do_arr4: | 1938 | 4.50M | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1939 | 4.50M | if(BOOST_JSON_UNLIKELY(! cs)) | 1940 | 128 | return maybe_suspend(cs.begin(), state::arr4, size); | 1941 | 4.50M | if(BOOST_JSON_LIKELY(*cs == ',')) | 1942 | 4.49M | { | 1943 | 4.49M | ++cs; | 1944 | 4.49M | do_arr5: | 1945 | 4.49M | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1946 | 4.49M | if(BOOST_JSON_UNLIKELY(! cs)) | 1947 | 145 | return maybe_suspend(cs.begin(), state::arr5, size); | 1948 | | // loop for next element | 1949 | 4.49M | if(! allow_trailing || *cs != ']') | 1950 | 4.49M | goto loop; | 1951 | 4.49M | } | 1952 | 7.36k | else if(BOOST_JSON_UNLIKELY(*cs != ']')) | 1953 | 721 | { | 1954 | 721 | if(allow_comments && *cs == '/') | 1955 | 226 | { | 1956 | 226 | do_arr6: | 1957 | 226 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); | 1958 | 226 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1959 | 13 | return suspend_or_fail(state::arr6, size); | 1960 | 213 | goto do_arr4; | 1961 | 226 | } | 1962 | 721 | BOOST_STATIC_CONSTEXPR source_location loc | 1963 | 495 | = BOOST_CURRENT_LOCATION; | 1964 | 495 | return fail(cs.begin(), error::syntax, &loc); | 1965 | 721 | } | 1966 | | // got closing bracket; fall through | 1967 | 4.50M | } | 1968 | 8.92k | if(BOOST_JSON_UNLIKELY( | 1969 | 8.92k | ! h_.on_array_end(size, ec_))) | 1970 | 0 | return fail(cs.begin()); | 1971 | 8.92k | ++depth_; | 1972 | 8.92k | ++cs; | 1973 | 8.92k | return cs.begin(); | 1974 | 8.92k | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::parse_array<false, false>(char const*, std::__1::integral_constant<bool, false>, std::__1::integral_constant<bool, false>, bool, bool, bool) Line | Count | Source | 1875 | 1.19k | { | 1876 | 1.19k | detail::const_stream_wrapper cs(p, end_); | 1877 | 1.19k | std::size_t size; | 1878 | 1.19k | if(! stack_empty && ! st_.empty()) | 1879 | 1.19k | { | 1880 | | // resume | 1881 | 1.19k | state st; | 1882 | 1.19k | st_.pop(st); | 1883 | 1.19k | st_.pop(size); | 1884 | 1.19k | switch(st) | 1885 | 1.19k | { | 1886 | 0 | default: BOOST_JSON_UNREACHABLE(); | 1887 | 40 | case state::arr1: goto do_arr1; | 1888 | 0 | case state::arr2: goto do_arr2; | 1889 | 941 | case state::arr3: goto do_arr3; | 1890 | 108 | case state::arr4: goto do_arr4; | 1891 | 108 | case state::arr5: goto do_arr5; | 1892 | 0 | case state::arr6: goto do_arr6; | 1893 | 1.19k | } | 1894 | 1.19k | } | 1895 | 0 | BOOST_ASSERT(*cs == '['); | 1896 | 0 | size = 0; | 1897 | 0 | if(BOOST_JSON_UNLIKELY(! depth_)) | 1898 | 0 | { | 1899 | 0 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 1900 | 0 | return fail(cs.begin(), error::too_deep, &loc); | 1901 | 0 | } | 1902 | 0 | --depth_; | 1903 | 0 | if(BOOST_JSON_UNLIKELY( | 1904 | 0 | ! h_.on_array_begin(ec_))) | 1905 | 0 | return fail(cs.begin()); | 1906 | 0 | ++cs; | 1907 | | // array: | 1908 | | // '[' *ws ']' | 1909 | | // '[' *ws value *ws *[ ',' *ws value *ws ] ']' | 1910 | 40 | do_arr1: | 1911 | 40 | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1912 | 40 | if(BOOST_JSON_UNLIKELY(! cs)) | 1913 | 40 | return maybe_suspend(cs.begin(), state::arr1, size); | 1914 | 0 | if(BOOST_JSON_LIKELY(*cs != ']')) | 1915 | 0 | { | 1916 | 0 | loop: | 1917 | 0 | 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 | 0 | if(BOOST_JSON_UNLIKELY(++size > | 1926 | 0 | 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 | 941 | do_arr3: | 1933 | | // array is not empty, value required | 1934 | 941 | cs = parse_value(cs.begin(), stack_empty, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | 1935 | 941 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1936 | 385 | return suspend_or_fail(state::arr3, size); | 1937 | 664 | do_arr4: | 1938 | 664 | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1939 | 664 | if(BOOST_JSON_UNLIKELY(! cs)) | 1940 | 664 | return maybe_suspend(cs.begin(), state::arr4, size); | 1941 | 0 | if(BOOST_JSON_LIKELY(*cs == ',')) | 1942 | 0 | { | 1943 | 0 | ++cs; | 1944 | 108 | do_arr5: | 1945 | 108 | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1946 | 108 | if(BOOST_JSON_UNLIKELY(! cs)) | 1947 | 108 | return maybe_suspend(cs.begin(), state::arr5, size); | 1948 | | // loop for next element | 1949 | 0 | if(! allow_trailing || *cs != ']') | 1950 | 0 | goto loop; | 1951 | 0 | } | 1952 | 0 | else if(BOOST_JSON_UNLIKELY(*cs != ']')) | 1953 | 0 | { | 1954 | 0 | 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 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1963 | 0 | = BOOST_CURRENT_LOCATION; | 1964 | 0 | return fail(cs.begin(), error::syntax, &loc); | 1965 | 0 | } | 1966 | | // got closing bracket; fall through | 1967 | 0 | } | 1968 | 0 | if(BOOST_JSON_UNLIKELY( | 1969 | 0 | ! h_.on_array_end(size, ec_))) | 1970 | 0 | return fail(cs.begin()); | 1971 | 0 | ++depth_; | 1972 | 0 | ++cs; | 1973 | 0 | return cs.begin(); | 1974 | 0 | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::parse_array<false, true>(char const*, std::__1::integral_constant<bool, false>, std::__1::integral_constant<bool, true>, bool, bool, bool) Line | Count | Source | 1875 | 1.65k | { | 1876 | 1.65k | detail::const_stream_wrapper cs(p, end_); | 1877 | 1.65k | std::size_t size; | 1878 | 1.65k | if(! stack_empty && ! st_.empty()) | 1879 | 1.65k | { | 1880 | | // resume | 1881 | 1.65k | state st; | 1882 | 1.65k | st_.pop(st); | 1883 | 1.65k | st_.pop(size); | 1884 | 1.65k | switch(st) | 1885 | 1.65k | { | 1886 | 0 | default: BOOST_JSON_UNREACHABLE(); | 1887 | 52 | case state::arr1: goto do_arr1; | 1888 | 17 | case state::arr2: goto do_arr2; | 1889 | 1.30k | case state::arr3: goto do_arr3; | 1890 | 128 | case state::arr4: goto do_arr4; | 1891 | 145 | case state::arr5: goto do_arr5; | 1892 | 8 | case state::arr6: goto do_arr6; | 1893 | 1.65k | } | 1894 | 1.65k | } | 1895 | 0 | BOOST_ASSERT(*cs == '['); | 1896 | 0 | size = 0; | 1897 | 0 | if(BOOST_JSON_UNLIKELY(! depth_)) | 1898 | 0 | { | 1899 | 0 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 1900 | 0 | return fail(cs.begin(), error::too_deep, &loc); | 1901 | 0 | } | 1902 | 0 | --depth_; | 1903 | 0 | if(BOOST_JSON_UNLIKELY( | 1904 | 0 | ! h_.on_array_begin(ec_))) | 1905 | 0 | return fail(cs.begin()); | 1906 | 0 | ++cs; | 1907 | | // array: | 1908 | | // '[' *ws ']' | 1909 | | // '[' *ws value *ws *[ ',' *ws value *ws ] ']' | 1910 | 52 | do_arr1: | 1911 | 52 | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1912 | 52 | if(BOOST_JSON_UNLIKELY(! cs)) | 1913 | 52 | return maybe_suspend(cs.begin(), state::arr1, size); | 1914 | 0 | if(BOOST_JSON_LIKELY(*cs != ']')) | 1915 | 0 | { | 1916 | 0 | loop: | 1917 | 0 | if(allow_comments && *cs == '/') | 1918 | 0 | { | 1919 | 17 | do_arr2: | 1920 | 17 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); | 1921 | 17 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1922 | 17 | return suspend_or_fail(state::arr2, size); | 1923 | 0 | goto do_arr1; | 1924 | 17 | } | 1925 | 0 | if(BOOST_JSON_UNLIKELY(++size > | 1926 | 0 | 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.30k | do_arr3: | 1933 | | // array is not empty, value required | 1934 | 1.30k | cs = parse_value(cs.begin(), stack_empty, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | 1935 | 1.30k | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1936 | 792 | return suspend_or_fail(state::arr3, size); | 1937 | 639 | do_arr4: | 1938 | 639 | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1939 | 639 | if(BOOST_JSON_UNLIKELY(! cs)) | 1940 | 639 | return maybe_suspend(cs.begin(), state::arr4, size); | 1941 | 0 | if(BOOST_JSON_LIKELY(*cs == ',')) | 1942 | 0 | { | 1943 | 0 | ++cs; | 1944 | 145 | do_arr5: | 1945 | 145 | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1946 | 145 | if(BOOST_JSON_UNLIKELY(! cs)) | 1947 | 145 | return maybe_suspend(cs.begin(), state::arr5, size); | 1948 | | // loop for next element | 1949 | 0 | if(! allow_trailing || *cs != ']') | 1950 | 0 | goto loop; | 1951 | 0 | } | 1952 | 0 | else if(BOOST_JSON_UNLIKELY(*cs != ']')) | 1953 | 0 | { | 1954 | 0 | if(allow_comments && *cs == '/') | 1955 | 0 | { | 1956 | 8 | do_arr6: | 1957 | 8 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); | 1958 | 8 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1959 | 8 | return suspend_or_fail(state::arr6, size); | 1960 | 0 | goto do_arr4; | 1961 | 8 | } | 1962 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 1963 | 0 | = BOOST_CURRENT_LOCATION; | 1964 | 0 | return fail(cs.begin(), error::syntax, &loc); | 1965 | 0 | } | 1966 | | // got closing bracket; fall through | 1967 | 0 | } | 1968 | 0 | if(BOOST_JSON_UNLIKELY( | 1969 | 0 | ! h_.on_array_end(size, ec_))) | 1970 | 0 | return fail(cs.begin()); | 1971 | 0 | ++depth_; | 1972 | 0 | ++cs; | 1973 | 0 | return cs.begin(); | 1974 | 0 | } |
|
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 | 10.4M | { |
1987 | 10.4M | constexpr bool precise_parsing = mode == number_precision::precise; |
1988 | 10.4M | 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 | 10.4M | bool const negative = first == '-'; |
1995 | 10.4M | bool const zero_first = first == '0'; |
1996 | 10.4M | bool const nonzero_first = first == '+'; |
1997 | 10.4M | detail::const_stream_wrapper cs(p, end_); |
1998 | 10.4M | number num; |
1999 | 10.4M | const char* begin = cs.begin(); |
2000 | 10.4M | if(stack_empty || st_.empty()) |
2001 | 10.4M | { |
2002 | 10.4M | num.bias = 0; |
2003 | 10.4M | num.exp = 0; |
2004 | 10.4M | num.frac = false; |
2005 | 10.4M | num_buf_.clear(); |
2006 | | |
2007 | | //---------------------------------- |
2008 | | // |
2009 | | // '-' |
2010 | | // leading minus sign |
2011 | | // |
2012 | 10.4M | BOOST_ASSERT(cs); |
2013 | 10.4M | if(negative) |
2014 | 71.3k | ++cs; |
2015 | | |
2016 | 10.4M | num.neg = negative; |
2017 | 10.4M | num.frac = false; |
2018 | 10.4M | num.exp = 0; |
2019 | 10.4M | num.bias = 0; |
2020 | | |
2021 | | // fast path |
2022 | 10.4M | if( cs.remain() >= 16 + 1 + 16 ) // digits . digits |
2023 | 10.4M | { |
2024 | 10.4M | int n1; |
2025 | | |
2026 | 10.4M | if( nonzero_first || |
2027 | 66.7k | (negative && *cs != '0') ) |
2028 | 9.68M | { |
2029 | 9.68M | n1 = detail::count_digits( cs.begin() ); |
2030 | 9.68M | BOOST_ASSERT(n1 >= 0 && n1 <= 16); |
2031 | | |
2032 | 9.68M | 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 | 9.68M | if( ! nonzero_first && n1 == 0 ) |
2040 | 29 | { |
2041 | | // digit required |
2042 | 29 | BOOST_STATIC_CONSTEXPR source_location loc |
2043 | 29 | = BOOST_CURRENT_LOCATION; |
2044 | 29 | return fail(cs.begin(), error::syntax, &loc); |
2045 | 29 | } |
2046 | | |
2047 | 9.68M | BOOST_IF_CONSTEXPR( !no_parsing ) |
2048 | 9.68M | num.mant = detail::parse_unsigned( 0, cs.begin(), n1 ); |
2049 | | else |
2050 | 535k | num.mant = 0; |
2051 | | |
2052 | 9.68M | cs += n1; |
2053 | | |
2054 | | // integer or floating-point with |
2055 | | // >= 16 leading digits |
2056 | 9.68M | if( n1 == 16 ) |
2057 | 69.7k | { |
2058 | 69.7k | goto do_num2; |
2059 | 69.7k | } |
2060 | 9.68M | } |
2061 | 735k | else |
2062 | 735k | { |
2063 | | // 0. floating-point or 0e integer |
2064 | 735k | num.mant = 0; |
2065 | 735k | n1 = 0; |
2066 | 735k | ++cs; |
2067 | 735k | } |
2068 | | |
2069 | 10.3M | { |
2070 | 10.3M | const char c = *cs; |
2071 | 10.3M | if(c != '.') |
2072 | 10.2M | { |
2073 | 10.2M | if((c | 32) == 'e') |
2074 | 4.14M | { |
2075 | 4.14M | ++cs; |
2076 | 4.14M | goto do_exp1; |
2077 | 4.14M | } |
2078 | 6.14M | BOOST_IF_CONSTEXPR( negative && !no_parsing ) |
2079 | 6.14M | num.mant = ~num.mant + 1; |
2080 | 6.14M | goto finish_signed; |
2081 | 10.2M | } |
2082 | 10.3M | } |
2083 | | |
2084 | | // floating-point number |
2085 | | |
2086 | 53.3k | ++cs; |
2087 | | |
2088 | 53.3k | int n2 = detail::count_digits( cs.begin() ); |
2089 | 53.3k | BOOST_ASSERT(n2 >= 0 && n2 <= 16); |
2090 | | |
2091 | 53.3k | if( n2 == 0 ) |
2092 | 34 | { |
2093 | | // digit required |
2094 | 34 | BOOST_STATIC_CONSTEXPR source_location loc |
2095 | 34 | = BOOST_CURRENT_LOCATION; |
2096 | 34 | return fail(cs.begin(), error::syntax, &loc); |
2097 | 34 | } |
2098 | | |
2099 | | // floating-point mantissa overflow |
2100 | 53.3k | if( n1 + n2 >= 19 ) |
2101 | 4.00k | { |
2102 | 4.00k | goto do_num7; |
2103 | 4.00k | } |
2104 | | |
2105 | 49.3k | BOOST_IF_CONSTEXPR( !no_parsing ) |
2106 | 49.3k | num.mant = detail::parse_unsigned( num.mant, cs.begin(), n2 ); |
2107 | | |
2108 | 49.3k | BOOST_ASSERT(num.bias == 0); |
2109 | | |
2110 | 49.3k | num.bias -= n2; |
2111 | | |
2112 | 49.3k | cs += n2; |
2113 | | |
2114 | 49.3k | char ch = *cs; |
2115 | | |
2116 | 49.3k | if( (ch | 32) == 'e' ) |
2117 | 9.64k | { |
2118 | 9.64k | ++cs; |
2119 | 9.64k | goto do_exp1; |
2120 | 9.64k | } |
2121 | 39.6k | else if( ch >= '0' && ch <= '9' ) |
2122 | 8.84k | { |
2123 | 8.84k | goto do_num8; |
2124 | 8.84k | } |
2125 | | |
2126 | 30.8k | goto finish_dub; |
2127 | 49.3k | } |
2128 | 10.4M | } |
2129 | 6.56k | else |
2130 | 6.56k | { |
2131 | 6.56k | num = num_; |
2132 | 6.56k | state st; |
2133 | 6.56k | st_.pop(st); |
2134 | 6.56k | switch(st) |
2135 | 6.56k | { |
2136 | 0 | default: BOOST_JSON_UNREACHABLE(); |
2137 | 58 | case state::num1: goto do_num1; |
2138 | 1.08k | case state::num2: goto do_num2; |
2139 | 547 | case state::num3: goto do_num3; |
2140 | 9 | case state::num4: goto do_num4; |
2141 | 1.03k | case state::num5: goto do_num5; |
2142 | 84 | case state::num6: goto do_num6; |
2143 | 38 | case state::num7: goto do_num7; |
2144 | 1.30k | case state::num8: goto do_num8; |
2145 | 191 | case state::exp1: goto do_exp1; |
2146 | 93 | case state::exp2: goto do_exp2; |
2147 | 2.12k | case state::exp3: goto do_exp3; |
2148 | 6.56k | } |
2149 | 6.56k | } |
2150 | | |
2151 | | //---------------------------------- |
2152 | | // |
2153 | | // DIGIT |
2154 | | // first digit |
2155 | | // |
2156 | 28.0k | do_num1: |
2157 | 28.0k | if(zero_first || nonzero_first || |
2158 | 4.64k | BOOST_JSON_LIKELY(cs)) |
2159 | 27.9k | { |
2160 | 27.9k | char const c = *cs; |
2161 | 27.9k | if(zero_first) |
2162 | 6.01k | { |
2163 | 6.01k | ++cs; |
2164 | 6.01k | num.mant = 0; |
2165 | 6.01k | goto do_num6; |
2166 | 6.01k | } |
2167 | 21.9k | else if(nonzero_first || BOOST_JSON_LIKELY( |
2168 | 21.9k | c >= '1' && c <= '9')) |
2169 | 20.9k | { |
2170 | 20.9k | ++cs; |
2171 | 20.9k | num.mant = c - '0'; |
2172 | 20.9k | } |
2173 | 972 | else if(BOOST_JSON_UNLIKELY( |
2174 | 972 | c == '0')) |
2175 | 869 | { |
2176 | 869 | ++cs; |
2177 | 869 | num.mant = 0; |
2178 | 869 | goto do_num6; |
2179 | 869 | } |
2180 | 103 | 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 | 103 | else |
2189 | 103 | { |
2190 | 103 | BOOST_STATIC_CONSTEXPR source_location loc |
2191 | 103 | = BOOST_CURRENT_LOCATION; |
2192 | 103 | return fail(cs.begin(), error::syntax, &loc); |
2193 | 103 | } |
2194 | 27.9k | } |
2195 | 125 | else |
2196 | 125 | { |
2197 | 125 | if(BOOST_JSON_UNLIKELY( |
2198 | 125 | ! h_.on_number_part( |
2199 | 125 | {begin, cs.used(begin)}, ec_))) |
2200 | 0 | return fail(cs.begin()); |
2201 | | |
2202 | 125 | BOOST_IF_CONSTEXPR( precise_parsing ) |
2203 | 125 | num_buf_.append( begin, cs.used(begin) ); |
2204 | 125 | return maybe_suspend( |
2205 | 125 | cs.begin(), state::num1, num); |
2206 | 125 | } |
2207 | | |
2208 | | //---------------------------------- |
2209 | | // |
2210 | | // 1*DIGIT |
2211 | | // significant digits left of decimal |
2212 | | // |
2213 | 91.7k | do_num2: |
2214 | 91.7k | if(negative || (!stack_empty && num.neg)) |
2215 | 15.8k | { |
2216 | 15.8k | for(;;) |
2217 | 49.7k | { |
2218 | 49.7k | if(BOOST_JSON_UNLIKELY(! cs)) |
2219 | 866 | { |
2220 | 866 | if(BOOST_JSON_UNLIKELY(more_)) |
2221 | 363 | { |
2222 | 363 | if(BOOST_JSON_UNLIKELY( |
2223 | 363 | ! h_.on_number_part( |
2224 | 363 | {begin, cs.used(begin)}, ec_))) |
2225 | 0 | return fail(cs.begin()); |
2226 | | |
2227 | 363 | BOOST_IF_CONSTEXPR( precise_parsing ) |
2228 | 363 | num_buf_.append( begin, cs.used(begin) ); |
2229 | 363 | return suspend(cs.begin(), state::num2, num); |
2230 | 363 | } |
2231 | 503 | goto finish_int; |
2232 | 866 | } |
2233 | 48.9k | char const c = *cs; |
2234 | 48.9k | if(BOOST_JSON_LIKELY( |
2235 | 48.9k | c >= '0' && c <= '9')) |
2236 | 40.1k | { |
2237 | 40.1k | ++cs; |
2238 | | // 9223372036854775808 INT64_MIN |
2239 | 40.1k | if( num.mant > 922337203685477580 || ( |
2240 | 35.1k | num.mant == 922337203685477580 && c > '8')) |
2241 | 6.24k | break; |
2242 | 33.9k | BOOST_IF_CONSTEXPR( !no_parsing ) |
2243 | 33.9k | num.mant = 10 * num.mant + ( c - '0' ); |
2244 | 33.9k | continue; |
2245 | 40.1k | } |
2246 | 8.75k | goto do_num6; // [.eE] |
2247 | 48.9k | } |
2248 | 15.8k | } |
2249 | 75.8k | else |
2250 | 75.8k | { |
2251 | 75.8k | for(;;) |
2252 | 407k | { |
2253 | 407k | if(BOOST_JSON_UNLIKELY(! cs)) |
2254 | 1.72k | { |
2255 | 1.72k | if(BOOST_JSON_UNLIKELY(more_)) |
2256 | 720 | { |
2257 | 720 | if(BOOST_JSON_UNLIKELY( |
2258 | 720 | ! h_.on_number_part( |
2259 | 720 | {begin, cs.used(begin)}, ec_))) |
2260 | 0 | return fail(cs.begin()); |
2261 | | |
2262 | 720 | BOOST_IF_CONSTEXPR( precise_parsing ) |
2263 | 720 | num_buf_.append( begin, cs.used(begin) ); |
2264 | 720 | return suspend(cs.begin(), state::num2, num); |
2265 | 720 | } |
2266 | 1.00k | goto finish_int; |
2267 | 1.72k | } |
2268 | 406k | char const c = *cs; |
2269 | 406k | if(BOOST_JSON_LIKELY( |
2270 | 406k | c >= '0' && c <= '9')) |
2271 | 350k | { |
2272 | 350k | ++cs; |
2273 | | // 18446744073709551615 UINT64_MAX |
2274 | 350k | if( num.mant > 1844674407370955161 || ( |
2275 | 333k | num.mant == 1844674407370955161 && c > '5')) |
2276 | 19.0k | break; |
2277 | 331k | BOOST_IF_CONSTEXPR( !no_parsing ) |
2278 | 331k | num.mant = 10 * num.mant + ( c - '0' ); |
2279 | 331k | } |
2280 | 55.1k | else |
2281 | 55.1k | { |
2282 | 55.1k | goto do_num6; // [.eE] |
2283 | 55.1k | } |
2284 | 406k | } |
2285 | 75.8k | } |
2286 | 25.2k | ++num.bias; |
2287 | | |
2288 | | //---------------------------------- |
2289 | | // |
2290 | | // 1*DIGIT |
2291 | | // non-significant digits left of decimal |
2292 | | // |
2293 | 25.8k | do_num3: |
2294 | 25.8k | for(;;) |
2295 | 32.9M | { |
2296 | 32.9M | if(BOOST_JSON_UNLIKELY(! cs)) |
2297 | 1.16k | { |
2298 | 1.16k | if(BOOST_JSON_UNLIKELY(more_)) |
2299 | 547 | { |
2300 | 547 | if(BOOST_JSON_UNLIKELY( |
2301 | 547 | ! h_.on_number_part( |
2302 | 547 | {begin, cs.used(begin)}, ec_))) |
2303 | 0 | return fail(cs.begin()); |
2304 | | |
2305 | 547 | BOOST_IF_CONSTEXPR( precise_parsing ) |
2306 | 547 | num_buf_.append( begin, cs.used(begin) ); |
2307 | 547 | return suspend(cs.begin(), state::num3, num); |
2308 | 547 | } |
2309 | 617 | goto finish_dub; |
2310 | 1.16k | } |
2311 | 32.9M | char const c = *cs; |
2312 | 32.9M | if(BOOST_JSON_UNLIKELY( |
2313 | 32.9M | c >= '0' && c <= '9')) |
2314 | 32.9M | { |
2315 | 32.9M | 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 | 32.9M | ++cs; |
2322 | 32.9M | ++num.bias; |
2323 | 32.9M | } |
2324 | 24.6k | else if(BOOST_JSON_LIKELY( |
2325 | 24.6k | c == '.')) |
2326 | 4.88k | { |
2327 | 4.88k | ++cs; |
2328 | 4.88k | break; |
2329 | 4.88k | } |
2330 | 19.7k | else if((c | 32) == 'e') |
2331 | 7.89k | { |
2332 | 7.89k | ++cs; |
2333 | 7.89k | goto do_exp1; |
2334 | 7.89k | } |
2335 | 11.8k | else |
2336 | 11.8k | { |
2337 | 11.8k | goto finish_dub; |
2338 | 11.8k | } |
2339 | 32.9M | } |
2340 | | |
2341 | | //---------------------------------- |
2342 | | // |
2343 | | // DIGIT |
2344 | | // first non-significant digit |
2345 | | // to the right of decimal |
2346 | | // |
2347 | 4.89k | do_num4: |
2348 | 4.89k | { |
2349 | 4.89k | if(BOOST_JSON_UNLIKELY(! cs)) |
2350 | 24 | { |
2351 | 24 | if(BOOST_JSON_UNLIKELY( |
2352 | 24 | ! h_.on_number_part( |
2353 | 24 | {begin, cs.used(begin)}, ec_))) |
2354 | 0 | return fail(cs.begin()); |
2355 | | |
2356 | 24 | BOOST_IF_CONSTEXPR( precise_parsing ) |
2357 | 24 | num_buf_.append( begin, cs.used(begin) ); |
2358 | 24 | return maybe_suspend( |
2359 | 24 | cs.begin(), state::num4, num); |
2360 | 24 | } |
2361 | 4.87k | char const c = *cs; |
2362 | 4.87k | if(BOOST_JSON_LIKELY( |
2363 | | //static_cast<unsigned char>(c - '0') < 10)) |
2364 | 4.87k | c >= '0' && c <= '9')) |
2365 | 4.84k | { |
2366 | 4.84k | ++cs; |
2367 | 4.84k | } |
2368 | 28 | else |
2369 | 28 | { |
2370 | | // digit required |
2371 | 28 | BOOST_STATIC_CONSTEXPR source_location loc |
2372 | 28 | = BOOST_CURRENT_LOCATION; |
2373 | 28 | return fail(cs.begin(), error::syntax, &loc); |
2374 | 28 | } |
2375 | 4.87k | } |
2376 | | |
2377 | | //---------------------------------- |
2378 | | // |
2379 | | // 1*DIGIT |
2380 | | // non-significant digits |
2381 | | // to the right of decimal |
2382 | | // |
2383 | 22.2k | do_num5: |
2384 | 22.2k | for(;;) |
2385 | 4.45M | { |
2386 | 4.45M | if(BOOST_JSON_UNLIKELY(! cs)) |
2387 | 2.16k | { |
2388 | 2.16k | if(BOOST_JSON_UNLIKELY(more_)) |
2389 | 1.03k | { |
2390 | 1.03k | if(BOOST_JSON_UNLIKELY( |
2391 | 1.03k | ! h_.on_number_part( |
2392 | 1.03k | {begin, cs.used(begin)}, ec_))) |
2393 | 0 | return fail(cs.begin()); |
2394 | | |
2395 | 1.03k | BOOST_IF_CONSTEXPR( precise_parsing ) |
2396 | 1.03k | num_buf_.append( begin, cs.used(begin) ); |
2397 | 1.03k | return suspend(cs.begin(), state::num5, num); |
2398 | 1.03k | } |
2399 | 1.12k | goto finish_dub; |
2400 | 2.16k | } |
2401 | 4.44M | char const c = *cs; |
2402 | 4.44M | if(BOOST_JSON_LIKELY( |
2403 | 4.44M | c >= '0' && c <= '9')) |
2404 | 4.42M | { |
2405 | 4.42M | ++cs; |
2406 | 4.42M | } |
2407 | 20.0k | else if((c | 32) == 'e') |
2408 | 5.69k | { |
2409 | 5.69k | ++cs; |
2410 | 5.69k | goto do_exp1; |
2411 | 5.69k | } |
2412 | 14.3k | else |
2413 | 14.3k | { |
2414 | 14.3k | goto finish_dub; |
2415 | 14.3k | } |
2416 | 4.44M | } |
2417 | | |
2418 | | //---------------------------------- |
2419 | | // |
2420 | | // [.eE] |
2421 | | // |
2422 | 70.8k | do_num6: |
2423 | 70.8k | { |
2424 | 70.8k | if(BOOST_JSON_UNLIKELY(! cs)) |
2425 | 190 | { |
2426 | 190 | if(BOOST_JSON_UNLIKELY(more_)) |
2427 | 84 | { |
2428 | 84 | if(BOOST_JSON_UNLIKELY( |
2429 | 84 | ! h_.on_number_part( |
2430 | 84 | {begin, cs.used(begin)}, ec_))) |
2431 | 0 | return fail(cs.begin()); |
2432 | | |
2433 | 84 | BOOST_IF_CONSTEXPR( precise_parsing ) |
2434 | 84 | num_buf_.append( begin, cs.used(begin) ); |
2435 | 84 | return suspend(cs.begin(), state::num6, num); |
2436 | 84 | } |
2437 | 106 | goto finish_int; |
2438 | 190 | } |
2439 | 70.6k | char const c = *cs; |
2440 | 70.6k | if(BOOST_JSON_LIKELY( |
2441 | 70.6k | c == '.')) |
2442 | 11.9k | { |
2443 | 11.9k | ++cs; |
2444 | 11.9k | } |
2445 | 58.7k | else if((c | 32) == 'e') |
2446 | 9.09k | { |
2447 | 9.09k | ++cs; |
2448 | 9.09k | goto do_exp1; |
2449 | 9.09k | } |
2450 | 49.6k | else |
2451 | 49.6k | { |
2452 | 49.6k | goto finish_int; |
2453 | 49.6k | } |
2454 | 70.6k | } |
2455 | | |
2456 | | //---------------------------------- |
2457 | | // |
2458 | | // DIGIT |
2459 | | // first significant digit |
2460 | | // to the right of decimal |
2461 | | // |
2462 | 16.0k | do_num7: |
2463 | 16.0k | { |
2464 | 16.0k | if(BOOST_JSON_UNLIKELY(! cs)) |
2465 | 94 | { |
2466 | 94 | if(BOOST_JSON_UNLIKELY(more_)) |
2467 | 38 | { |
2468 | 38 | if(BOOST_JSON_UNLIKELY( |
2469 | 38 | ! h_.on_number_part( |
2470 | 38 | {begin, cs.used(begin)}, ec_))) |
2471 | 0 | return fail(cs.begin()); |
2472 | | |
2473 | 38 | BOOST_IF_CONSTEXPR( precise_parsing ) |
2474 | 38 | num_buf_.append( begin, cs.used(begin) ); |
2475 | 38 | return suspend(cs.begin(), state::num7, num); |
2476 | 38 | } |
2477 | | // digit required |
2478 | 94 | BOOST_STATIC_CONSTEXPR source_location loc |
2479 | 56 | = BOOST_CURRENT_LOCATION; |
2480 | 56 | return fail(cs.begin(), error::syntax, &loc); |
2481 | 94 | } |
2482 | 15.9k | char const c = *cs; |
2483 | 15.9k | if(BOOST_JSON_UNLIKELY( |
2484 | 15.9k | c < '0' || c > '9')) |
2485 | 130 | { |
2486 | | // digit required |
2487 | 130 | BOOST_STATIC_CONSTEXPR source_location loc |
2488 | 130 | = BOOST_CURRENT_LOCATION; |
2489 | 130 | return fail(cs.begin(), error::syntax, &loc); |
2490 | 130 | } |
2491 | 15.9k | } |
2492 | | |
2493 | | //---------------------------------- |
2494 | | // |
2495 | | // 1*DIGIT |
2496 | | // significant digits |
2497 | | // to the right of decimal |
2498 | | // |
2499 | 25.9k | do_num8: |
2500 | 25.9k | for(;;) |
2501 | 27.9M | { |
2502 | 27.9M | if(BOOST_JSON_UNLIKELY(! cs)) |
2503 | 2.94k | { |
2504 | 2.94k | if(BOOST_JSON_UNLIKELY(more_)) |
2505 | 1.30k | { |
2506 | 1.30k | if(BOOST_JSON_UNLIKELY( |
2507 | 1.30k | ! h_.on_number_part( |
2508 | 1.30k | {begin, cs.used(begin)}, ec_))) |
2509 | 0 | return fail(cs.begin()); |
2510 | | |
2511 | 1.30k | BOOST_IF_CONSTEXPR( precise_parsing ) |
2512 | 1.30k | num_buf_.append( begin, cs.used(begin) ); |
2513 | 1.30k | return suspend(cs.begin(), state::num8, num); |
2514 | 1.30k | } |
2515 | 1.64k | goto finish_dub; |
2516 | 2.94k | } |
2517 | 27.9M | char const c = *cs; |
2518 | 27.9M | if(BOOST_JSON_LIKELY( |
2519 | 27.9M | c >= '0' && c <= '9')) |
2520 | 27.9M | { |
2521 | 27.9M | ++cs; |
2522 | 27.9M | if(!no_parsing && BOOST_JSON_LIKELY( |
2523 | 27.9M | num.mant <= 9007199254740991)) // 2^53-1 |
2524 | 27.9M | { |
2525 | 27.9M | 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 | 27.9M | --num.bias; |
2532 | 27.9M | num.mant = 10 * num.mant + ( c - '0' ); |
2533 | 27.9M | } |
2534 | 16.3k | else |
2535 | 16.3k | { |
2536 | 16.3k | goto do_num5; |
2537 | 16.3k | } |
2538 | 27.9M | } |
2539 | 6.61k | else if((c | 32) == 'e') |
2540 | 2.48k | { |
2541 | 2.48k | ++cs; |
2542 | 2.48k | goto do_exp1; |
2543 | 2.48k | } |
2544 | 4.13k | else |
2545 | 4.13k | { |
2546 | 4.13k | goto finish_dub; |
2547 | 4.13k | } |
2548 | 27.9M | } |
2549 | | |
2550 | | //---------------------------------- |
2551 | | // |
2552 | | // *[+-] |
2553 | | // |
2554 | 4.18M | do_exp1: |
2555 | 4.18M | if(BOOST_JSON_UNLIKELY(! cs)) |
2556 | 466 | { |
2557 | 466 | if(BOOST_JSON_UNLIKELY( |
2558 | 466 | ! h_.on_number_part( |
2559 | 466 | {begin, cs.used(begin)}, ec_))) |
2560 | 0 | return fail(cs.begin()); |
2561 | | |
2562 | 466 | BOOST_IF_CONSTEXPR( precise_parsing ) |
2563 | 466 | num_buf_.append( begin, cs.used(begin) ); |
2564 | 466 | return maybe_suspend( |
2565 | 466 | cs.begin(), state::exp1, num); |
2566 | 466 | } |
2567 | 4.18M | if(*cs == '+') |
2568 | 3.06k | { |
2569 | 3.06k | ++cs; |
2570 | 3.06k | } |
2571 | 4.17M | else if(*cs == '-') |
2572 | 46.1k | { |
2573 | 46.1k | ++cs; |
2574 | 46.1k | num.frac = true; |
2575 | 46.1k | } |
2576 | | |
2577 | | //---------------------------------- |
2578 | | // |
2579 | | // DIGIT |
2580 | | // first digit of the exponent |
2581 | | // |
2582 | 4.18M | do_exp2: |
2583 | 4.18M | { |
2584 | 4.18M | if(BOOST_JSON_UNLIKELY(! cs)) |
2585 | 219 | { |
2586 | 219 | if(BOOST_JSON_UNLIKELY(more_)) |
2587 | 93 | { |
2588 | 93 | if(BOOST_JSON_UNLIKELY( |
2589 | 93 | ! h_.on_number_part( |
2590 | 93 | {begin, cs.used(begin)}, ec_))) |
2591 | 0 | return fail(cs.begin()); |
2592 | | |
2593 | 93 | BOOST_IF_CONSTEXPR( precise_parsing ) |
2594 | 93 | num_buf_.append( begin, cs.used(begin) ); |
2595 | 93 | return suspend(cs.begin(), state::exp2, num); |
2596 | 93 | } |
2597 | | // digit required |
2598 | 219 | BOOST_STATIC_CONSTEXPR source_location loc |
2599 | 126 | = BOOST_CURRENT_LOCATION; |
2600 | 126 | return fail(cs.begin(), error::syntax, &loc); |
2601 | 219 | } |
2602 | 4.18M | char const c = *cs; |
2603 | 4.18M | if(BOOST_JSON_UNLIKELY( |
2604 | 4.18M | c < '0' || c > '9')) |
2605 | 255 | { |
2606 | | // digit required |
2607 | 255 | BOOST_STATIC_CONSTEXPR source_location loc |
2608 | 255 | = BOOST_CURRENT_LOCATION; |
2609 | 255 | return fail(cs.begin(), error::syntax, &loc); |
2610 | 255 | } |
2611 | 4.18M | ++cs; |
2612 | 4.18M | num.exp = c - '0'; |
2613 | 4.18M | } |
2614 | | |
2615 | | //---------------------------------- |
2616 | | // |
2617 | | // 1*DIGIT |
2618 | | // subsequent digits in the exponent |
2619 | | // |
2620 | 4.18M | do_exp3: |
2621 | 4.18M | for(;;) |
2622 | 8.53M | { |
2623 | 8.53M | if(BOOST_JSON_UNLIKELY(! cs)) |
2624 | 5.26k | { |
2625 | 5.26k | if(BOOST_JSON_UNLIKELY(more_)) |
2626 | 2.12k | { |
2627 | 2.12k | if(BOOST_JSON_UNLIKELY( |
2628 | 2.12k | ! h_.on_number_part( |
2629 | 2.12k | {begin, cs.used(begin)}, ec_))) |
2630 | 0 | return fail(cs.begin()); |
2631 | | |
2632 | 2.12k | BOOST_IF_CONSTEXPR( precise_parsing ) |
2633 | 2.12k | num_buf_.append( begin, cs.used(begin) ); |
2634 | 2.12k | return suspend(cs.begin(), state::exp3, num); |
2635 | 2.12k | } |
2636 | 5.26k | } |
2637 | 8.53M | else |
2638 | 8.53M | { |
2639 | 8.53M | char const c = *cs; |
2640 | 8.53M | if(BOOST_JSON_LIKELY( c >= '0' && c <= '9' )) |
2641 | 4.35M | { |
2642 | 4.35M | if(BOOST_JSON_UNLIKELY( |
2643 | | // 2147483647 INT_MAX |
2644 | 4.35M | num.exp > 214748364 || |
2645 | 4.35M | (num.exp == 214748364 && c > '7') |
2646 | 4.35M | )) |
2647 | 62.1k | num.exp = INT_MAX; |
2648 | 4.29M | else BOOST_IF_CONSTEXPR( !no_parsing ) |
2649 | 4.29M | num.exp = 10 * num.exp + ( c - '0' ); |
2650 | | |
2651 | 4.35M | ++cs; |
2652 | 4.35M | continue; |
2653 | 4.35M | } |
2654 | 8.53M | } |
2655 | 4.18M | BOOST_ASSERT(num.exp >= 0); |
2656 | 4.18M | if ( num.frac ) |
2657 | 46.0k | { |
2658 | 46.0k | if(BOOST_JSON_UNLIKELY( num.bias < (INT_MIN + num.exp) )) |
2659 | 3.86k | { |
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.86k | if(BOOST_JSON_UNLIKELY( |
2664 | 3.86k | (num.exp == INT_MAX) && |
2665 | 3.86k | (num.bias < 0) && |
2666 | 3.86k | (num.exp + num.bias < 308) && |
2667 | 3.86k | 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.86k | num.bias = 0; |
2675 | 3.86k | num.exp = INT_MAX; |
2676 | 3.86k | } |
2677 | 46.0k | } |
2678 | 4.13M | else if (BOOST_JSON_UNLIKELY( num.bias > (INT_MAX - num.exp) )) |
2679 | 2.77k | { |
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 | 2.77k | if(BOOST_JSON_UNLIKELY( |
2684 | 2.77k | (num.exp == INT_MAX) && |
2685 | 2.77k | (num.bias > 0) && |
2686 | 2.77k | (num.exp - num.bias < 308) && |
2687 | 2.77k | 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 | 2.77k | num.bias = 0; |
2695 | 2.77k | num.exp = INT_MAX; |
2696 | 2.77k | } |
2697 | 4.18M | goto finish_dub; |
2698 | 4.18M | } |
2699 | | |
2700 | 51.2k | finish_int: |
2701 | 51.2k | if(negative || (!stack_empty && num.neg)) |
2702 | 4.97k | { |
2703 | 4.97k | if(BOOST_JSON_UNLIKELY( |
2704 | 4.97k | ! h_.on_int64(static_cast< |
2705 | 4.97k | int64_t>(~num.mant + 1), {begin, cs.used(begin)}, ec_))) |
2706 | 0 | return fail(cs.begin()); |
2707 | 4.97k | return cs.begin(); |
2708 | 4.97k | } |
2709 | 46.2k | if(num.mant <= INT64_MAX) |
2710 | 20.3k | { |
2711 | 6.16M | finish_signed: |
2712 | 6.16M | if(BOOST_JSON_UNLIKELY( |
2713 | 6.16M | ! h_.on_int64(static_cast< |
2714 | 6.16M | int64_t>(num.mant), {begin, cs.used(begin)}, ec_))) |
2715 | 0 | return fail(cs.begin()); |
2716 | 6.16M | return cs.begin(); |
2717 | 6.16M | } |
2718 | 25.8k | if(BOOST_JSON_UNLIKELY( |
2719 | 25.8k | ! h_.on_uint64(num.mant, {begin, cs.used(begin)}, ec_))) |
2720 | 0 | return fail(cs.begin()); |
2721 | 25.8k | return cs.begin(); |
2722 | 4.24M | finish_dub: |
2723 | 4.24M | double d; |
2724 | 4.24M | std::size_t const size = cs.used(begin); |
2725 | 4.24M | BOOST_ASSERT( !num_buf_.size() || precise_parsing ); |
2726 | | BOOST_IF_CONSTEXPR( precise_parsing ) |
2727 | 52.4k | { |
2728 | 52.4k | char const* data = begin; |
2729 | 52.4k | 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 | 52.4k | if(BOOST_JSON_UNLIKELY( num_buf_.size() )) |
2734 | 3.38k | { |
2735 | 3.38k | data = num_buf_.append( begin, size ); |
2736 | 3.38k | full_size = num_buf_.size(); |
2737 | 3.38k | } |
2738 | 52.4k | auto const err = detail::charconv::from_chars( |
2739 | 52.4k | data, data + full_size, d ); |
2740 | 52.4k | BOOST_ASSERT( err.ec != std::errc::invalid_argument ); |
2741 | 52.4k | BOOST_ASSERT( err.ptr == data + full_size ); |
2742 | 52.4k | (void)err; |
2743 | | } |
2744 | 4.19M | else BOOST_IF_CONSTEXPR( no_parsing ) |
2745 | 4.19M | d = 0; |
2746 | | else |
2747 | 4.09M | d = detail::dec_to_float( |
2748 | 4.09M | num.mant, |
2749 | 4.09M | num.bias + (num.frac ? |
2750 | 4.05M | -num.exp : num.exp), |
2751 | 4.09M | num.neg); |
2752 | 4.24M | if(BOOST_JSON_UNLIKELY( |
2753 | 4.24M | ! h_.on_double(d, {begin, size}, ec_))) |
2754 | 0 | return fail(cs.begin()); |
2755 | 4.24M | return cs.begin(); |
2756 | 4.24M | } char const* boost::json::basic_parser<boost::json::detail::handler>::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 | 189k | { | 1987 | 189k | constexpr bool precise_parsing = mode == number_precision::precise; | 1988 | 189k | 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 | 189k | bool const negative = first == '-'; | 1995 | 189k | bool const zero_first = first == '0'; | 1996 | 189k | bool const nonzero_first = first == '+'; | 1997 | 189k | detail::const_stream_wrapper cs(p, end_); | 1998 | 189k | number num; | 1999 | 189k | const char* begin = cs.begin(); | 2000 | 189k | if(stack_empty || st_.empty()) | 2001 | 189k | { | 2002 | 189k | num.bias = 0; | 2003 | 189k | num.exp = 0; | 2004 | 189k | num.frac = false; | 2005 | 189k | num_buf_.clear(); | 2006 | | | 2007 | | //---------------------------------- | 2008 | | // | 2009 | | // '-' | 2010 | | // leading minus sign | 2011 | | // | 2012 | 189k | BOOST_ASSERT(cs); | 2013 | 189k | if(negative) | 2014 | 0 | ++cs; | 2015 | | | 2016 | 189k | num.neg = negative; | 2017 | 189k | num.frac = false; | 2018 | 189k | num.exp = 0; | 2019 | 189k | num.bias = 0; | 2020 | | | 2021 | | // fast path | 2022 | 189k | if( cs.remain() >= 16 + 1 + 16 ) // digits . digits | 2023 | 185k | { | 2024 | 185k | int n1; | 2025 | | | 2026 | 185k | if( nonzero_first || | 2027 | 0 | (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 | 185k | else | 2062 | 185k | { | 2063 | | // 0. floating-point or 0e integer | 2064 | 185k | num.mant = 0; | 2065 | 185k | n1 = 0; | 2066 | 185k | ++cs; | 2067 | 185k | } | 2068 | | | 2069 | 185k | { | 2070 | 185k | const char c = *cs; | 2071 | 185k | if(c != '.') | 2072 | 177k | { | 2073 | 177k | if((c | 32) == 'e') | 2074 | 3.22k | { | 2075 | 3.22k | ++cs; | 2076 | 3.22k | goto do_exp1; | 2077 | 3.22k | } | 2078 | 174k | BOOST_IF_CONSTEXPR( negative && !no_parsing ) | 2079 | 174k | num.mant = ~num.mant + 1; | 2080 | 174k | goto finish_signed; | 2081 | 177k | } | 2082 | 185k | } | 2083 | | | 2084 | | // floating-point number | 2085 | | | 2086 | 8.38k | ++cs; | 2087 | | | 2088 | 8.38k | int n2 = detail::count_digits( cs.begin() ); | 2089 | 8.38k | BOOST_ASSERT(n2 >= 0 && n2 <= 16); | 2090 | | | 2091 | 8.38k | if( n2 == 0 ) | 2092 | 7 | { | 2093 | | // digit required | 2094 | 7 | BOOST_STATIC_CONSTEXPR source_location loc | 2095 | 7 | = BOOST_CURRENT_LOCATION; | 2096 | 7 | return fail(cs.begin(), error::syntax, &loc); | 2097 | 7 | } | 2098 | | | 2099 | | // floating-point mantissa overflow | 2100 | 8.37k | if( n1 + n2 >= 19 ) | 2101 | 0 | { | 2102 | 0 | goto do_num7; | 2103 | 0 | } | 2104 | | | 2105 | 8.37k | BOOST_IF_CONSTEXPR( !no_parsing ) | 2106 | 8.37k | num.mant = detail::parse_unsigned( num.mant, cs.begin(), n2 ); | 2107 | | | 2108 | 8.37k | BOOST_ASSERT(num.bias == 0); | 2109 | | | 2110 | 8.37k | num.bias -= n2; | 2111 | | | 2112 | 8.37k | cs += n2; | 2113 | | | 2114 | 8.37k | char ch = *cs; | 2115 | | | 2116 | 8.37k | if( (ch | 32) == 'e' ) | 2117 | 2.35k | { | 2118 | 2.35k | ++cs; | 2119 | 2.35k | goto do_exp1; | 2120 | 2.35k | } | 2121 | 6.02k | else if( ch >= '0' && ch <= '9' ) | 2122 | 2.18k | { | 2123 | 2.18k | goto do_num8; | 2124 | 2.18k | } | 2125 | | | 2126 | 3.83k | goto finish_dub; | 2127 | 8.37k | } | 2128 | 189k | } | 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 | 3.76k | do_num1: | 2157 | 3.76k | if(zero_first || nonzero_first || | 2158 | 0 | BOOST_JSON_LIKELY(cs)) | 2159 | 3.76k | { | 2160 | 3.76k | char const c = *cs; | 2161 | 3.76k | if(zero_first) | 2162 | 3.76k | { | 2163 | 3.76k | ++cs; | 2164 | 3.76k | num.mant = 0; | 2165 | 3.76k | goto do_num6; | 2166 | 3.76k | } | 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 | 3.76k | } | 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 | 1.09k | do_num5: | 2384 | 1.09k | for(;;) | 2385 | 3.12k | { | 2386 | 3.12k | if(BOOST_JSON_UNLIKELY(! cs)) | 2387 | 35 | { | 2388 | 35 | if(BOOST_JSON_UNLIKELY(more_)) | 2389 | 16 | { | 2390 | 16 | if(BOOST_JSON_UNLIKELY( | 2391 | 16 | ! h_.on_number_part( | 2392 | 16 | {begin, cs.used(begin)}, ec_))) | 2393 | 0 | return fail(cs.begin()); | 2394 | | | 2395 | 16 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2396 | 16 | num_buf_.append( begin, cs.used(begin) ); | 2397 | 16 | return suspend(cs.begin(), state::num5, num); | 2398 | 16 | } | 2399 | 19 | goto finish_dub; | 2400 | 35 | } | 2401 | 3.09k | char const c = *cs; | 2402 | 3.09k | if(BOOST_JSON_LIKELY( | 2403 | 3.09k | c >= '0' && c <= '9')) | 2404 | 2.03k | { | 2405 | 2.03k | ++cs; | 2406 | 2.03k | } | 2407 | 1.06k | else if((c | 32) == 'e') | 2408 | 424 | { | 2409 | 424 | ++cs; | 2410 | 424 | goto do_exp1; | 2411 | 424 | } | 2412 | 636 | else | 2413 | 636 | { | 2414 | 636 | goto finish_dub; | 2415 | 636 | } | 2416 | 3.09k | } | 2417 | | | 2418 | | //---------------------------------- | 2419 | | // | 2420 | | // [.eE] | 2421 | | // | 2422 | 3.76k | do_num6: | 2423 | 3.76k | { | 2424 | 3.76k | if(BOOST_JSON_UNLIKELY(! cs)) | 2425 | 38 | { | 2426 | 38 | if(BOOST_JSON_UNLIKELY(more_)) | 2427 | 22 | { | 2428 | 22 | if(BOOST_JSON_UNLIKELY( | 2429 | 22 | ! h_.on_number_part( | 2430 | 22 | {begin, cs.used(begin)}, ec_))) | 2431 | 0 | return fail(cs.begin()); | 2432 | | | 2433 | 22 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2434 | 22 | num_buf_.append( begin, cs.used(begin) ); | 2435 | 22 | return suspend(cs.begin(), state::num6, num); | 2436 | 22 | } | 2437 | 16 | goto finish_int; | 2438 | 38 | } | 2439 | 3.73k | char const c = *cs; | 2440 | 3.73k | if(BOOST_JSON_LIKELY( | 2441 | 3.73k | c == '.')) | 2442 | 741 | { | 2443 | 741 | ++cs; | 2444 | 741 | } | 2445 | 2.99k | else if((c | 32) == 'e') | 2446 | 978 | { | 2447 | 978 | ++cs; | 2448 | 978 | goto do_exp1; | 2449 | 978 | } | 2450 | 2.01k | else | 2451 | 2.01k | { | 2452 | 2.01k | goto finish_int; | 2453 | 2.01k | } | 2454 | 3.73k | } | 2455 | | | 2456 | | //---------------------------------- | 2457 | | // | 2458 | | // DIGIT | 2459 | | // first significant digit | 2460 | | // to the right of decimal | 2461 | | // | 2462 | 741 | do_num7: | 2463 | 741 | { | 2464 | 741 | if(BOOST_JSON_UNLIKELY(! cs)) | 2465 | 10 | { | 2466 | 10 | if(BOOST_JSON_UNLIKELY(more_)) | 2467 | 4 | { | 2468 | 4 | if(BOOST_JSON_UNLIKELY( | 2469 | 4 | ! h_.on_number_part( | 2470 | 4 | {begin, cs.used(begin)}, ec_))) | 2471 | 0 | return fail(cs.begin()); | 2472 | | | 2473 | 4 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2474 | 4 | num_buf_.append( begin, cs.used(begin) ); | 2475 | 4 | return suspend(cs.begin(), state::num7, num); | 2476 | 4 | } | 2477 | | // digit required | 2478 | 10 | BOOST_STATIC_CONSTEXPR source_location loc | 2479 | 6 | = BOOST_CURRENT_LOCATION; | 2480 | 6 | return fail(cs.begin(), error::syntax, &loc); | 2481 | 10 | } | 2482 | 731 | char const c = *cs; | 2483 | 731 | if(BOOST_JSON_UNLIKELY( | 2484 | 731 | c < '0' || c > '9')) | 2485 | 33 | { | 2486 | | // digit required | 2487 | 33 | BOOST_STATIC_CONSTEXPR source_location loc | 2488 | 33 | = BOOST_CURRENT_LOCATION; | 2489 | 33 | return fail(cs.begin(), error::syntax, &loc); | 2490 | 33 | } | 2491 | 731 | } | 2492 | | | 2493 | | //---------------------------------- | 2494 | | // | 2495 | | // 1*DIGIT | 2496 | | // significant digits | 2497 | | // to the right of decimal | 2498 | | // | 2499 | 2.88k | do_num8: | 2500 | 2.88k | for(;;) | 2501 | 10.1M | { | 2502 | 10.1M | if(BOOST_JSON_UNLIKELY(! cs)) | 2503 | 211 | { | 2504 | 211 | if(BOOST_JSON_UNLIKELY(more_)) | 2505 | 102 | { | 2506 | 102 | if(BOOST_JSON_UNLIKELY( | 2507 | 102 | ! h_.on_number_part( | 2508 | 102 | {begin, cs.used(begin)}, ec_))) | 2509 | 0 | return fail(cs.begin()); | 2510 | | | 2511 | 102 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2512 | 102 | num_buf_.append( begin, cs.used(begin) ); | 2513 | 102 | return suspend(cs.begin(), state::num8, num); | 2514 | 102 | } | 2515 | 109 | goto finish_dub; | 2516 | 211 | } | 2517 | 10.1M | char const c = *cs; | 2518 | 10.1M | if(BOOST_JSON_LIKELY( | 2519 | 10.1M | c >= '0' && c <= '9')) | 2520 | 10.1M | { | 2521 | 10.1M | ++cs; | 2522 | 10.1M | if(!no_parsing && BOOST_JSON_LIKELY( | 2523 | 10.1M | num.mant <= 9007199254740991)) // 2^53-1 | 2524 | 10.1M | { | 2525 | 10.1M | 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 | 10.1M | --num.bias; | 2532 | 10.1M | num.mant = 10 * num.mant + ( c - '0' ); | 2533 | 10.1M | } | 2534 | 1.09k | else | 2535 | 1.09k | { | 2536 | 1.09k | goto do_num5; | 2537 | 1.09k | } | 2538 | 10.1M | } | 2539 | 1.58k | else if((c | 32) == 'e') | 2540 | 641 | { | 2541 | 641 | ++cs; | 2542 | 641 | goto do_exp1; | 2543 | 641 | } | 2544 | 940 | else | 2545 | 940 | { | 2546 | 940 | goto finish_dub; | 2547 | 940 | } | 2548 | 10.1M | } | 2549 | | | 2550 | | //---------------------------------- | 2551 | | // | 2552 | | // *[+-] | 2553 | | // | 2554 | 7.62k | do_exp1: | 2555 | 7.62k | if(BOOST_JSON_UNLIKELY(! cs)) | 2556 | 41 | { | 2557 | 41 | if(BOOST_JSON_UNLIKELY( | 2558 | 41 | ! h_.on_number_part( | 2559 | 41 | {begin, cs.used(begin)}, ec_))) | 2560 | 0 | return fail(cs.begin()); | 2561 | | | 2562 | 41 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2563 | 41 | num_buf_.append( begin, cs.used(begin) ); | 2564 | 41 | return maybe_suspend( | 2565 | 41 | cs.begin(), state::exp1, num); | 2566 | 41 | } | 2567 | 7.57k | if(*cs == '+') | 2568 | 808 | { | 2569 | 808 | ++cs; | 2570 | 808 | } | 2571 | 6.77k | else if(*cs == '-') | 2572 | 1.84k | { | 2573 | 1.84k | ++cs; | 2574 | 1.84k | num.frac = true; | 2575 | 1.84k | } | 2576 | | | 2577 | | //---------------------------------- | 2578 | | // | 2579 | | // DIGIT | 2580 | | // first digit of the exponent | 2581 | | // | 2582 | 7.57k | do_exp2: | 2583 | 7.57k | { | 2584 | 7.57k | if(BOOST_JSON_UNLIKELY(! cs)) | 2585 | 20 | { | 2586 | 20 | if(BOOST_JSON_UNLIKELY(more_)) | 2587 | 11 | { | 2588 | 11 | if(BOOST_JSON_UNLIKELY( | 2589 | 11 | ! h_.on_number_part( | 2590 | 11 | {begin, cs.used(begin)}, ec_))) | 2591 | 0 | return fail(cs.begin()); | 2592 | | | 2593 | 11 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2594 | 11 | num_buf_.append( begin, cs.used(begin) ); | 2595 | 11 | return suspend(cs.begin(), state::exp2, num); | 2596 | 11 | } | 2597 | | // digit required | 2598 | 20 | BOOST_STATIC_CONSTEXPR source_location loc | 2599 | 9 | = BOOST_CURRENT_LOCATION; | 2600 | 9 | return fail(cs.begin(), error::syntax, &loc); | 2601 | 20 | } | 2602 | 7.55k | char const c = *cs; | 2603 | 7.55k | if(BOOST_JSON_UNLIKELY( | 2604 | 7.55k | c < '0' || c > '9')) | 2605 | 43 | { | 2606 | | // digit required | 2607 | 43 | BOOST_STATIC_CONSTEXPR source_location loc | 2608 | 43 | = BOOST_CURRENT_LOCATION; | 2609 | 43 | return fail(cs.begin(), error::syntax, &loc); | 2610 | 43 | } | 2611 | 7.51k | ++cs; | 2612 | 7.51k | num.exp = c - '0'; | 2613 | 7.51k | } | 2614 | | | 2615 | | //---------------------------------- | 2616 | | // | 2617 | | // 1*DIGIT | 2618 | | // subsequent digits in the exponent | 2619 | | // | 2620 | 7.51k | do_exp3: | 2621 | 7.51k | for(;;) | 2622 | 26.9k | { | 2623 | 26.9k | if(BOOST_JSON_UNLIKELY(! cs)) | 2624 | 445 | { | 2625 | 445 | if(BOOST_JSON_UNLIKELY(more_)) | 2626 | 135 | { | 2627 | 135 | if(BOOST_JSON_UNLIKELY( | 2628 | 135 | ! h_.on_number_part( | 2629 | 135 | {begin, cs.used(begin)}, ec_))) | 2630 | 0 | return fail(cs.begin()); | 2631 | | | 2632 | 135 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2633 | 135 | num_buf_.append( begin, cs.used(begin) ); | 2634 | 135 | return suspend(cs.begin(), state::exp3, num); | 2635 | 135 | } | 2636 | 445 | } | 2637 | 26.5k | else | 2638 | 26.5k | { | 2639 | 26.5k | char const c = *cs; | 2640 | 26.5k | if(BOOST_JSON_LIKELY( c >= '0' && c <= '9' )) | 2641 | 19.4k | { | 2642 | 19.4k | if(BOOST_JSON_UNLIKELY( | 2643 | | // 2147483647 INT_MAX | 2644 | 19.4k | num.exp > 214748364 || | 2645 | 19.4k | (num.exp == 214748364 && c > '7') | 2646 | 19.4k | )) | 2647 | 2.58k | num.exp = INT_MAX; | 2648 | 16.8k | else BOOST_IF_CONSTEXPR( !no_parsing ) | 2649 | 16.8k | num.exp = 10 * num.exp + ( c - '0' ); | 2650 | | | 2651 | 19.4k | ++cs; | 2652 | 19.4k | continue; | 2653 | 19.4k | } | 2654 | 26.5k | } | 2655 | 7.38k | BOOST_ASSERT(num.exp >= 0); | 2656 | 7.38k | if ( num.frac ) | 2657 | 1.79k | { | 2658 | 1.79k | if(BOOST_JSON_UNLIKELY( num.bias < (INT_MIN + num.exp) )) | 2659 | 976 | { | 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 | 976 | if(BOOST_JSON_UNLIKELY( | 2664 | 976 | (num.exp == INT_MAX) && | 2665 | 976 | (num.bias < 0) && | 2666 | 976 | (num.exp + num.bias < 308) && | 2667 | 976 | 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 | 976 | num.bias = 0; | 2675 | 976 | num.exp = INT_MAX; | 2676 | 976 | } | 2677 | 1.79k | } | 2678 | 5.58k | 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 | 7.38k | goto finish_dub; | 2698 | 7.38k | } | 2699 | | | 2700 | 2.02k | finish_int: | 2701 | 2.02k | 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 | 2.02k | if(num.mant <= INT64_MAX) | 2710 | 2.02k | { | 2711 | 176k | finish_signed: | 2712 | 176k | if(BOOST_JSON_UNLIKELY( | 2713 | 176k | ! h_.on_int64(static_cast< | 2714 | 176k | int64_t>(num.mant), {begin, cs.used(begin)}, ec_))) | 2715 | 0 | return fail(cs.begin()); | 2716 | 176k | return cs.begin(); | 2717 | 176k | } | 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 | 12.9k | finish_dub: | 2723 | 12.9k | double d; | 2724 | 12.9k | std::size_t const size = cs.used(begin); | 2725 | 12.9k | BOOST_ASSERT( !num_buf_.size() || precise_parsing ); | 2726 | | BOOST_IF_CONSTEXPR( precise_parsing ) | 2727 | | { | 2728 | | char const* data = begin; | 2729 | | 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 | 12.9k | else BOOST_IF_CONSTEXPR( no_parsing ) | 2745 | 12.9k | d = 0; | 2746 | 12.9k | else | 2747 | 12.9k | d = detail::dec_to_float( | 2748 | 12.9k | num.mant, | 2749 | 12.9k | num.bias + (num.frac ? | 2750 | 11.1k | -num.exp : num.exp), | 2751 | 12.9k | num.neg); | 2752 | 12.9k | if(BOOST_JSON_UNLIKELY( | 2753 | 12.9k | ! h_.on_double(d, {begin, size}, ec_))) | 2754 | 0 | return fail(cs.begin()); | 2755 | 12.9k | return cs.begin(); | 2756 | 12.9k | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::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>) Line | Count | Source | 1986 | 518k | { | 1987 | 518k | constexpr bool precise_parsing = mode == number_precision::precise; | 1988 | 518k | 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 | 518k | bool const negative = first == '-'; | 1995 | 518k | bool const zero_first = first == '0'; | 1996 | 518k | bool const nonzero_first = first == '+'; | 1997 | 518k | detail::const_stream_wrapper cs(p, end_); | 1998 | 518k | number num; | 1999 | 518k | const char* begin = cs.begin(); | 2000 | 518k | if(stack_empty || st_.empty()) | 2001 | 518k | { | 2002 | 518k | num.bias = 0; | 2003 | 518k | num.exp = 0; | 2004 | 518k | num.frac = false; | 2005 | 518k | num_buf_.clear(); | 2006 | | | 2007 | | //---------------------------------- | 2008 | | // | 2009 | | // '-' | 2010 | | // leading minus sign | 2011 | | // | 2012 | 518k | BOOST_ASSERT(cs); | 2013 | 518k | if(negative) | 2014 | 0 | ++cs; | 2015 | | | 2016 | 518k | num.neg = negative; | 2017 | 518k | num.frac = false; | 2018 | 518k | num.exp = 0; | 2019 | 518k | num.bias = 0; | 2020 | | | 2021 | | // fast path | 2022 | 518k | if( cs.remain() >= 16 + 1 + 16 ) // digits . digits | 2023 | 517k | { | 2024 | 517k | int n1; | 2025 | | | 2026 | 517k | if( nonzero_first || | 2027 | 0 | (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 | 517k | else | 2062 | 517k | { | 2063 | | // 0. floating-point or 0e integer | 2064 | 517k | num.mant = 0; | 2065 | 517k | n1 = 0; | 2066 | 517k | ++cs; | 2067 | 517k | } | 2068 | | | 2069 | 517k | { | 2070 | 517k | const char c = *cs; | 2071 | 517k | if(c != '.') | 2072 | 513k | { | 2073 | 513k | if((c | 32) == 'e') | 2074 | 1.29k | { | 2075 | 1.29k | ++cs; | 2076 | 1.29k | goto do_exp1; | 2077 | 1.29k | } | 2078 | 512k | BOOST_IF_CONSTEXPR( negative && !no_parsing ) | 2079 | 512k | num.mant = ~num.mant + 1; | 2080 | 512k | goto finish_signed; | 2081 | 513k | } | 2082 | 517k | } | 2083 | | | 2084 | | // floating-point number | 2085 | | | 2086 | 3.49k | ++cs; | 2087 | | | 2088 | 3.49k | int n2 = detail::count_digits( cs.begin() ); | 2089 | 3.49k | BOOST_ASSERT(n2 >= 0 && n2 <= 16); | 2090 | | | 2091 | 3.49k | 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 | 3.49k | if( n1 + n2 >= 19 ) | 2101 | 0 | { | 2102 | 0 | goto do_num7; | 2103 | 0 | } | 2104 | | | 2105 | 3.49k | BOOST_IF_CONSTEXPR( !no_parsing ) | 2106 | 3.49k | num.mant = detail::parse_unsigned( num.mant, cs.begin(), n2 ); | 2107 | | | 2108 | 3.49k | BOOST_ASSERT(num.bias == 0); | 2109 | | | 2110 | 3.49k | num.bias -= n2; | 2111 | | | 2112 | 3.49k | cs += n2; | 2113 | | | 2114 | 3.49k | char ch = *cs; | 2115 | | | 2116 | 3.49k | if( (ch | 32) == 'e' ) | 2117 | 610 | { | 2118 | 610 | ++cs; | 2119 | 610 | goto do_exp1; | 2120 | 610 | } | 2121 | 2.88k | else if( ch >= '0' && ch <= '9' ) | 2122 | 1.48k | { | 2123 | 1.48k | goto do_num8; | 2124 | 1.48k | } | 2125 | | | 2126 | 1.40k | goto finish_dub; | 2127 | 3.49k | } | 2128 | 518k | } | 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.36k | do_num1: | 2157 | 1.36k | if(zero_first || nonzero_first || | 2158 | 0 | BOOST_JSON_LIKELY(cs)) | 2159 | 1.36k | { | 2160 | 1.36k | char const c = *cs; | 2161 | 1.36k | if(zero_first) | 2162 | 1.36k | { | 2163 | 1.36k | ++cs; | 2164 | 1.36k | num.mant = 0; | 2165 | 1.36k | goto do_num6; | 2166 | 1.36k | } | 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.36k | } | 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 | 1.09k | do_num5: | 2384 | 1.09k | for(;;) | 2385 | 509k | { | 2386 | 509k | if(BOOST_JSON_UNLIKELY(! cs)) | 2387 | 113 | { | 2388 | 113 | if(BOOST_JSON_UNLIKELY(more_)) | 2389 | 113 | { | 2390 | 113 | if(BOOST_JSON_UNLIKELY( | 2391 | 113 | ! h_.on_number_part( | 2392 | 113 | {begin, cs.used(begin)}, ec_))) | 2393 | 0 | return fail(cs.begin()); | 2394 | | | 2395 | 113 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2396 | 113 | num_buf_.append( begin, cs.used(begin) ); | 2397 | 113 | return suspend(cs.begin(), state::num5, num); | 2398 | 113 | } | 2399 | 0 | goto finish_dub; | 2400 | 113 | } | 2401 | 509k | char const c = *cs; | 2402 | 509k | if(BOOST_JSON_LIKELY( | 2403 | 509k | c >= '0' && c <= '9')) | 2404 | 508k | { | 2405 | 508k | ++cs; | 2406 | 508k | } | 2407 | 983 | else if((c | 32) == 'e') | 2408 | 325 | { | 2409 | 325 | ++cs; | 2410 | 325 | goto do_exp1; | 2411 | 325 | } | 2412 | 658 | else | 2413 | 658 | { | 2414 | 658 | goto finish_dub; | 2415 | 658 | } | 2416 | 509k | } | 2417 | | | 2418 | | //---------------------------------- | 2419 | | // | 2420 | | // [.eE] | 2421 | | // | 2422 | 1.36k | do_num6: | 2423 | 1.36k | { | 2424 | 1.36k | if(BOOST_JSON_UNLIKELY(! cs)) | 2425 | 25 | { | 2426 | 25 | if(BOOST_JSON_UNLIKELY(more_)) | 2427 | 25 | { | 2428 | 25 | if(BOOST_JSON_UNLIKELY( | 2429 | 25 | ! h_.on_number_part( | 2430 | 25 | {begin, cs.used(begin)}, ec_))) | 2431 | 0 | return fail(cs.begin()); | 2432 | | | 2433 | 25 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2434 | 25 | num_buf_.append( begin, cs.used(begin) ); | 2435 | 25 | return suspend(cs.begin(), state::num6, num); | 2436 | 25 | } | 2437 | 0 | goto finish_int; | 2438 | 25 | } | 2439 | 1.34k | char const c = *cs; | 2440 | 1.34k | if(BOOST_JSON_LIKELY( | 2441 | 1.34k | c == '.')) | 2442 | 442 | { | 2443 | 442 | ++cs; | 2444 | 442 | } | 2445 | 898 | else if((c | 32) == 'e') | 2446 | 393 | { | 2447 | 393 | ++cs; | 2448 | 393 | goto do_exp1; | 2449 | 393 | } | 2450 | 505 | else | 2451 | 505 | { | 2452 | 505 | goto finish_int; | 2453 | 505 | } | 2454 | 1.34k | } | 2455 | | | 2456 | | //---------------------------------- | 2457 | | // | 2458 | | // DIGIT | 2459 | | // first significant digit | 2460 | | // to the right of decimal | 2461 | | // | 2462 | 442 | do_num7: | 2463 | 442 | { | 2464 | 442 | if(BOOST_JSON_UNLIKELY(! cs)) | 2465 | 3 | { | 2466 | 3 | if(BOOST_JSON_UNLIKELY(more_)) | 2467 | 3 | { | 2468 | 3 | if(BOOST_JSON_UNLIKELY( | 2469 | 3 | ! h_.on_number_part( | 2470 | 3 | {begin, cs.used(begin)}, ec_))) | 2471 | 0 | return fail(cs.begin()); | 2472 | | | 2473 | 3 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2474 | 3 | num_buf_.append( begin, cs.used(begin) ); | 2475 | 3 | return suspend(cs.begin(), state::num7, num); | 2476 | 3 | } | 2477 | | // digit required | 2478 | 3 | BOOST_STATIC_CONSTEXPR source_location loc | 2479 | 0 | = BOOST_CURRENT_LOCATION; | 2480 | 0 | return fail(cs.begin(), error::syntax, &loc); | 2481 | 3 | } | 2482 | 439 | char const c = *cs; | 2483 | 439 | if(BOOST_JSON_UNLIKELY( | 2484 | 439 | 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 | 439 | } | 2492 | | | 2493 | | //---------------------------------- | 2494 | | // | 2495 | | // 1*DIGIT | 2496 | | // significant digits | 2497 | | // to the right of decimal | 2498 | | // | 2499 | 1.90k | do_num8: | 2500 | 1.90k | for(;;) | 2501 | 10.5M | { | 2502 | 10.5M | if(BOOST_JSON_UNLIKELY(! cs)) | 2503 | 133 | { | 2504 | 133 | if(BOOST_JSON_UNLIKELY(more_)) | 2505 | 133 | { | 2506 | 133 | if(BOOST_JSON_UNLIKELY( | 2507 | 133 | ! h_.on_number_part( | 2508 | 133 | {begin, cs.used(begin)}, ec_))) | 2509 | 0 | return fail(cs.begin()); | 2510 | | | 2511 | 133 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2512 | 133 | num_buf_.append( begin, cs.used(begin) ); | 2513 | 133 | return suspend(cs.begin(), state::num8, num); | 2514 | 133 | } | 2515 | 0 | goto finish_dub; | 2516 | 133 | } | 2517 | 10.5M | char const c = *cs; | 2518 | 10.5M | if(BOOST_JSON_LIKELY( | 2519 | 10.5M | c >= '0' && c <= '9')) | 2520 | 10.5M | { | 2521 | 10.5M | ++cs; | 2522 | 10.5M | if(!no_parsing && BOOST_JSON_LIKELY( | 2523 | 10.5M | num.mant <= 9007199254740991)) // 2^53-1 | 2524 | 10.4M | { | 2525 | 10.4M | 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 | 10.4M | --num.bias; | 2532 | 10.4M | num.mant = 10 * num.mant + ( c - '0' ); | 2533 | 10.4M | } | 2534 | 1.09k | else | 2535 | 1.09k | { | 2536 | 1.09k | goto do_num5; | 2537 | 1.09k | } | 2538 | 10.5M | } | 2539 | 680 | else if((c | 32) == 'e') | 2540 | 299 | { | 2541 | 299 | ++cs; | 2542 | 299 | goto do_exp1; | 2543 | 299 | } | 2544 | 381 | else | 2545 | 381 | { | 2546 | 381 | goto finish_dub; | 2547 | 381 | } | 2548 | 10.5M | } | 2549 | | | 2550 | | //---------------------------------- | 2551 | | // | 2552 | | // *[+-] | 2553 | | // | 2554 | 2.92k | do_exp1: | 2555 | 2.92k | 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 | 0 | return fail(cs.begin()); | 2561 | | | 2562 | 20 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2563 | 20 | num_buf_.append( begin, cs.used(begin) ); | 2564 | 20 | return maybe_suspend( | 2565 | 20 | cs.begin(), state::exp1, num); | 2566 | 20 | } | 2567 | 2.90k | if(*cs == '+') | 2568 | 225 | { | 2569 | 225 | ++cs; | 2570 | 225 | } | 2571 | 2.68k | else if(*cs == '-') | 2572 | 1.04k | { | 2573 | 1.04k | ++cs; | 2574 | 1.04k | num.frac = true; | 2575 | 1.04k | } | 2576 | | | 2577 | | //---------------------------------- | 2578 | | // | 2579 | | // DIGIT | 2580 | | // first digit of the exponent | 2581 | | // | 2582 | 2.90k | do_exp2: | 2583 | 2.90k | { | 2584 | 2.90k | if(BOOST_JSON_UNLIKELY(! cs)) | 2585 | 10 | { | 2586 | 10 | if(BOOST_JSON_UNLIKELY(more_)) | 2587 | 10 | { | 2588 | 10 | if(BOOST_JSON_UNLIKELY( | 2589 | 10 | ! h_.on_number_part( | 2590 | 10 | {begin, cs.used(begin)}, ec_))) | 2591 | 0 | return fail(cs.begin()); | 2592 | | | 2593 | 10 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2594 | 10 | num_buf_.append( begin, cs.used(begin) ); | 2595 | 10 | return suspend(cs.begin(), state::exp2, num); | 2596 | 10 | } | 2597 | | // digit required | 2598 | 10 | BOOST_STATIC_CONSTEXPR source_location loc | 2599 | 0 | = BOOST_CURRENT_LOCATION; | 2600 | 0 | return fail(cs.begin(), error::syntax, &loc); | 2601 | 10 | } | 2602 | 2.89k | char const c = *cs; | 2603 | 2.89k | if(BOOST_JSON_UNLIKELY( | 2604 | 2.89k | c < '0' || c > '9')) | 2605 | 19 | { | 2606 | | // digit required | 2607 | 19 | BOOST_STATIC_CONSTEXPR source_location loc | 2608 | 19 | = BOOST_CURRENT_LOCATION; | 2609 | 19 | return fail(cs.begin(), error::syntax, &loc); | 2610 | 19 | } | 2611 | 2.87k | ++cs; | 2612 | 2.87k | num.exp = c - '0'; | 2613 | 2.87k | } | 2614 | | | 2615 | | //---------------------------------- | 2616 | | // | 2617 | | // 1*DIGIT | 2618 | | // subsequent digits in the exponent | 2619 | | // | 2620 | 2.87k | do_exp3: | 2621 | 2.87k | for(;;) | 2622 | 23.9k | { | 2623 | 23.9k | if(BOOST_JSON_UNLIKELY(! cs)) | 2624 | 178 | { | 2625 | 178 | if(BOOST_JSON_UNLIKELY(more_)) | 2626 | 178 | { | 2627 | 178 | if(BOOST_JSON_UNLIKELY( | 2628 | 178 | ! h_.on_number_part( | 2629 | 178 | {begin, cs.used(begin)}, ec_))) | 2630 | 0 | return fail(cs.begin()); | 2631 | | | 2632 | 178 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2633 | 178 | num_buf_.append( begin, cs.used(begin) ); | 2634 | 178 | return suspend(cs.begin(), state::exp3, num); | 2635 | 178 | } | 2636 | 178 | } | 2637 | 23.7k | else | 2638 | 23.7k | { | 2639 | 23.7k | char const c = *cs; | 2640 | 23.7k | if(BOOST_JSON_LIKELY( c >= '0' && c <= '9' )) | 2641 | 21.0k | { | 2642 | 21.0k | if(BOOST_JSON_UNLIKELY( | 2643 | | // 2147483647 INT_MAX | 2644 | 21.0k | num.exp > 214748364 || | 2645 | 21.0k | (num.exp == 214748364 && c > '7') | 2646 | 21.0k | )) | 2647 | 2.01k | num.exp = INT_MAX; | 2648 | 19.0k | else BOOST_IF_CONSTEXPR( !no_parsing ) | 2649 | 19.0k | num.exp = 10 * num.exp + ( c - '0' ); | 2650 | | | 2651 | 21.0k | ++cs; | 2652 | 21.0k | continue; | 2653 | 21.0k | } | 2654 | 23.7k | } | 2655 | 2.69k | BOOST_ASSERT(num.exp >= 0); | 2656 | 2.69k | if ( num.frac ) | 2657 | 1.00k | { | 2658 | 1.00k | if(BOOST_JSON_UNLIKELY( num.bias < (INT_MIN + num.exp) )) | 2659 | 424 | { | 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 | 424 | if(BOOST_JSON_UNLIKELY( | 2664 | 424 | (num.exp == INT_MAX) && | 2665 | 424 | (num.bias < 0) && | 2666 | 424 | (num.exp + num.bias < 308) && | 2667 | 424 | 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 | 424 | num.bias = 0; | 2675 | 424 | num.exp = INT_MAX; | 2676 | 424 | } | 2677 | 1.00k | } | 2678 | 1.69k | 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 | 2.69k | goto finish_dub; | 2698 | 2.69k | } | 2699 | | | 2700 | 505 | finish_int: | 2701 | 505 | 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 | 505 | if(num.mant <= INT64_MAX) | 2710 | 505 | { | 2711 | 513k | finish_signed: | 2712 | 513k | if(BOOST_JSON_UNLIKELY( | 2713 | 513k | ! h_.on_int64(static_cast< | 2714 | 513k | int64_t>(num.mant), {begin, cs.used(begin)}, ec_))) | 2715 | 0 | return fail(cs.begin()); | 2716 | 513k | return cs.begin(); | 2717 | 513k | } | 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 | 5.14k | finish_dub: | 2723 | 5.14k | double d; | 2724 | 5.14k | std::size_t const size = cs.used(begin); | 2725 | 5.14k | BOOST_ASSERT( !num_buf_.size() || precise_parsing ); | 2726 | | BOOST_IF_CONSTEXPR( precise_parsing ) | 2727 | 5.14k | { | 2728 | 5.14k | char const* data = begin; | 2729 | 5.14k | 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 | 5.14k | 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 | 5.14k | auto const err = detail::charconv::from_chars( | 2739 | 5.14k | data, data + full_size, d ); | 2740 | 5.14k | BOOST_ASSERT( err.ec != std::errc::invalid_argument ); | 2741 | 5.14k | BOOST_ASSERT( err.ptr == data + full_size ); | 2742 | 5.14k | (void)err; | 2743 | | } | 2744 | | else BOOST_IF_CONSTEXPR( no_parsing ) | 2745 | | d = 0; | 2746 | | else | 2747 | | d = detail::dec_to_float( | 2748 | | num.mant, | 2749 | | num.bias + (num.frac ? | 2750 | | -num.exp : num.exp), | 2751 | | num.neg); | 2752 | 5.14k | if(BOOST_JSON_UNLIKELY( | 2753 | 5.14k | ! h_.on_double(d, {begin, size}, ec_))) | 2754 | 0 | return fail(cs.begin()); | 2755 | 5.14k | return cs.begin(); | 2756 | 5.14k | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::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>) Line | Count | Source | 1986 | 20.0k | { | 1987 | 20.0k | constexpr bool precise_parsing = mode == number_precision::precise; | 1988 | 20.0k | 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 | 20.0k | bool const negative = first == '-'; | 1995 | 20.0k | bool const zero_first = first == '0'; | 1996 | 20.0k | bool const nonzero_first = first == '+'; | 1997 | 20.0k | detail::const_stream_wrapper cs(p, end_); | 1998 | 20.0k | number num; | 1999 | 20.0k | const char* begin = cs.begin(); | 2000 | 20.0k | if(stack_empty || st_.empty()) | 2001 | 20.0k | { | 2002 | 20.0k | num.bias = 0; | 2003 | 20.0k | num.exp = 0; | 2004 | 20.0k | num.frac = false; | 2005 | 20.0k | num_buf_.clear(); | 2006 | | | 2007 | | //---------------------------------- | 2008 | | // | 2009 | | // '-' | 2010 | | // leading minus sign | 2011 | | // | 2012 | 20.0k | BOOST_ASSERT(cs); | 2013 | 20.0k | if(negative) | 2014 | 0 | ++cs; | 2015 | | | 2016 | 20.0k | num.neg = negative; | 2017 | 20.0k | num.frac = false; | 2018 | 20.0k | num.exp = 0; | 2019 | 20.0k | num.bias = 0; | 2020 | | | 2021 | | // fast path | 2022 | 20.0k | if( cs.remain() >= 16 + 1 + 16 ) // digits . digits | 2023 | 19.1k | { | 2024 | 19.1k | int n1; | 2025 | | | 2026 | 19.1k | if( nonzero_first || | 2027 | 0 | (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 | 0 | else | 2050 | 0 | 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.1k | else | 2062 | 19.1k | { | 2063 | | // 0. floating-point or 0e integer | 2064 | 19.1k | num.mant = 0; | 2065 | 19.1k | n1 = 0; | 2066 | 19.1k | ++cs; | 2067 | 19.1k | } | 2068 | | | 2069 | 19.1k | { | 2070 | 19.1k | const char c = *cs; | 2071 | 19.1k | if(c != '.') | 2072 | 17.9k | { | 2073 | 17.9k | if((c | 32) == 'e') | 2074 | 691 | { | 2075 | 691 | ++cs; | 2076 | 691 | goto do_exp1; | 2077 | 691 | } | 2078 | 17.2k | BOOST_IF_CONSTEXPR( negative && !no_parsing ) | 2079 | 17.2k | num.mant = ~num.mant + 1; | 2080 | 17.2k | goto finish_signed; | 2081 | 17.9k | } | 2082 | 19.1k | } | 2083 | | | 2084 | | // floating-point number | 2085 | | | 2086 | 1.22k | ++cs; | 2087 | | | 2088 | 1.22k | int n2 = detail::count_digits( cs.begin() ); | 2089 | 1.22k | BOOST_ASSERT(n2 >= 0 && n2 <= 16); | 2090 | | | 2091 | 1.22k | if( n2 == 0 ) | 2092 | 2 | { | 2093 | | // digit required | 2094 | 2 | BOOST_STATIC_CONSTEXPR source_location loc | 2095 | 2 | = BOOST_CURRENT_LOCATION; | 2096 | 2 | return fail(cs.begin(), error::syntax, &loc); | 2097 | 2 | } | 2098 | | | 2099 | | // floating-point mantissa overflow | 2100 | 1.22k | if( n1 + n2 >= 19 ) | 2101 | 0 | { | 2102 | 0 | goto do_num7; | 2103 | 0 | } | 2104 | | | 2105 | 1.22k | BOOST_IF_CONSTEXPR( !no_parsing ) | 2106 | 1.22k | num.mant = detail::parse_unsigned( num.mant, cs.begin(), n2 ); | 2107 | | | 2108 | 1.22k | BOOST_ASSERT(num.bias == 0); | 2109 | | | 2110 | 1.22k | num.bias -= n2; | 2111 | | | 2112 | 1.22k | cs += n2; | 2113 | | | 2114 | 1.22k | char ch = *cs; | 2115 | | | 2116 | 1.22k | if( (ch | 32) == 'e' ) | 2117 | 197 | { | 2118 | 197 | ++cs; | 2119 | 197 | goto do_exp1; | 2120 | 197 | } | 2121 | 1.03k | else if( ch >= '0' && ch <= '9' ) | 2122 | 493 | { | 2123 | 493 | goto do_num8; | 2124 | 493 | } | 2125 | | | 2126 | 537 | goto finish_dub; | 2127 | 1.22k | } | 2128 | 20.0k | } | 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 | 885 | do_num1: | 2157 | 885 | if(zero_first || nonzero_first || | 2158 | 0 | BOOST_JSON_LIKELY(cs)) | 2159 | 885 | { | 2160 | 885 | char const c = *cs; | 2161 | 885 | if(zero_first) | 2162 | 885 | { | 2163 | 885 | ++cs; | 2164 | 885 | num.mant = 0; | 2165 | 885 | goto do_num6; | 2166 | 885 | } | 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 | 885 | } | 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 | 631 | do_num5: | 2384 | 631 | for(;;) | 2385 | 1.46k | { | 2386 | 1.46k | if(BOOST_JSON_UNLIKELY(! cs)) | 2387 | 26 | { | 2388 | 26 | if(BOOST_JSON_UNLIKELY(more_)) | 2389 | 26 | { | 2390 | 26 | if(BOOST_JSON_UNLIKELY( | 2391 | 26 | ! h_.on_number_part( | 2392 | 26 | {begin, cs.used(begin)}, ec_))) | 2393 | 0 | return fail(cs.begin()); | 2394 | | | 2395 | 26 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2396 | 26 | num_buf_.append( begin, cs.used(begin) ); | 2397 | 26 | return suspend(cs.begin(), state::num5, num); | 2398 | 26 | } | 2399 | 0 | goto finish_dub; | 2400 | 26 | } | 2401 | 1.44k | char const c = *cs; | 2402 | 1.44k | if(BOOST_JSON_LIKELY( | 2403 | 1.44k | c >= '0' && c <= '9')) | 2404 | 838 | { | 2405 | 838 | ++cs; | 2406 | 838 | } | 2407 | 605 | else if((c | 32) == 'e') | 2408 | 203 | { | 2409 | 203 | ++cs; | 2410 | 203 | goto do_exp1; | 2411 | 203 | } | 2412 | 402 | else | 2413 | 402 | { | 2414 | 402 | goto finish_dub; | 2415 | 402 | } | 2416 | 1.44k | } | 2417 | | | 2418 | | //---------------------------------- | 2419 | | // | 2420 | | // [.eE] | 2421 | | // | 2422 | 885 | do_num6: | 2423 | 885 | { | 2424 | 885 | if(BOOST_JSON_UNLIKELY(! cs)) | 2425 | 21 | { | 2426 | 21 | if(BOOST_JSON_UNLIKELY(more_)) | 2427 | 21 | { | 2428 | 21 | if(BOOST_JSON_UNLIKELY( | 2429 | 21 | ! h_.on_number_part( | 2430 | 21 | {begin, cs.used(begin)}, ec_))) | 2431 | 0 | return fail(cs.begin()); | 2432 | | | 2433 | 21 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2434 | 21 | num_buf_.append( begin, cs.used(begin) ); | 2435 | 21 | return suspend(cs.begin(), state::num6, num); | 2436 | 21 | } | 2437 | 0 | goto finish_int; | 2438 | 21 | } | 2439 | 864 | char const c = *cs; | 2440 | 864 | if(BOOST_JSON_LIKELY( | 2441 | 864 | c == '.')) | 2442 | 154 | { | 2443 | 154 | ++cs; | 2444 | 154 | } | 2445 | 710 | else if((c | 32) == 'e') | 2446 | 203 | { | 2447 | 203 | ++cs; | 2448 | 203 | goto do_exp1; | 2449 | 203 | } | 2450 | 507 | else | 2451 | 507 | { | 2452 | 507 | goto finish_int; | 2453 | 507 | } | 2454 | 864 | } | 2455 | | | 2456 | | //---------------------------------- | 2457 | | // | 2458 | | // DIGIT | 2459 | | // first significant digit | 2460 | | // to the right of decimal | 2461 | | // | 2462 | 154 | do_num7: | 2463 | 154 | { | 2464 | 154 | if(BOOST_JSON_UNLIKELY(! cs)) | 2465 | 5 | { | 2466 | 5 | if(BOOST_JSON_UNLIKELY(more_)) | 2467 | 5 | { | 2468 | 5 | if(BOOST_JSON_UNLIKELY( | 2469 | 5 | ! h_.on_number_part( | 2470 | 5 | {begin, cs.used(begin)}, ec_))) | 2471 | 0 | return fail(cs.begin()); | 2472 | | | 2473 | 5 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2474 | 5 | num_buf_.append( begin, cs.used(begin) ); | 2475 | 5 | return suspend(cs.begin(), state::num7, num); | 2476 | 5 | } | 2477 | | // digit required | 2478 | 5 | BOOST_STATIC_CONSTEXPR source_location loc | 2479 | 0 | = BOOST_CURRENT_LOCATION; | 2480 | 0 | return fail(cs.begin(), error::syntax, &loc); | 2481 | 5 | } | 2482 | 149 | char const c = *cs; | 2483 | 149 | if(BOOST_JSON_UNLIKELY( | 2484 | 149 | c < '0' || c > '9')) | 2485 | 11 | { | 2486 | | // digit required | 2487 | 11 | BOOST_STATIC_CONSTEXPR source_location loc | 2488 | 11 | = BOOST_CURRENT_LOCATION; | 2489 | 11 | return fail(cs.begin(), error::syntax, &loc); | 2490 | 11 | } | 2491 | 149 | } | 2492 | | | 2493 | | //---------------------------------- | 2494 | | // | 2495 | | // 1*DIGIT | 2496 | | // significant digits | 2497 | | // to the right of decimal | 2498 | | // | 2499 | 631 | do_num8: | 2500 | 631 | for(;;) | 2501 | 631 | { | 2502 | 631 | if(BOOST_JSON_UNLIKELY(! cs)) | 2503 | 0 | { | 2504 | 0 | 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 | 0 | goto finish_dub; | 2516 | 0 | } | 2517 | 631 | char const c = *cs; | 2518 | 631 | if(BOOST_JSON_LIKELY( | 2519 | 631 | c >= '0' && c <= '9')) | 2520 | 631 | { | 2521 | 631 | ++cs; | 2522 | 631 | if(!no_parsing && BOOST_JSON_LIKELY( | 2523 | 631 | num.mant <= 9007199254740991)) // 2^53-1 | 2524 | 0 | { | 2525 | 0 | 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 | 0 | --num.bias; | 2532 | 0 | num.mant = 10 * num.mant + ( c - '0' ); | 2533 | 0 | } | 2534 | 631 | else | 2535 | 631 | { | 2536 | 631 | goto do_num5; | 2537 | 631 | } | 2538 | 631 | } | 2539 | 0 | else if((c | 32) == 'e') | 2540 | 0 | { | 2541 | 0 | ++cs; | 2542 | 0 | goto do_exp1; | 2543 | 0 | } | 2544 | 0 | else | 2545 | 0 | { | 2546 | 0 | goto finish_dub; | 2547 | 0 | } | 2548 | 631 | } | 2549 | | | 2550 | | //---------------------------------- | 2551 | | // | 2552 | | // *[+-] | 2553 | | // | 2554 | 1.29k | do_exp1: | 2555 | 1.29k | if(BOOST_JSON_UNLIKELY(! cs)) | 2556 | 12 | { | 2557 | 12 | if(BOOST_JSON_UNLIKELY( | 2558 | 12 | ! h_.on_number_part( | 2559 | 12 | {begin, cs.used(begin)}, ec_))) | 2560 | 0 | return fail(cs.begin()); | 2561 | | | 2562 | 12 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2563 | 12 | num_buf_.append( begin, cs.used(begin) ); | 2564 | 12 | return maybe_suspend( | 2565 | 12 | cs.begin(), state::exp1, num); | 2566 | 12 | } | 2567 | 1.28k | if(*cs == '+') | 2568 | 204 | { | 2569 | 204 | ++cs; | 2570 | 204 | } | 2571 | 1.07k | else if(*cs == '-') | 2572 | 228 | { | 2573 | 228 | ++cs; | 2574 | 228 | num.frac = true; | 2575 | 228 | } | 2576 | | | 2577 | | //---------------------------------- | 2578 | | // | 2579 | | // DIGIT | 2580 | | // first digit of the exponent | 2581 | | // | 2582 | 1.28k | do_exp2: | 2583 | 1.28k | { | 2584 | 1.28k | if(BOOST_JSON_UNLIKELY(! cs)) | 2585 | 11 | { | 2586 | 11 | if(BOOST_JSON_UNLIKELY(more_)) | 2587 | 11 | { | 2588 | 11 | if(BOOST_JSON_UNLIKELY( | 2589 | 11 | ! h_.on_number_part( | 2590 | 11 | {begin, cs.used(begin)}, ec_))) | 2591 | 0 | return fail(cs.begin()); | 2592 | | | 2593 | 11 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2594 | 11 | num_buf_.append( begin, cs.used(begin) ); | 2595 | 11 | return suspend(cs.begin(), state::exp2, num); | 2596 | 11 | } | 2597 | | // digit required | 2598 | 11 | BOOST_STATIC_CONSTEXPR source_location loc | 2599 | 0 | = BOOST_CURRENT_LOCATION; | 2600 | 0 | return fail(cs.begin(), error::syntax, &loc); | 2601 | 11 | } | 2602 | 1.27k | char const c = *cs; | 2603 | 1.27k | if(BOOST_JSON_UNLIKELY( | 2604 | 1.27k | c < '0' || c > '9')) | 2605 | 19 | { | 2606 | | // digit required | 2607 | 19 | BOOST_STATIC_CONSTEXPR source_location loc | 2608 | 19 | = BOOST_CURRENT_LOCATION; | 2609 | 19 | return fail(cs.begin(), error::syntax, &loc); | 2610 | 19 | } | 2611 | 1.25k | ++cs; | 2612 | 1.25k | num.exp = c - '0'; | 2613 | 1.25k | } | 2614 | | | 2615 | | //---------------------------------- | 2616 | | // | 2617 | | // 1*DIGIT | 2618 | | // subsequent digits in the exponent | 2619 | | // | 2620 | 1.25k | do_exp3: | 2621 | 1.25k | for(;;) | 2622 | 1.65k | { | 2623 | 1.65k | if(BOOST_JSON_UNLIKELY(! cs)) | 2624 | 23 | { | 2625 | 23 | if(BOOST_JSON_UNLIKELY(more_)) | 2626 | 23 | { | 2627 | 23 | if(BOOST_JSON_UNLIKELY( | 2628 | 23 | ! h_.on_number_part( | 2629 | 23 | {begin, cs.used(begin)}, ec_))) | 2630 | 0 | return fail(cs.begin()); | 2631 | | | 2632 | 23 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2633 | 23 | num_buf_.append( begin, cs.used(begin) ); | 2634 | 23 | return suspend(cs.begin(), state::exp3, num); | 2635 | 23 | } | 2636 | 23 | } | 2637 | 1.62k | else | 2638 | 1.62k | { | 2639 | 1.62k | char const c = *cs; | 2640 | 1.62k | if(BOOST_JSON_LIKELY( c >= '0' && c <= '9' )) | 2641 | 399 | { | 2642 | 399 | if(BOOST_JSON_UNLIKELY( | 2643 | | // 2147483647 INT_MAX | 2644 | 399 | num.exp > 214748364 || | 2645 | 399 | (num.exp == 214748364 && c > '7') | 2646 | 399 | )) | 2647 | 0 | num.exp = INT_MAX; | 2648 | 399 | else BOOST_IF_CONSTEXPR( !no_parsing ) | 2649 | 399 | num.exp = 10 * num.exp + ( c - '0' ); | 2650 | | | 2651 | 399 | ++cs; | 2652 | 399 | continue; | 2653 | 399 | } | 2654 | 1.62k | } | 2655 | 1.22k | BOOST_ASSERT(num.exp >= 0); | 2656 | 1.22k | if ( num.frac ) | 2657 | 222 | { | 2658 | 222 | if(BOOST_JSON_UNLIKELY( num.bias < (INT_MIN + num.exp) )) | 2659 | 0 | { | 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 | 0 | if(BOOST_JSON_UNLIKELY( | 2664 | 0 | (num.exp == INT_MAX) && | 2665 | 0 | (num.bias < 0) && | 2666 | 0 | (num.exp + num.bias < 308) && | 2667 | 0 | 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 | 0 | num.bias = 0; | 2675 | 0 | num.exp = INT_MAX; | 2676 | 0 | } | 2677 | 222 | } | 2678 | 1.00k | 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 | 1.22k | goto finish_dub; | 2698 | 1.22k | } | 2699 | | | 2700 | 507 | finish_int: | 2701 | 507 | 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 | 507 | if(num.mant <= INT64_MAX) | 2710 | 507 | { | 2711 | 17.7k | finish_signed: | 2712 | 17.7k | if(BOOST_JSON_UNLIKELY( | 2713 | 17.7k | ! h_.on_int64(static_cast< | 2714 | 17.7k | int64_t>(num.mant), {begin, cs.used(begin)}, ec_))) | 2715 | 0 | return fail(cs.begin()); | 2716 | 17.7k | return cs.begin(); | 2717 | 17.7k | } | 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 | 2.16k | finish_dub: | 2723 | 2.16k | double d; | 2724 | 2.16k | std::size_t const size = cs.used(begin); | 2725 | 2.16k | BOOST_ASSERT( !num_buf_.size() || precise_parsing ); | 2726 | | BOOST_IF_CONSTEXPR( precise_parsing ) | 2727 | | { | 2728 | | char const* data = begin; | 2729 | | 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 | 2.16k | else BOOST_IF_CONSTEXPR( no_parsing ) | 2745 | 2.16k | d = 0; | 2746 | | else | 2747 | | d = detail::dec_to_float( | 2748 | | num.mant, | 2749 | | num.bias + (num.frac ? | 2750 | | -num.exp : num.exp), | 2751 | | num.neg); | 2752 | 2.16k | if(BOOST_JSON_UNLIKELY( | 2753 | 2.16k | ! h_.on_double(d, {begin, size}, ec_))) | 2754 | 0 | return fail(cs.begin()); | 2755 | 2.16k | return cs.begin(); | 2756 | 2.16k | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::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 | 46.7k | { | 1987 | 46.7k | constexpr bool precise_parsing = mode == number_precision::precise; | 1988 | 46.7k | 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 | 46.7k | bool const negative = first == '-'; | 1995 | 46.7k | bool const zero_first = first == '0'; | 1996 | 46.7k | bool const nonzero_first = first == '+'; | 1997 | 46.7k | detail::const_stream_wrapper cs(p, end_); | 1998 | 46.7k | number num; | 1999 | 46.7k | const char* begin = cs.begin(); | 2000 | 46.7k | if(stack_empty || st_.empty()) | 2001 | 46.7k | { | 2002 | 46.7k | num.bias = 0; | 2003 | 46.7k | num.exp = 0; | 2004 | 46.7k | num.frac = false; | 2005 | 46.7k | num_buf_.clear(); | 2006 | | | 2007 | | //---------------------------------- | 2008 | | // | 2009 | | // '-' | 2010 | | // leading minus sign | 2011 | | // | 2012 | 46.7k | BOOST_ASSERT(cs); | 2013 | 46.7k | if(negative) | 2014 | 46.7k | ++cs; | 2015 | | | 2016 | 46.7k | num.neg = negative; | 2017 | 46.7k | num.frac = false; | 2018 | 46.7k | num.exp = 0; | 2019 | 46.7k | num.bias = 0; | 2020 | | | 2021 | | // fast path | 2022 | 46.7k | if( cs.remain() >= 16 + 1 + 16 ) // digits . digits | 2023 | 43.9k | { | 2024 | 43.9k | int n1; | 2025 | | | 2026 | 43.9k | if( nonzero_first || | 2027 | 43.9k | (negative && *cs != '0') ) | 2028 | 40.5k | { | 2029 | 40.5k | n1 = detail::count_digits( cs.begin() ); | 2030 | 40.5k | BOOST_ASSERT(n1 >= 0 && n1 <= 16); | 2031 | | | 2032 | 40.5k | 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 | 40.5k | if( ! nonzero_first && n1 == 0 ) | 2040 | 18 | { | 2041 | | // digit required | 2042 | 18 | BOOST_STATIC_CONSTEXPR source_location loc | 2043 | 18 | = BOOST_CURRENT_LOCATION; | 2044 | 18 | return fail(cs.begin(), error::syntax, &loc); | 2045 | 18 | } | 2046 | | | 2047 | 40.4k | BOOST_IF_CONSTEXPR( !no_parsing ) | 2048 | 40.4k | num.mant = detail::parse_unsigned( 0, cs.begin(), n1 ); | 2049 | | else | 2050 | | num.mant = 0; | 2051 | | | 2052 | 40.4k | cs += n1; | 2053 | | | 2054 | | // integer or floating-point with | 2055 | | // >= 16 leading digits | 2056 | 40.4k | if( n1 == 16 ) | 2057 | 7.27k | { | 2058 | 7.27k | goto do_num2; | 2059 | 7.27k | } | 2060 | 40.4k | } | 2061 | 3.43k | else | 2062 | 3.43k | { | 2063 | | // 0. floating-point or 0e integer | 2064 | 3.43k | num.mant = 0; | 2065 | 3.43k | n1 = 0; | 2066 | 3.43k | ++cs; | 2067 | 3.43k | } | 2068 | | | 2069 | 36.6k | { | 2070 | 36.6k | const char c = *cs; | 2071 | 36.6k | if(c != '.') | 2072 | 28.3k | { | 2073 | 28.3k | if((c | 32) == 'e') | 2074 | 9.46k | { | 2075 | 9.46k | ++cs; | 2076 | 9.46k | goto do_exp1; | 2077 | 9.46k | } | 2078 | 18.9k | BOOST_IF_CONSTEXPR( negative && !no_parsing ) | 2079 | 18.9k | num.mant = ~num.mant + 1; | 2080 | 18.9k | goto finish_signed; | 2081 | 28.3k | } | 2082 | 36.6k | } | 2083 | | | 2084 | | // floating-point number | 2085 | | | 2086 | 8.25k | ++cs; | 2087 | | | 2088 | 8.25k | int n2 = detail::count_digits( cs.begin() ); | 2089 | 8.25k | BOOST_ASSERT(n2 >= 0 && n2 <= 16); | 2090 | | | 2091 | 8.25k | if( n2 == 0 ) | 2092 | 5 | { | 2093 | | // digit required | 2094 | 5 | BOOST_STATIC_CONSTEXPR source_location loc | 2095 | 5 | = BOOST_CURRENT_LOCATION; | 2096 | 5 | return fail(cs.begin(), error::syntax, &loc); | 2097 | 5 | } | 2098 | | | 2099 | | // floating-point mantissa overflow | 2100 | 8.24k | if( n1 + n2 >= 19 ) | 2101 | 530 | { | 2102 | 530 | goto do_num7; | 2103 | 530 | } | 2104 | | | 2105 | 7.71k | BOOST_IF_CONSTEXPR( !no_parsing ) | 2106 | 7.71k | num.mant = detail::parse_unsigned( num.mant, cs.begin(), n2 ); | 2107 | | | 2108 | 7.71k | BOOST_ASSERT(num.bias == 0); | 2109 | | | 2110 | 7.71k | num.bias -= n2; | 2111 | | | 2112 | 7.71k | cs += n2; | 2113 | | | 2114 | 7.71k | char ch = *cs; | 2115 | | | 2116 | 7.71k | if( (ch | 32) == 'e' ) | 2117 | 2.26k | { | 2118 | 2.26k | ++cs; | 2119 | 2.26k | goto do_exp1; | 2120 | 2.26k | } | 2121 | 5.45k | else if( ch >= '0' && ch <= '9' ) | 2122 | 1.02k | { | 2123 | 1.02k | goto do_num8; | 2124 | 1.02k | } | 2125 | | | 2126 | 4.43k | goto finish_dub; | 2127 | 7.71k | } | 2128 | 46.7k | } | 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 | 2.82k | do_num1: | 2157 | 2.82k | if(zero_first || nonzero_first || | 2158 | 2.82k | BOOST_JSON_LIKELY(cs)) | 2159 | 2.79k | { | 2160 | 2.79k | char const c = *cs; | 2161 | 2.79k | if(zero_first) | 2162 | 0 | { | 2163 | 0 | ++cs; | 2164 | 0 | num.mant = 0; | 2165 | 0 | goto do_num6; | 2166 | 0 | } | 2167 | 2.79k | else if(nonzero_first || BOOST_JSON_LIKELY( | 2168 | 2.79k | c >= '1' && c <= '9')) | 2169 | 2.26k | { | 2170 | 2.26k | ++cs; | 2171 | 2.26k | num.mant = c - '0'; | 2172 | 2.26k | } | 2173 | 534 | else if(BOOST_JSON_UNLIKELY( | 2174 | 534 | c == '0')) | 2175 | 478 | { | 2176 | 478 | ++cs; | 2177 | 478 | num.mant = 0; | 2178 | 478 | goto do_num6; | 2179 | 478 | } | 2180 | 56 | 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 | 56 | else | 2189 | 56 | { | 2190 | 56 | BOOST_STATIC_CONSTEXPR source_location loc | 2191 | 56 | = BOOST_CURRENT_LOCATION; | 2192 | 56 | return fail(cs.begin(), error::syntax, &loc); | 2193 | 56 | } | 2194 | 2.79k | } | 2195 | 26 | else | 2196 | 26 | { | 2197 | 26 | if(BOOST_JSON_UNLIKELY( | 2198 | 26 | ! h_.on_number_part( | 2199 | 26 | {begin, cs.used(begin)}, ec_))) | 2200 | 0 | return fail(cs.begin()); | 2201 | | | 2202 | 26 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2203 | 26 | num_buf_.append( begin, cs.used(begin) ); | 2204 | 26 | return maybe_suspend( | 2205 | 26 | cs.begin(), state::num1, num); | 2206 | 26 | } | 2207 | | | 2208 | | //---------------------------------- | 2209 | | // | 2210 | | // 1*DIGIT | 2211 | | // significant digits left of decimal | 2212 | | // | 2213 | 9.54k | do_num2: | 2214 | 9.54k | if(negative || (!stack_empty && num.neg)) | 2215 | 9.54k | { | 2216 | 9.54k | for(;;) | 2217 | 30.6k | { | 2218 | 30.6k | if(BOOST_JSON_UNLIKELY(! cs)) | 2219 | 309 | { | 2220 | 309 | if(BOOST_JSON_UNLIKELY(more_)) | 2221 | 169 | { | 2222 | 169 | if(BOOST_JSON_UNLIKELY( | 2223 | 169 | ! h_.on_number_part( | 2224 | 169 | {begin, cs.used(begin)}, ec_))) | 2225 | 0 | return fail(cs.begin()); | 2226 | | | 2227 | 169 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2228 | 169 | num_buf_.append( begin, cs.used(begin) ); | 2229 | 169 | return suspend(cs.begin(), state::num2, num); | 2230 | 169 | } | 2231 | 140 | goto finish_int; | 2232 | 309 | } | 2233 | 30.3k | char const c = *cs; | 2234 | 30.3k | if(BOOST_JSON_LIKELY( | 2235 | 30.3k | c >= '0' && c <= '9')) | 2236 | 24.6k | { | 2237 | 24.6k | ++cs; | 2238 | | // 9223372036854775808 INT64_MIN | 2239 | 24.6k | if( num.mant > 922337203685477580 || ( | 2240 | 21.6k | num.mant == 922337203685477580 && c > '8')) | 2241 | 3.58k | break; | 2242 | 21.0k | BOOST_IF_CONSTEXPR( !no_parsing ) | 2243 | 21.0k | num.mant = 10 * num.mant + ( c - '0' ); | 2244 | 21.0k | continue; | 2245 | 24.6k | } | 2246 | 5.64k | goto do_num6; // [.eE] | 2247 | 30.3k | } | 2248 | 9.54k | } | 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 | 3.58k | ++num.bias; | 2287 | | | 2288 | | //---------------------------------- | 2289 | | // | 2290 | | // 1*DIGIT | 2291 | | // non-significant digits left of decimal | 2292 | | // | 2293 | 3.58k | do_num3: | 2294 | 3.58k | for(;;) | 2295 | 8.81M | { | 2296 | 8.81M | if(BOOST_JSON_UNLIKELY(! cs)) | 2297 | 59 | { | 2298 | 59 | if(BOOST_JSON_UNLIKELY(more_)) | 2299 | 30 | { | 2300 | 30 | if(BOOST_JSON_UNLIKELY( | 2301 | 30 | ! h_.on_number_part( | 2302 | 30 | {begin, cs.used(begin)}, ec_))) | 2303 | 0 | return fail(cs.begin()); | 2304 | | | 2305 | 30 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2306 | 30 | num_buf_.append( begin, cs.used(begin) ); | 2307 | 30 | return suspend(cs.begin(), state::num3, num); | 2308 | 30 | } | 2309 | 29 | goto finish_dub; | 2310 | 59 | } | 2311 | 8.81M | char const c = *cs; | 2312 | 8.81M | if(BOOST_JSON_UNLIKELY( | 2313 | 8.81M | c >= '0' && c <= '9')) | 2314 | 8.80M | { | 2315 | 8.80M | 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 | 8.80M | ++cs; | 2322 | 8.80M | ++num.bias; | 2323 | 8.80M | } | 2324 | 3.52k | else if(BOOST_JSON_LIKELY( | 2325 | 3.52k | c == '.')) | 2326 | 506 | { | 2327 | 506 | ++cs; | 2328 | 506 | break; | 2329 | 506 | } | 2330 | 3.02k | else if((c | 32) == 'e') | 2331 | 1.30k | { | 2332 | 1.30k | ++cs; | 2333 | 1.30k | goto do_exp1; | 2334 | 1.30k | } | 2335 | 1.71k | else | 2336 | 1.71k | { | 2337 | 1.71k | goto finish_dub; | 2338 | 1.71k | } | 2339 | 8.81M | } | 2340 | | | 2341 | | //---------------------------------- | 2342 | | // | 2343 | | // DIGIT | 2344 | | // first non-significant digit | 2345 | | // to the right of decimal | 2346 | | // | 2347 | 506 | do_num4: | 2348 | 506 | { | 2349 | 506 | 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 | 0 | return fail(cs.begin()); | 2355 | | | 2356 | 5 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2357 | 5 | num_buf_.append( begin, cs.used(begin) ); | 2358 | 5 | return maybe_suspend( | 2359 | 5 | cs.begin(), state::num4, num); | 2360 | 5 | } | 2361 | 501 | char const c = *cs; | 2362 | 501 | if(BOOST_JSON_LIKELY( | 2363 | | //static_cast<unsigned char>(c - '0') < 10)) | 2364 | 501 | c >= '0' && c <= '9')) | 2365 | 490 | { | 2366 | 490 | ++cs; | 2367 | 490 | } | 2368 | 11 | else | 2369 | 11 | { | 2370 | | // digit required | 2371 | 11 | BOOST_STATIC_CONSTEXPR source_location loc | 2372 | 11 | = BOOST_CURRENT_LOCATION; | 2373 | 11 | return fail(cs.begin(), error::syntax, &loc); | 2374 | 11 | } | 2375 | 501 | } | 2376 | | | 2377 | | //---------------------------------- | 2378 | | // | 2379 | | // 1*DIGIT | 2380 | | // non-significant digits | 2381 | | // to the right of decimal | 2382 | | // | 2383 | 2.13k | do_num5: | 2384 | 2.13k | for(;;) | 2385 | 6.32k | { | 2386 | 6.32k | if(BOOST_JSON_UNLIKELY(! cs)) | 2387 | 59 | { | 2388 | 59 | if(BOOST_JSON_UNLIKELY(more_)) | 2389 | 27 | { | 2390 | 27 | if(BOOST_JSON_UNLIKELY( | 2391 | 27 | ! h_.on_number_part( | 2392 | 27 | {begin, cs.used(begin)}, ec_))) | 2393 | 0 | return fail(cs.begin()); | 2394 | | | 2395 | 27 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2396 | 27 | num_buf_.append( begin, cs.used(begin) ); | 2397 | 27 | return suspend(cs.begin(), state::num5, num); | 2398 | 27 | } | 2399 | 32 | goto finish_dub; | 2400 | 59 | } | 2401 | 6.26k | char const c = *cs; | 2402 | 6.26k | if(BOOST_JSON_LIKELY( | 2403 | 6.26k | c >= '0' && c <= '9')) | 2404 | 4.18k | { | 2405 | 4.18k | ++cs; | 2406 | 4.18k | } | 2407 | 2.07k | else if((c | 32) == 'e') | 2408 | 430 | { | 2409 | 430 | ++cs; | 2410 | 430 | goto do_exp1; | 2411 | 430 | } | 2412 | 1.64k | else | 2413 | 1.64k | { | 2414 | 1.64k | goto finish_dub; | 2415 | 1.64k | } | 2416 | 6.26k | } | 2417 | | | 2418 | | //---------------------------------- | 2419 | | // | 2420 | | // [.eE] | 2421 | | // | 2422 | 6.12k | do_num6: | 2423 | 6.12k | { | 2424 | 6.12k | if(BOOST_JSON_UNLIKELY(! cs)) | 2425 | 12 | { | 2426 | 12 | if(BOOST_JSON_UNLIKELY(more_)) | 2427 | 6 | { | 2428 | 6 | if(BOOST_JSON_UNLIKELY( | 2429 | 6 | ! h_.on_number_part( | 2430 | 6 | {begin, cs.used(begin)}, ec_))) | 2431 | 0 | return fail(cs.begin()); | 2432 | | | 2433 | 6 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2434 | 6 | num_buf_.append( begin, cs.used(begin) ); | 2435 | 6 | return suspend(cs.begin(), state::num6, num); | 2436 | 6 | } | 2437 | 6 | goto finish_int; | 2438 | 12 | } | 2439 | 6.11k | char const c = *cs; | 2440 | 6.11k | if(BOOST_JSON_LIKELY( | 2441 | 6.11k | c == '.')) | 2442 | 1.77k | { | 2443 | 1.77k | ++cs; | 2444 | 1.77k | } | 2445 | 4.33k | else if((c | 32) == 'e') | 2446 | 1.33k | { | 2447 | 1.33k | ++cs; | 2448 | 1.33k | goto do_exp1; | 2449 | 1.33k | } | 2450 | 2.99k | else | 2451 | 2.99k | { | 2452 | 2.99k | goto finish_int; | 2453 | 2.99k | } | 2454 | 6.11k | } | 2455 | | | 2456 | | //---------------------------------- | 2457 | | // | 2458 | | // DIGIT | 2459 | | // first significant digit | 2460 | | // to the right of decimal | 2461 | | // | 2462 | 2.30k | do_num7: | 2463 | 2.30k | { | 2464 | 2.30k | if(BOOST_JSON_UNLIKELY(! cs)) | 2465 | 13 | { | 2466 | 13 | if(BOOST_JSON_UNLIKELY(more_)) | 2467 | 6 | { | 2468 | 6 | if(BOOST_JSON_UNLIKELY( | 2469 | 6 | ! h_.on_number_part( | 2470 | 6 | {begin, cs.used(begin)}, ec_))) | 2471 | 0 | return fail(cs.begin()); | 2472 | | | 2473 | 6 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2474 | 6 | num_buf_.append( begin, cs.used(begin) ); | 2475 | 6 | return suspend(cs.begin(), state::num7, num); | 2476 | 6 | } | 2477 | | // digit required | 2478 | 13 | BOOST_STATIC_CONSTEXPR source_location loc | 2479 | 7 | = BOOST_CURRENT_LOCATION; | 2480 | 7 | return fail(cs.begin(), error::syntax, &loc); | 2481 | 13 | } | 2482 | 2.29k | char const c = *cs; | 2483 | 2.29k | if(BOOST_JSON_UNLIKELY( | 2484 | 2.29k | c < '0' || c > '9')) | 2485 | 17 | { | 2486 | | // digit required | 2487 | 17 | BOOST_STATIC_CONSTEXPR source_location loc | 2488 | 17 | = BOOST_CURRENT_LOCATION; | 2489 | 17 | return fail(cs.begin(), error::syntax, &loc); | 2490 | 17 | } | 2491 | 2.29k | } | 2492 | | | 2493 | | //---------------------------------- | 2494 | | // | 2495 | | // 1*DIGIT | 2496 | | // significant digits | 2497 | | // to the right of decimal | 2498 | | // | 2499 | 3.29k | do_num8: | 2500 | 3.29k | for(;;) | 2501 | 2.17M | { | 2502 | 2.17M | if(BOOST_JSON_UNLIKELY(! cs)) | 2503 | 224 | { | 2504 | 224 | if(BOOST_JSON_UNLIKELY(more_)) | 2505 | 103 | { | 2506 | 103 | if(BOOST_JSON_UNLIKELY( | 2507 | 103 | ! h_.on_number_part( | 2508 | 103 | {begin, cs.used(begin)}, ec_))) | 2509 | 0 | return fail(cs.begin()); | 2510 | | | 2511 | 103 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2512 | 103 | num_buf_.append( begin, cs.used(begin) ); | 2513 | 103 | return suspend(cs.begin(), state::num8, num); | 2514 | 103 | } | 2515 | 121 | goto finish_dub; | 2516 | 224 | } | 2517 | 2.17M | char const c = *cs; | 2518 | 2.17M | if(BOOST_JSON_LIKELY( | 2519 | 2.17M | c >= '0' && c <= '9')) | 2520 | 2.17M | { | 2521 | 2.17M | ++cs; | 2522 | 2.17M | if(!no_parsing && BOOST_JSON_LIKELY( | 2523 | 2.17M | num.mant <= 9007199254740991)) // 2^53-1 | 2524 | 2.16M | { | 2525 | 2.16M | 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.16M | --num.bias; | 2532 | 2.16M | num.mant = 10 * num.mant + ( c - '0' ); | 2533 | 2.16M | } | 2534 | 1.64k | else | 2535 | 1.64k | { | 2536 | 1.64k | goto do_num5; | 2537 | 1.64k | } | 2538 | 2.17M | } | 2539 | 1.42k | else if((c | 32) == 'e') | 2540 | 580 | { | 2541 | 580 | ++cs; | 2542 | 580 | goto do_exp1; | 2543 | 580 | } | 2544 | 847 | else | 2545 | 847 | { | 2546 | 847 | goto finish_dub; | 2547 | 847 | } | 2548 | 2.17M | } | 2549 | | | 2550 | | //---------------------------------- | 2551 | | // | 2552 | | // *[+-] | 2553 | | // | 2554 | 15.3k | do_exp1: | 2555 | 15.3k | if(BOOST_JSON_UNLIKELY(! cs)) | 2556 | 63 | { | 2557 | 63 | if(BOOST_JSON_UNLIKELY( | 2558 | 63 | ! h_.on_number_part( | 2559 | 63 | {begin, cs.used(begin)}, ec_))) | 2560 | 0 | return fail(cs.begin()); | 2561 | | | 2562 | 63 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2563 | 63 | num_buf_.append( begin, cs.used(begin) ); | 2564 | 63 | return maybe_suspend( | 2565 | 63 | cs.begin(), state::exp1, num); | 2566 | 63 | } | 2567 | 15.3k | if(*cs == '+') | 2568 | 458 | { | 2569 | 458 | ++cs; | 2570 | 458 | } | 2571 | 14.8k | else if(*cs == '-') | 2572 | 3.98k | { | 2573 | 3.98k | ++cs; | 2574 | 3.98k | num.frac = true; | 2575 | 3.98k | } | 2576 | | | 2577 | | //---------------------------------- | 2578 | | // | 2579 | | // DIGIT | 2580 | | // first digit of the exponent | 2581 | | // | 2582 | 15.3k | do_exp2: | 2583 | 15.3k | { | 2584 | 15.3k | if(BOOST_JSON_UNLIKELY(! cs)) | 2585 | 20 | { | 2586 | 20 | if(BOOST_JSON_UNLIKELY(more_)) | 2587 | 8 | { | 2588 | 8 | if(BOOST_JSON_UNLIKELY( | 2589 | 8 | ! h_.on_number_part( | 2590 | 8 | {begin, cs.used(begin)}, ec_))) | 2591 | 0 | return fail(cs.begin()); | 2592 | | | 2593 | 8 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2594 | 8 | num_buf_.append( begin, cs.used(begin) ); | 2595 | 8 | return suspend(cs.begin(), state::exp2, num); | 2596 | 8 | } | 2597 | | // digit required | 2598 | 20 | BOOST_STATIC_CONSTEXPR source_location loc | 2599 | 12 | = BOOST_CURRENT_LOCATION; | 2600 | 12 | return fail(cs.begin(), error::syntax, &loc); | 2601 | 20 | } | 2602 | 15.3k | char const c = *cs; | 2603 | 15.3k | if(BOOST_JSON_UNLIKELY( | 2604 | 15.3k | c < '0' || c > '9')) | 2605 | 53 | { | 2606 | | // digit required | 2607 | 53 | BOOST_STATIC_CONSTEXPR source_location loc | 2608 | 53 | = BOOST_CURRENT_LOCATION; | 2609 | 53 | return fail(cs.begin(), error::syntax, &loc); | 2610 | 53 | } | 2611 | 15.2k | ++cs; | 2612 | 15.2k | num.exp = c - '0'; | 2613 | 15.2k | } | 2614 | | | 2615 | | //---------------------------------- | 2616 | | // | 2617 | | // 1*DIGIT | 2618 | | // subsequent digits in the exponent | 2619 | | // | 2620 | 15.2k | do_exp3: | 2621 | 15.2k | for(;;) | 2622 | 53.6k | { | 2623 | 53.6k | if(BOOST_JSON_UNLIKELY(! cs)) | 2624 | 443 | { | 2625 | 443 | if(BOOST_JSON_UNLIKELY(more_)) | 2626 | 82 | { | 2627 | 82 | if(BOOST_JSON_UNLIKELY( | 2628 | 82 | ! h_.on_number_part( | 2629 | 82 | {begin, cs.used(begin)}, ec_))) | 2630 | 0 | return fail(cs.begin()); | 2631 | | | 2632 | 82 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2633 | 82 | num_buf_.append( begin, cs.used(begin) ); | 2634 | 82 | return suspend(cs.begin(), state::exp3, num); | 2635 | 82 | } | 2636 | 443 | } | 2637 | 53.1k | else | 2638 | 53.1k | { | 2639 | 53.1k | char const c = *cs; | 2640 | 53.1k | if(BOOST_JSON_LIKELY( c >= '0' && c <= '9' )) | 2641 | 38.3k | { | 2642 | 38.3k | if(BOOST_JSON_UNLIKELY( | 2643 | | // 2147483647 INT_MAX | 2644 | 38.3k | num.exp > 214748364 || | 2645 | 38.3k | (num.exp == 214748364 && c > '7') | 2646 | 38.3k | )) | 2647 | 2.79k | num.exp = INT_MAX; | 2648 | 35.5k | else BOOST_IF_CONSTEXPR( !no_parsing ) | 2649 | 35.5k | num.exp = 10 * num.exp + ( c - '0' ); | 2650 | | | 2651 | 38.3k | ++cs; | 2652 | 38.3k | continue; | 2653 | 38.3k | } | 2654 | 53.1k | } | 2655 | 15.1k | BOOST_ASSERT(num.exp >= 0); | 2656 | 15.1k | if ( num.frac ) | 2657 | 3.97k | { | 2658 | 3.97k | if(BOOST_JSON_UNLIKELY( num.bias < (INT_MIN + num.exp) )) | 2659 | 811 | { | 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 | 811 | if(BOOST_JSON_UNLIKELY( | 2664 | 811 | (num.exp == INT_MAX) && | 2665 | 811 | (num.bias < 0) && | 2666 | 811 | (num.exp + num.bias < 308) && | 2667 | 811 | 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 | 811 | num.bias = 0; | 2675 | 811 | num.exp = INT_MAX; | 2676 | 811 | } | 2677 | 3.97k | } | 2678 | 11.1k | else if (BOOST_JSON_UNLIKELY( num.bias > (INT_MAX - num.exp) )) | 2679 | 969 | { | 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 | 969 | if(BOOST_JSON_UNLIKELY( | 2684 | 969 | (num.exp == INT_MAX) && | 2685 | 969 | (num.bias > 0) && | 2686 | 969 | (num.exp - num.bias < 308) && | 2687 | 969 | 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 | 969 | num.bias = 0; | 2695 | 969 | num.exp = INT_MAX; | 2696 | 969 | } | 2697 | 15.1k | goto finish_dub; | 2698 | 15.1k | } | 2699 | | | 2700 | 3.14k | finish_int: | 2701 | 3.14k | if(negative || (!stack_empty && num.neg)) | 2702 | 3.14k | { | 2703 | 3.14k | if(BOOST_JSON_UNLIKELY( | 2704 | 3.14k | ! h_.on_int64(static_cast< | 2705 | 3.14k | int64_t>(~num.mant + 1), {begin, cs.used(begin)}, ec_))) | 2706 | 0 | return fail(cs.begin()); | 2707 | 3.14k | return cs.begin(); | 2708 | 3.14k | } | 2709 | 0 | if(num.mant <= INT64_MAX) | 2710 | 0 | { | 2711 | 18.9k | finish_signed: | 2712 | 18.9k | if(BOOST_JSON_UNLIKELY( | 2713 | 18.9k | ! h_.on_int64(static_cast< | 2714 | 18.9k | int64_t>(num.mant), {begin, cs.used(begin)}, ec_))) | 2715 | 0 | return fail(cs.begin()); | 2716 | 18.9k | return cs.begin(); | 2717 | 18.9k | } | 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 | 23.9k | finish_dub: | 2723 | 23.9k | double d; | 2724 | 23.9k | std::size_t const size = cs.used(begin); | 2725 | 23.9k | BOOST_ASSERT( !num_buf_.size() || precise_parsing ); | 2726 | | BOOST_IF_CONSTEXPR( precise_parsing ) | 2727 | | { | 2728 | | char const* data = begin; | 2729 | | 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 | 23.9k | else BOOST_IF_CONSTEXPR( no_parsing ) | 2745 | 23.9k | d = 0; | 2746 | 23.9k | else | 2747 | 23.9k | d = detail::dec_to_float( | 2748 | 23.9k | num.mant, | 2749 | 23.9k | num.bias + (num.frac ? | 2750 | 20.0k | -num.exp : num.exp), | 2751 | 23.9k | num.neg); | 2752 | 23.9k | if(BOOST_JSON_UNLIKELY( | 2753 | 23.9k | ! h_.on_double(d, {begin, size}, ec_))) | 2754 | 0 | return fail(cs.begin()); | 2755 | 23.9k | return cs.begin(); | 2756 | 23.9k | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::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>) Line | Count | Source | 1986 | 20.2k | { | 1987 | 20.2k | constexpr bool precise_parsing = mode == number_precision::precise; | 1988 | 20.2k | 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 | 20.2k | bool const negative = first == '-'; | 1995 | 20.2k | bool const zero_first = first == '0'; | 1996 | 20.2k | bool const nonzero_first = first == '+'; | 1997 | 20.2k | detail::const_stream_wrapper cs(p, end_); | 1998 | 20.2k | number num; | 1999 | 20.2k | const char* begin = cs.begin(); | 2000 | 20.2k | if(stack_empty || st_.empty()) | 2001 | 20.2k | { | 2002 | 20.2k | num.bias = 0; | 2003 | 20.2k | num.exp = 0; | 2004 | 20.2k | num.frac = false; | 2005 | 20.2k | num_buf_.clear(); | 2006 | | | 2007 | | //---------------------------------- | 2008 | | // | 2009 | | // '-' | 2010 | | // leading minus sign | 2011 | | // | 2012 | 20.2k | BOOST_ASSERT(cs); | 2013 | 20.2k | if(negative) | 2014 | 20.2k | ++cs; | 2015 | | | 2016 | 20.2k | num.neg = negative; | 2017 | 20.2k | num.frac = false; | 2018 | 20.2k | num.exp = 0; | 2019 | 20.2k | num.bias = 0; | 2020 | | | 2021 | | // fast path | 2022 | 20.2k | if( cs.remain() >= 16 + 1 + 16 ) // digits . digits | 2023 | 19.1k | { | 2024 | 19.1k | int n1; | 2025 | | | 2026 | 19.1k | if( nonzero_first || | 2027 | 19.1k | (negative && *cs != '0') ) | 2028 | 9.75k | { | 2029 | 9.75k | n1 = detail::count_digits( cs.begin() ); | 2030 | 9.75k | BOOST_ASSERT(n1 >= 0 && n1 <= 16); | 2031 | | | 2032 | 9.75k | 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 | 9.75k | if( ! nonzero_first && n1 == 0 ) | 2040 | 7 | { | 2041 | | // digit required | 2042 | 7 | BOOST_STATIC_CONSTEXPR source_location loc | 2043 | 7 | = BOOST_CURRENT_LOCATION; | 2044 | 7 | return fail(cs.begin(), error::syntax, &loc); | 2045 | 7 | } | 2046 | | | 2047 | 9.74k | BOOST_IF_CONSTEXPR( !no_parsing ) | 2048 | 9.74k | num.mant = detail::parse_unsigned( 0, cs.begin(), n1 ); | 2049 | | else | 2050 | | num.mant = 0; | 2051 | | | 2052 | 9.74k | cs += n1; | 2053 | | | 2054 | | // integer or floating-point with | 2055 | | // >= 16 leading digits | 2056 | 9.74k | if( n1 == 16 ) | 2057 | 3.79k | { | 2058 | 3.79k | goto do_num2; | 2059 | 3.79k | } | 2060 | 9.74k | } | 2061 | 9.36k | else | 2062 | 9.36k | { | 2063 | | // 0. floating-point or 0e integer | 2064 | 9.36k | num.mant = 0; | 2065 | 9.36k | n1 = 0; | 2066 | 9.36k | ++cs; | 2067 | 9.36k | } | 2068 | | | 2069 | 15.3k | { | 2070 | 15.3k | const char c = *cs; | 2071 | 15.3k | if(c != '.') | 2072 | 11.0k | { | 2073 | 11.0k | if((c | 32) == 'e') | 2074 | 1.42k | { | 2075 | 1.42k | ++cs; | 2076 | 1.42k | goto do_exp1; | 2077 | 1.42k | } | 2078 | 9.62k | BOOST_IF_CONSTEXPR( negative && !no_parsing ) | 2079 | 9.62k | num.mant = ~num.mant + 1; | 2080 | 9.62k | goto finish_signed; | 2081 | 11.0k | } | 2082 | 15.3k | } | 2083 | | | 2084 | | // floating-point number | 2085 | | | 2086 | 4.27k | ++cs; | 2087 | | | 2088 | 4.27k | int n2 = detail::count_digits( cs.begin() ); | 2089 | 4.27k | BOOST_ASSERT(n2 >= 0 && n2 <= 16); | 2090 | | | 2091 | 4.27k | 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 | 4.26k | if( n1 + n2 >= 19 ) | 2101 | 501 | { | 2102 | 501 | goto do_num7; | 2103 | 501 | } | 2104 | | | 2105 | 3.76k | BOOST_IF_CONSTEXPR( !no_parsing ) | 2106 | 3.76k | num.mant = detail::parse_unsigned( num.mant, cs.begin(), n2 ); | 2107 | | | 2108 | 3.76k | BOOST_ASSERT(num.bias == 0); | 2109 | | | 2110 | 3.76k | num.bias -= n2; | 2111 | | | 2112 | 3.76k | cs += n2; | 2113 | | | 2114 | 3.76k | char ch = *cs; | 2115 | | | 2116 | 3.76k | if( (ch | 32) == 'e' ) | 2117 | 634 | { | 2118 | 634 | ++cs; | 2119 | 634 | goto do_exp1; | 2120 | 634 | } | 2121 | 3.13k | else if( ch >= '0' && ch <= '9' ) | 2122 | 379 | { | 2123 | 379 | goto do_num8; | 2124 | 379 | } | 2125 | | | 2126 | 2.75k | goto finish_dub; | 2127 | 3.76k | } | 2128 | 20.2k | } | 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.15k | do_num1: | 2157 | 1.15k | if(zero_first || nonzero_first || | 2158 | 1.15k | BOOST_JSON_LIKELY(cs)) | 2159 | 1.13k | { | 2160 | 1.13k | char const c = *cs; | 2161 | 1.13k | if(zero_first) | 2162 | 0 | { | 2163 | 0 | ++cs; | 2164 | 0 | num.mant = 0; | 2165 | 0 | goto do_num6; | 2166 | 0 | } | 2167 | 1.13k | else if(nonzero_first || BOOST_JSON_LIKELY( | 2168 | 1.13k | c >= '1' && c <= '9')) | 2169 | 858 | { | 2170 | 858 | ++cs; | 2171 | 858 | num.mant = c - '0'; | 2172 | 858 | } | 2173 | 276 | else if(BOOST_JSON_UNLIKELY( | 2174 | 276 | c == '0')) | 2175 | 251 | { | 2176 | 251 | ++cs; | 2177 | 251 | num.mant = 0; | 2178 | 251 | goto do_num6; | 2179 | 251 | } | 2180 | 25 | 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 | 25 | else | 2189 | 25 | { | 2190 | 25 | BOOST_STATIC_CONSTEXPR source_location loc | 2191 | 25 | = BOOST_CURRENT_LOCATION; | 2192 | 25 | return fail(cs.begin(), error::syntax, &loc); | 2193 | 25 | } | 2194 | 1.13k | } | 2195 | 21 | else | 2196 | 21 | { | 2197 | 21 | if(BOOST_JSON_UNLIKELY( | 2198 | 21 | ! h_.on_number_part( | 2199 | 21 | {begin, cs.used(begin)}, ec_))) | 2200 | 0 | return fail(cs.begin()); | 2201 | | | 2202 | 21 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2203 | 21 | num_buf_.append( begin, cs.used(begin) ); | 2204 | 21 | return maybe_suspend( | 2205 | 21 | cs.begin(), state::num1, num); | 2206 | 21 | } | 2207 | | | 2208 | | //---------------------------------- | 2209 | | // | 2210 | | // 1*DIGIT | 2211 | | // significant digits left of decimal | 2212 | | // | 2213 | 4.64k | do_num2: | 2214 | 4.64k | if(negative || (!stack_empty && num.neg)) | 2215 | 4.64k | { | 2216 | 4.64k | for(;;) | 2217 | 16.2k | { | 2218 | 16.2k | if(BOOST_JSON_UNLIKELY(! cs)) | 2219 | 165 | { | 2220 | 165 | if(BOOST_JSON_UNLIKELY(more_)) | 2221 | 165 | { | 2222 | 165 | if(BOOST_JSON_UNLIKELY( | 2223 | 165 | ! h_.on_number_part( | 2224 | 165 | {begin, cs.used(begin)}, ec_))) | 2225 | 0 | return fail(cs.begin()); | 2226 | | | 2227 | 165 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2228 | 165 | num_buf_.append( begin, cs.used(begin) ); | 2229 | 165 | return suspend(cs.begin(), state::num2, num); | 2230 | 165 | } | 2231 | 0 | goto finish_int; | 2232 | 165 | } | 2233 | 16.1k | char const c = *cs; | 2234 | 16.1k | if(BOOST_JSON_LIKELY( | 2235 | 16.1k | c >= '0' && c <= '9')) | 2236 | 14.2k | { | 2237 | 14.2k | ++cs; | 2238 | | // 9223372036854775808 INT64_MIN | 2239 | 14.2k | if( num.mant > 922337203685477580 || ( | 2240 | 12.2k | num.mant == 922337203685477580 && c > '8')) | 2241 | 2.66k | break; | 2242 | 11.6k | BOOST_IF_CONSTEXPR( !no_parsing ) | 2243 | 11.6k | num.mant = 10 * num.mant + ( c - '0' ); | 2244 | 11.6k | continue; | 2245 | 14.2k | } | 2246 | 1.82k | goto do_num6; // [.eE] | 2247 | 16.1k | } | 2248 | 4.64k | } | 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 | 2.66k | ++num.bias; | 2287 | | | 2288 | | //---------------------------------- | 2289 | | // | 2290 | | // 1*DIGIT | 2291 | | // non-significant digits left of decimal | 2292 | | // | 2293 | 2.66k | do_num3: | 2294 | 2.66k | for(;;) | 2295 | 9.01M | { | 2296 | 9.01M | if(BOOST_JSON_UNLIKELY(! cs)) | 2297 | 65 | { | 2298 | 65 | if(BOOST_JSON_UNLIKELY(more_)) | 2299 | 65 | { | 2300 | 65 | if(BOOST_JSON_UNLIKELY( | 2301 | 65 | ! h_.on_number_part( | 2302 | 65 | {begin, cs.used(begin)}, ec_))) | 2303 | 0 | return fail(cs.begin()); | 2304 | | | 2305 | 65 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2306 | 65 | num_buf_.append( begin, cs.used(begin) ); | 2307 | 65 | return suspend(cs.begin(), state::num3, num); | 2308 | 65 | } | 2309 | 0 | goto finish_dub; | 2310 | 65 | } | 2311 | 9.01M | char const c = *cs; | 2312 | 9.01M | if(BOOST_JSON_UNLIKELY( | 2313 | 9.01M | c >= '0' && c <= '9')) | 2314 | 9.00M | { | 2315 | 9.00M | 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 | 9.00M | ++cs; | 2322 | 9.00M | ++num.bias; | 2323 | 9.00M | } | 2324 | 2.59k | else if(BOOST_JSON_LIKELY( | 2325 | 2.59k | c == '.')) | 2326 | 619 | { | 2327 | 619 | ++cs; | 2328 | 619 | break; | 2329 | 619 | } | 2330 | 1.97k | else if((c | 32) == 'e') | 2331 | 575 | { | 2332 | 575 | ++cs; | 2333 | 575 | goto do_exp1; | 2334 | 575 | } | 2335 | 1.40k | else | 2336 | 1.40k | { | 2337 | 1.40k | goto finish_dub; | 2338 | 1.40k | } | 2339 | 9.01M | } | 2340 | | | 2341 | | //---------------------------------- | 2342 | | // | 2343 | | // DIGIT | 2344 | | // first non-significant digit | 2345 | | // to the right of decimal | 2346 | | // | 2347 | 619 | do_num4: | 2348 | 619 | { | 2349 | 619 | 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 | 0 | return fail(cs.begin()); | 2355 | | | 2356 | 3 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2357 | 3 | num_buf_.append( begin, cs.used(begin) ); | 2358 | 3 | return maybe_suspend( | 2359 | 3 | cs.begin(), state::num4, num); | 2360 | 3 | } | 2361 | 616 | char const c = *cs; | 2362 | 616 | if(BOOST_JSON_LIKELY( | 2363 | | //static_cast<unsigned char>(c - '0') < 10)) | 2364 | 616 | c >= '0' && c <= '9')) | 2365 | 614 | { | 2366 | 614 | ++cs; | 2367 | 614 | } | 2368 | 2 | else | 2369 | 2 | { | 2370 | | // digit required | 2371 | 2 | BOOST_STATIC_CONSTEXPR source_location loc | 2372 | 2 | = BOOST_CURRENT_LOCATION; | 2373 | 2 | return fail(cs.begin(), error::syntax, &loc); | 2374 | 2 | } | 2375 | 616 | } | 2376 | | | 2377 | | //---------------------------------- | 2378 | | // | 2379 | | // 1*DIGIT | 2380 | | // non-significant digits | 2381 | | // to the right of decimal | 2382 | | // | 2383 | 1.54k | do_num5: | 2384 | 1.54k | for(;;) | 2385 | 1.08M | { | 2386 | 1.08M | if(BOOST_JSON_UNLIKELY(! cs)) | 2387 | 40 | { | 2388 | 40 | if(BOOST_JSON_UNLIKELY(more_)) | 2389 | 40 | { | 2390 | 40 | if(BOOST_JSON_UNLIKELY( | 2391 | 40 | ! h_.on_number_part( | 2392 | 40 | {begin, cs.used(begin)}, ec_))) | 2393 | 0 | return fail(cs.begin()); | 2394 | | | 2395 | 40 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2396 | 40 | num_buf_.append( begin, cs.used(begin) ); | 2397 | 40 | return suspend(cs.begin(), state::num5, num); | 2398 | 40 | } | 2399 | 0 | goto finish_dub; | 2400 | 40 | } | 2401 | 1.08M | char const c = *cs; | 2402 | 1.08M | if(BOOST_JSON_LIKELY( | 2403 | 1.08M | c >= '0' && c <= '9')) | 2404 | 1.08M | { | 2405 | 1.08M | ++cs; | 2406 | 1.08M | } | 2407 | 1.50k | else if((c | 32) == 'e') | 2408 | 377 | { | 2409 | 377 | ++cs; | 2410 | 377 | goto do_exp1; | 2411 | 377 | } | 2412 | 1.12k | else | 2413 | 1.12k | { | 2414 | 1.12k | goto finish_dub; | 2415 | 1.12k | } | 2416 | 1.08M | } | 2417 | | | 2418 | | //---------------------------------- | 2419 | | // | 2420 | | // [.eE] | 2421 | | // | 2422 | 2.07k | do_num6: | 2423 | 2.07k | { | 2424 | 2.07k | if(BOOST_JSON_UNLIKELY(! cs)) | 2425 | 5 | { | 2426 | 5 | if(BOOST_JSON_UNLIKELY(more_)) | 2427 | 5 | { | 2428 | 5 | if(BOOST_JSON_UNLIKELY( | 2429 | 5 | ! h_.on_number_part( | 2430 | 5 | {begin, cs.used(begin)}, ec_))) | 2431 | 0 | return fail(cs.begin()); | 2432 | | | 2433 | 5 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2434 | 5 | num_buf_.append( begin, cs.used(begin) ); | 2435 | 5 | return suspend(cs.begin(), state::num6, num); | 2436 | 5 | } | 2437 | 0 | goto finish_int; | 2438 | 5 | } | 2439 | 2.06k | char const c = *cs; | 2440 | 2.06k | if(BOOST_JSON_LIKELY( | 2441 | 2.06k | c == '.')) | 2442 | 750 | { | 2443 | 750 | ++cs; | 2444 | 750 | } | 2445 | 1.31k | else if((c | 32) == 'e') | 2446 | 484 | { | 2447 | 484 | ++cs; | 2448 | 484 | goto do_exp1; | 2449 | 484 | } | 2450 | 835 | else | 2451 | 835 | { | 2452 | 835 | goto finish_int; | 2453 | 835 | } | 2454 | 2.06k | } | 2455 | | | 2456 | | //---------------------------------- | 2457 | | // | 2458 | | // DIGIT | 2459 | | // first significant digit | 2460 | | // to the right of decimal | 2461 | | // | 2462 | 1.25k | do_num7: | 2463 | 1.25k | { | 2464 | 1.25k | if(BOOST_JSON_UNLIKELY(! cs)) | 2465 | 4 | { | 2466 | 4 | if(BOOST_JSON_UNLIKELY(more_)) | 2467 | 4 | { | 2468 | 4 | if(BOOST_JSON_UNLIKELY( | 2469 | 4 | ! h_.on_number_part( | 2470 | 4 | {begin, cs.used(begin)}, ec_))) | 2471 | 0 | return fail(cs.begin()); | 2472 | | | 2473 | 4 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2474 | 4 | num_buf_.append( begin, cs.used(begin) ); | 2475 | 4 | return suspend(cs.begin(), state::num7, num); | 2476 | 4 | } | 2477 | | // digit required | 2478 | 4 | BOOST_STATIC_CONSTEXPR source_location loc | 2479 | 0 | = BOOST_CURRENT_LOCATION; | 2480 | 0 | return fail(cs.begin(), error::syntax, &loc); | 2481 | 4 | } | 2482 | 1.24k | char const c = *cs; | 2483 | 1.24k | if(BOOST_JSON_UNLIKELY( | 2484 | 1.24k | c < '0' || c > '9')) | 2485 | 11 | { | 2486 | | // digit required | 2487 | 11 | BOOST_STATIC_CONSTEXPR source_location loc | 2488 | 11 | = BOOST_CURRENT_LOCATION; | 2489 | 11 | return fail(cs.begin(), error::syntax, &loc); | 2490 | 11 | } | 2491 | 1.24k | } | 2492 | | | 2493 | | //---------------------------------- | 2494 | | // | 2495 | | // 1*DIGIT | 2496 | | // significant digits | 2497 | | // to the right of decimal | 2498 | | // | 2499 | 1.61k | do_num8: | 2500 | 1.61k | for(;;) | 2501 | 5.03M | { | 2502 | 5.03M | if(BOOST_JSON_UNLIKELY(! cs)) | 2503 | 21 | { | 2504 | 21 | if(BOOST_JSON_UNLIKELY(more_)) | 2505 | 21 | { | 2506 | 21 | if(BOOST_JSON_UNLIKELY( | 2507 | 21 | ! h_.on_number_part( | 2508 | 21 | {begin, cs.used(begin)}, ec_))) | 2509 | 0 | return fail(cs.begin()); | 2510 | | | 2511 | 21 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2512 | 21 | num_buf_.append( begin, cs.used(begin) ); | 2513 | 21 | return suspend(cs.begin(), state::num8, num); | 2514 | 21 | } | 2515 | 0 | goto finish_dub; | 2516 | 21 | } | 2517 | 5.03M | char const c = *cs; | 2518 | 5.03M | if(BOOST_JSON_LIKELY( | 2519 | 5.03M | c >= '0' && c <= '9')) | 2520 | 5.03M | { | 2521 | 5.03M | ++cs; | 2522 | 5.03M | if(!no_parsing && BOOST_JSON_LIKELY( | 2523 | 5.03M | num.mant <= 9007199254740991)) // 2^53-1 | 2524 | 5.03M | { | 2525 | 5.03M | 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 | 5.03M | --num.bias; | 2532 | 5.03M | num.mant = 10 * num.mant + ( c - '0' ); | 2533 | 5.03M | } | 2534 | 930 | else | 2535 | 930 | { | 2536 | 930 | goto do_num5; | 2537 | 930 | } | 2538 | 5.03M | } | 2539 | 664 | else if((c | 32) == 'e') | 2540 | 285 | { | 2541 | 285 | ++cs; | 2542 | 285 | goto do_exp1; | 2543 | 285 | } | 2544 | 379 | else | 2545 | 379 | { | 2546 | 379 | goto finish_dub; | 2547 | 379 | } | 2548 | 5.03M | } | 2549 | | | 2550 | | //---------------------------------- | 2551 | | // | 2552 | | // *[+-] | 2553 | | // | 2554 | 3.78k | do_exp1: | 2555 | 3.78k | if(BOOST_JSON_UNLIKELY(! cs)) | 2556 | 26 | { | 2557 | 26 | if(BOOST_JSON_UNLIKELY( | 2558 | 26 | ! h_.on_number_part( | 2559 | 26 | {begin, cs.used(begin)}, ec_))) | 2560 | 0 | return fail(cs.begin()); | 2561 | | | 2562 | 26 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2563 | 26 | num_buf_.append( begin, cs.used(begin) ); | 2564 | 26 | return maybe_suspend( | 2565 | 26 | cs.begin(), state::exp1, num); | 2566 | 26 | } | 2567 | 3.75k | if(*cs == '+') | 2568 | 225 | { | 2569 | 225 | ++cs; | 2570 | 225 | } | 2571 | 3.53k | else if(*cs == '-') | 2572 | 1.02k | { | 2573 | 1.02k | ++cs; | 2574 | 1.02k | num.frac = true; | 2575 | 1.02k | } | 2576 | | | 2577 | | //---------------------------------- | 2578 | | // | 2579 | | // DIGIT | 2580 | | // first digit of the exponent | 2581 | | // | 2582 | 3.75k | do_exp2: | 2583 | 3.75k | { | 2584 | 3.75k | if(BOOST_JSON_UNLIKELY(! cs)) | 2585 | 10 | { | 2586 | 10 | if(BOOST_JSON_UNLIKELY(more_)) | 2587 | 10 | { | 2588 | 10 | if(BOOST_JSON_UNLIKELY( | 2589 | 10 | ! h_.on_number_part( | 2590 | 10 | {begin, cs.used(begin)}, ec_))) | 2591 | 0 | return fail(cs.begin()); | 2592 | | | 2593 | 10 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2594 | 10 | num_buf_.append( begin, cs.used(begin) ); | 2595 | 10 | return suspend(cs.begin(), state::exp2, num); | 2596 | 10 | } | 2597 | | // digit required | 2598 | 10 | BOOST_STATIC_CONSTEXPR source_location loc | 2599 | 0 | = BOOST_CURRENT_LOCATION; | 2600 | 0 | return fail(cs.begin(), error::syntax, &loc); | 2601 | 10 | } | 2602 | 3.74k | char const c = *cs; | 2603 | 3.74k | if(BOOST_JSON_UNLIKELY( | 2604 | 3.74k | c < '0' || c > '9')) | 2605 | 13 | { | 2606 | | // digit required | 2607 | 13 | BOOST_STATIC_CONSTEXPR source_location loc | 2608 | 13 | = BOOST_CURRENT_LOCATION; | 2609 | 13 | return fail(cs.begin(), error::syntax, &loc); | 2610 | 13 | } | 2611 | 3.73k | ++cs; | 2612 | 3.73k | num.exp = c - '0'; | 2613 | 3.73k | } | 2614 | | | 2615 | | //---------------------------------- | 2616 | | // | 2617 | | // 1*DIGIT | 2618 | | // subsequent digits in the exponent | 2619 | | // | 2620 | 3.73k | do_exp3: | 2621 | 3.73k | for(;;) | 2622 | 22.7k | { | 2623 | 22.7k | if(BOOST_JSON_UNLIKELY(! cs)) | 2624 | 97 | { | 2625 | 97 | if(BOOST_JSON_UNLIKELY(more_)) | 2626 | 97 | { | 2627 | 97 | if(BOOST_JSON_UNLIKELY( | 2628 | 97 | ! h_.on_number_part( | 2629 | 97 | {begin, cs.used(begin)}, ec_))) | 2630 | 0 | return fail(cs.begin()); | 2631 | | | 2632 | 97 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2633 | 97 | num_buf_.append( begin, cs.used(begin) ); | 2634 | 97 | return suspend(cs.begin(), state::exp3, num); | 2635 | 97 | } | 2636 | 97 | } | 2637 | 22.6k | else | 2638 | 22.6k | { | 2639 | 22.6k | char const c = *cs; | 2640 | 22.6k | if(BOOST_JSON_LIKELY( c >= '0' && c <= '9' )) | 2641 | 19.0k | { | 2642 | 19.0k | if(BOOST_JSON_UNLIKELY( | 2643 | | // 2147483647 INT_MAX | 2644 | 19.0k | num.exp > 214748364 || | 2645 | 19.0k | (num.exp == 214748364 && c > '7') | 2646 | 19.0k | )) | 2647 | 7.37k | num.exp = INT_MAX; | 2648 | 11.6k | else BOOST_IF_CONSTEXPR( !no_parsing ) | 2649 | 11.6k | num.exp = 10 * num.exp + ( c - '0' ); | 2650 | | | 2651 | 19.0k | ++cs; | 2652 | 19.0k | continue; | 2653 | 19.0k | } | 2654 | 22.6k | } | 2655 | 3.63k | BOOST_ASSERT(num.exp >= 0); | 2656 | 3.63k | if ( num.frac ) | 2657 | 1.01k | { | 2658 | 1.01k | if(BOOST_JSON_UNLIKELY( num.bias < (INT_MIN + num.exp) )) | 2659 | 425 | { | 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 | 425 | if(BOOST_JSON_UNLIKELY( | 2664 | 425 | (num.exp == INT_MAX) && | 2665 | 425 | (num.bias < 0) && | 2666 | 425 | (num.exp + num.bias < 308) && | 2667 | 425 | 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 | 425 | num.bias = 0; | 2675 | 425 | num.exp = INT_MAX; | 2676 | 425 | } | 2677 | 1.01k | } | 2678 | 2.62k | else if (BOOST_JSON_UNLIKELY( num.bias > (INT_MAX - num.exp) )) | 2679 | 305 | { | 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 | 305 | if(BOOST_JSON_UNLIKELY( | 2684 | 305 | (num.exp == INT_MAX) && | 2685 | 305 | (num.bias > 0) && | 2686 | 305 | (num.exp - num.bias < 308) && | 2687 | 305 | 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 | 305 | num.bias = 0; | 2695 | 305 | num.exp = INT_MAX; | 2696 | 305 | } | 2697 | 3.63k | goto finish_dub; | 2698 | 3.63k | } | 2699 | | | 2700 | 835 | finish_int: | 2701 | 835 | if(negative || (!stack_empty && num.neg)) | 2702 | 835 | { | 2703 | 835 | if(BOOST_JSON_UNLIKELY( | 2704 | 835 | ! h_.on_int64(static_cast< | 2705 | 835 | int64_t>(~num.mant + 1), {begin, cs.used(begin)}, ec_))) | 2706 | 0 | return fail(cs.begin()); | 2707 | 835 | return cs.begin(); | 2708 | 835 | } | 2709 | 0 | if(num.mant <= INT64_MAX) | 2710 | 0 | { | 2711 | 9.62k | finish_signed: | 2712 | 9.62k | if(BOOST_JSON_UNLIKELY( | 2713 | 9.62k | ! h_.on_int64(static_cast< | 2714 | 9.62k | int64_t>(num.mant), {begin, cs.used(begin)}, ec_))) | 2715 | 0 | return fail(cs.begin()); | 2716 | 9.62k | return cs.begin(); | 2717 | 9.62k | } | 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 | 9.29k | finish_dub: | 2723 | 9.29k | double d; | 2724 | 9.29k | std::size_t const size = cs.used(begin); | 2725 | 9.29k | BOOST_ASSERT( !num_buf_.size() || precise_parsing ); | 2726 | | BOOST_IF_CONSTEXPR( precise_parsing ) | 2727 | 9.29k | { | 2728 | 9.29k | char const* data = begin; | 2729 | 9.29k | 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 | 9.29k | 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 | 9.29k | auto const err = detail::charconv::from_chars( | 2739 | 9.29k | data, data + full_size, d ); | 2740 | 9.29k | BOOST_ASSERT( err.ec != std::errc::invalid_argument ); | 2741 | 9.29k | BOOST_ASSERT( err.ptr == data + full_size ); | 2742 | 9.29k | (void)err; | 2743 | | } | 2744 | | else BOOST_IF_CONSTEXPR( no_parsing ) | 2745 | | d = 0; | 2746 | | else | 2747 | | d = detail::dec_to_float( | 2748 | | num.mant, | 2749 | | num.bias + (num.frac ? | 2750 | | -num.exp : num.exp), | 2751 | | num.neg); | 2752 | 9.29k | if(BOOST_JSON_UNLIKELY( | 2753 | 9.29k | ! h_.on_double(d, {begin, size}, ec_))) | 2754 | 0 | return fail(cs.begin()); | 2755 | 9.29k | return cs.begin(); | 2756 | 9.29k | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::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>) Line | Count | Source | 1986 | 4.28k | { | 1987 | 4.28k | constexpr bool precise_parsing = mode == number_precision::precise; | 1988 | 4.28k | 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 | 4.28k | bool const negative = first == '-'; | 1995 | 4.28k | bool const zero_first = first == '0'; | 1996 | 4.28k | bool const nonzero_first = first == '+'; | 1997 | 4.28k | detail::const_stream_wrapper cs(p, end_); | 1998 | 4.28k | number num; | 1999 | 4.28k | const char* begin = cs.begin(); | 2000 | 4.28k | if(stack_empty || st_.empty()) | 2001 | 4.28k | { | 2002 | 4.28k | num.bias = 0; | 2003 | 4.28k | num.exp = 0; | 2004 | 4.28k | num.frac = false; | 2005 | 4.28k | num_buf_.clear(); | 2006 | | | 2007 | | //---------------------------------- | 2008 | | // | 2009 | | // '-' | 2010 | | // leading minus sign | 2011 | | // | 2012 | 4.28k | BOOST_ASSERT(cs); | 2013 | 4.28k | if(negative) | 2014 | 4.28k | ++cs; | 2015 | | | 2016 | 4.28k | num.neg = negative; | 2017 | 4.28k | num.frac = false; | 2018 | 4.28k | num.exp = 0; | 2019 | 4.28k | num.bias = 0; | 2020 | | | 2021 | | // fast path | 2022 | 4.28k | if( cs.remain() >= 16 + 1 + 16 ) // digits . digits | 2023 | 3.68k | { | 2024 | 3.68k | int n1; | 2025 | | | 2026 | 3.68k | if( nonzero_first || | 2027 | 3.68k | (negative && *cs != '0') ) | 2028 | 2.71k | { | 2029 | 2.71k | n1 = detail::count_digits( cs.begin() ); | 2030 | 2.71k | BOOST_ASSERT(n1 >= 0 && n1 <= 16); | 2031 | | | 2032 | 2.71k | 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 | 2.71k | if( ! nonzero_first && n1 == 0 ) | 2040 | 4 | { | 2041 | | // digit required | 2042 | 4 | BOOST_STATIC_CONSTEXPR source_location loc | 2043 | 4 | = BOOST_CURRENT_LOCATION; | 2044 | 4 | return fail(cs.begin(), error::syntax, &loc); | 2045 | 4 | } | 2046 | | | 2047 | 2.70k | BOOST_IF_CONSTEXPR( !no_parsing ) | 2048 | 2.70k | num.mant = detail::parse_unsigned( 0, cs.begin(), n1 ); | 2049 | 2.70k | else | 2050 | 2.70k | num.mant = 0; | 2051 | | | 2052 | 2.70k | cs += n1; | 2053 | | | 2054 | | // integer or floating-point with | 2055 | | // >= 16 leading digits | 2056 | 2.70k | if( n1 == 16 ) | 2057 | 892 | { | 2058 | 892 | goto do_num2; | 2059 | 892 | } | 2060 | 2.70k | } | 2061 | 973 | else | 2062 | 973 | { | 2063 | | // 0. floating-point or 0e integer | 2064 | 973 | num.mant = 0; | 2065 | 973 | n1 = 0; | 2066 | 973 | ++cs; | 2067 | 973 | } | 2068 | | | 2069 | 2.78k | { | 2070 | 2.78k | const char c = *cs; | 2071 | 2.78k | if(c != '.') | 2072 | 1.71k | { | 2073 | 1.71k | if((c | 32) == 'e') | 2074 | 809 | { | 2075 | 809 | ++cs; | 2076 | 809 | goto do_exp1; | 2077 | 809 | } | 2078 | 901 | BOOST_IF_CONSTEXPR( negative && !no_parsing ) | 2079 | 901 | num.mant = ~num.mant + 1; | 2080 | 901 | goto finish_signed; | 2081 | 1.71k | } | 2082 | 2.78k | } | 2083 | | | 2084 | | // floating-point number | 2085 | | | 2086 | 1.07k | ++cs; | 2087 | | | 2088 | 1.07k | int n2 = detail::count_digits( cs.begin() ); | 2089 | 1.07k | BOOST_ASSERT(n2 >= 0 && n2 <= 16); | 2090 | | | 2091 | 1.07k | 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 | 1.07k | if( n1 + n2 >= 19 ) | 2101 | 211 | { | 2102 | 211 | goto do_num7; | 2103 | 211 | } | 2104 | | | 2105 | 864 | BOOST_IF_CONSTEXPR( !no_parsing ) | 2106 | 864 | num.mant = detail::parse_unsigned( num.mant, cs.begin(), n2 ); | 2107 | | | 2108 | 864 | BOOST_ASSERT(num.bias == 0); | 2109 | | | 2110 | 864 | num.bias -= n2; | 2111 | | | 2112 | 864 | cs += n2; | 2113 | | | 2114 | 864 | char ch = *cs; | 2115 | | | 2116 | 864 | if( (ch | 32) == 'e' ) | 2117 | 204 | { | 2118 | 204 | ++cs; | 2119 | 204 | goto do_exp1; | 2120 | 204 | } | 2121 | 660 | else if( ch >= '0' && ch <= '9' ) | 2122 | 213 | { | 2123 | 213 | goto do_num8; | 2124 | 213 | } | 2125 | | | 2126 | 447 | goto finish_dub; | 2127 | 864 | } | 2128 | 4.28k | } | 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 | 603 | do_num1: | 2157 | 603 | if(zero_first || nonzero_first || | 2158 | 603 | BOOST_JSON_LIKELY(cs)) | 2159 | 583 | { | 2160 | 583 | char const c = *cs; | 2161 | 583 | if(zero_first) | 2162 | 0 | { | 2163 | 0 | ++cs; | 2164 | 0 | num.mant = 0; | 2165 | 0 | goto do_num6; | 2166 | 0 | } | 2167 | 583 | else if(nonzero_first || BOOST_JSON_LIKELY( | 2168 | 583 | c >= '1' && c <= '9')) | 2169 | 421 | { | 2170 | 421 | ++cs; | 2171 | 421 | num.mant = c - '0'; | 2172 | 421 | } | 2173 | 162 | else if(BOOST_JSON_UNLIKELY( | 2174 | 162 | c == '0')) | 2175 | 140 | { | 2176 | 140 | ++cs; | 2177 | 140 | num.mant = 0; | 2178 | 140 | goto do_num6; | 2179 | 140 | } | 2180 | 22 | 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 | 22 | else | 2189 | 22 | { | 2190 | 22 | BOOST_STATIC_CONSTEXPR source_location loc | 2191 | 22 | = BOOST_CURRENT_LOCATION; | 2192 | 22 | return fail(cs.begin(), error::syntax, &loc); | 2193 | 22 | } | 2194 | 583 | } | 2195 | 20 | else | 2196 | 20 | { | 2197 | 20 | if(BOOST_JSON_UNLIKELY( | 2198 | 20 | ! h_.on_number_part( | 2199 | 20 | {begin, cs.used(begin)}, ec_))) | 2200 | 0 | return fail(cs.begin()); | 2201 | | | 2202 | 20 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2203 | 20 | num_buf_.append( begin, cs.used(begin) ); | 2204 | 20 | return maybe_suspend( | 2205 | 20 | cs.begin(), state::num1, num); | 2206 | 20 | } | 2207 | | | 2208 | | //---------------------------------- | 2209 | | // | 2210 | | // 1*DIGIT | 2211 | | // significant digits left of decimal | 2212 | | // | 2213 | 1.31k | do_num2: | 2214 | 1.31k | if(negative || (!stack_empty && num.neg)) | 2215 | 1.31k | { | 2216 | 1.31k | for(;;) | 2217 | 2.54k | { | 2218 | 2.54k | if(BOOST_JSON_UNLIKELY(! cs)) | 2219 | 29 | { | 2220 | 29 | if(BOOST_JSON_UNLIKELY(more_)) | 2221 | 29 | { | 2222 | 29 | if(BOOST_JSON_UNLIKELY( | 2223 | 29 | ! h_.on_number_part( | 2224 | 29 | {begin, cs.used(begin)}, ec_))) | 2225 | 0 | return fail(cs.begin()); | 2226 | | | 2227 | 29 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2228 | 29 | num_buf_.append( begin, cs.used(begin) ); | 2229 | 29 | return suspend(cs.begin(), state::num2, num); | 2230 | 29 | } | 2231 | 0 | goto finish_int; | 2232 | 29 | } | 2233 | 2.51k | char const c = *cs; | 2234 | 2.51k | if(BOOST_JSON_LIKELY( | 2235 | 2.51k | c >= '0' && c <= '9')) | 2236 | 1.23k | { | 2237 | 1.23k | ++cs; | 2238 | | // 9223372036854775808 INT64_MIN | 2239 | 1.23k | if( num.mant > 922337203685477580 || ( | 2240 | 1.23k | num.mant == 922337203685477580 && c > '8')) | 2241 | 0 | break; | 2242 | 1.23k | BOOST_IF_CONSTEXPR( !no_parsing ) | 2243 | 1.23k | num.mant = 10 * num.mant + ( c - '0' ); | 2244 | 1.23k | continue; | 2245 | 1.23k | } | 2246 | 1.28k | goto do_num6; // [.eE] | 2247 | 2.51k | } | 2248 | 1.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 | 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 | 876 | do_num5: | 2384 | 876 | for(;;) | 2385 | 4.34k | { | 2386 | 4.34k | if(BOOST_JSON_UNLIKELY(! cs)) | 2387 | 22 | { | 2388 | 22 | if(BOOST_JSON_UNLIKELY(more_)) | 2389 | 22 | { | 2390 | 22 | if(BOOST_JSON_UNLIKELY( | 2391 | 22 | ! h_.on_number_part( | 2392 | 22 | {begin, cs.used(begin)}, ec_))) | 2393 | 0 | return fail(cs.begin()); | 2394 | | | 2395 | 22 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2396 | 22 | num_buf_.append( begin, cs.used(begin) ); | 2397 | 22 | return suspend(cs.begin(), state::num5, num); | 2398 | 22 | } | 2399 | 0 | goto finish_dub; | 2400 | 22 | } | 2401 | 4.32k | char const c = *cs; | 2402 | 4.32k | if(BOOST_JSON_LIKELY( | 2403 | 4.32k | c >= '0' && c <= '9')) | 2404 | 3.47k | { | 2405 | 3.47k | ++cs; | 2406 | 3.47k | } | 2407 | 854 | else if((c | 32) == 'e') | 2408 | 214 | { | 2409 | 214 | ++cs; | 2410 | 214 | goto do_exp1; | 2411 | 214 | } | 2412 | 640 | else | 2413 | 640 | { | 2414 | 640 | goto finish_dub; | 2415 | 640 | } | 2416 | 4.32k | } | 2417 | | | 2418 | | //---------------------------------- | 2419 | | // | 2420 | | // [.eE] | 2421 | | // | 2422 | 1.42k | do_num6: | 2423 | 1.42k | { | 2424 | 1.42k | if(BOOST_JSON_UNLIKELY(! cs)) | 2425 | 5 | { | 2426 | 5 | if(BOOST_JSON_UNLIKELY(more_)) | 2427 | 5 | { | 2428 | 5 | if(BOOST_JSON_UNLIKELY( | 2429 | 5 | ! h_.on_number_part( | 2430 | 5 | {begin, cs.used(begin)}, ec_))) | 2431 | 0 | return fail(cs.begin()); | 2432 | | | 2433 | 5 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2434 | 5 | num_buf_.append( begin, cs.used(begin) ); | 2435 | 5 | return suspend(cs.begin(), state::num6, num); | 2436 | 5 | } | 2437 | 0 | goto finish_int; | 2438 | 5 | } | 2439 | 1.41k | char const c = *cs; | 2440 | 1.41k | if(BOOST_JSON_LIKELY( | 2441 | 1.41k | c == '.')) | 2442 | 458 | { | 2443 | 458 | ++cs; | 2444 | 458 | } | 2445 | 961 | else if((c | 32) == 'e') | 2446 | 344 | { | 2447 | 344 | ++cs; | 2448 | 344 | goto do_exp1; | 2449 | 344 | } | 2450 | 617 | else | 2451 | 617 | { | 2452 | 617 | goto finish_int; | 2453 | 617 | } | 2454 | 1.41k | } | 2455 | | | 2456 | | //---------------------------------- | 2457 | | // | 2458 | | // DIGIT | 2459 | | // first significant digit | 2460 | | // to the right of decimal | 2461 | | // | 2462 | 669 | do_num7: | 2463 | 669 | { | 2464 | 669 | if(BOOST_JSON_UNLIKELY(! cs)) | 2465 | 4 | { | 2466 | 4 | if(BOOST_JSON_UNLIKELY(more_)) | 2467 | 4 | { | 2468 | 4 | if(BOOST_JSON_UNLIKELY( | 2469 | 4 | ! h_.on_number_part( | 2470 | 4 | {begin, cs.used(begin)}, ec_))) | 2471 | 0 | return fail(cs.begin()); | 2472 | | | 2473 | 4 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2474 | 4 | num_buf_.append( begin, cs.used(begin) ); | 2475 | 4 | return suspend(cs.begin(), state::num7, num); | 2476 | 4 | } | 2477 | | // digit required | 2478 | 4 | BOOST_STATIC_CONSTEXPR source_location loc | 2479 | 0 | = BOOST_CURRENT_LOCATION; | 2480 | 0 | return fail(cs.begin(), error::syntax, &loc); | 2481 | 4 | } | 2482 | 665 | char const c = *cs; | 2483 | 665 | if(BOOST_JSON_UNLIKELY( | 2484 | 665 | c < '0' || c > '9')) | 2485 | 2 | { | 2486 | | // digit required | 2487 | 2 | BOOST_STATIC_CONSTEXPR source_location loc | 2488 | 2 | = BOOST_CURRENT_LOCATION; | 2489 | 2 | return fail(cs.begin(), error::syntax, &loc); | 2490 | 2 | } | 2491 | 665 | } | 2492 | | | 2493 | | //---------------------------------- | 2494 | | // | 2495 | | // 1*DIGIT | 2496 | | // significant digits | 2497 | | // to the right of decimal | 2498 | | // | 2499 | 876 | do_num8: | 2500 | 876 | for(;;) | 2501 | 876 | { | 2502 | 876 | if(BOOST_JSON_UNLIKELY(! cs)) | 2503 | 0 | { | 2504 | 0 | 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 | 0 | goto finish_dub; | 2516 | 0 | } | 2517 | 876 | char const c = *cs; | 2518 | 876 | if(BOOST_JSON_LIKELY( | 2519 | 876 | c >= '0' && c <= '9')) | 2520 | 876 | { | 2521 | 876 | ++cs; | 2522 | 876 | if(!no_parsing && BOOST_JSON_LIKELY( | 2523 | 876 | num.mant <= 9007199254740991)) // 2^53-1 | 2524 | 0 | { | 2525 | 0 | 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 | 0 | --num.bias; | 2532 | 0 | num.mant = 10 * num.mant + ( c - '0' ); | 2533 | 0 | } | 2534 | 876 | else | 2535 | 876 | { | 2536 | 876 | goto do_num5; | 2537 | 876 | } | 2538 | 876 | } | 2539 | 0 | else if((c | 32) == 'e') | 2540 | 0 | { | 2541 | 0 | ++cs; | 2542 | 0 | goto do_exp1; | 2543 | 0 | } | 2544 | 0 | else | 2545 | 0 | { | 2546 | 0 | goto finish_dub; | 2547 | 0 | } | 2548 | 876 | } | 2549 | | | 2550 | | //---------------------------------- | 2551 | | // | 2552 | | // *[+-] | 2553 | | // | 2554 | 1.57k | do_exp1: | 2555 | 1.57k | if(BOOST_JSON_UNLIKELY(! cs)) | 2556 | 14 | { | 2557 | 14 | if(BOOST_JSON_UNLIKELY( | 2558 | 14 | ! h_.on_number_part( | 2559 | 14 | {begin, cs.used(begin)}, ec_))) | 2560 | 0 | return fail(cs.begin()); | 2561 | | | 2562 | 14 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2563 | 14 | num_buf_.append( begin, cs.used(begin) ); | 2564 | 14 | return maybe_suspend( | 2565 | 14 | cs.begin(), state::exp1, num); | 2566 | 14 | } | 2567 | 1.55k | if(*cs == '+') | 2568 | 200 | { | 2569 | 200 | ++cs; | 2570 | 200 | } | 2571 | 1.35k | else if(*cs == '-') | 2572 | 199 | { | 2573 | 199 | ++cs; | 2574 | 199 | num.frac = true; | 2575 | 199 | } | 2576 | | | 2577 | | //---------------------------------- | 2578 | | // | 2579 | | // DIGIT | 2580 | | // first digit of the exponent | 2581 | | // | 2582 | 1.55k | do_exp2: | 2583 | 1.55k | { | 2584 | 1.55k | if(BOOST_JSON_UNLIKELY(! cs)) | 2585 | 11 | { | 2586 | 11 | if(BOOST_JSON_UNLIKELY(more_)) | 2587 | 11 | { | 2588 | 11 | if(BOOST_JSON_UNLIKELY( | 2589 | 11 | ! h_.on_number_part( | 2590 | 11 | {begin, cs.used(begin)}, ec_))) | 2591 | 0 | return fail(cs.begin()); | 2592 | | | 2593 | 11 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2594 | 11 | num_buf_.append( begin, cs.used(begin) ); | 2595 | 11 | return suspend(cs.begin(), state::exp2, num); | 2596 | 11 | } | 2597 | | // digit required | 2598 | 11 | BOOST_STATIC_CONSTEXPR source_location loc | 2599 | 0 | = BOOST_CURRENT_LOCATION; | 2600 | 0 | return fail(cs.begin(), error::syntax, &loc); | 2601 | 11 | } | 2602 | 1.54k | char const c = *cs; | 2603 | 1.54k | if(BOOST_JSON_UNLIKELY( | 2604 | 1.54k | c < '0' || c > '9')) | 2605 | 10 | { | 2606 | | // digit required | 2607 | 10 | BOOST_STATIC_CONSTEXPR source_location loc | 2608 | 10 | = BOOST_CURRENT_LOCATION; | 2609 | 10 | return fail(cs.begin(), error::syntax, &loc); | 2610 | 10 | } | 2611 | 1.53k | ++cs; | 2612 | 1.53k | num.exp = c - '0'; | 2613 | 1.53k | } | 2614 | | | 2615 | | //---------------------------------- | 2616 | | // | 2617 | | // 1*DIGIT | 2618 | | // subsequent digits in the exponent | 2619 | | // | 2620 | 1.53k | do_exp3: | 2621 | 1.53k | for(;;) | 2622 | 2.23k | { | 2623 | 2.23k | if(BOOST_JSON_UNLIKELY(! cs)) | 2624 | 24 | { | 2625 | 24 | if(BOOST_JSON_UNLIKELY(more_)) | 2626 | 24 | { | 2627 | 24 | if(BOOST_JSON_UNLIKELY( | 2628 | 24 | ! h_.on_number_part( | 2629 | 24 | {begin, cs.used(begin)}, ec_))) | 2630 | 0 | return fail(cs.begin()); | 2631 | | | 2632 | 24 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2633 | 24 | num_buf_.append( begin, cs.used(begin) ); | 2634 | 24 | return suspend(cs.begin(), state::exp3, num); | 2635 | 24 | } | 2636 | 24 | } | 2637 | 2.21k | else | 2638 | 2.21k | { | 2639 | 2.21k | char const c = *cs; | 2640 | 2.21k | if(BOOST_JSON_LIKELY( c >= '0' && c <= '9' )) | 2641 | 703 | { | 2642 | 703 | if(BOOST_JSON_UNLIKELY( | 2643 | | // 2147483647 INT_MAX | 2644 | 703 | num.exp > 214748364 || | 2645 | 703 | (num.exp == 214748364 && c > '7') | 2646 | 703 | )) | 2647 | 0 | num.exp = INT_MAX; | 2648 | 703 | else BOOST_IF_CONSTEXPR( !no_parsing ) | 2649 | 703 | num.exp = 10 * num.exp + ( c - '0' ); | 2650 | | | 2651 | 703 | ++cs; | 2652 | 703 | continue; | 2653 | 703 | } | 2654 | 2.21k | } | 2655 | 1.51k | BOOST_ASSERT(num.exp >= 0); | 2656 | 1.51k | if ( num.frac ) | 2657 | 196 | { | 2658 | 196 | if(BOOST_JSON_UNLIKELY( num.bias < (INT_MIN + num.exp) )) | 2659 | 0 | { | 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 | 0 | if(BOOST_JSON_UNLIKELY( | 2664 | 0 | (num.exp == INT_MAX) && | 2665 | 0 | (num.bias < 0) && | 2666 | 0 | (num.exp + num.bias < 308) && | 2667 | 0 | 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 | 0 | num.bias = 0; | 2675 | 0 | num.exp = INT_MAX; | 2676 | 0 | } | 2677 | 196 | } | 2678 | 1.31k | 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 | 1.51k | goto finish_dub; | 2698 | 1.51k | } | 2699 | | | 2700 | 617 | finish_int: | 2701 | 617 | if(negative || (!stack_empty && num.neg)) | 2702 | 617 | { | 2703 | 617 | if(BOOST_JSON_UNLIKELY( | 2704 | 617 | ! h_.on_int64(static_cast< | 2705 | 617 | int64_t>(~num.mant + 1), {begin, cs.used(begin)}, ec_))) | 2706 | 0 | return fail(cs.begin()); | 2707 | 617 | return cs.begin(); | 2708 | 617 | } | 2709 | 0 | if(num.mant <= INT64_MAX) | 2710 | 0 | { | 2711 | 901 | finish_signed: | 2712 | 901 | if(BOOST_JSON_UNLIKELY( | 2713 | 901 | ! h_.on_int64(static_cast< | 2714 | 901 | int64_t>(num.mant), {begin, cs.used(begin)}, ec_))) | 2715 | 0 | return fail(cs.begin()); | 2716 | 901 | return cs.begin(); | 2717 | 901 | } | 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 | 2.59k | finish_dub: | 2723 | 2.59k | double d; | 2724 | 2.59k | std::size_t const size = cs.used(begin); | 2725 | 2.59k | BOOST_ASSERT( !num_buf_.size() || precise_parsing ); | 2726 | | BOOST_IF_CONSTEXPR( precise_parsing ) | 2727 | | { | 2728 | | char const* data = begin; | 2729 | | 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 | 2.59k | else BOOST_IF_CONSTEXPR( no_parsing ) | 2745 | 2.59k | d = 0; | 2746 | | else | 2747 | | d = detail::dec_to_float( | 2748 | | num.mant, | 2749 | | num.bias + (num.frac ? | 2750 | | -num.exp : num.exp), | 2751 | | num.neg); | 2752 | 2.59k | if(BOOST_JSON_UNLIKELY( | 2753 | 2.59k | ! h_.on_double(d, {begin, size}, ec_))) | 2754 | 0 | return fail(cs.begin()); | 2755 | 2.59k | return cs.begin(); | 2756 | 2.59k | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::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 | 9.02M | { | 1987 | 9.02M | constexpr bool precise_parsing = mode == number_precision::precise; | 1988 | 9.02M | 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 | 9.02M | bool const negative = first == '-'; | 1995 | 9.02M | bool const zero_first = first == '0'; | 1996 | 9.02M | bool const nonzero_first = first == '+'; | 1997 | 9.02M | detail::const_stream_wrapper cs(p, end_); | 1998 | 9.02M | number num; | 1999 | 9.02M | const char* begin = cs.begin(); | 2000 | 9.02M | if(stack_empty || st_.empty()) | 2001 | 9.02M | { | 2002 | 9.02M | num.bias = 0; | 2003 | 9.02M | num.exp = 0; | 2004 | 9.02M | num.frac = false; | 2005 | 9.02M | num_buf_.clear(); | 2006 | | | 2007 | | //---------------------------------- | 2008 | | // | 2009 | | // '-' | 2010 | | // leading minus sign | 2011 | | // | 2012 | 9.02M | BOOST_ASSERT(cs); | 2013 | 9.02M | if(negative) | 2014 | 0 | ++cs; | 2015 | | | 2016 | 9.02M | num.neg = negative; | 2017 | 9.02M | num.frac = false; | 2018 | 9.02M | num.exp = 0; | 2019 | 9.02M | num.bias = 0; | 2020 | | | 2021 | | // fast path | 2022 | 9.02M | if( cs.remain() >= 16 + 1 + 16 ) // digits . digits | 2023 | 9.00M | { | 2024 | 9.00M | int n1; | 2025 | | | 2026 | 9.00M | if( nonzero_first || | 2027 | 0 | (negative && *cs != '0') ) | 2028 | 9.00M | { | 2029 | 9.00M | n1 = detail::count_digits( cs.begin() ); | 2030 | 9.00M | BOOST_ASSERT(n1 >= 0 && n1 <= 16); | 2031 | | | 2032 | 9.00M | 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 | 9.00M | 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 | 9.00M | BOOST_IF_CONSTEXPR( !no_parsing ) | 2048 | 9.00M | num.mant = detail::parse_unsigned( 0, cs.begin(), n1 ); | 2049 | | else | 2050 | | num.mant = 0; | 2051 | | | 2052 | 9.00M | cs += n1; | 2053 | | | 2054 | | // integer or floating-point with | 2055 | | // >= 16 leading digits | 2056 | 9.00M | if( n1 == 16 ) | 2057 | 43.2k | { | 2058 | 43.2k | goto do_num2; | 2059 | 43.2k | } | 2060 | 9.00M | } | 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 | 8.96M | { | 2070 | 8.96M | const char c = *cs; | 2071 | 8.96M | if(c != '.') | 2072 | 8.95M | { | 2073 | 8.95M | if((c | 32) == 'e') | 2074 | 4.02M | { | 2075 | 4.02M | ++cs; | 2076 | 4.02M | goto do_exp1; | 2077 | 4.02M | } | 2078 | 4.92M | BOOST_IF_CONSTEXPR( negative && !no_parsing ) | 2079 | 4.92M | num.mant = ~num.mant + 1; | 2080 | 4.92M | goto finish_signed; | 2081 | 8.95M | } | 2082 | 8.96M | } | 2083 | | | 2084 | | // floating-point number | 2085 | | | 2086 | 14.3k | ++cs; | 2087 | | | 2088 | 14.3k | int n2 = detail::count_digits( cs.begin() ); | 2089 | 14.3k | BOOST_ASSERT(n2 >= 0 && n2 <= 16); | 2090 | | | 2091 | 14.3k | 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 | 14.3k | if( n1 + n2 >= 19 ) | 2101 | 663 | { | 2102 | 663 | goto do_num7; | 2103 | 663 | } | 2104 | | | 2105 | 13.6k | BOOST_IF_CONSTEXPR( !no_parsing ) | 2106 | 13.6k | num.mant = detail::parse_unsigned( num.mant, cs.begin(), n2 ); | 2107 | | | 2108 | 13.6k | BOOST_ASSERT(num.bias == 0); | 2109 | | | 2110 | 13.6k | num.bias -= n2; | 2111 | | | 2112 | 13.6k | cs += n2; | 2113 | | | 2114 | 13.6k | char ch = *cs; | 2115 | | | 2116 | 13.6k | if( (ch | 32) == 'e' ) | 2117 | 1.90k | { | 2118 | 1.90k | ++cs; | 2119 | 1.90k | goto do_exp1; | 2120 | 1.90k | } | 2121 | 11.7k | else if( ch >= '0' && ch <= '9' ) | 2122 | 607 | { | 2123 | 607 | goto do_num8; | 2124 | 607 | } | 2125 | | | 2126 | 11.1k | goto finish_dub; | 2127 | 13.6k | } | 2128 | 9.02M | } | 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 | 11.3k | do_num1: | 2157 | 11.3k | if(zero_first || nonzero_first || | 2158 | 0 | BOOST_JSON_LIKELY(cs)) | 2159 | 11.3k | { | 2160 | 11.3k | char const c = *cs; | 2161 | 11.3k | if(zero_first) | 2162 | 0 | { | 2163 | 0 | ++cs; | 2164 | 0 | num.mant = 0; | 2165 | 0 | goto do_num6; | 2166 | 0 | } | 2167 | 11.3k | else if(nonzero_first || BOOST_JSON_LIKELY( | 2168 | 11.3k | c >= '1' && c <= '9')) | 2169 | 11.3k | { | 2170 | 11.3k | ++cs; | 2171 | 11.3k | num.mant = c - '0'; | 2172 | 11.3k | } | 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 | 11.3k | } | 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 | 54.6k | do_num2: | 2214 | 54.6k | 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 | 54.6k | else | 2250 | 54.6k | { | 2251 | 54.6k | for(;;) | 2252 | 204k | { | 2253 | 204k | if(BOOST_JSON_UNLIKELY(! cs)) | 2254 | 634 | { | 2255 | 634 | if(BOOST_JSON_UNLIKELY(more_)) | 2256 | 346 | { | 2257 | 346 | if(BOOST_JSON_UNLIKELY( | 2258 | 346 | ! h_.on_number_part( | 2259 | 346 | {begin, cs.used(begin)}, ec_))) | 2260 | 0 | return fail(cs.begin()); | 2261 | | | 2262 | 346 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2263 | 346 | num_buf_.append( begin, cs.used(begin) ); | 2264 | 346 | return suspend(cs.begin(), state::num2, num); | 2265 | 346 | } | 2266 | 288 | goto finish_int; | 2267 | 634 | } | 2268 | 203k | char const c = *cs; | 2269 | 203k | if(BOOST_JSON_LIKELY( | 2270 | 203k | c >= '0' && c <= '9')) | 2271 | 158k | { | 2272 | 158k | ++cs; | 2273 | | // 18446744073709551615 UINT64_MAX | 2274 | 158k | if( num.mant > 1844674407370955161 || ( | 2275 | 150k | num.mant == 1844674407370955161 && c > '5')) | 2276 | 9.11k | break; | 2277 | 149k | BOOST_IF_CONSTEXPR( !no_parsing ) | 2278 | 149k | num.mant = 10 * num.mant + ( c - '0' ); | 2279 | 149k | } | 2280 | 44.8k | else | 2281 | 44.8k | { | 2282 | 44.8k | goto do_num6; // [.eE] | 2283 | 44.8k | } | 2284 | 203k | } | 2285 | 54.6k | } | 2286 | 9.11k | ++num.bias; | 2287 | | | 2288 | | //---------------------------------- | 2289 | | // | 2290 | | // 1*DIGIT | 2291 | | // non-significant digits left of decimal | 2292 | | // | 2293 | 9.11k | do_num3: | 2294 | 9.11k | for(;;) | 2295 | 8.73M | { | 2296 | 8.73M | if(BOOST_JSON_UNLIKELY(! cs)) | 2297 | 72 | { | 2298 | 72 | if(BOOST_JSON_UNLIKELY(more_)) | 2299 | 31 | { | 2300 | 31 | if(BOOST_JSON_UNLIKELY( | 2301 | 31 | ! h_.on_number_part( | 2302 | 31 | {begin, cs.used(begin)}, ec_))) | 2303 | 0 | return fail(cs.begin()); | 2304 | | | 2305 | 31 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2306 | 31 | num_buf_.append( begin, cs.used(begin) ); | 2307 | 31 | return suspend(cs.begin(), state::num3, num); | 2308 | 31 | } | 2309 | 41 | goto finish_dub; | 2310 | 72 | } | 2311 | 8.73M | char const c = *cs; | 2312 | 8.73M | if(BOOST_JSON_UNLIKELY( | 2313 | 8.73M | c >= '0' && c <= '9')) | 2314 | 8.72M | { | 2315 | 8.72M | 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 | 8.72M | ++cs; | 2322 | 8.72M | ++num.bias; | 2323 | 8.72M | } | 2324 | 9.04k | else if(BOOST_JSON_LIKELY( | 2325 | 9.04k | c == '.')) | 2326 | 1.26k | { | 2327 | 1.26k | ++cs; | 2328 | 1.26k | break; | 2329 | 1.26k | } | 2330 | 7.78k | else if((c | 32) == 'e') | 2331 | 1.81k | { | 2332 | 1.81k | ++cs; | 2333 | 1.81k | goto do_exp1; | 2334 | 1.81k | } | 2335 | 5.96k | else | 2336 | 5.96k | { | 2337 | 5.96k | goto finish_dub; | 2338 | 5.96k | } | 2339 | 8.73M | } | 2340 | | | 2341 | | //---------------------------------- | 2342 | | // | 2343 | | // DIGIT | 2344 | | // first non-significant digit | 2345 | | // to the right of decimal | 2346 | | // | 2347 | 1.26k | do_num4: | 2348 | 1.26k | { | 2349 | 1.26k | if(BOOST_JSON_UNLIKELY(! cs)) | 2350 | 4 | { | 2351 | 4 | if(BOOST_JSON_UNLIKELY( | 2352 | 4 | ! h_.on_number_part( | 2353 | 4 | {begin, cs.used(begin)}, ec_))) | 2354 | 0 | 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 | 4 | } | 2361 | 1.26k | char const c = *cs; | 2362 | 1.26k | if(BOOST_JSON_LIKELY( | 2363 | | //static_cast<unsigned char>(c - '0') < 10)) | 2364 | 1.26k | c >= '0' && c <= '9')) | 2365 | 1.24k | { | 2366 | 1.24k | ++cs; | 2367 | 1.24k | } | 2368 | 11 | else | 2369 | 11 | { | 2370 | | // digit required | 2371 | 11 | BOOST_STATIC_CONSTEXPR source_location loc | 2372 | 11 | = BOOST_CURRENT_LOCATION; | 2373 | 11 | return fail(cs.begin(), error::syntax, &loc); | 2374 | 11 | } | 2375 | 1.26k | } | 2376 | | | 2377 | | //---------------------------------- | 2378 | | // | 2379 | | // 1*DIGIT | 2380 | | // non-significant digits | 2381 | | // to the right of decimal | 2382 | | // | 2383 | 4.57k | do_num5: | 2384 | 4.57k | for(;;) | 2385 | 21.4k | { | 2386 | 21.4k | if(BOOST_JSON_UNLIKELY(! cs)) | 2387 | 86 | { | 2388 | 86 | if(BOOST_JSON_UNLIKELY(more_)) | 2389 | 46 | { | 2390 | 46 | if(BOOST_JSON_UNLIKELY( | 2391 | 46 | ! h_.on_number_part( | 2392 | 46 | {begin, cs.used(begin)}, ec_))) | 2393 | 0 | return fail(cs.begin()); | 2394 | | | 2395 | 46 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2396 | 46 | num_buf_.append( begin, cs.used(begin) ); | 2397 | 46 | return suspend(cs.begin(), state::num5, num); | 2398 | 46 | } | 2399 | 40 | goto finish_dub; | 2400 | 86 | } | 2401 | 21.3k | char const c = *cs; | 2402 | 21.3k | if(BOOST_JSON_LIKELY( | 2403 | 21.3k | c >= '0' && c <= '9')) | 2404 | 16.8k | { | 2405 | 16.8k | ++cs; | 2406 | 16.8k | } | 2407 | 4.48k | else if((c | 32) == 'e') | 2408 | 535 | { | 2409 | 535 | ++cs; | 2410 | 535 | goto do_exp1; | 2411 | 535 | } | 2412 | 3.94k | else | 2413 | 3.94k | { | 2414 | 3.94k | goto finish_dub; | 2415 | 3.94k | } | 2416 | 21.3k | } | 2417 | | | 2418 | | //---------------------------------- | 2419 | | // | 2420 | | // [.eE] | 2421 | | // | 2422 | 44.8k | do_num6: | 2423 | 44.8k | { | 2424 | 44.8k | 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 | 44.8k | char const c = *cs; | 2440 | 44.8k | if(BOOST_JSON_LIKELY( | 2441 | 44.8k | c == '.')) | 2442 | 4.28k | { | 2443 | 4.28k | ++cs; | 2444 | 4.28k | } | 2445 | 40.5k | else if((c | 32) == 'e') | 2446 | 2.97k | { | 2447 | 2.97k | ++cs; | 2448 | 2.97k | goto do_exp1; | 2449 | 2.97k | } | 2450 | 37.6k | else | 2451 | 37.6k | { | 2452 | 37.6k | goto finish_int; | 2453 | 37.6k | } | 2454 | 44.8k | } | 2455 | | | 2456 | | //---------------------------------- | 2457 | | // | 2458 | | // DIGIT | 2459 | | // first significant digit | 2460 | | // to the right of decimal | 2461 | | // | 2462 | 4.94k | do_num7: | 2463 | 4.94k | { | 2464 | 4.94k | if(BOOST_JSON_UNLIKELY(! cs)) | 2465 | 8 | { | 2466 | 8 | if(BOOST_JSON_UNLIKELY(more_)) | 2467 | 3 | { | 2468 | 3 | if(BOOST_JSON_UNLIKELY( | 2469 | 3 | ! h_.on_number_part( | 2470 | 3 | {begin, cs.used(begin)}, ec_))) | 2471 | 0 | return fail(cs.begin()); | 2472 | | | 2473 | 3 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2474 | 3 | num_buf_.append( begin, cs.used(begin) ); | 2475 | 3 | return suspend(cs.begin(), state::num7, num); | 2476 | 3 | } | 2477 | | // digit required | 2478 | 8 | BOOST_STATIC_CONSTEXPR source_location loc | 2479 | 5 | = BOOST_CURRENT_LOCATION; | 2480 | 5 | return fail(cs.begin(), error::syntax, &loc); | 2481 | 8 | } | 2482 | 4.93k | char const c = *cs; | 2483 | 4.93k | if(BOOST_JSON_UNLIKELY( | 2484 | 4.93k | c < '0' || c > '9')) | 2485 | 22 | { | 2486 | | // digit required | 2487 | 22 | BOOST_STATIC_CONSTEXPR source_location loc | 2488 | 22 | = BOOST_CURRENT_LOCATION; | 2489 | 22 | return fail(cs.begin(), error::syntax, &loc); | 2490 | 22 | } | 2491 | 4.93k | } | 2492 | | | 2493 | | //---------------------------------- | 2494 | | // | 2495 | | // 1*DIGIT | 2496 | | // significant digits | 2497 | | // to the right of decimal | 2498 | | // | 2499 | 5.52k | do_num8: | 2500 | 5.52k | for(;;) | 2501 | 16.5k | { | 2502 | 16.5k | if(BOOST_JSON_UNLIKELY(! cs)) | 2503 | 581 | { | 2504 | 581 | if(BOOST_JSON_UNLIKELY(more_)) | 2505 | 473 | { | 2506 | 473 | if(BOOST_JSON_UNLIKELY( | 2507 | 473 | ! h_.on_number_part( | 2508 | 473 | {begin, cs.used(begin)}, ec_))) | 2509 | 0 | return fail(cs.begin()); | 2510 | | | 2511 | 473 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2512 | 473 | num_buf_.append( begin, cs.used(begin) ); | 2513 | 473 | return suspend(cs.begin(), state::num8, num); | 2514 | 473 | } | 2515 | 108 | goto finish_dub; | 2516 | 581 | } | 2517 | 15.9k | char const c = *cs; | 2518 | 15.9k | if(BOOST_JSON_LIKELY( | 2519 | 15.9k | c >= '0' && c <= '9')) | 2520 | 14.3k | { | 2521 | 14.3k | ++cs; | 2522 | 14.3k | if(!no_parsing && BOOST_JSON_LIKELY( | 2523 | 14.3k | num.mant <= 9007199254740991)) // 2^53-1 | 2524 | 11.0k | { | 2525 | 11.0k | 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 | 11.0k | --num.bias; | 2532 | 11.0k | num.mant = 10 * num.mant + ( c - '0' ); | 2533 | 11.0k | } | 2534 | 3.32k | else | 2535 | 3.32k | { | 2536 | 3.32k | goto do_num5; | 2537 | 3.32k | } | 2538 | 14.3k | } | 2539 | 1.62k | else if((c | 32) == 'e') | 2540 | 367 | { | 2541 | 367 | ++cs; | 2542 | 367 | goto do_exp1; | 2543 | 367 | } | 2544 | 1.25k | else | 2545 | 1.25k | { | 2546 | 1.25k | goto finish_dub; | 2547 | 1.25k | } | 2548 | 15.9k | } | 2549 | | | 2550 | | //---------------------------------- | 2551 | | // | 2552 | | // *[+-] | 2553 | | // | 2554 | 4.03M | do_exp1: | 2555 | 4.03M | if(BOOST_JSON_UNLIKELY(! cs)) | 2556 | 55 | { | 2557 | 55 | if(BOOST_JSON_UNLIKELY( | 2558 | 55 | ! h_.on_number_part( | 2559 | 55 | {begin, cs.used(begin)}, ec_))) | 2560 | 0 | return fail(cs.begin()); | 2561 | | | 2562 | 55 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2563 | 55 | num_buf_.append( begin, cs.used(begin) ); | 2564 | 55 | return maybe_suspend( | 2565 | 55 | cs.begin(), state::exp1, num); | 2566 | 55 | } | 2567 | 4.03M | if(*cs == '+') | 2568 | 470 | { | 2569 | 470 | ++cs; | 2570 | 470 | } | 2571 | 4.03M | else if(*cs == '-') | 2572 | 30.3k | { | 2573 | 30.3k | ++cs; | 2574 | 30.3k | num.frac = true; | 2575 | 30.3k | } | 2576 | | | 2577 | | //---------------------------------- | 2578 | | // | 2579 | | // DIGIT | 2580 | | // first digit of the exponent | 2581 | | // | 2582 | 4.03M | do_exp2: | 2583 | 4.03M | { | 2584 | 4.03M | if(BOOST_JSON_UNLIKELY(! cs)) | 2585 | 24 | { | 2586 | 24 | if(BOOST_JSON_UNLIKELY(more_)) | 2587 | 12 | { | 2588 | 12 | if(BOOST_JSON_UNLIKELY( | 2589 | 12 | ! h_.on_number_part( | 2590 | 12 | {begin, cs.used(begin)}, ec_))) | 2591 | 0 | return fail(cs.begin()); | 2592 | | | 2593 | 12 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2594 | 12 | num_buf_.append( begin, cs.used(begin) ); | 2595 | 12 | return suspend(cs.begin(), state::exp2, num); | 2596 | 12 | } | 2597 | | // digit required | 2598 | 24 | BOOST_STATIC_CONSTEXPR source_location loc | 2599 | 12 | = BOOST_CURRENT_LOCATION; | 2600 | 12 | return fail(cs.begin(), error::syntax, &loc); | 2601 | 24 | } | 2602 | 4.03M | char const c = *cs; | 2603 | 4.03M | if(BOOST_JSON_UNLIKELY( | 2604 | 4.03M | c < '0' || c > '9')) | 2605 | 52 | { | 2606 | | // digit required | 2607 | 52 | BOOST_STATIC_CONSTEXPR source_location loc | 2608 | 52 | = BOOST_CURRENT_LOCATION; | 2609 | 52 | return fail(cs.begin(), error::syntax, &loc); | 2610 | 52 | } | 2611 | 4.03M | ++cs; | 2612 | 4.03M | num.exp = c - '0'; | 2613 | 4.03M | } | 2614 | | | 2615 | | //---------------------------------- | 2616 | | // | 2617 | | // 1*DIGIT | 2618 | | // subsequent digits in the exponent | 2619 | | // | 2620 | 4.03M | do_exp3: | 2621 | 4.03M | for(;;) | 2622 | 8.14M | { | 2623 | 8.14M | if(BOOST_JSON_UNLIKELY(! cs)) | 2624 | 777 | { | 2625 | 777 | if(BOOST_JSON_UNLIKELY(more_)) | 2626 | 435 | { | 2627 | 435 | if(BOOST_JSON_UNLIKELY( | 2628 | 435 | ! h_.on_number_part( | 2629 | 435 | {begin, cs.used(begin)}, ec_))) | 2630 | 0 | return fail(cs.begin()); | 2631 | | | 2632 | 435 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2633 | 435 | num_buf_.append( begin, cs.used(begin) ); | 2634 | 435 | return suspend(cs.begin(), state::exp3, num); | 2635 | 435 | } | 2636 | 777 | } | 2637 | 8.14M | else | 2638 | 8.14M | { | 2639 | 8.14M | char const c = *cs; | 2640 | 8.14M | if(BOOST_JSON_LIKELY( c >= '0' && c <= '9' )) | 2641 | 4.11M | { | 2642 | 4.11M | if(BOOST_JSON_UNLIKELY( | 2643 | | // 2147483647 INT_MAX | 2644 | 4.11M | num.exp > 214748364 || | 2645 | 4.11M | (num.exp == 214748364 && c > '7') | 2646 | 4.11M | )) | 2647 | 38.3k | num.exp = INT_MAX; | 2648 | 4.07M | else BOOST_IF_CONSTEXPR( !no_parsing ) | 2649 | 4.07M | num.exp = 10 * num.exp + ( c - '0' ); | 2650 | | | 2651 | 4.11M | ++cs; | 2652 | 4.11M | continue; | 2653 | 4.11M | } | 2654 | 8.14M | } | 2655 | 4.03M | BOOST_ASSERT(num.exp >= 0); | 2656 | 4.03M | if ( num.frac ) | 2657 | 30.2k | { | 2658 | 30.2k | if(BOOST_JSON_UNLIKELY( num.bias < (INT_MIN + num.exp) )) | 2659 | 782 | { | 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 | 782 | if(BOOST_JSON_UNLIKELY( | 2664 | 782 | (num.exp == INT_MAX) && | 2665 | 782 | (num.bias < 0) && | 2666 | 782 | (num.exp + num.bias < 308) && | 2667 | 782 | 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 | 782 | num.bias = 0; | 2675 | 782 | num.exp = INT_MAX; | 2676 | 782 | } | 2677 | 30.2k | } | 2678 | 4.00M | else if (BOOST_JSON_UNLIKELY( num.bias > (INT_MAX - num.exp) )) | 2679 | 985 | { | 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 | 985 | if(BOOST_JSON_UNLIKELY( | 2684 | 985 | (num.exp == INT_MAX) && | 2685 | 985 | (num.bias > 0) && | 2686 | 985 | (num.exp - num.bias < 308) && | 2687 | 985 | 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 | 985 | num.bias = 0; | 2695 | 985 | num.exp = INT_MAX; | 2696 | 985 | } | 2697 | 4.03M | goto finish_dub; | 2698 | 4.03M | } | 2699 | | | 2700 | 37.8k | finish_int: | 2701 | 37.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 | 37.8k | if(num.mant <= INT64_MAX) | 2710 | 12.9k | { | 2711 | 4.93M | finish_signed: | 2712 | 4.93M | if(BOOST_JSON_UNLIKELY( | 2713 | 4.93M | ! h_.on_int64(static_cast< | 2714 | 4.93M | int64_t>(num.mant), {begin, cs.used(begin)}, ec_))) | 2715 | 0 | return fail(cs.begin()); | 2716 | 4.93M | return cs.begin(); | 2717 | 4.93M | } | 2718 | 24.9k | if(BOOST_JSON_UNLIKELY( | 2719 | 24.9k | ! h_.on_uint64(num.mant, {begin, cs.used(begin)}, ec_))) | 2720 | 0 | return fail(cs.begin()); | 2721 | 24.9k | return cs.begin(); | 2722 | 4.05M | finish_dub: | 2723 | 4.05M | double d; | 2724 | 4.05M | std::size_t const size = cs.used(begin); | 2725 | 4.05M | BOOST_ASSERT( !num_buf_.size() || precise_parsing ); | 2726 | | BOOST_IF_CONSTEXPR( precise_parsing ) | 2727 | | { | 2728 | | char const* data = begin; | 2729 | | 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 | 4.05M | else BOOST_IF_CONSTEXPR( no_parsing ) | 2745 | 4.05M | d = 0; | 2746 | 4.05M | else | 2747 | 4.05M | d = detail::dec_to_float( | 2748 | 4.05M | num.mant, | 2749 | 4.05M | num.bias + (num.frac ? | 2750 | 4.02M | -num.exp : num.exp), | 2751 | 4.05M | num.neg); | 2752 | 4.05M | if(BOOST_JSON_UNLIKELY( | 2753 | 4.05M | ! h_.on_double(d, {begin, size}, ec_))) | 2754 | 0 | return fail(cs.begin()); | 2755 | 4.05M | return cs.begin(); | 2756 | 4.05M | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::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>) Line | Count | Source | 1986 | 90.9k | { | 1987 | 90.9k | constexpr bool precise_parsing = mode == number_precision::precise; | 1988 | 90.9k | 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 | 90.9k | bool const negative = first == '-'; | 1995 | 90.9k | bool const zero_first = first == '0'; | 1996 | 90.9k | bool const nonzero_first = first == '+'; | 1997 | 90.9k | detail::const_stream_wrapper cs(p, end_); | 1998 | 90.9k | number num; | 1999 | 90.9k | const char* begin = cs.begin(); | 2000 | 90.9k | if(stack_empty || st_.empty()) | 2001 | 90.9k | { | 2002 | 90.9k | num.bias = 0; | 2003 | 90.9k | num.exp = 0; | 2004 | 90.9k | num.frac = false; | 2005 | 90.9k | num_buf_.clear(); | 2006 | | | 2007 | | //---------------------------------- | 2008 | | // | 2009 | | // '-' | 2010 | | // leading minus sign | 2011 | | // | 2012 | 90.9k | BOOST_ASSERT(cs); | 2013 | 90.9k | if(negative) | 2014 | 0 | ++cs; | 2015 | | | 2016 | 90.9k | num.neg = negative; | 2017 | 90.9k | num.frac = false; | 2018 | 90.9k | num.exp = 0; | 2019 | 90.9k | num.bias = 0; | 2020 | | | 2021 | | // fast path | 2022 | 90.9k | if( cs.remain() >= 16 + 1 + 16 ) // digits . digits | 2023 | 86.2k | { | 2024 | 86.2k | int n1; | 2025 | | | 2026 | 86.2k | if( nonzero_first || | 2027 | 0 | (negative && *cs != '0') ) | 2028 | 86.2k | { | 2029 | 86.2k | n1 = detail::count_digits( cs.begin() ); | 2030 | 86.2k | BOOST_ASSERT(n1 >= 0 && n1 <= 16); | 2031 | | | 2032 | 86.2k | 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 | 86.2k | 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 | 86.2k | BOOST_IF_CONSTEXPR( !no_parsing ) | 2048 | 86.2k | num.mant = detail::parse_unsigned( 0, cs.begin(), n1 ); | 2049 | | else | 2050 | | num.mant = 0; | 2051 | | | 2052 | 86.2k | cs += n1; | 2053 | | | 2054 | | // integer or floating-point with | 2055 | | // >= 16 leading digits | 2056 | 86.2k | if( n1 == 16 ) | 2057 | 13.4k | { | 2058 | 13.4k | goto do_num2; | 2059 | 13.4k | } | 2060 | 86.2k | } | 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 | 72.7k | { | 2070 | 72.7k | const char c = *cs; | 2071 | 72.7k | if(c != '.') | 2072 | 62.5k | { | 2073 | 62.5k | if((c | 32) == 'e') | 2074 | 12.3k | { | 2075 | 12.3k | ++cs; | 2076 | 12.3k | goto do_exp1; | 2077 | 12.3k | } | 2078 | 50.1k | BOOST_IF_CONSTEXPR( negative && !no_parsing ) | 2079 | 50.1k | num.mant = ~num.mant + 1; | 2080 | 50.1k | goto finish_signed; | 2081 | 62.5k | } | 2082 | 72.7k | } | 2083 | | | 2084 | | // floating-point number | 2085 | | | 2086 | 10.2k | ++cs; | 2087 | | | 2088 | 10.2k | int n2 = detail::count_digits( cs.begin() ); | 2089 | 10.2k | BOOST_ASSERT(n2 >= 0 && n2 <= 16); | 2090 | | | 2091 | 10.2k | if( n2 == 0 ) | 2092 | 3 | { | 2093 | | // digit required | 2094 | 3 | BOOST_STATIC_CONSTEXPR source_location loc | 2095 | 3 | = BOOST_CURRENT_LOCATION; | 2096 | 3 | return fail(cs.begin(), error::syntax, &loc); | 2097 | 3 | } | 2098 | | | 2099 | | // floating-point mantissa overflow | 2100 | 10.2k | if( n1 + n2 >= 19 ) | 2101 | 1.88k | { | 2102 | 1.88k | goto do_num7; | 2103 | 1.88k | } | 2104 | | | 2105 | 8.33k | BOOST_IF_CONSTEXPR( !no_parsing ) | 2106 | 8.33k | num.mant = detail::parse_unsigned( num.mant, cs.begin(), n2 ); | 2107 | | | 2108 | 8.33k | BOOST_ASSERT(num.bias == 0); | 2109 | | | 2110 | 8.33k | num.bias -= n2; | 2111 | | | 2112 | 8.33k | cs += n2; | 2113 | | | 2114 | 8.33k | char ch = *cs; | 2115 | | | 2116 | 8.33k | if( (ch | 32) == 'e' ) | 2117 | 1.11k | { | 2118 | 1.11k | ++cs; | 2119 | 1.11k | goto do_exp1; | 2120 | 1.11k | } | 2121 | 7.21k | else if( ch >= '0' && ch <= '9' ) | 2122 | 2.07k | { | 2123 | 2.07k | goto do_num8; | 2124 | 2.07k | } | 2125 | | | 2126 | 5.14k | goto finish_dub; | 2127 | 8.33k | } | 2128 | 90.9k | } | 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 | 4.72k | do_num1: | 2157 | 4.72k | if(zero_first || nonzero_first || | 2158 | 0 | BOOST_JSON_LIKELY(cs)) | 2159 | 4.72k | { | 2160 | 4.72k | char const c = *cs; | 2161 | 4.72k | if(zero_first) | 2162 | 0 | { | 2163 | 0 | ++cs; | 2164 | 0 | num.mant = 0; | 2165 | 0 | goto do_num6; | 2166 | 0 | } | 2167 | 4.72k | else if(nonzero_first || BOOST_JSON_LIKELY( | 2168 | 4.72k | c >= '1' && c <= '9')) | 2169 | 4.72k | { | 2170 | 4.72k | ++cs; | 2171 | 4.72k | num.mant = c - '0'; | 2172 | 4.72k | } | 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 | 4.72k | } | 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 | 18.2k | do_num2: | 2214 | 18.2k | 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 | 18.2k | else | 2250 | 18.2k | { | 2251 | 18.2k | for(;;) | 2252 | 84.8k | { | 2253 | 84.8k | if(BOOST_JSON_UNLIKELY(! cs)) | 2254 | 319 | { | 2255 | 319 | if(BOOST_JSON_UNLIKELY(more_)) | 2256 | 319 | { | 2257 | 319 | if(BOOST_JSON_UNLIKELY( | 2258 | 319 | ! h_.on_number_part( | 2259 | 319 | {begin, cs.used(begin)}, ec_))) | 2260 | 0 | return fail(cs.begin()); | 2261 | | | 2262 | 319 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2263 | 319 | num_buf_.append( begin, cs.used(begin) ); | 2264 | 319 | return suspend(cs.begin(), state::num2, num); | 2265 | 319 | } | 2266 | 0 | goto finish_int; | 2267 | 319 | } | 2268 | 84.5k | char const c = *cs; | 2269 | 84.5k | if(BOOST_JSON_LIKELY( | 2270 | 84.5k | c >= '0' && c <= '9')) | 2271 | 76.5k | { | 2272 | 76.5k | ++cs; | 2273 | | // 18446744073709551615 UINT64_MAX | 2274 | 76.5k | if( num.mant > 1844674407370955161 || ( | 2275 | 67.6k | num.mant == 1844674407370955161 && c > '5')) | 2276 | 9.89k | break; | 2277 | 66.6k | BOOST_IF_CONSTEXPR( !no_parsing ) | 2278 | 66.6k | num.mant = 10 * num.mant + ( c - '0' ); | 2279 | 66.6k | } | 2280 | 7.99k | else | 2281 | 7.99k | { | 2282 | 7.99k | goto do_num6; // [.eE] | 2283 | 7.99k | } | 2284 | 84.5k | } | 2285 | 18.2k | } | 2286 | 9.89k | ++num.bias; | 2287 | | | 2288 | | //---------------------------------- | 2289 | | // | 2290 | | // 1*DIGIT | 2291 | | // non-significant digits left of decimal | 2292 | | // | 2293 | 9.89k | do_num3: | 2294 | 9.89k | for(;;) | 2295 | 6.39M | { | 2296 | 6.39M | if(BOOST_JSON_UNLIKELY(! cs)) | 2297 | 421 | { | 2298 | 421 | if(BOOST_JSON_UNLIKELY(more_)) | 2299 | 421 | { | 2300 | 421 | if(BOOST_JSON_UNLIKELY( | 2301 | 421 | ! h_.on_number_part( | 2302 | 421 | {begin, cs.used(begin)}, ec_))) | 2303 | 0 | return fail(cs.begin()); | 2304 | | | 2305 | 421 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2306 | 421 | num_buf_.append( begin, cs.used(begin) ); | 2307 | 421 | return suspend(cs.begin(), state::num3, num); | 2308 | 421 | } | 2309 | 0 | goto finish_dub; | 2310 | 421 | } | 2311 | 6.39M | char const c = *cs; | 2312 | 6.39M | if(BOOST_JSON_UNLIKELY( | 2313 | 6.39M | c >= '0' && c <= '9')) | 2314 | 6.38M | { | 2315 | 6.38M | 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 | 6.38M | ++cs; | 2322 | 6.38M | ++num.bias; | 2323 | 6.38M | } | 2324 | 9.47k | else if(BOOST_JSON_LIKELY( | 2325 | 9.47k | c == '.')) | 2326 | 2.49k | { | 2327 | 2.49k | ++cs; | 2328 | 2.49k | break; | 2329 | 2.49k | } | 2330 | 6.98k | else if((c | 32) == 'e') | 2331 | 4.19k | { | 2332 | 4.19k | ++cs; | 2333 | 4.19k | goto do_exp1; | 2334 | 4.19k | } | 2335 | 2.78k | else | 2336 | 2.78k | { | 2337 | 2.78k | goto finish_dub; | 2338 | 2.78k | } | 2339 | 6.39M | } | 2340 | | | 2341 | | //---------------------------------- | 2342 | | // | 2343 | | // DIGIT | 2344 | | // first non-significant digit | 2345 | | // to the right of decimal | 2346 | | // | 2347 | 2.49k | do_num4: | 2348 | 2.49k | { | 2349 | 2.49k | 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 | 0 | return fail(cs.begin()); | 2355 | | | 2356 | 3 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2357 | 3 | num_buf_.append( begin, cs.used(begin) ); | 2358 | 3 | return maybe_suspend( | 2359 | 3 | cs.begin(), state::num4, num); | 2360 | 3 | } | 2361 | 2.49k | char const c = *cs; | 2362 | 2.49k | if(BOOST_JSON_LIKELY( | 2363 | | //static_cast<unsigned char>(c - '0') < 10)) | 2364 | 2.49k | c >= '0' && c <= '9')) | 2365 | 2.48k | { | 2366 | 2.48k | ++cs; | 2367 | 2.48k | } | 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 | 2.49k | } | 2376 | | | 2377 | | //---------------------------------- | 2378 | | // | 2379 | | // 1*DIGIT | 2380 | | // non-significant digits | 2381 | | // to the right of decimal | 2382 | | // | 2383 | 8.28k | do_num5: | 2384 | 8.28k | for(;;) | 2385 | 2.81M | { | 2386 | 2.81M | if(BOOST_JSON_UNLIKELY(! cs)) | 2387 | 724 | { | 2388 | 724 | if(BOOST_JSON_UNLIKELY(more_)) | 2389 | 724 | { | 2390 | 724 | if(BOOST_JSON_UNLIKELY( | 2391 | 724 | ! h_.on_number_part( | 2392 | 724 | {begin, cs.used(begin)}, ec_))) | 2393 | 0 | return fail(cs.begin()); | 2394 | | | 2395 | 724 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2396 | 724 | num_buf_.append( begin, cs.used(begin) ); | 2397 | 724 | return suspend(cs.begin(), state::num5, num); | 2398 | 724 | } | 2399 | 0 | goto finish_dub; | 2400 | 724 | } | 2401 | 2.81M | char const c = *cs; | 2402 | 2.81M | if(BOOST_JSON_LIKELY( | 2403 | 2.81M | c >= '0' && c <= '9')) | 2404 | 2.80M | { | 2405 | 2.80M | ++cs; | 2406 | 2.80M | } | 2407 | 7.56k | else if((c | 32) == 'e') | 2408 | 2.98k | { | 2409 | 2.98k | ++cs; | 2410 | 2.98k | goto do_exp1; | 2411 | 2.98k | } | 2412 | 4.57k | else | 2413 | 4.57k | { | 2414 | 4.57k | goto finish_dub; | 2415 | 4.57k | } | 2416 | 2.81M | } | 2417 | | | 2418 | | //---------------------------------- | 2419 | | // | 2420 | | // [.eE] | 2421 | | // | 2422 | 7.99k | do_num6: | 2423 | 7.99k | { | 2424 | 7.99k | 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 | 7.99k | char const c = *cs; | 2440 | 7.99k | if(BOOST_JSON_LIKELY( | 2441 | 7.99k | c == '.')) | 2442 | 2.97k | { | 2443 | 2.97k | ++cs; | 2444 | 2.97k | } | 2445 | 5.02k | else if((c | 32) == 'e') | 2446 | 1.96k | { | 2447 | 1.96k | ++cs; | 2448 | 1.96k | goto do_exp1; | 2449 | 1.96k | } | 2450 | 3.05k | else | 2451 | 3.05k | { | 2452 | 3.05k | goto finish_int; | 2453 | 3.05k | } | 2454 | 7.99k | } | 2455 | | | 2456 | | //---------------------------------- | 2457 | | // | 2458 | | // DIGIT | 2459 | | // first significant digit | 2460 | | // to the right of decimal | 2461 | | // | 2462 | 4.85k | do_num7: | 2463 | 4.85k | { | 2464 | 4.85k | if(BOOST_JSON_UNLIKELY(! cs)) | 2465 | 4 | { | 2466 | 4 | if(BOOST_JSON_UNLIKELY(more_)) | 2467 | 4 | { | 2468 | 4 | if(BOOST_JSON_UNLIKELY( | 2469 | 4 | ! h_.on_number_part( | 2470 | 4 | {begin, cs.used(begin)}, ec_))) | 2471 | 0 | return fail(cs.begin()); | 2472 | | | 2473 | 4 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2474 | 4 | num_buf_.append( begin, cs.used(begin) ); | 2475 | 4 | return suspend(cs.begin(), state::num7, num); | 2476 | 4 | } | 2477 | | // digit required | 2478 | 4 | BOOST_STATIC_CONSTEXPR source_location loc | 2479 | 0 | = BOOST_CURRENT_LOCATION; | 2480 | 0 | return fail(cs.begin(), error::syntax, &loc); | 2481 | 4 | } | 2482 | 4.85k | char const c = *cs; | 2483 | 4.85k | if(BOOST_JSON_UNLIKELY( | 2484 | 4.85k | c < '0' || c > '9')) | 2485 | 9 | { | 2486 | | // digit required | 2487 | 9 | BOOST_STATIC_CONSTEXPR source_location loc | 2488 | 9 | = BOOST_CURRENT_LOCATION; | 2489 | 9 | return fail(cs.begin(), error::syntax, &loc); | 2490 | 9 | } | 2491 | 4.85k | } | 2492 | | | 2493 | | //---------------------------------- | 2494 | | // | 2495 | | // 1*DIGIT | 2496 | | // significant digits | 2497 | | // to the right of decimal | 2498 | | // | 2499 | 6.91k | do_num8: | 2500 | 6.91k | for(;;) | 2501 | 30.3k | { | 2502 | 30.3k | if(BOOST_JSON_UNLIKELY(! cs)) | 2503 | 472 | { | 2504 | 472 | if(BOOST_JSON_UNLIKELY(more_)) | 2505 | 472 | { | 2506 | 472 | if(BOOST_JSON_UNLIKELY( | 2507 | 472 | ! h_.on_number_part( | 2508 | 472 | {begin, cs.used(begin)}, ec_))) | 2509 | 0 | return fail(cs.begin()); | 2510 | | | 2511 | 472 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2512 | 472 | num_buf_.append( begin, cs.used(begin) ); | 2513 | 472 | return suspend(cs.begin(), state::num8, num); | 2514 | 472 | } | 2515 | 0 | goto finish_dub; | 2516 | 472 | } | 2517 | 29.8k | char const c = *cs; | 2518 | 29.8k | if(BOOST_JSON_LIKELY( | 2519 | 29.8k | c >= '0' && c <= '9')) | 2520 | 29.1k | { | 2521 | 29.1k | ++cs; | 2522 | 29.1k | if(!no_parsing && BOOST_JSON_LIKELY( | 2523 | 29.1k | num.mant <= 9007199254740991)) // 2^53-1 | 2524 | 23.3k | { | 2525 | 23.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 | 23.3k | --num.bias; | 2532 | 23.3k | num.mant = 10 * num.mant + ( c - '0' ); | 2533 | 23.3k | } | 2534 | 5.80k | else | 2535 | 5.80k | { | 2536 | 5.80k | goto do_num5; | 2537 | 5.80k | } | 2538 | 29.1k | } | 2539 | 643 | else if((c | 32) == 'e') | 2540 | 312 | { | 2541 | 312 | ++cs; | 2542 | 312 | goto do_exp1; | 2543 | 312 | } | 2544 | 331 | else | 2545 | 331 | { | 2546 | 331 | goto finish_dub; | 2547 | 331 | } | 2548 | 29.8k | } | 2549 | | | 2550 | | //---------------------------------- | 2551 | | // | 2552 | | // *[+-] | 2553 | | // | 2554 | 22.9k | do_exp1: | 2555 | 22.9k | if(BOOST_JSON_UNLIKELY(! cs)) | 2556 | 30 | { | 2557 | 30 | if(BOOST_JSON_UNLIKELY( | 2558 | 30 | ! h_.on_number_part( | 2559 | 30 | {begin, cs.used(begin)}, ec_))) | 2560 | 0 | return fail(cs.begin()); | 2561 | | | 2562 | 30 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2563 | 30 | num_buf_.append( begin, cs.used(begin) ); | 2564 | 30 | return maybe_suspend( | 2565 | 30 | cs.begin(), state::exp1, num); | 2566 | 30 | } | 2567 | 22.9k | if(*cs == '+') | 2568 | 281 | { | 2569 | 281 | ++cs; | 2570 | 281 | } | 2571 | 22.6k | else if(*cs == '-') | 2572 | 6.35k | { | 2573 | 6.35k | ++cs; | 2574 | 6.35k | num.frac = true; | 2575 | 6.35k | } | 2576 | | | 2577 | | //---------------------------------- | 2578 | | // | 2579 | | // DIGIT | 2580 | | // first digit of the exponent | 2581 | | // | 2582 | 22.9k | do_exp2: | 2583 | 22.9k | { | 2584 | 22.9k | if(BOOST_JSON_UNLIKELY(! cs)) | 2585 | 9 | { | 2586 | 9 | if(BOOST_JSON_UNLIKELY(more_)) | 2587 | 9 | { | 2588 | 9 | if(BOOST_JSON_UNLIKELY( | 2589 | 9 | ! h_.on_number_part( | 2590 | 9 | {begin, cs.used(begin)}, ec_))) | 2591 | 0 | return fail(cs.begin()); | 2592 | | | 2593 | 9 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2594 | 9 | num_buf_.append( begin, cs.used(begin) ); | 2595 | 9 | return suspend(cs.begin(), state::exp2, num); | 2596 | 9 | } | 2597 | | // digit required | 2598 | 9 | BOOST_STATIC_CONSTEXPR source_location loc | 2599 | 0 | = BOOST_CURRENT_LOCATION; | 2600 | 0 | return fail(cs.begin(), error::syntax, &loc); | 2601 | 9 | } | 2602 | 22.9k | char const c = *cs; | 2603 | 22.9k | if(BOOST_JSON_UNLIKELY( | 2604 | 22.9k | c < '0' || c > '9')) | 2605 | 27 | { | 2606 | | // digit required | 2607 | 27 | BOOST_STATIC_CONSTEXPR source_location loc | 2608 | 27 | = BOOST_CURRENT_LOCATION; | 2609 | 27 | return fail(cs.begin(), error::syntax, &loc); | 2610 | 27 | } | 2611 | 22.8k | ++cs; | 2612 | 22.8k | num.exp = c - '0'; | 2613 | 22.8k | } | 2614 | | | 2615 | | //---------------------------------- | 2616 | | // | 2617 | | // 1*DIGIT | 2618 | | // subsequent digits in the exponent | 2619 | | // | 2620 | 22.8k | do_exp3: | 2621 | 22.8k | for(;;) | 2622 | 74.0k | { | 2623 | 74.0k | if(BOOST_JSON_UNLIKELY(! cs)) | 2624 | 1.12k | { | 2625 | 1.12k | if(BOOST_JSON_UNLIKELY(more_)) | 2626 | 1.12k | { | 2627 | 1.12k | if(BOOST_JSON_UNLIKELY( | 2628 | 1.12k | ! h_.on_number_part( | 2629 | 1.12k | {begin, cs.used(begin)}, ec_))) | 2630 | 0 | return fail(cs.begin()); | 2631 | | | 2632 | 1.12k | BOOST_IF_CONSTEXPR( precise_parsing ) | 2633 | 1.12k | num_buf_.append( begin, cs.used(begin) ); | 2634 | 1.12k | return suspend(cs.begin(), state::exp3, num); | 2635 | 1.12k | } | 2636 | 1.12k | } | 2637 | 72.9k | else | 2638 | 72.9k | { | 2639 | 72.9k | char const c = *cs; | 2640 | 72.9k | if(BOOST_JSON_LIKELY( c >= '0' && c <= '9' )) | 2641 | 51.1k | { | 2642 | 51.1k | if(BOOST_JSON_UNLIKELY( | 2643 | | // 2147483647 INT_MAX | 2644 | 51.1k | num.exp > 214748364 || | 2645 | 51.1k | (num.exp == 214748364 && c > '7') | 2646 | 51.1k | )) | 2647 | 9.01k | num.exp = INT_MAX; | 2648 | 42.1k | else BOOST_IF_CONSTEXPR( !no_parsing ) | 2649 | 42.1k | num.exp = 10 * num.exp + ( c - '0' ); | 2650 | | | 2651 | 51.1k | ++cs; | 2652 | 51.1k | continue; | 2653 | 51.1k | } | 2654 | 72.9k | } | 2655 | 21.7k | BOOST_ASSERT(num.exp >= 0); | 2656 | 21.7k | if ( num.frac ) | 2657 | 5.84k | { | 2658 | 5.84k | if(BOOST_JSON_UNLIKELY( num.bias < (INT_MIN + num.exp) )) | 2659 | 391 | { | 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 | 391 | if(BOOST_JSON_UNLIKELY( | 2664 | 391 | (num.exp == INT_MAX) && | 2665 | 391 | (num.bias < 0) && | 2666 | 391 | (num.exp + num.bias < 308) && | 2667 | 391 | 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 | 391 | num.bias = 0; | 2675 | 391 | num.exp = INT_MAX; | 2676 | 391 | } | 2677 | 5.84k | } | 2678 | 15.9k | else if (BOOST_JSON_UNLIKELY( num.bias > (INT_MAX - num.exp) )) | 2679 | 424 | { | 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 | 424 | if(BOOST_JSON_UNLIKELY( | 2684 | 424 | (num.exp == INT_MAX) && | 2685 | 424 | (num.bias > 0) && | 2686 | 424 | (num.exp - num.bias < 308) && | 2687 | 424 | 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 | 424 | num.bias = 0; | 2695 | 424 | num.exp = INT_MAX; | 2696 | 424 | } | 2697 | 21.7k | goto finish_dub; | 2698 | 21.7k | } | 2699 | | | 2700 | 3.05k | finish_int: | 2701 | 3.05k | 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 | 3.05k | if(num.mant <= INT64_MAX) | 2710 | 2.33k | { | 2711 | 52.4k | finish_signed: | 2712 | 52.4k | if(BOOST_JSON_UNLIKELY( | 2713 | 52.4k | ! h_.on_int64(static_cast< | 2714 | 52.4k | int64_t>(num.mant), {begin, cs.used(begin)}, ec_))) | 2715 | 0 | return fail(cs.begin()); | 2716 | 52.4k | return cs.begin(); | 2717 | 52.4k | } | 2718 | 718 | if(BOOST_JSON_UNLIKELY( | 2719 | 718 | ! h_.on_uint64(num.mant, {begin, cs.used(begin)}, ec_))) | 2720 | 0 | return fail(cs.begin()); | 2721 | 718 | return cs.begin(); | 2722 | 34.6k | finish_dub: | 2723 | 34.6k | double d; | 2724 | 34.6k | std::size_t const size = cs.used(begin); | 2725 | 34.6k | BOOST_ASSERT( !num_buf_.size() || precise_parsing ); | 2726 | | BOOST_IF_CONSTEXPR( precise_parsing ) | 2727 | 34.6k | { | 2728 | 34.6k | char const* data = begin; | 2729 | 34.6k | 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 | 34.6k | 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 | 34.6k | auto const err = detail::charconv::from_chars( | 2739 | 34.6k | data, data + full_size, d ); | 2740 | 34.6k | BOOST_ASSERT( err.ec != std::errc::invalid_argument ); | 2741 | 34.6k | BOOST_ASSERT( err.ptr == data + full_size ); | 2742 | 34.6k | (void)err; | 2743 | | } | 2744 | | else BOOST_IF_CONSTEXPR( no_parsing ) | 2745 | | d = 0; | 2746 | | else | 2747 | | d = detail::dec_to_float( | 2748 | | num.mant, | 2749 | | num.bias + (num.frac ? | 2750 | | -num.exp : num.exp), | 2751 | | num.neg); | 2752 | 34.6k | if(BOOST_JSON_UNLIKELY( | 2753 | 34.6k | ! h_.on_double(d, {begin, size}, ec_))) | 2754 | 0 | return fail(cs.begin()); | 2755 | 34.6k | return cs.begin(); | 2756 | 34.6k | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::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>) Line | Count | Source | 1986 | 533k | { | 1987 | 533k | constexpr bool precise_parsing = mode == number_precision::precise; | 1988 | 533k | 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 | 533k | bool const negative = first == '-'; | 1995 | 533k | bool const zero_first = first == '0'; | 1996 | 533k | bool const nonzero_first = first == '+'; | 1997 | 533k | detail::const_stream_wrapper cs(p, end_); | 1998 | 533k | number num; | 1999 | 533k | const char* begin = cs.begin(); | 2000 | 533k | if(stack_empty || st_.empty()) | 2001 | 533k | { | 2002 | 533k | num.bias = 0; | 2003 | 533k | num.exp = 0; | 2004 | 533k | num.frac = false; | 2005 | 533k | num_buf_.clear(); | 2006 | | | 2007 | | //---------------------------------- | 2008 | | // | 2009 | | // '-' | 2010 | | // leading minus sign | 2011 | | // | 2012 | 533k | BOOST_ASSERT(cs); | 2013 | 533k | if(negative) | 2014 | 0 | ++cs; | 2015 | | | 2016 | 533k | num.neg = negative; | 2017 | 533k | num.frac = false; | 2018 | 533k | num.exp = 0; | 2019 | 533k | num.bias = 0; | 2020 | | | 2021 | | // fast path | 2022 | 533k | if( cs.remain() >= 16 + 1 + 16 ) // digits . digits | 2023 | 532k | { | 2024 | 532k | int n1; | 2025 | | | 2026 | 532k | if( nonzero_first || | 2027 | 0 | (negative && *cs != '0') ) | 2028 | 532k | { | 2029 | 532k | n1 = detail::count_digits( cs.begin() ); | 2030 | 532k | BOOST_ASSERT(n1 >= 0 && n1 <= 16); | 2031 | | | 2032 | 532k | 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 | 532k | 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 | 532k | BOOST_IF_CONSTEXPR( !no_parsing ) | 2048 | 532k | num.mant = detail::parse_unsigned( 0, cs.begin(), n1 ); | 2049 | 532k | else | 2050 | 532k | num.mant = 0; | 2051 | | | 2052 | 532k | cs += n1; | 2053 | | | 2054 | | // integer or floating-point with | 2055 | | // >= 16 leading digits | 2056 | 532k | if( n1 == 16 ) | 2057 | 1.03k | { | 2058 | 1.03k | goto do_num2; | 2059 | 1.03k | } | 2060 | 532k | } | 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 | 531k | { | 2070 | 531k | const char c = *cs; | 2071 | 531k | if(c != '.') | 2072 | 529k | { | 2073 | 529k | if((c | 32) == 'e') | 2074 | 90.4k | { | 2075 | 90.4k | ++cs; | 2076 | 90.4k | goto do_exp1; | 2077 | 90.4k | } | 2078 | 439k | BOOST_IF_CONSTEXPR( negative && !no_parsing ) | 2079 | 439k | num.mant = ~num.mant + 1; | 2080 | 439k | goto finish_signed; | 2081 | 529k | } | 2082 | 531k | } | 2083 | | | 2084 | | // floating-point number | 2085 | | | 2086 | 2.10k | ++cs; | 2087 | | | 2088 | 2.10k | int n2 = detail::count_digits( cs.begin() ); | 2089 | 2.10k | BOOST_ASSERT(n2 >= 0 && n2 <= 16); | 2090 | | | 2091 | 2.10k | if( n2 == 0 ) | 2092 | 2 | { | 2093 | | // digit required | 2094 | 2 | BOOST_STATIC_CONSTEXPR source_location loc | 2095 | 2 | = BOOST_CURRENT_LOCATION; | 2096 | 2 | return fail(cs.begin(), error::syntax, &loc); | 2097 | 2 | } | 2098 | | | 2099 | | // floating-point mantissa overflow | 2100 | 2.10k | if( n1 + n2 >= 19 ) | 2101 | 207 | { | 2102 | 207 | goto do_num7; | 2103 | 207 | } | 2104 | | | 2105 | 1.89k | BOOST_IF_CONSTEXPR( !no_parsing ) | 2106 | 1.89k | num.mant = detail::parse_unsigned( num.mant, cs.begin(), n2 ); | 2107 | | | 2108 | 1.89k | BOOST_ASSERT(num.bias == 0); | 2109 | | | 2110 | 1.89k | num.bias -= n2; | 2111 | | | 2112 | 1.89k | cs += n2; | 2113 | | | 2114 | 1.89k | char ch = *cs; | 2115 | | | 2116 | 1.89k | if( (ch | 32) == 'e' ) | 2117 | 371 | { | 2118 | 371 | ++cs; | 2119 | 371 | goto do_exp1; | 2120 | 371 | } | 2121 | 1.52k | else if( ch >= '0' && ch <= '9' ) | 2122 | 387 | { | 2123 | 387 | goto do_num8; | 2124 | 387 | } | 2125 | | | 2126 | 1.13k | goto finish_dub; | 2127 | 1.89k | } | 2128 | 533k | } | 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.32k | do_num1: | 2157 | 1.32k | if(zero_first || nonzero_first || | 2158 | 0 | BOOST_JSON_LIKELY(cs)) | 2159 | 1.32k | { | 2160 | 1.32k | char const c = *cs; | 2161 | 1.32k | if(zero_first) | 2162 | 0 | { | 2163 | 0 | ++cs; | 2164 | 0 | num.mant = 0; | 2165 | 0 | goto do_num6; | 2166 | 0 | } | 2167 | 1.32k | else if(nonzero_first || BOOST_JSON_LIKELY( | 2168 | 1.32k | c >= '1' && c <= '9')) | 2169 | 1.32k | { | 2170 | 1.32k | ++cs; | 2171 | 1.32k | num.mant = c - '0'; | 2172 | 1.32k | } | 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.32k | } | 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 | 2.35k | do_num2: | 2214 | 2.35k | 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 | 2.35k | else | 2250 | 2.35k | { | 2251 | 2.35k | for(;;) | 2252 | 118k | { | 2253 | 118k | if(BOOST_JSON_UNLIKELY(! cs)) | 2254 | 55 | { | 2255 | 55 | if(BOOST_JSON_UNLIKELY(more_)) | 2256 | 55 | { | 2257 | 55 | if(BOOST_JSON_UNLIKELY( | 2258 | 55 | ! h_.on_number_part( | 2259 | 55 | {begin, cs.used(begin)}, ec_))) | 2260 | 0 | return fail(cs.begin()); | 2261 | | | 2262 | 55 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2263 | 55 | num_buf_.append( begin, cs.used(begin) ); | 2264 | 55 | return suspend(cs.begin(), state::num2, num); | 2265 | 55 | } | 2266 | 0 | goto finish_int; | 2267 | 55 | } | 2268 | 117k | char const c = *cs; | 2269 | 117k | if(BOOST_JSON_LIKELY( | 2270 | 117k | c >= '0' && c <= '9')) | 2271 | 115k | { | 2272 | 115k | ++cs; | 2273 | | // 18446744073709551615 UINT64_MAX | 2274 | 115k | if( num.mant > 1844674407370955161 || ( | 2275 | 115k | num.mant == 1844674407370955161 && c > '5')) | 2276 | 0 | break; | 2277 | 115k | BOOST_IF_CONSTEXPR( !no_parsing ) | 2278 | 115k | num.mant = 10 * num.mant + ( c - '0' ); | 2279 | 115k | } | 2280 | 2.29k | else | 2281 | 2.29k | { | 2282 | 2.29k | goto do_num6; // [.eE] | 2283 | 2.29k | } | 2284 | 117k | } | 2285 | 2.35k | } | 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 | 966 | do_num5: | 2384 | 966 | for(;;) | 2385 | 3.57k | { | 2386 | 3.57k | if(BOOST_JSON_UNLIKELY(! cs)) | 2387 | 22 | { | 2388 | 22 | if(BOOST_JSON_UNLIKELY(more_)) | 2389 | 22 | { | 2390 | 22 | if(BOOST_JSON_UNLIKELY( | 2391 | 22 | ! h_.on_number_part( | 2392 | 22 | {begin, cs.used(begin)}, ec_))) | 2393 | 0 | return fail(cs.begin()); | 2394 | | | 2395 | 22 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2396 | 22 | num_buf_.append( begin, cs.used(begin) ); | 2397 | 22 | return suspend(cs.begin(), state::num5, num); | 2398 | 22 | } | 2399 | 0 | goto finish_dub; | 2400 | 22 | } | 2401 | 3.55k | char const c = *cs; | 2402 | 3.55k | if(BOOST_JSON_LIKELY( | 2403 | 3.55k | c >= '0' && c <= '9')) | 2404 | 2.61k | { | 2405 | 2.61k | ++cs; | 2406 | 2.61k | } | 2407 | 944 | else if((c | 32) == 'e') | 2408 | 204 | { | 2409 | 204 | ++cs; | 2410 | 204 | goto do_exp1; | 2411 | 204 | } | 2412 | 740 | else | 2413 | 740 | { | 2414 | 740 | goto finish_dub; | 2415 | 740 | } | 2416 | 3.55k | } | 2417 | | | 2418 | | //---------------------------------- | 2419 | | // | 2420 | | // [.eE] | 2421 | | // | 2422 | 2.29k | do_num6: | 2423 | 2.29k | { | 2424 | 2.29k | 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 | 2.29k | char const c = *cs; | 2440 | 2.29k | if(BOOST_JSON_LIKELY( | 2441 | 2.29k | c == '.')) | 2442 | 388 | { | 2443 | 388 | ++cs; | 2444 | 388 | } | 2445 | 1.91k | else if((c | 32) == 'e') | 2446 | 408 | { | 2447 | 408 | ++cs; | 2448 | 408 | goto do_exp1; | 2449 | 408 | } | 2450 | 1.50k | else | 2451 | 1.50k | { | 2452 | 1.50k | goto finish_int; | 2453 | 1.50k | } | 2454 | 2.29k | } | 2455 | | | 2456 | | //---------------------------------- | 2457 | | // | 2458 | | // DIGIT | 2459 | | // first significant digit | 2460 | | // to the right of decimal | 2461 | | // | 2462 | 595 | do_num7: | 2463 | 595 | { | 2464 | 595 | if(BOOST_JSON_UNLIKELY(! cs)) | 2465 | 5 | { | 2466 | 5 | if(BOOST_JSON_UNLIKELY(more_)) | 2467 | 5 | { | 2468 | 5 | if(BOOST_JSON_UNLIKELY( | 2469 | 5 | ! h_.on_number_part( | 2470 | 5 | {begin, cs.used(begin)}, ec_))) | 2471 | 0 | return fail(cs.begin()); | 2472 | | | 2473 | 5 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2474 | 5 | num_buf_.append( begin, cs.used(begin) ); | 2475 | 5 | return suspend(cs.begin(), state::num7, num); | 2476 | 5 | } | 2477 | | // digit required | 2478 | 5 | BOOST_STATIC_CONSTEXPR source_location loc | 2479 | 0 | = BOOST_CURRENT_LOCATION; | 2480 | 0 | return fail(cs.begin(), error::syntax, &loc); | 2481 | 5 | } | 2482 | 590 | char const c = *cs; | 2483 | 590 | if(BOOST_JSON_UNLIKELY( | 2484 | 590 | c < '0' || c > '9')) | 2485 | 11 | { | 2486 | | // digit required | 2487 | 11 | BOOST_STATIC_CONSTEXPR source_location loc | 2488 | 11 | = BOOST_CURRENT_LOCATION; | 2489 | 11 | return fail(cs.begin(), error::syntax, &loc); | 2490 | 11 | } | 2491 | 590 | } | 2492 | | | 2493 | | //---------------------------------- | 2494 | | // | 2495 | | // 1*DIGIT | 2496 | | // significant digits | 2497 | | // to the right of decimal | 2498 | | // | 2499 | 966 | do_num8: | 2500 | 966 | for(;;) | 2501 | 966 | { | 2502 | 966 | if(BOOST_JSON_UNLIKELY(! cs)) | 2503 | 0 | { | 2504 | 0 | 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 | 0 | goto finish_dub; | 2516 | 0 | } | 2517 | 966 | char const c = *cs; | 2518 | 966 | if(BOOST_JSON_LIKELY( | 2519 | 966 | c >= '0' && c <= '9')) | 2520 | 966 | { | 2521 | 966 | ++cs; | 2522 | 966 | if(!no_parsing && BOOST_JSON_LIKELY( | 2523 | 966 | num.mant <= 9007199254740991)) // 2^53-1 | 2524 | 0 | { | 2525 | 0 | 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 | 0 | --num.bias; | 2532 | 0 | num.mant = 10 * num.mant + ( c - '0' ); | 2533 | 0 | } | 2534 | 966 | else | 2535 | 966 | { | 2536 | 966 | goto do_num5; | 2537 | 966 | } | 2538 | 966 | } | 2539 | 0 | else if((c | 32) == 'e') | 2540 | 0 | { | 2541 | 0 | ++cs; | 2542 | 0 | goto do_exp1; | 2543 | 0 | } | 2544 | 0 | else | 2545 | 0 | { | 2546 | 0 | goto finish_dub; | 2547 | 0 | } | 2548 | 966 | } | 2549 | | | 2550 | | //---------------------------------- | 2551 | | // | 2552 | | // *[+-] | 2553 | | // | 2554 | 91.3k | do_exp1: | 2555 | 91.3k | if(BOOST_JSON_UNLIKELY(! cs)) | 2556 | 14 | { | 2557 | 14 | if(BOOST_JSON_UNLIKELY( | 2558 | 14 | ! h_.on_number_part( | 2559 | 14 | {begin, cs.used(begin)}, ec_))) | 2560 | 0 | return fail(cs.begin()); | 2561 | | | 2562 | 14 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2563 | 14 | num_buf_.append( begin, cs.used(begin) ); | 2564 | 14 | return maybe_suspend( | 2565 | 14 | cs.begin(), state::exp1, num); | 2566 | 14 | } | 2567 | 91.3k | if(*cs == '+') | 2568 | 198 | { | 2569 | 198 | ++cs; | 2570 | 198 | } | 2571 | 91.1k | else if(*cs == '-') | 2572 | 1.10k | { | 2573 | 1.10k | ++cs; | 2574 | 1.10k | num.frac = true; | 2575 | 1.10k | } | 2576 | | | 2577 | | //---------------------------------- | 2578 | | // | 2579 | | // DIGIT | 2580 | | // first digit of the exponent | 2581 | | // | 2582 | 91.3k | do_exp2: | 2583 | 91.3k | { | 2584 | 91.3k | if(BOOST_JSON_UNLIKELY(! cs)) | 2585 | 11 | { | 2586 | 11 | if(BOOST_JSON_UNLIKELY(more_)) | 2587 | 11 | { | 2588 | 11 | if(BOOST_JSON_UNLIKELY( | 2589 | 11 | ! h_.on_number_part( | 2590 | 11 | {begin, cs.used(begin)}, ec_))) | 2591 | 0 | return fail(cs.begin()); | 2592 | | | 2593 | 11 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2594 | 11 | num_buf_.append( begin, cs.used(begin) ); | 2595 | 11 | return suspend(cs.begin(), state::exp2, num); | 2596 | 11 | } | 2597 | | // digit required | 2598 | 11 | BOOST_STATIC_CONSTEXPR source_location loc | 2599 | 0 | = BOOST_CURRENT_LOCATION; | 2600 | 0 | return fail(cs.begin(), error::syntax, &loc); | 2601 | 11 | } | 2602 | 91.3k | char const c = *cs; | 2603 | 91.3k | if(BOOST_JSON_UNLIKELY( | 2604 | 91.3k | c < '0' || c > '9')) | 2605 | 19 | { | 2606 | | // digit required | 2607 | 19 | BOOST_STATIC_CONSTEXPR source_location loc | 2608 | 19 | = BOOST_CURRENT_LOCATION; | 2609 | 19 | return fail(cs.begin(), error::syntax, &loc); | 2610 | 19 | } | 2611 | 91.3k | ++cs; | 2612 | 91.3k | num.exp = c - '0'; | 2613 | 91.3k | } | 2614 | | | 2615 | | //---------------------------------- | 2616 | | // | 2617 | | // 1*DIGIT | 2618 | | // subsequent digits in the exponent | 2619 | | // | 2620 | 91.3k | do_exp3: | 2621 | 91.3k | for(;;) | 2622 | 182k | { | 2623 | 182k | if(BOOST_JSON_UNLIKELY(! cs)) | 2624 | 27 | { | 2625 | 27 | if(BOOST_JSON_UNLIKELY(more_)) | 2626 | 27 | { | 2627 | 27 | if(BOOST_JSON_UNLIKELY( | 2628 | 27 | ! h_.on_number_part( | 2629 | 27 | {begin, cs.used(begin)}, ec_))) | 2630 | 0 | return fail(cs.begin()); | 2631 | | | 2632 | 27 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2633 | 27 | num_buf_.append( begin, cs.used(begin) ); | 2634 | 27 | return suspend(cs.begin(), state::exp3, num); | 2635 | 27 | } | 2636 | 27 | } | 2637 | 182k | else | 2638 | 182k | { | 2639 | 182k | char const c = *cs; | 2640 | 182k | if(BOOST_JSON_LIKELY( c >= '0' && c <= '9' )) | 2641 | 90.9k | { | 2642 | 90.9k | if(BOOST_JSON_UNLIKELY( | 2643 | | // 2147483647 INT_MAX | 2644 | 90.9k | num.exp > 214748364 || | 2645 | 90.9k | (num.exp == 214748364 && c > '7') | 2646 | 90.9k | )) | 2647 | 0 | num.exp = INT_MAX; | 2648 | 90.9k | else BOOST_IF_CONSTEXPR( !no_parsing ) | 2649 | 90.9k | num.exp = 10 * num.exp + ( c - '0' ); | 2650 | | | 2651 | 90.9k | ++cs; | 2652 | 90.9k | continue; | 2653 | 90.9k | } | 2654 | 182k | } | 2655 | 91.3k | BOOST_ASSERT(num.exp >= 0); | 2656 | 91.3k | if ( num.frac ) | 2657 | 1.09k | { | 2658 | 1.09k | if(BOOST_JSON_UNLIKELY( num.bias < (INT_MIN + num.exp) )) | 2659 | 0 | { | 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 | 0 | if(BOOST_JSON_UNLIKELY( | 2664 | 0 | (num.exp == INT_MAX) && | 2665 | 0 | (num.bias < 0) && | 2666 | 0 | (num.exp + num.bias < 308) && | 2667 | 0 | 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 | 0 | num.bias = 0; | 2675 | 0 | num.exp = INT_MAX; | 2676 | 0 | } | 2677 | 1.09k | } | 2678 | 90.2k | 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 | 91.3k | goto finish_dub; | 2698 | 91.3k | } | 2699 | | | 2700 | 1.50k | finish_int: | 2701 | 1.50k | 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 | 1.50k | if(num.mant <= INT64_MAX) | 2710 | 1.50k | { | 2711 | 440k | finish_signed: | 2712 | 440k | if(BOOST_JSON_UNLIKELY( | 2713 | 440k | ! h_.on_int64(static_cast< | 2714 | 440k | int64_t>(num.mant), {begin, cs.used(begin)}, ec_))) | 2715 | 0 | return fail(cs.begin()); | 2716 | 440k | return cs.begin(); | 2717 | 440k | } | 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 | 93.1k | finish_dub: | 2723 | 93.1k | double d; | 2724 | 93.1k | std::size_t const size = cs.used(begin); | 2725 | 93.1k | BOOST_ASSERT( !num_buf_.size() || precise_parsing ); | 2726 | | BOOST_IF_CONSTEXPR( precise_parsing ) | 2727 | | { | 2728 | | char const* data = begin; | 2729 | | 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 | 93.1k | else BOOST_IF_CONSTEXPR( no_parsing ) | 2745 | 93.1k | d = 0; | 2746 | | else | 2747 | | d = detail::dec_to_float( | 2748 | | num.mant, | 2749 | | num.bias + (num.frac ? | 2750 | | -num.exp : num.exp), | 2751 | | num.neg); | 2752 | 93.1k | if(BOOST_JSON_UNLIKELY( | 2753 | 93.1k | ! h_.on_double(d, {begin, size}, ec_))) | 2754 | 0 | return fail(cs.begin()); | 2755 | 93.1k | return cs.begin(); | 2756 | 93.1k | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::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>) Line | Count | Source | 1986 | 2.16k | { | 1987 | 2.16k | constexpr bool precise_parsing = mode == number_precision::precise; | 1988 | 2.16k | 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 | 2.16k | bool const negative = first == '-'; | 1995 | 2.16k | bool const zero_first = first == '0'; | 1996 | 2.16k | bool const nonzero_first = first == '+'; | 1997 | 2.16k | detail::const_stream_wrapper cs(p, end_); | 1998 | 2.16k | number num; | 1999 | 2.16k | const char* begin = cs.begin(); | 2000 | 2.16k | if(stack_empty || st_.empty()) | 2001 | 0 | { | 2002 | 0 | num.bias = 0; | 2003 | 0 | num.exp = 0; | 2004 | 0 | num.frac = false; | 2005 | 0 | num_buf_.clear(); | 2006 | | | 2007 | | //---------------------------------- | 2008 | | // | 2009 | | // '-' | 2010 | | // leading minus sign | 2011 | | // | 2012 | 0 | BOOST_ASSERT(cs); | 2013 | 0 | if(negative) | 2014 | 0 | ++cs; | 2015 | |
| 2016 | 0 | num.neg = negative; | 2017 | 0 | num.frac = false; | 2018 | 0 | num.exp = 0; | 2019 | 0 | num.bias = 0; | 2020 | | | 2021 | | // fast path | 2022 | 0 | if( cs.remain() >= 16 + 1 + 16 ) // digits . digits | 2023 | 0 | { | 2024 | 0 | int n1; | 2025 | |
| 2026 | 0 | if( nonzero_first || | 2027 | 0 | (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 | 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 | 0 | { | 2070 | 0 | const char c = *cs; | 2071 | 0 | if(c != '.') | 2072 | 0 | { | 2073 | 0 | if((c | 32) == 'e') | 2074 | 0 | { | 2075 | 0 | ++cs; | 2076 | 0 | goto do_exp1; | 2077 | 0 | } | 2078 | 0 | BOOST_IF_CONSTEXPR( negative && !no_parsing ) | 2079 | 0 | num.mant = ~num.mant + 1; | 2080 | 0 | goto finish_signed; | 2081 | 0 | } | 2082 | 0 | } | 2083 | | | 2084 | | // floating-point number | 2085 | | | 2086 | 0 | ++cs; | 2087 | |
| 2088 | 0 | int n2 = detail::count_digits( cs.begin() ); | 2089 | 0 | BOOST_ASSERT(n2 >= 0 && n2 <= 16); | 2090 | |
| 2091 | 0 | if( n2 == 0 ) | 2092 | 0 | { | 2093 | | // digit required | 2094 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 2095 | 0 | = BOOST_CURRENT_LOCATION; | 2096 | 0 | return fail(cs.begin(), error::syntax, &loc); | 2097 | 0 | } | 2098 | | | 2099 | | // floating-point mantissa overflow | 2100 | 0 | if( n1 + n2 >= 19 ) | 2101 | 0 | { | 2102 | 0 | goto do_num7; | 2103 | 0 | } | 2104 | | | 2105 | 0 | BOOST_IF_CONSTEXPR( !no_parsing ) | 2106 | 0 | num.mant = detail::parse_unsigned( num.mant, cs.begin(), n2 ); | 2107 | |
| 2108 | 0 | BOOST_ASSERT(num.bias == 0); | 2109 | |
| 2110 | 0 | num.bias -= n2; | 2111 | |
| 2112 | 0 | cs += n2; | 2113 | |
| 2114 | 0 | char ch = *cs; | 2115 | |
| 2116 | 0 | if( (ch | 32) == 'e' ) | 2117 | 0 | { | 2118 | 0 | ++cs; | 2119 | 0 | goto do_exp1; | 2120 | 0 | } | 2121 | 0 | else if( ch >= '0' && ch <= '9' ) | 2122 | 0 | { | 2123 | 0 | goto do_num8; | 2124 | 0 | } | 2125 | | | 2126 | 0 | goto finish_dub; | 2127 | 0 | } | 2128 | 0 | } | 2129 | 2.16k | else | 2130 | 2.16k | { | 2131 | 2.16k | num = num_; | 2132 | 2.16k | state st; | 2133 | 2.16k | st_.pop(st); | 2134 | 2.16k | switch(st) | 2135 | 2.16k | { | 2136 | 0 | default: BOOST_JSON_UNREACHABLE(); | 2137 | 17 | case state::num1: goto do_num1; | 2138 | 515 | case state::num2: goto do_num2; | 2139 | 61 | case state::num3: goto do_num3; | 2140 | 3 | case state::num4: goto do_num4; | 2141 | 89 | case state::num5: goto do_num5; | 2142 | 28 | case state::num6: goto do_num6; | 2143 | 13 | case state::num7: goto do_num7; | 2144 | 678 | case state::num8: goto do_num8; | 2145 | 75 | case state::exp1: goto do_exp1; | 2146 | 31 | case state::exp2: goto do_exp2; | 2147 | 652 | case state::exp3: goto do_exp3; | 2148 | 2.16k | } | 2149 | 2.16k | } | 2150 | | | 2151 | | //---------------------------------- | 2152 | | // | 2153 | | // DIGIT | 2154 | | // first digit | 2155 | | // | 2156 | 17 | do_num1: | 2157 | 17 | if(zero_first || nonzero_first || | 2158 | 17 | BOOST_JSON_LIKELY(cs)) | 2159 | 0 | { | 2160 | 0 | char const c = *cs; | 2161 | 0 | if(zero_first) | 2162 | 0 | { | 2163 | 0 | ++cs; | 2164 | 0 | num.mant = 0; | 2165 | 0 | goto do_num6; | 2166 | 0 | } | 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 | 0 | } | 2195 | 17 | else | 2196 | 17 | { | 2197 | 17 | if(BOOST_JSON_UNLIKELY( | 2198 | 17 | ! h_.on_number_part( | 2199 | 17 | {begin, cs.used(begin)}, ec_))) | 2200 | 0 | return fail(cs.begin()); | 2201 | | | 2202 | 17 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2203 | 17 | num_buf_.append( begin, cs.used(begin) ); | 2204 | 17 | return maybe_suspend( | 2205 | 17 | cs.begin(), state::num1, num); | 2206 | 17 | } | 2207 | | | 2208 | | //---------------------------------- | 2209 | | // | 2210 | | // 1*DIGIT | 2211 | | // significant digits left of decimal | 2212 | | // | 2213 | 515 | do_num2: | 2214 | 515 | if(negative || (!stack_empty && num.neg)) | 2215 | 169 | { | 2216 | 169 | for(;;) | 2217 | 169 | { | 2218 | 169 | if(BOOST_JSON_UNLIKELY(! cs)) | 2219 | 169 | { | 2220 | 169 | 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 | 169 | goto finish_int; | 2232 | 169 | } | 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 | 169 | } | 2249 | 346 | else | 2250 | 346 | { | 2251 | 346 | for(;;) | 2252 | 346 | { | 2253 | 346 | if(BOOST_JSON_UNLIKELY(! cs)) | 2254 | 346 | { | 2255 | 346 | 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 | 346 | goto finish_int; | 2267 | 346 | } | 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 | 346 | } | 2286 | 0 | ++num.bias; | 2287 | | | 2288 | | //---------------------------------- | 2289 | | // | 2290 | | // 1*DIGIT | 2291 | | // non-significant digits left of decimal | 2292 | | // | 2293 | 61 | do_num3: | 2294 | 61 | for(;;) | 2295 | 61 | { | 2296 | 61 | if(BOOST_JSON_UNLIKELY(! cs)) | 2297 | 61 | { | 2298 | 61 | 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 | 61 | goto finish_dub; | 2310 | 61 | } | 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 | 3 | do_num4: | 2348 | 3 | { | 2349 | 3 | 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 | 0 | return fail(cs.begin()); | 2355 | | | 2356 | 3 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2357 | 3 | num_buf_.append( begin, cs.used(begin) ); | 2358 | 3 | return maybe_suspend( | 2359 | 3 | cs.begin(), state::num4, num); | 2360 | 3 | } | 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 | 89 | do_num5: | 2384 | 89 | for(;;) | 2385 | 89 | { | 2386 | 89 | if(BOOST_JSON_UNLIKELY(! cs)) | 2387 | 89 | { | 2388 | 89 | 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 | 89 | goto finish_dub; | 2400 | 89 | } | 2401 | 0 | char const c = *cs; | 2402 | 0 | if(BOOST_JSON_LIKELY( | 2403 | 0 | c >= '0' && c <= '9')) | 2404 | 0 | { | 2405 | 0 | ++cs; | 2406 | 0 | } | 2407 | 0 | else if((c | 32) == 'e') | 2408 | 0 | { | 2409 | 0 | ++cs; | 2410 | 0 | goto do_exp1; | 2411 | 0 | } | 2412 | 0 | else | 2413 | 0 | { | 2414 | 0 | goto finish_dub; | 2415 | 0 | } | 2416 | 0 | } | 2417 | | | 2418 | | //---------------------------------- | 2419 | | // | 2420 | | // [.eE] | 2421 | | // | 2422 | 28 | do_num6: | 2423 | 28 | { | 2424 | 28 | if(BOOST_JSON_UNLIKELY(! cs)) | 2425 | 28 | { | 2426 | 28 | 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 | 28 | goto finish_int; | 2438 | 28 | } | 2439 | 0 | char const c = *cs; | 2440 | 0 | if(BOOST_JSON_LIKELY( | 2441 | 0 | c == '.')) | 2442 | 0 | { | 2443 | 0 | ++cs; | 2444 | 0 | } | 2445 | 0 | else if((c | 32) == 'e') | 2446 | 0 | { | 2447 | 0 | ++cs; | 2448 | 0 | goto do_exp1; | 2449 | 0 | } | 2450 | 0 | else | 2451 | 0 | { | 2452 | 0 | goto finish_int; | 2453 | 0 | } | 2454 | 0 | } | 2455 | | | 2456 | | //---------------------------------- | 2457 | | // | 2458 | | // DIGIT | 2459 | | // first significant digit | 2460 | | // to the right of decimal | 2461 | | // | 2462 | 13 | do_num7: | 2463 | 13 | { | 2464 | 13 | 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 | 0 | char const c = *cs; | 2483 | 0 | if(BOOST_JSON_UNLIKELY( | 2484 | 0 | c < '0' || c > '9')) | 2485 | 0 | { | 2486 | | // digit required | 2487 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 2488 | 0 | = BOOST_CURRENT_LOCATION; | 2489 | 0 | return fail(cs.begin(), error::syntax, &loc); | 2490 | 0 | } | 2491 | 0 | } | 2492 | | | 2493 | | //---------------------------------- | 2494 | | // | 2495 | | // 1*DIGIT | 2496 | | // significant digits | 2497 | | // to the right of decimal | 2498 | | // | 2499 | 678 | do_num8: | 2500 | 678 | for(;;) | 2501 | 678 | { | 2502 | 678 | if(BOOST_JSON_UNLIKELY(! cs)) | 2503 | 678 | { | 2504 | 678 | 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 | 678 | goto finish_dub; | 2516 | 678 | } | 2517 | 0 | char const c = *cs; | 2518 | 0 | if(BOOST_JSON_LIKELY( | 2519 | 0 | c >= '0' && c <= '9')) | 2520 | 0 | { | 2521 | 0 | ++cs; | 2522 | 0 | if(!no_parsing && BOOST_JSON_LIKELY( | 2523 | 0 | num.mant <= 9007199254740991)) // 2^53-1 | 2524 | 0 | { | 2525 | 0 | 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 | 0 | --num.bias; | 2532 | 0 | num.mant = 10 * num.mant + ( c - '0' ); | 2533 | 0 | } | 2534 | 0 | else | 2535 | 0 | { | 2536 | 0 | goto do_num5; | 2537 | 0 | } | 2538 | 0 | } | 2539 | 0 | else if((c | 32) == 'e') | 2540 | 0 | { | 2541 | 0 | ++cs; | 2542 | 0 | goto do_exp1; | 2543 | 0 | } | 2544 | 0 | else | 2545 | 0 | { | 2546 | 0 | goto finish_dub; | 2547 | 0 | } | 2548 | 0 | } | 2549 | | | 2550 | | //---------------------------------- | 2551 | | // | 2552 | | // *[+-] | 2553 | | // | 2554 | 75 | do_exp1: | 2555 | 75 | if(BOOST_JSON_UNLIKELY(! cs)) | 2556 | 75 | { | 2557 | 75 | if(BOOST_JSON_UNLIKELY( | 2558 | 75 | ! h_.on_number_part( | 2559 | 75 | {begin, cs.used(begin)}, ec_))) | 2560 | 0 | return fail(cs.begin()); | 2561 | | | 2562 | 75 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2563 | 75 | num_buf_.append( begin, cs.used(begin) ); | 2564 | 75 | return maybe_suspend( | 2565 | 75 | cs.begin(), state::exp1, num); | 2566 | 75 | } | 2567 | 0 | if(*cs == '+') | 2568 | 0 | { | 2569 | 0 | ++cs; | 2570 | 0 | } | 2571 | 0 | else if(*cs == '-') | 2572 | 0 | { | 2573 | 0 | ++cs; | 2574 | 0 | num.frac = true; | 2575 | 0 | } | 2576 | | | 2577 | | //---------------------------------- | 2578 | | // | 2579 | | // DIGIT | 2580 | | // first digit of the exponent | 2581 | | // | 2582 | 31 | do_exp2: | 2583 | 31 | { | 2584 | 31 | if(BOOST_JSON_UNLIKELY(! cs)) | 2585 | 31 | { | 2586 | 31 | 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 | 31 | BOOST_STATIC_CONSTEXPR source_location loc | 2599 | 31 | = BOOST_CURRENT_LOCATION; | 2600 | 31 | return fail(cs.begin(), error::syntax, &loc); | 2601 | 31 | } | 2602 | 0 | char const c = *cs; | 2603 | 0 | if(BOOST_JSON_UNLIKELY( | 2604 | 0 | c < '0' || c > '9')) | 2605 | 0 | { | 2606 | | // digit required | 2607 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 2608 | 0 | = BOOST_CURRENT_LOCATION; | 2609 | 0 | return fail(cs.begin(), error::syntax, &loc); | 2610 | 0 | } | 2611 | 0 | ++cs; | 2612 | 0 | num.exp = c - '0'; | 2613 | 0 | } | 2614 | | | 2615 | | //---------------------------------- | 2616 | | // | 2617 | | // 1*DIGIT | 2618 | | // subsequent digits in the exponent | 2619 | | // | 2620 | 652 | do_exp3: | 2621 | 652 | for(;;) | 2622 | 652 | { | 2623 | 652 | if(BOOST_JSON_UNLIKELY(! cs)) | 2624 | 652 | { | 2625 | 652 | 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 | 652 | } | 2637 | 0 | else | 2638 | 0 | { | 2639 | 0 | char const c = *cs; | 2640 | 0 | if(BOOST_JSON_LIKELY( c >= '0' && c <= '9' )) | 2641 | 0 | { | 2642 | 0 | if(BOOST_JSON_UNLIKELY( | 2643 | | // 2147483647 INT_MAX | 2644 | 0 | num.exp > 214748364 || | 2645 | 0 | (num.exp == 214748364 && c > '7') | 2646 | 0 | )) | 2647 | 0 | num.exp = INT_MAX; | 2648 | 0 | else BOOST_IF_CONSTEXPR( !no_parsing ) | 2649 | 0 | num.exp = 10 * num.exp + ( c - '0' ); | 2650 | |
| 2651 | 0 | ++cs; | 2652 | 0 | continue; | 2653 | 0 | } | 2654 | 0 | } | 2655 | 652 | BOOST_ASSERT(num.exp >= 0); | 2656 | 652 | if ( num.frac ) | 2657 | 172 | { | 2658 | 172 | if(BOOST_JSON_UNLIKELY( num.bias < (INT_MIN + num.exp) )) | 2659 | 24 | { | 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 | 24 | if(BOOST_JSON_UNLIKELY( | 2664 | 24 | (num.exp == INT_MAX) && | 2665 | 24 | (num.bias < 0) && | 2666 | 24 | (num.exp + num.bias < 308) && | 2667 | 24 | 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 | 24 | num.bias = 0; | 2675 | 24 | num.exp = INT_MAX; | 2676 | 24 | } | 2677 | 172 | } | 2678 | 480 | else if (BOOST_JSON_UNLIKELY( num.bias > (INT_MAX - num.exp) )) | 2679 | 44 | { | 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 | 44 | if(BOOST_JSON_UNLIKELY( | 2684 | 44 | (num.exp == INT_MAX) && | 2685 | 44 | (num.bias > 0) && | 2686 | 44 | (num.exp - num.bias < 308) && | 2687 | 44 | 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 | 44 | num.bias = 0; | 2695 | 44 | num.exp = INT_MAX; | 2696 | 44 | } | 2697 | 652 | goto finish_dub; | 2698 | 652 | } | 2699 | | | 2700 | 543 | finish_int: | 2701 | 543 | if(negative || (!stack_empty && num.neg)) | 2702 | 175 | { | 2703 | 175 | if(BOOST_JSON_UNLIKELY( | 2704 | 175 | ! h_.on_int64(static_cast< | 2705 | 175 | int64_t>(~num.mant + 1), {begin, cs.used(begin)}, ec_))) | 2706 | 0 | return fail(cs.begin()); | 2707 | 175 | return cs.begin(); | 2708 | 175 | } | 2709 | 368 | if(num.mant <= INT64_MAX) | 2710 | 257 | { | 2711 | 257 | finish_signed: | 2712 | 257 | if(BOOST_JSON_UNLIKELY( | 2713 | 257 | ! h_.on_int64(static_cast< | 2714 | 257 | int64_t>(num.mant), {begin, cs.used(begin)}, ec_))) | 2715 | 0 | return fail(cs.begin()); | 2716 | 257 | return cs.begin(); | 2717 | 257 | } | 2718 | 111 | if(BOOST_JSON_UNLIKELY( | 2719 | 111 | ! h_.on_uint64(num.mant, {begin, cs.used(begin)}, ec_))) | 2720 | 0 | return fail(cs.begin()); | 2721 | 111 | return cs.begin(); | 2722 | 1.48k | finish_dub: | 2723 | 1.48k | double d; | 2724 | 1.48k | std::size_t const size = cs.used(begin); | 2725 | 1.48k | BOOST_ASSERT( !num_buf_.size() || precise_parsing ); | 2726 | | BOOST_IF_CONSTEXPR( precise_parsing ) | 2727 | | { | 2728 | | char const* data = begin; | 2729 | | 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 | 1.48k | else BOOST_IF_CONSTEXPR( no_parsing ) | 2745 | 1.48k | d = 0; | 2746 | 1.48k | else | 2747 | 1.48k | d = detail::dec_to_float( | 2748 | 1.48k | num.mant, | 2749 | 1.48k | num.bias + (num.frac ? | 2750 | 1.30k | -num.exp : num.exp), | 2751 | 1.48k | num.neg); | 2752 | 1.48k | if(BOOST_JSON_UNLIKELY( | 2753 | 1.48k | ! h_.on_double(d, {begin, size}, ec_))) | 2754 | 0 | return fail(cs.begin()); | 2755 | 1.48k | return cs.begin(); | 2756 | 1.48k | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::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>) Line | Count | Source | 1986 | 4.04k | { | 1987 | 4.04k | constexpr bool precise_parsing = mode == number_precision::precise; | 1988 | 4.04k | 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 | 4.04k | bool const negative = first == '-'; | 1995 | 4.04k | bool const zero_first = first == '0'; | 1996 | 4.04k | bool const nonzero_first = first == '+'; | 1997 | 4.04k | detail::const_stream_wrapper cs(p, end_); | 1998 | 4.04k | number num; | 1999 | 4.04k | const char* begin = cs.begin(); | 2000 | 4.04k | if(stack_empty || st_.empty()) | 2001 | 0 | { | 2002 | 0 | num.bias = 0; | 2003 | 0 | num.exp = 0; | 2004 | 0 | num.frac = false; | 2005 | 0 | num_buf_.clear(); | 2006 | | | 2007 | | //---------------------------------- | 2008 | | // | 2009 | | // '-' | 2010 | | // leading minus sign | 2011 | | // | 2012 | 0 | BOOST_ASSERT(cs); | 2013 | 0 | if(negative) | 2014 | 0 | ++cs; | 2015 | |
| 2016 | 0 | num.neg = negative; | 2017 | 0 | num.frac = false; | 2018 | 0 | num.exp = 0; | 2019 | 0 | num.bias = 0; | 2020 | | | 2021 | | // fast path | 2022 | 0 | if( cs.remain() >= 16 + 1 + 16 ) // digits . digits | 2023 | 0 | { | 2024 | 0 | int n1; | 2025 | |
| 2026 | 0 | if( nonzero_first || | 2027 | 0 | (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 | 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 | 0 | { | 2070 | 0 | const char c = *cs; | 2071 | 0 | if(c != '.') | 2072 | 0 | { | 2073 | 0 | if((c | 32) == 'e') | 2074 | 0 | { | 2075 | 0 | ++cs; | 2076 | 0 | goto do_exp1; | 2077 | 0 | } | 2078 | 0 | BOOST_IF_CONSTEXPR( negative && !no_parsing ) | 2079 | 0 | num.mant = ~num.mant + 1; | 2080 | 0 | goto finish_signed; | 2081 | 0 | } | 2082 | 0 | } | 2083 | | | 2084 | | // floating-point number | 2085 | | | 2086 | 0 | ++cs; | 2087 | |
| 2088 | 0 | int n2 = detail::count_digits( cs.begin() ); | 2089 | 0 | BOOST_ASSERT(n2 >= 0 && n2 <= 16); | 2090 | |
| 2091 | 0 | if( n2 == 0 ) | 2092 | 0 | { | 2093 | | // digit required | 2094 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 2095 | 0 | = BOOST_CURRENT_LOCATION; | 2096 | 0 | return fail(cs.begin(), error::syntax, &loc); | 2097 | 0 | } | 2098 | | | 2099 | | // floating-point mantissa overflow | 2100 | 0 | if( n1 + n2 >= 19 ) | 2101 | 0 | { | 2102 | 0 | goto do_num7; | 2103 | 0 | } | 2104 | | | 2105 | 0 | BOOST_IF_CONSTEXPR( !no_parsing ) | 2106 | 0 | num.mant = detail::parse_unsigned( num.mant, cs.begin(), n2 ); | 2107 | |
| 2108 | 0 | BOOST_ASSERT(num.bias == 0); | 2109 | |
| 2110 | 0 | num.bias -= n2; | 2111 | |
| 2112 | 0 | cs += n2; | 2113 | |
| 2114 | 0 | char ch = *cs; | 2115 | |
| 2116 | 0 | if( (ch | 32) == 'e' ) | 2117 | 0 | { | 2118 | 0 | ++cs; | 2119 | 0 | goto do_exp1; | 2120 | 0 | } | 2121 | 0 | else if( ch >= '0' && ch <= '9' ) | 2122 | 0 | { | 2123 | 0 | goto do_num8; | 2124 | 0 | } | 2125 | | | 2126 | 0 | goto finish_dub; | 2127 | 0 | } | 2128 | 0 | } | 2129 | 4.04k | else | 2130 | 4.04k | { | 2131 | 4.04k | num = num_; | 2132 | 4.04k | state st; | 2133 | 4.04k | st_.pop(st); | 2134 | 4.04k | switch(st) | 2135 | 4.04k | { | 2136 | 0 | default: BOOST_JSON_UNREACHABLE(); | 2137 | 21 | case state::num1: goto do_num1; | 2138 | 484 | case state::num2: goto do_num2; | 2139 | 486 | case state::num3: goto do_num3; | 2140 | 6 | case state::num4: goto do_num4; | 2141 | 877 | case state::num5: goto do_num5; | 2142 | 30 | case state::num6: goto do_num6; | 2143 | 11 | case state::num7: goto do_num7; | 2144 | 626 | case state::num8: goto do_num8; | 2145 | 76 | case state::exp1: goto do_exp1; | 2146 | 29 | case state::exp2: goto do_exp2; | 2147 | 1.39k | case state::exp3: goto do_exp3; | 2148 | 4.04k | } | 2149 | 4.04k | } | 2150 | | | 2151 | | //---------------------------------- | 2152 | | // | 2153 | | // DIGIT | 2154 | | // first digit | 2155 | | // | 2156 | 21 | do_num1: | 2157 | 21 | if(zero_first || nonzero_first || | 2158 | 21 | BOOST_JSON_LIKELY(cs)) | 2159 | 0 | { | 2160 | 0 | char const c = *cs; | 2161 | 0 | if(zero_first) | 2162 | 0 | { | 2163 | 0 | ++cs; | 2164 | 0 | num.mant = 0; | 2165 | 0 | goto do_num6; | 2166 | 0 | } | 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 | 0 | } | 2195 | 21 | else | 2196 | 21 | { | 2197 | 21 | if(BOOST_JSON_UNLIKELY( | 2198 | 21 | ! h_.on_number_part( | 2199 | 21 | {begin, cs.used(begin)}, ec_))) | 2200 | 0 | return fail(cs.begin()); | 2201 | | | 2202 | 21 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2203 | 21 | num_buf_.append( begin, cs.used(begin) ); | 2204 | 21 | return maybe_suspend( | 2205 | 21 | cs.begin(), state::num1, num); | 2206 | 21 | } | 2207 | | | 2208 | | //---------------------------------- | 2209 | | // | 2210 | | // 1*DIGIT | 2211 | | // significant digits left of decimal | 2212 | | // | 2213 | 484 | do_num2: | 2214 | 484 | if(negative || (!stack_empty && num.neg)) | 2215 | 165 | { | 2216 | 165 | for(;;) | 2217 | 165 | { | 2218 | 165 | if(BOOST_JSON_UNLIKELY(! cs)) | 2219 | 165 | { | 2220 | 165 | 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 | 165 | goto finish_int; | 2232 | 165 | } | 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 | 165 | } | 2249 | 319 | else | 2250 | 319 | { | 2251 | 319 | for(;;) | 2252 | 319 | { | 2253 | 319 | if(BOOST_JSON_UNLIKELY(! cs)) | 2254 | 319 | { | 2255 | 319 | 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 | 319 | goto finish_int; | 2267 | 319 | } | 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 | 319 | } | 2286 | 0 | ++num.bias; | 2287 | | | 2288 | | //---------------------------------- | 2289 | | // | 2290 | | // 1*DIGIT | 2291 | | // non-significant digits left of decimal | 2292 | | // | 2293 | 486 | do_num3: | 2294 | 486 | for(;;) | 2295 | 486 | { | 2296 | 486 | if(BOOST_JSON_UNLIKELY(! cs)) | 2297 | 486 | { | 2298 | 486 | 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 | 486 | goto finish_dub; | 2310 | 486 | } | 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 | 6 | do_num4: | 2348 | 6 | { | 2349 | 6 | if(BOOST_JSON_UNLIKELY(! cs)) | 2350 | 6 | { | 2351 | 6 | if(BOOST_JSON_UNLIKELY( | 2352 | 6 | ! h_.on_number_part( | 2353 | 6 | {begin, cs.used(begin)}, ec_))) | 2354 | 0 | 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 | 6 | } | 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 | 877 | do_num5: | 2384 | 877 | for(;;) | 2385 | 877 | { | 2386 | 877 | if(BOOST_JSON_UNLIKELY(! cs)) | 2387 | 877 | { | 2388 | 877 | 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 | 877 | goto finish_dub; | 2400 | 877 | } | 2401 | 0 | char const c = *cs; | 2402 | 0 | if(BOOST_JSON_LIKELY( | 2403 | 0 | c >= '0' && c <= '9')) | 2404 | 0 | { | 2405 | 0 | ++cs; | 2406 | 0 | } | 2407 | 0 | else if((c | 32) == 'e') | 2408 | 0 | { | 2409 | 0 | ++cs; | 2410 | 0 | goto do_exp1; | 2411 | 0 | } | 2412 | 0 | else | 2413 | 0 | { | 2414 | 0 | goto finish_dub; | 2415 | 0 | } | 2416 | 0 | } | 2417 | | | 2418 | | //---------------------------------- | 2419 | | // | 2420 | | // [.eE] | 2421 | | // | 2422 | 30 | do_num6: | 2423 | 30 | { | 2424 | 30 | if(BOOST_JSON_UNLIKELY(! cs)) | 2425 | 30 | { | 2426 | 30 | 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 | 30 | goto finish_int; | 2438 | 30 | } | 2439 | 0 | char const c = *cs; | 2440 | 0 | if(BOOST_JSON_LIKELY( | 2441 | 0 | c == '.')) | 2442 | 0 | { | 2443 | 0 | ++cs; | 2444 | 0 | } | 2445 | 0 | else if((c | 32) == 'e') | 2446 | 0 | { | 2447 | 0 | ++cs; | 2448 | 0 | goto do_exp1; | 2449 | 0 | } | 2450 | 0 | else | 2451 | 0 | { | 2452 | 0 | goto finish_int; | 2453 | 0 | } | 2454 | 0 | } | 2455 | | | 2456 | | //---------------------------------- | 2457 | | // | 2458 | | // DIGIT | 2459 | | // first significant digit | 2460 | | // to the right of decimal | 2461 | | // | 2462 | 11 | do_num7: | 2463 | 11 | { | 2464 | 11 | if(BOOST_JSON_UNLIKELY(! cs)) | 2465 | 11 | { | 2466 | 11 | 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 | 11 | BOOST_STATIC_CONSTEXPR source_location loc | 2479 | 11 | = BOOST_CURRENT_LOCATION; | 2480 | 11 | return fail(cs.begin(), error::syntax, &loc); | 2481 | 11 | } | 2482 | 0 | char const c = *cs; | 2483 | 0 | if(BOOST_JSON_UNLIKELY( | 2484 | 0 | c < '0' || c > '9')) | 2485 | 0 | { | 2486 | | // digit required | 2487 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 2488 | 0 | = BOOST_CURRENT_LOCATION; | 2489 | 0 | return fail(cs.begin(), error::syntax, &loc); | 2490 | 0 | } | 2491 | 0 | } | 2492 | | | 2493 | | //---------------------------------- | 2494 | | // | 2495 | | // 1*DIGIT | 2496 | | // significant digits | 2497 | | // to the right of decimal | 2498 | | // | 2499 | 626 | do_num8: | 2500 | 626 | for(;;) | 2501 | 626 | { | 2502 | 626 | if(BOOST_JSON_UNLIKELY(! cs)) | 2503 | 626 | { | 2504 | 626 | 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 | 626 | goto finish_dub; | 2516 | 626 | } | 2517 | 0 | char const c = *cs; | 2518 | 0 | if(BOOST_JSON_LIKELY( | 2519 | 0 | c >= '0' && c <= '9')) | 2520 | 0 | { | 2521 | 0 | ++cs; | 2522 | 0 | if(!no_parsing && BOOST_JSON_LIKELY( | 2523 | 0 | num.mant <= 9007199254740991)) // 2^53-1 | 2524 | 0 | { | 2525 | 0 | 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 | 0 | --num.bias; | 2532 | 0 | num.mant = 10 * num.mant + ( c - '0' ); | 2533 | 0 | } | 2534 | 0 | else | 2535 | 0 | { | 2536 | 0 | goto do_num5; | 2537 | 0 | } | 2538 | 0 | } | 2539 | 0 | else if((c | 32) == 'e') | 2540 | 0 | { | 2541 | 0 | ++cs; | 2542 | 0 | goto do_exp1; | 2543 | 0 | } | 2544 | 0 | else | 2545 | 0 | { | 2546 | 0 | goto finish_dub; | 2547 | 0 | } | 2548 | 0 | } | 2549 | | | 2550 | | //---------------------------------- | 2551 | | // | 2552 | | // *[+-] | 2553 | | // | 2554 | 76 | do_exp1: | 2555 | 76 | if(BOOST_JSON_UNLIKELY(! cs)) | 2556 | 76 | { | 2557 | 76 | if(BOOST_JSON_UNLIKELY( | 2558 | 76 | ! h_.on_number_part( | 2559 | 76 | {begin, cs.used(begin)}, ec_))) | 2560 | 0 | return fail(cs.begin()); | 2561 | | | 2562 | 76 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2563 | 76 | num_buf_.append( begin, cs.used(begin) ); | 2564 | 76 | return maybe_suspend( | 2565 | 76 | cs.begin(), state::exp1, num); | 2566 | 76 | } | 2567 | 0 | if(*cs == '+') | 2568 | 0 | { | 2569 | 0 | ++cs; | 2570 | 0 | } | 2571 | 0 | else if(*cs == '-') | 2572 | 0 | { | 2573 | 0 | ++cs; | 2574 | 0 | num.frac = true; | 2575 | 0 | } | 2576 | | | 2577 | | //---------------------------------- | 2578 | | // | 2579 | | // DIGIT | 2580 | | // first digit of the exponent | 2581 | | // | 2582 | 29 | do_exp2: | 2583 | 29 | { | 2584 | 29 | if(BOOST_JSON_UNLIKELY(! cs)) | 2585 | 29 | { | 2586 | 29 | 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 | 29 | BOOST_STATIC_CONSTEXPR source_location loc | 2599 | 29 | = BOOST_CURRENT_LOCATION; | 2600 | 29 | return fail(cs.begin(), error::syntax, &loc); | 2601 | 29 | } | 2602 | 0 | char const c = *cs; | 2603 | 0 | if(BOOST_JSON_UNLIKELY( | 2604 | 0 | c < '0' || c > '9')) | 2605 | 0 | { | 2606 | | // digit required | 2607 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 2608 | 0 | = BOOST_CURRENT_LOCATION; | 2609 | 0 | return fail(cs.begin(), error::syntax, &loc); | 2610 | 0 | } | 2611 | 0 | ++cs; | 2612 | 0 | num.exp = c - '0'; | 2613 | 0 | } | 2614 | | | 2615 | | //---------------------------------- | 2616 | | // | 2617 | | // 1*DIGIT | 2618 | | // subsequent digits in the exponent | 2619 | | // | 2620 | 1.39k | do_exp3: | 2621 | 1.39k | for(;;) | 2622 | 1.39k | { | 2623 | 1.39k | if(BOOST_JSON_UNLIKELY(! cs)) | 2624 | 1.39k | { | 2625 | 1.39k | 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 | 1.39k | } | 2637 | 0 | else | 2638 | 0 | { | 2639 | 0 | char const c = *cs; | 2640 | 0 | if(BOOST_JSON_LIKELY( c >= '0' && c <= '9' )) | 2641 | 0 | { | 2642 | 0 | if(BOOST_JSON_UNLIKELY( | 2643 | | // 2147483647 INT_MAX | 2644 | 0 | num.exp > 214748364 || | 2645 | 0 | (num.exp == 214748364 && c > '7') | 2646 | 0 | )) | 2647 | 0 | num.exp = INT_MAX; | 2648 | 0 | else BOOST_IF_CONSTEXPR( !no_parsing ) | 2649 | 0 | num.exp = 10 * num.exp + ( c - '0' ); | 2650 | |
| 2651 | 0 | ++cs; | 2652 | 0 | continue; | 2653 | 0 | } | 2654 | 0 | } | 2655 | 1.39k | BOOST_ASSERT(num.exp >= 0); | 2656 | 1.39k | if ( num.frac ) | 2657 | 541 | { | 2658 | 541 | if(BOOST_JSON_UNLIKELY( num.bias < (INT_MIN + num.exp) )) | 2659 | 29 | { | 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 | 29 | if(BOOST_JSON_UNLIKELY( | 2664 | 29 | (num.exp == INT_MAX) && | 2665 | 29 | (num.bias < 0) && | 2666 | 29 | (num.exp + num.bias < 308) && | 2667 | 29 | 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 | 29 | num.bias = 0; | 2675 | 29 | num.exp = INT_MAX; | 2676 | 29 | } | 2677 | 541 | } | 2678 | 858 | else if (BOOST_JSON_UNLIKELY( num.bias > (INT_MAX - num.exp) )) | 2679 | 47 | { | 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 | 47 | if(BOOST_JSON_UNLIKELY( | 2684 | 47 | (num.exp == INT_MAX) && | 2685 | 47 | (num.bias > 0) && | 2686 | 47 | (num.exp - num.bias < 308) && | 2687 | 47 | 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 | 47 | num.bias = 0; | 2695 | 47 | num.exp = INT_MAX; | 2696 | 47 | } | 2697 | 1.39k | goto finish_dub; | 2698 | 1.39k | } | 2699 | | | 2700 | 514 | finish_int: | 2701 | 514 | if(negative || (!stack_empty && num.neg)) | 2702 | 170 | { | 2703 | 170 | if(BOOST_JSON_UNLIKELY( | 2704 | 170 | ! h_.on_int64(static_cast< | 2705 | 170 | int64_t>(~num.mant + 1), {begin, cs.used(begin)}, ec_))) | 2706 | 0 | return fail(cs.begin()); | 2707 | 170 | return cs.begin(); | 2708 | 170 | } | 2709 | 344 | if(num.mant <= INT64_MAX) | 2710 | 251 | { | 2711 | 251 | finish_signed: | 2712 | 251 | if(BOOST_JSON_UNLIKELY( | 2713 | 251 | ! h_.on_int64(static_cast< | 2714 | 251 | int64_t>(num.mant), {begin, cs.used(begin)}, ec_))) | 2715 | 0 | return fail(cs.begin()); | 2716 | 251 | return cs.begin(); | 2717 | 251 | } | 2718 | 93 | if(BOOST_JSON_UNLIKELY( | 2719 | 93 | ! h_.on_uint64(num.mant, {begin, cs.used(begin)}, ec_))) | 2720 | 0 | return fail(cs.begin()); | 2721 | 93 | return cs.begin(); | 2722 | 3.38k | finish_dub: | 2723 | 3.38k | double d; | 2724 | 3.38k | std::size_t const size = cs.used(begin); | 2725 | 3.38k | BOOST_ASSERT( !num_buf_.size() || precise_parsing ); | 2726 | | BOOST_IF_CONSTEXPR( precise_parsing ) | 2727 | 3.38k | { | 2728 | 3.38k | char const* data = begin; | 2729 | 3.38k | 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 | 3.38k | if(BOOST_JSON_UNLIKELY( num_buf_.size() )) | 2734 | 3.38k | { | 2735 | 3.38k | data = num_buf_.append( begin, size ); | 2736 | 3.38k | full_size = num_buf_.size(); | 2737 | 3.38k | } | 2738 | 3.38k | auto const err = detail::charconv::from_chars( | 2739 | 3.38k | data, data + full_size, d ); | 2740 | 3.38k | BOOST_ASSERT( err.ec != std::errc::invalid_argument ); | 2741 | 3.38k | BOOST_ASSERT( err.ptr == data + full_size ); | 2742 | 3.38k | (void)err; | 2743 | | } | 2744 | | else BOOST_IF_CONSTEXPR( no_parsing ) | 2745 | | d = 0; | 2746 | | else | 2747 | | d = detail::dec_to_float( | 2748 | | num.mant, | 2749 | | num.bias + (num.frac ? | 2750 | | -num.exp : num.exp), | 2751 | | num.neg); | 2752 | 3.38k | if(BOOST_JSON_UNLIKELY( | 2753 | 3.38k | ! h_.on_double(d, {begin, size}, ec_))) | 2754 | 0 | return fail(cs.begin()); | 2755 | 3.38k | return cs.begin(); | 2756 | 3.38k | } |
char const* boost::json::basic_parser<boost::json::detail::handler>::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>) Line | Count | Source | 1986 | 361 | { | 1987 | 361 | constexpr bool precise_parsing = mode == number_precision::precise; | 1988 | 361 | 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 | 361 | bool const negative = first == '-'; | 1995 | 361 | bool const zero_first = first == '0'; | 1996 | 361 | bool const nonzero_first = first == '+'; | 1997 | 361 | detail::const_stream_wrapper cs(p, end_); | 1998 | 361 | number num; | 1999 | 361 | const char* begin = cs.begin(); | 2000 | 361 | if(stack_empty || st_.empty()) | 2001 | 0 | { | 2002 | 0 | num.bias = 0; | 2003 | 0 | num.exp = 0; | 2004 | 0 | num.frac = false; | 2005 | 0 | num_buf_.clear(); | 2006 | | | 2007 | | //---------------------------------- | 2008 | | // | 2009 | | // '-' | 2010 | | // leading minus sign | 2011 | | // | 2012 | 0 | BOOST_ASSERT(cs); | 2013 | 0 | if(negative) | 2014 | 0 | ++cs; | 2015 | |
| 2016 | 0 | num.neg = negative; | 2017 | 0 | num.frac = false; | 2018 | 0 | num.exp = 0; | 2019 | 0 | num.bias = 0; | 2020 | | | 2021 | | // fast path | 2022 | 0 | if( cs.remain() >= 16 + 1 + 16 ) // digits . digits | 2023 | 0 | { | 2024 | 0 | int n1; | 2025 | |
| 2026 | 0 | if( nonzero_first || | 2027 | 0 | (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 | 0 | else | 2050 | 0 | 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 | 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 | 0 | { | 2070 | 0 | const char c = *cs; | 2071 | 0 | if(c != '.') | 2072 | 0 | { | 2073 | 0 | if((c | 32) == 'e') | 2074 | 0 | { | 2075 | 0 | ++cs; | 2076 | 0 | goto do_exp1; | 2077 | 0 | } | 2078 | 0 | BOOST_IF_CONSTEXPR( negative && !no_parsing ) | 2079 | 0 | num.mant = ~num.mant + 1; | 2080 | 0 | goto finish_signed; | 2081 | 0 | } | 2082 | 0 | } | 2083 | | | 2084 | | // floating-point number | 2085 | | | 2086 | 0 | ++cs; | 2087 | |
| 2088 | 0 | int n2 = detail::count_digits( cs.begin() ); | 2089 | 0 | BOOST_ASSERT(n2 >= 0 && n2 <= 16); | 2090 | |
| 2091 | 0 | if( n2 == 0 ) | 2092 | 0 | { | 2093 | | // digit required | 2094 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 2095 | 0 | = BOOST_CURRENT_LOCATION; | 2096 | 0 | return fail(cs.begin(), error::syntax, &loc); | 2097 | 0 | } | 2098 | | | 2099 | | // floating-point mantissa overflow | 2100 | 0 | if( n1 + n2 >= 19 ) | 2101 | 0 | { | 2102 | 0 | goto do_num7; | 2103 | 0 | } | 2104 | | | 2105 | 0 | BOOST_IF_CONSTEXPR( !no_parsing ) | 2106 | 0 | num.mant = detail::parse_unsigned( num.mant, cs.begin(), n2 ); | 2107 | |
| 2108 | 0 | BOOST_ASSERT(num.bias == 0); | 2109 | |
| 2110 | 0 | num.bias -= n2; | 2111 | |
| 2112 | 0 | cs += n2; | 2113 | |
| 2114 | 0 | char ch = *cs; | 2115 | |
| 2116 | 0 | if( (ch | 32) == 'e' ) | 2117 | 0 | { | 2118 | 0 | ++cs; | 2119 | 0 | goto do_exp1; | 2120 | 0 | } | 2121 | 0 | else if( ch >= '0' && ch <= '9' ) | 2122 | 0 | { | 2123 | 0 | goto do_num8; | 2124 | 0 | } | 2125 | | | 2126 | 0 | goto finish_dub; | 2127 | 0 | } | 2128 | 0 | } | 2129 | 361 | else | 2130 | 361 | { | 2131 | 361 | num = num_; | 2132 | 361 | state st; | 2133 | 361 | st_.pop(st); | 2134 | 361 | switch(st) | 2135 | 361 | { | 2136 | 0 | default: BOOST_JSON_UNREACHABLE(); | 2137 | 20 | case state::num1: goto do_num1; | 2138 | 84 | case state::num2: goto do_num2; | 2139 | 0 | case state::num3: goto do_num3; | 2140 | 0 | case state::num4: goto do_num4; | 2141 | 70 | case state::num5: goto do_num5; | 2142 | 26 | case state::num6: goto do_num6; | 2143 | 14 | case state::num7: goto do_num7; | 2144 | 0 | case state::num8: goto do_num8; | 2145 | 40 | case state::exp1: goto do_exp1; | 2146 | 33 | case state::exp2: goto do_exp2; | 2147 | 74 | case state::exp3: goto do_exp3; | 2148 | 361 | } | 2149 | 361 | } | 2150 | | | 2151 | | //---------------------------------- | 2152 | | // | 2153 | | // DIGIT | 2154 | | // first digit | 2155 | | // | 2156 | 20 | do_num1: | 2157 | 20 | if(zero_first || nonzero_first || | 2158 | 20 | BOOST_JSON_LIKELY(cs)) | 2159 | 0 | { | 2160 | 0 | char const c = *cs; | 2161 | 0 | if(zero_first) | 2162 | 0 | { | 2163 | 0 | ++cs; | 2164 | 0 | num.mant = 0; | 2165 | 0 | goto do_num6; | 2166 | 0 | } | 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 | 0 | } | 2195 | 20 | else | 2196 | 20 | { | 2197 | 20 | if(BOOST_JSON_UNLIKELY( | 2198 | 20 | ! h_.on_number_part( | 2199 | 20 | {begin, cs.used(begin)}, ec_))) | 2200 | 0 | return fail(cs.begin()); | 2201 | | | 2202 | 20 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2203 | 20 | num_buf_.append( begin, cs.used(begin) ); | 2204 | 20 | return maybe_suspend( | 2205 | 20 | cs.begin(), state::num1, num); | 2206 | 20 | } | 2207 | | | 2208 | | //---------------------------------- | 2209 | | // | 2210 | | // 1*DIGIT | 2211 | | // significant digits left of decimal | 2212 | | // | 2213 | 84 | do_num2: | 2214 | 84 | if(negative || (!stack_empty && num.neg)) | 2215 | 29 | { | 2216 | 29 | for(;;) | 2217 | 29 | { | 2218 | 29 | if(BOOST_JSON_UNLIKELY(! cs)) | 2219 | 29 | { | 2220 | 29 | 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 | 29 | goto finish_int; | 2232 | 29 | } | 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 | 29 | } | 2249 | 55 | else | 2250 | 55 | { | 2251 | 55 | for(;;) | 2252 | 55 | { | 2253 | 55 | if(BOOST_JSON_UNLIKELY(! cs)) | 2254 | 55 | { | 2255 | 55 | 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 | 55 | goto finish_int; | 2267 | 55 | } | 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 | 55 | } | 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 | 70 | do_num5: | 2384 | 70 | for(;;) | 2385 | 70 | { | 2386 | 70 | if(BOOST_JSON_UNLIKELY(! cs)) | 2387 | 70 | { | 2388 | 70 | 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 | 70 | goto finish_dub; | 2400 | 70 | } | 2401 | 0 | char const c = *cs; | 2402 | 0 | if(BOOST_JSON_LIKELY( | 2403 | 0 | c >= '0' && c <= '9')) | 2404 | 0 | { | 2405 | 0 | ++cs; | 2406 | 0 | } | 2407 | 0 | else if((c | 32) == 'e') | 2408 | 0 | { | 2409 | 0 | ++cs; | 2410 | 0 | goto do_exp1; | 2411 | 0 | } | 2412 | 0 | else | 2413 | 0 | { | 2414 | 0 | goto finish_dub; | 2415 | 0 | } | 2416 | 0 | } | 2417 | | | 2418 | | //---------------------------------- | 2419 | | // | 2420 | | // [.eE] | 2421 | | // | 2422 | 26 | do_num6: | 2423 | 26 | { | 2424 | 26 | if(BOOST_JSON_UNLIKELY(! cs)) | 2425 | 26 | { | 2426 | 26 | 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 | 26 | goto finish_int; | 2438 | 26 | } | 2439 | 0 | char const c = *cs; | 2440 | 0 | if(BOOST_JSON_LIKELY( | 2441 | 0 | c == '.')) | 2442 | 0 | { | 2443 | 0 | ++cs; | 2444 | 0 | } | 2445 | 0 | else if((c | 32) == 'e') | 2446 | 0 | { | 2447 | 0 | ++cs; | 2448 | 0 | goto do_exp1; | 2449 | 0 | } | 2450 | 0 | else | 2451 | 0 | { | 2452 | 0 | goto finish_int; | 2453 | 0 | } | 2454 | 0 | } | 2455 | | | 2456 | | //---------------------------------- | 2457 | | // | 2458 | | // DIGIT | 2459 | | // first significant digit | 2460 | | // to the right of decimal | 2461 | | // | 2462 | 14 | do_num7: | 2463 | 14 | { | 2464 | 14 | if(BOOST_JSON_UNLIKELY(! cs)) | 2465 | 14 | { | 2466 | 14 | 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 | 14 | BOOST_STATIC_CONSTEXPR source_location loc | 2479 | 14 | = BOOST_CURRENT_LOCATION; | 2480 | 14 | return fail(cs.begin(), error::syntax, &loc); | 2481 | 14 | } | 2482 | 0 | char const c = *cs; | 2483 | 0 | if(BOOST_JSON_UNLIKELY( | 2484 | 0 | c < '0' || c > '9')) | 2485 | 0 | { | 2486 | | // digit required | 2487 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 2488 | 0 | = BOOST_CURRENT_LOCATION; | 2489 | 0 | return fail(cs.begin(), error::syntax, &loc); | 2490 | 0 | } | 2491 | 0 | } | 2492 | | | 2493 | | //---------------------------------- | 2494 | | // | 2495 | | // 1*DIGIT | 2496 | | // significant digits | 2497 | | // to the right of decimal | 2498 | | // | 2499 | 0 | do_num8: | 2500 | 0 | for(;;) | 2501 | 0 | { | 2502 | 0 | if(BOOST_JSON_UNLIKELY(! cs)) | 2503 | 0 | { | 2504 | 0 | 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 | 0 | goto finish_dub; | 2516 | 0 | } | 2517 | 0 | char const c = *cs; | 2518 | 0 | if(BOOST_JSON_LIKELY( | 2519 | 0 | c >= '0' && c <= '9')) | 2520 | 0 | { | 2521 | 0 | ++cs; | 2522 | 0 | if(!no_parsing && BOOST_JSON_LIKELY( | 2523 | 0 | num.mant <= 9007199254740991)) // 2^53-1 | 2524 | 0 | { | 2525 | 0 | 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 | 0 | --num.bias; | 2532 | 0 | num.mant = 10 * num.mant + ( c - '0' ); | 2533 | 0 | } | 2534 | 0 | else | 2535 | 0 | { | 2536 | 0 | goto do_num5; | 2537 | 0 | } | 2538 | 0 | } | 2539 | 0 | else if((c | 32) == 'e') | 2540 | 0 | { | 2541 | 0 | ++cs; | 2542 | 0 | goto do_exp1; | 2543 | 0 | } | 2544 | 0 | else | 2545 | 0 | { | 2546 | 0 | goto finish_dub; | 2547 | 0 | } | 2548 | 0 | } | 2549 | | | 2550 | | //---------------------------------- | 2551 | | // | 2552 | | // *[+-] | 2553 | | // | 2554 | 40 | do_exp1: | 2555 | 40 | if(BOOST_JSON_UNLIKELY(! cs)) | 2556 | 40 | { | 2557 | 40 | if(BOOST_JSON_UNLIKELY( | 2558 | 40 | ! h_.on_number_part( | 2559 | 40 | {begin, cs.used(begin)}, ec_))) | 2560 | 0 | return fail(cs.begin()); | 2561 | | | 2562 | 40 | BOOST_IF_CONSTEXPR( precise_parsing ) | 2563 | 40 | num_buf_.append( begin, cs.used(begin) ); | 2564 | 40 | return maybe_suspend( | 2565 | 40 | cs.begin(), state::exp1, num); | 2566 | 40 | } | 2567 | 0 | if(*cs == '+') | 2568 | 0 | { | 2569 | 0 | ++cs; | 2570 | 0 | } | 2571 | 0 | else if(*cs == '-') | 2572 | 0 | { | 2573 | 0 | ++cs; | 2574 | 0 | num.frac = true; | 2575 | 0 | } | 2576 | | | 2577 | | //---------------------------------- | 2578 | | // | 2579 | | // DIGIT | 2580 | | // first digit of the exponent | 2581 | | // | 2582 | 33 | do_exp2: | 2583 | 33 | { | 2584 | 33 | if(BOOST_JSON_UNLIKELY(! cs)) | 2585 | 33 | { | 2586 | 33 | 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 | 33 | BOOST_STATIC_CONSTEXPR source_location loc | 2599 | 33 | = BOOST_CURRENT_LOCATION; | 2600 | 33 | return fail(cs.begin(), error::syntax, &loc); | 2601 | 33 | } | 2602 | 0 | char const c = *cs; | 2603 | 0 | if(BOOST_JSON_UNLIKELY( | 2604 | 0 | c < '0' || c > '9')) | 2605 | 0 | { | 2606 | | // digit required | 2607 | 0 | BOOST_STATIC_CONSTEXPR source_location loc | 2608 | 0 | = BOOST_CURRENT_LOCATION; | 2609 | 0 | return fail(cs.begin(), error::syntax, &loc); | 2610 | 0 | } | 2611 | 0 | ++cs; | 2612 | 0 | num.exp = c - '0'; | 2613 | 0 | } | 2614 | | | 2615 | | //---------------------------------- | 2616 | | // | 2617 | | // 1*DIGIT | 2618 | | // subsequent digits in the exponent | 2619 | | // | 2620 | 74 | do_exp3: | 2621 | 74 | for(;;) | 2622 | 74 | { | 2623 | 74 | if(BOOST_JSON_UNLIKELY(! cs)) | 2624 | 74 | { | 2625 | 74 | 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 | 74 | } | 2637 | 0 | else | 2638 | 0 | { | 2639 | 0 | char const c = *cs; | 2640 | 0 | if(BOOST_JSON_LIKELY( c >= '0' && c <= '9' )) | 2641 | 0 | { | 2642 | 0 | if(BOOST_JSON_UNLIKELY( | 2643 | | // 2147483647 INT_MAX | 2644 | 0 | num.exp > 214748364 || | 2645 | 0 | (num.exp == 214748364 && c > '7') | 2646 | 0 | )) | 2647 | 0 | num.exp = INT_MAX; | 2648 | 0 | else BOOST_IF_CONSTEXPR( !no_parsing ) | 2649 | 0 | num.exp = 10 * num.exp + ( c - '0' ); | 2650 | |
| 2651 | 0 | ++cs; | 2652 | 0 | continue; | 2653 | 0 | } | 2654 | 0 | } | 2655 | 74 | BOOST_ASSERT(num.exp >= 0); | 2656 | 74 | if ( num.frac ) | 2657 | 7 | { | 2658 | 7 | if(BOOST_JSON_UNLIKELY( num.bias < (INT_MIN + num.exp) )) | 2659 | 0 | { | 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 | 0 | if(BOOST_JSON_UNLIKELY( | 2664 | 0 | (num.exp == INT_MAX) && | 2665 | 0 | (num.bias < 0) && | 2666 | 0 | (num.exp + num.bias < 308) && | 2667 | 0 | 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 | 0 | num.bias = 0; | 2675 | 0 | num.exp = INT_MAX; | 2676 | 0 | } | 2677 | 7 | } | 2678 | 67 | 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 | 74 | goto finish_dub; | 2698 | 74 | } | 2699 | | | 2700 | 110 | finish_int: | 2701 | 110 | if(negative || (!stack_empty && num.neg)) | 2702 | 34 | { | 2703 | 34 | if(BOOST_JSON_UNLIKELY( | 2704 | 34 | ! h_.on_int64(static_cast< | 2705 | 34 | int64_t>(~num.mant + 1), {begin, cs.used(begin)}, ec_))) | 2706 | 0 | return fail(cs.begin()); | 2707 | 34 | return cs.begin(); | 2708 | 34 | } | 2709 | 76 | if(num.mant <= INT64_MAX) | 2710 | 76 | { | 2711 | 76 | finish_signed: | 2712 | 76 | if(BOOST_JSON_UNLIKELY( | 2713 | 76 | ! h_.on_int64(static_cast< | 2714 | 76 | int64_t>(num.mant), {begin, cs.used(begin)}, ec_))) | 2715 | 0 | return fail(cs.begin()); | 2716 | 76 | return cs.begin(); | 2717 | 76 | } | 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 | 144 | finish_dub: | 2723 | 144 | double d; | 2724 | 144 | std::size_t const size = cs.used(begin); | 2725 | 144 | BOOST_ASSERT( !num_buf_.size() || precise_parsing ); | 2726 | | BOOST_IF_CONSTEXPR( precise_parsing ) | 2727 | | { | 2728 | | char const* data = begin; | 2729 | | 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 | 144 | else BOOST_IF_CONSTEXPR( no_parsing ) | 2745 | 144 | d = 0; | 2746 | | else | 2747 | | d = detail::dec_to_float( | 2748 | | num.mant, | 2749 | | num.bias + (num.frac ? | 2750 | | -num.exp : num.exp), | 2751 | | num.neg); | 2752 | 144 | if(BOOST_JSON_UNLIKELY( | 2753 | 144 | ! h_.on_double(d, {begin, size}, ec_))) | 2754 | 0 | return fail(cs.begin()); | 2755 | 144 | return cs.begin(); | 2756 | 144 | } |
|
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 | 22.1k | : h_(std::forward<Args>(args)...) |
2767 | 22.1k | , opt_(opt) |
2768 | 22.1k | { |
2769 | 22.1k | } boost::json::basic_parser<boost::json::detail::handler>::basic_parser<boost::json::storage_ptr, unsigned char*&, unsigned long&>(boost::json::parse_options const&, boost::json::storage_ptr&&, unsigned char*&, unsigned long&) Line | Count | Source | 2766 | 13.5k | : h_(std::forward<Args>(args)...) | 2767 | 13.5k | , opt_(opt) | 2768 | 13.5k | { | 2769 | 13.5k | } |
boost::json::basic_parser<boost::json::detail::handler>::basic_parser<boost::json::storage_ptr, decltype(nullptr), int>(boost::json::parse_options const&, boost::json::storage_ptr&&, decltype(nullptr)&&, int&&) Line | Count | Source | 2766 | 8.56k | : h_(std::forward<Args>(args)...) | 2767 | 8.56k | , opt_(opt) | 2768 | 8.56k | { | 2769 | 8.56k | } |
|
2770 | | |
2771 | | //---------------------------------------------------------- |
2772 | | |
2773 | | template<class Handler> |
2774 | | void |
2775 | | basic_parser<Handler>:: |
2776 | | reset() noexcept |
2777 | 35.9k | { |
2778 | 35.9k | ec_ = {}; |
2779 | 35.9k | st_.clear(); |
2780 | 35.9k | more_ = true; |
2781 | 35.9k | done_ = false; |
2782 | 35.9k | clean_ = true; |
2783 | 35.9k | num_buf_.clear(); |
2784 | 35.9k | } |
2785 | | |
2786 | | template<class Handler> |
2787 | | void |
2788 | | basic_parser<Handler>:: |
2789 | | fail(system::error_code ec) noexcept |
2790 | 2.32k | { |
2791 | 2.32k | if(! ec) |
2792 | 0 | { |
2793 | | // assign an arbitrary |
2794 | | // error code to prevent UB |
2795 | 0 | BOOST_JSON_FAIL(ec_, error::incomplete); |
2796 | 0 | } |
2797 | 2.32k | else |
2798 | 2.32k | { |
2799 | 2.32k | ec_ = ec; |
2800 | 2.32k | } |
2801 | 2.32k | done_ = false; |
2802 | 2.32k | } |
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 | 32.4k | { |
2815 | | // see if we exited via exception |
2816 | | // on the last call to write_some |
2817 | 32.4k | 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 | 32.4k | if(ec_) |
2826 | 0 | { |
2827 | | // error is sticky |
2828 | 0 | ec = ec_; |
2829 | 0 | return 0; |
2830 | 0 | } |
2831 | 32.4k | clean_ = false; |
2832 | 32.4k | more_ = more; |
2833 | 32.4k | end_ = data + size; |
2834 | 32.4k | const char* p; |
2835 | 32.4k | if(BOOST_JSON_LIKELY(st_.empty())) |
2836 | 22.1k | { |
2837 | | // first time |
2838 | 22.1k | depth_ = opt_.max_depth; |
2839 | 22.1k | if(BOOST_JSON_UNLIKELY( |
2840 | 22.1k | ! h_.on_document_begin(ec_))) |
2841 | 0 | { |
2842 | 0 | ec = ec_; |
2843 | 0 | return 0; |
2844 | 0 | } |
2845 | 22.1k | p = parse_document(data, std::true_type()); |
2846 | 22.1k | } |
2847 | 10.3k | else |
2848 | 10.3k | { |
2849 | 10.3k | p = parse_document(data, std::false_type()); |
2850 | 10.3k | } |
2851 | | |
2852 | 32.4k | if(BOOST_JSON_LIKELY(p != sentinel())) |
2853 | 11.3k | { |
2854 | 11.3k | BOOST_ASSERT(! ec_); |
2855 | 11.3k | if(! done_) |
2856 | 9.45k | { |
2857 | 9.45k | done_ = true; |
2858 | 9.45k | h_.on_document_end(ec_); |
2859 | 9.45k | } |
2860 | 11.3k | } |
2861 | 21.1k | else |
2862 | 21.1k | { |
2863 | 21.1k | if(! ec_) |
2864 | 15.3k | { |
2865 | 15.3k | if(! more_) |
2866 | 5.02k | { |
2867 | 5.02k | BOOST_JSON_FAIL(ec_, error::incomplete); |
2868 | 5.02k | } |
2869 | 10.3k | else if(! st_.empty()) |
2870 | 10.3k | { |
2871 | | // consume as much trailing whitespace in |
2872 | | // the JSON document as possible, but still |
2873 | | // consider the parse complete |
2874 | 10.3k | state st; |
2875 | 10.3k | st_.peek(st); |
2876 | 10.3k | if( st == state::doc3 && |
2877 | 1.93k | ! done_) |
2878 | 1.93k | { |
2879 | 1.93k | done_ = true; |
2880 | 1.93k | h_.on_document_end(ec_); |
2881 | 1.93k | } |
2882 | 10.3k | } |
2883 | 15.3k | } |
2884 | 21.1k | p = end_; |
2885 | 21.1k | } |
2886 | 32.4k | ec = ec_; |
2887 | 32.4k | clean_ = true; |
2888 | 32.4k | return p - data; |
2889 | 32.4k | } |
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 |