Coverage Report

Created: 2025-06-13 06:26

/src/boost/boost/json/basic_parser_impl.hpp
Line
Count
Source (jump to first uncovered line)
1
//
2
// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
3
// Copyright (c) 2020 Krystian Stasiowski (sdkrystian@gmail.com)
4
//
5
// Distributed under the Boost Software License, Version 1.0. (See accompanying
6
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7
//
8
// Official repository: https://github.com/boostorg/json
9
//
10
11
#ifndef BOOST_JSON_BASIC_PARSER_IMPL_HPP
12
#define BOOST_JSON_BASIC_PARSER_IMPL_HPP
13
14
#include <boost/json/detail/config.hpp>
15
#include <boost/json/detail/literals.hpp>
16
#include <boost/json/basic_parser.hpp>
17
#include <boost/json/error.hpp>
18
#include <boost/json/detail/buffer.hpp>
19
#include <boost/json/detail/charconv/from_chars.hpp>
20
#include <boost/json/detail/sse2.hpp>
21
#include <boost/mp11/algorithm.hpp>
22
#include <boost/mp11/integral.hpp>
23
#include <cmath>
24
#include <limits>
25
#include <cstring>
26
27
#ifdef _MSC_VER
28
#pragma warning(push)
29
#pragma warning(disable: 4702) // unreachable code
30
#pragma warning(disable: 4127) // conditional expression is constant
31
#endif
32
33
/*  This file must be manually included to get the
34
    function template definitions for basic_parser.
35
*/
36
37
/*  Reference:
38
39
    https://www.json.org/
40
41
    RFC 7159: The JavaScript Object Notation (JSON) Data Interchange Format
42
    https://tools.ietf.org/html/rfc7159
43
44
    https://ampl.com/netlib/fp/dtoa.c
45
*/
46
47
#ifndef BOOST_JSON_DOCS
48
49
namespace boost {
50
namespace json {
51
namespace detail {
52
53
inline
54
double
55
pow10(int exp) noexcept
56
5.61M
{
57
5.61M
    static double const tab[618] = {
58
5.61M
                        1e-308, 1e-307, 1e-306, 1e-305, 1e-304, 1e-303, 1e-302, 1e-301,
59
60
5.61M
        1e-300, 1e-299, 1e-298, 1e-297, 1e-296, 1e-295, 1e-294, 1e-293, 1e-292, 1e-291,
61
5.61M
        1e-290, 1e-289, 1e-288, 1e-287, 1e-286, 1e-285, 1e-284, 1e-283, 1e-282, 1e-281,
62
5.61M
        1e-280, 1e-279, 1e-278, 1e-277, 1e-276, 1e-275, 1e-274, 1e-273, 1e-272, 1e-271,
63
5.61M
        1e-270, 1e-269, 1e-268, 1e-267, 1e-266, 1e-265, 1e-264, 1e-263, 1e-262, 1e-261,
64
5.61M
        1e-260, 1e-259, 1e-258, 1e-257, 1e-256, 1e-255, 1e-254, 1e-253, 1e-252, 1e-251,
65
5.61M
        1e-250, 1e-249, 1e-248, 1e-247, 1e-246, 1e-245, 1e-244, 1e-243, 1e-242, 1e-241,
66
5.61M
        1e-240, 1e-239, 1e-238, 1e-237, 1e-236, 1e-235, 1e-234, 1e-233, 1e-232, 1e-231,
67
5.61M
        1e-230, 1e-229, 1e-228, 1e-227, 1e-226, 1e-225, 1e-224, 1e-223, 1e-222, 1e-221,
68
5.61M
        1e-220, 1e-219, 1e-218, 1e-217, 1e-216, 1e-215, 1e-214, 1e-213, 1e-212, 1e-211,
69
5.61M
        1e-210, 1e-209, 1e-208, 1e-207, 1e-206, 1e-205, 1e-204, 1e-203, 1e-202, 1e-201,
70
71
5.61M
        1e-200, 1e-199, 1e-198, 1e-197, 1e-196, 1e-195, 1e-194, 1e-193, 1e-192, 1e-191,
72
5.61M
        1e-190, 1e-189, 1e-188, 1e-187, 1e-186, 1e-185, 1e-184, 1e-183, 1e-182, 1e-181,
73
5.61M
        1e-180, 1e-179, 1e-178, 1e-177, 1e-176, 1e-175, 1e-174, 1e-173, 1e-172, 1e-171,
74
5.61M
        1e-170, 1e-169, 1e-168, 1e-167, 1e-166, 1e-165, 1e-164, 1e-163, 1e-162, 1e-161,
75
5.61M
        1e-160, 1e-159, 1e-158, 1e-157, 1e-156, 1e-155, 1e-154, 1e-153, 1e-152, 1e-151,
76
5.61M
        1e-150, 1e-149, 1e-148, 1e-147, 1e-146, 1e-145, 1e-144, 1e-143, 1e-142, 1e-141,
77
5.61M
        1e-140, 1e-139, 1e-138, 1e-137, 1e-136, 1e-135, 1e-134, 1e-133, 1e-132, 1e-131,
78
5.61M
        1e-130, 1e-129, 1e-128, 1e-127, 1e-126, 1e-125, 1e-124, 1e-123, 1e-122, 1e-121,
79
5.61M
        1e-120, 1e-119, 1e-118, 1e-117, 1e-116, 1e-115, 1e-114, 1e-113, 1e-112, 1e-111,
80
5.61M
        1e-110, 1e-109, 1e-108, 1e-107, 1e-106, 1e-105, 1e-104, 1e-103, 1e-102, 1e-101,
81
82
5.61M
        1e-100, 1e-099, 1e-098, 1e-097, 1e-096, 1e-095, 1e-094, 1e-093, 1e-092, 1e-091,
83
5.61M
        1e-090, 1e-089, 1e-088, 1e-087, 1e-086, 1e-085, 1e-084, 1e-083, 1e-082, 1e-081,
84
5.61M
        1e-080, 1e-079, 1e-078, 1e-077, 1e-076, 1e-075, 1e-074, 1e-073, 1e-072, 1e-071,
85
5.61M
        1e-070, 1e-069, 1e-068, 1e-067, 1e-066, 1e-065, 1e-064, 1e-063, 1e-062, 1e-061,
86
5.61M
        1e-060, 1e-059, 1e-058, 1e-057, 1e-056, 1e-055, 1e-054, 1e-053, 1e-052, 1e-051,
87
5.61M
        1e-050, 1e-049, 1e-048, 1e-047, 1e-046, 1e-045, 1e-044, 1e-043, 1e-042, 1e-041,
88
5.61M
        1e-040, 1e-039, 1e-038, 1e-037, 1e-036, 1e-035, 1e-034, 1e-033, 1e-032, 1e-031,
89
5.61M
        1e-030, 1e-029, 1e-028, 1e-027, 1e-026, 1e-025, 1e-024, 1e-023, 1e-022, 1e-021,
90
5.61M
        1e-020, 1e-019, 1e-018, 1e-017, 1e-016, 1e-015, 1e-014, 1e-013, 1e-012, 1e-011,
91
5.61M
        1e-010, 1e-009, 1e-008, 1e-007, 1e-006, 1e-005, 1e-004, 1e-003, 1e-002, 1e-001,
92
93
5.61M
        1e+000, 1e+001, 1e+002, 1e+003, 1e+004, 1e+005, 1e+006, 1e+007, 1e+008, 1e+009,
94
5.61M
        1e+010, 1e+011, 1e+012, 1e+013, 1e+014, 1e+015, 1e+016, 1e+017, 1e+018, 1e+019,
95
5.61M
        1e+020, 1e+021, 1e+022, 1e+023, 1e+024, 1e+025, 1e+026, 1e+027, 1e+028, 1e+029,
96
5.61M
        1e+030, 1e+031, 1e+032, 1e+033, 1e+034, 1e+035, 1e+036, 1e+037, 1e+038, 1e+039,
97
5.61M
        1e+040, 1e+041, 1e+042, 1e+043, 1e+044, 1e+045, 1e+046, 1e+047, 1e+048, 1e+049,
98
5.61M
        1e+050, 1e+051, 1e+052, 1e+053, 1e+054, 1e+055, 1e+056, 1e+057, 1e+058, 1e+059,
99
5.61M
        1e+060, 1e+061, 1e+062, 1e+063, 1e+064, 1e+065, 1e+066, 1e+067, 1e+068, 1e+069,
100
5.61M
        1e+070, 1e+071, 1e+072, 1e+073, 1e+074, 1e+075, 1e+076, 1e+077, 1e+078, 1e+079,
101
5.61M
        1e+080, 1e+081, 1e+082, 1e+083, 1e+084, 1e+085, 1e+086, 1e+087, 1e+088, 1e+089,
102
5.61M
        1e+090, 1e+091, 1e+092, 1e+093, 1e+094, 1e+095, 1e+096, 1e+097, 1e+098, 1e+099,
103
104
5.61M
        1e+100, 1e+101, 1e+102, 1e+103, 1e+104, 1e+105, 1e+106, 1e+107, 1e+108, 1e+109,
105
5.61M
        1e+110, 1e+111, 1e+112, 1e+113, 1e+114, 1e+115, 1e+116, 1e+117, 1e+118, 1e+119,
106
5.61M
        1e+120, 1e+121, 1e+122, 1e+123, 1e+124, 1e+125, 1e+126, 1e+127, 1e+128, 1e+129,
107
5.61M
        1e+130, 1e+131, 1e+132, 1e+133, 1e+134, 1e+135, 1e+136, 1e+137, 1e+138, 1e+139,
108
5.61M
        1e+140, 1e+141, 1e+142, 1e+143, 1e+144, 1e+145, 1e+146, 1e+147, 1e+148, 1e+149,
109
5.61M
        1e+150, 1e+151, 1e+152, 1e+153, 1e+154, 1e+155, 1e+156, 1e+157, 1e+158, 1e+159,
110
5.61M
        1e+160, 1e+161, 1e+162, 1e+163, 1e+164, 1e+165, 1e+166, 1e+167, 1e+168, 1e+169,
111
5.61M
        1e+170, 1e+171, 1e+172, 1e+173, 1e+174, 1e+175, 1e+176, 1e+177, 1e+178, 1e+179,
112
5.61M
        1e+180, 1e+181, 1e+182, 1e+183, 1e+184, 1e+185, 1e+186, 1e+187, 1e+188, 1e+189,
113
5.61M
        1e+190, 1e+191, 1e+192, 1e+193, 1e+194, 1e+195, 1e+196, 1e+197, 1e+198, 1e+199,
114
115
5.61M
        1e+200, 1e+201, 1e+202, 1e+203, 1e+204, 1e+205, 1e+206, 1e+207, 1e+208, 1e+209,
116
5.61M
        1e+210, 1e+211, 1e+212, 1e+213, 1e+214, 1e+215, 1e+216, 1e+217, 1e+218, 1e+219,
117
5.61M
        1e+220, 1e+221, 1e+222, 1e+223, 1e+224, 1e+225, 1e+226, 1e+227, 1e+228, 1e+229,
118
5.61M
        1e+230, 1e+231, 1e+232, 1e+233, 1e+234, 1e+235, 1e+236, 1e+237, 1e+238, 1e+239,
119
5.61M
        1e+240, 1e+241, 1e+242, 1e+243, 1e+244, 1e+245, 1e+246, 1e+247, 1e+248, 1e+249,
120
5.61M
        1e+250, 1e+251, 1e+252, 1e+253, 1e+254, 1e+255, 1e+256, 1e+257, 1e+258, 1e+259,
121
5.61M
        1e+260, 1e+261, 1e+262, 1e+263, 1e+264, 1e+265, 1e+266, 1e+267, 1e+268, 1e+269,
122
5.61M
        1e+270, 1e+271, 1e+272, 1e+273, 1e+274, 1e+275, 1e+276, 1e+277, 1e+278, 1e+279,
123
5.61M
        1e+280, 1e+281, 1e+282, 1e+283, 1e+284, 1e+285, 1e+286, 1e+287, 1e+288, 1e+289,
124
5.61M
        1e+290, 1e+291, 1e+292, 1e+293, 1e+294, 1e+295, 1e+296, 1e+297, 1e+298, 1e+299,
125
126
5.61M
        1e+300, 1e+301, 1e+302, 1e+303, 1e+304, 1e+305, 1e+306, 1e+307, 1e+308 };
127
128
5.61M
    if( exp > 308 )
129
41.3k
    {
130
41.3k
        return std::numeric_limits<double>::infinity();
131
41.3k
    }
132
5.57M
    else if( exp < -308 )
133
3.89k
    {
134
        // due to the way pow10 is used by dec_to_float,
135
        // we can afford to return 0.0 here
136
3.89k
        return 0.0;
137
3.89k
    }
138
5.57M
    else
139
5.57M
    {
140
5.57M
        exp += 308;
141
5.57M
        BOOST_ASSERT(exp >= 0 && exp < 618);
142
5.57M
        return tab[exp];
143
5.57M
    }
144
5.61M
}
145
146
inline
147
double
148
dec_to_float(
149
    std::uint64_t m,
150
    std::int32_t e,
151
    bool neg) noexcept
152
5.61M
{
153
    // convert to double explicitly to silence warnings
154
5.61M
    double x = static_cast<double>(m);
155
5.61M
    if(neg)
156
20.0k
        x = -x;
157
158
5.61M
    if(e < -305)
159
4.61k
    {
160
4.61k
        x *= 1e-305 ;
161
4.61k
        e += 305;
162
4.61k
    }
163
164
5.61M
    if(e >= -22 && e < 0)
165
26.9k
        return x / pow10(-e);
166
167
5.59M
    return x * pow10(e);
168
5.61M
}
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
1.17M
{
181
    // by Peter Dimov
182
1.17M
    if( c >= '0' && c <= '9' )
183
1.08M
        return c - '0';
184
81.2k
    c &= ~0x20;
185
81.2k
    if( c >= 'A' && c <= 'F' )
186
80.8k
        return 10 + c - 'A';
187
351
    return -1;
188
81.2k
}
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
9.66M
    {
206
9.66M
        return parser->parse_number(
207
9.66M
            p,
208
9.66M
            std::integral_constant<bool, StackEmpty_>(),
209
9.66M
            std::integral_constant<char, First_>(),
210
9.66M
            std::integral_constant<
211
9.66M
                number_precision, static_cast<number_precision>(N)>() );
212
9.66M
    }
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
63.9k
    {
206
63.9k
        return parser->parse_number(
207
63.9k
            p,
208
63.9k
            std::integral_constant<bool, StackEmpty_>(),
209
63.9k
            std::integral_constant<char, First_>(),
210
63.9k
            std::integral_constant<
211
63.9k
                number_precision, static_cast<number_precision>(N)>() );
212
63.9k
    }
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
302k
    {
206
302k
        return parser->parse_number(
207
302k
            p,
208
302k
            std::integral_constant<bool, StackEmpty_>(),
209
302k
            std::integral_constant<char, First_>(),
210
302k
            std::integral_constant<
211
302k
                number_precision, static_cast<number_precision>(N)>() );
212
302k
    }
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
45.5k
    {
206
45.5k
        return parser->parse_number(
207
45.5k
            p,
208
45.5k
            std::integral_constant<bool, StackEmpty_>(),
209
45.5k
            std::integral_constant<char, First_>(),
210
45.5k
            std::integral_constant<
211
45.5k
                number_precision, static_cast<number_precision>(N)>() );
212
45.5k
    }
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
29.6k
    {
206
29.6k
        return parser->parse_number(
207
29.6k
            p,
208
29.6k
            std::integral_constant<bool, StackEmpty_>(),
209
29.6k
            std::integral_constant<char, First_>(),
210
29.6k
            std::integral_constant<
211
29.6k
                number_precision, static_cast<number_precision>(N)>() );
212
29.6k
    }
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
16.9k
    {
206
16.9k
        return parser->parse_number(
207
16.9k
            p,
208
16.9k
            std::integral_constant<bool, StackEmpty_>(),
209
16.9k
            std::integral_constant<char, First_>(),
210
16.9k
            std::integral_constant<
211
16.9k
                number_precision, static_cast<number_precision>(N)>() );
212
16.9k
    }
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.63k
    {
206
4.63k
        return parser->parse_number(
207
4.63k
            p,
208
4.63k
            std::integral_constant<bool, StackEmpty_>(),
209
4.63k
            std::integral_constant<char, First_>(),
210
4.63k
            std::integral_constant<
211
4.63k
                number_precision, static_cast<number_precision>(N)>() );
212
4.63k
    }
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
8.31M
    {
206
8.31M
        return parser->parse_number(
207
8.31M
            p,
208
8.31M
            std::integral_constant<bool, StackEmpty_>(),
209
8.31M
            std::integral_constant<char, First_>(),
210
8.31M
            std::integral_constant<
211
8.31M
                number_precision, static_cast<number_precision>(N)>() );
212
8.31M
    }
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
280k
    {
206
280k
        return parser->parse_number(
207
280k
            p,
208
280k
            std::integral_constant<bool, StackEmpty_>(),
209
280k
            std::integral_constant<char, First_>(),
210
280k
            std::integral_constant<
211
280k
                number_precision, static_cast<number_precision>(N)>() );
212
280k
    }
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
603k
    {
206
603k
        return parser->parse_number(
207
603k
            p,
208
603k
            std::integral_constant<bool, StackEmpty_>(),
209
603k
            std::integral_constant<char, First_>(),
210
603k
            std::integral_constant<
211
603k
                number_precision, static_cast<number_precision>(N)>() );
212
603k
    }
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.12k
    {
206
2.12k
        return parser->parse_number(
207
2.12k
            p,
208
2.12k
            std::integral_constant<bool, StackEmpty_>(),
209
2.12k
            std::integral_constant<char, First_>(),
210
2.12k
            std::integral_constant<
211
2.12k
                number_precision, static_cast<number_precision>(N)>() );
212
2.12k
    }
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.35k
    {
206
4.35k
        return parser->parse_number(
207
4.35k
            p,
208
4.35k
            std::integral_constant<bool, StackEmpty_>(),
209
4.35k
            std::integral_constant<char, First_>(),
210
4.35k
            std::integral_constant<
211
4.35k
                number_precision, static_cast<number_precision>(N)>() );
212
4.35k
    }
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
360
    {
206
360
        return parser->parse_number(
207
360
            p,
208
360
            std::integral_constant<bool, StackEmpty_>(),
209
360
            std::integral_constant<char, First_>(),
210
360
            std::integral_constant<
211
360
                number_precision, static_cast<number_precision>(N)>() );
212
360
    }
213
};
214
215
//----------------------------------------------------------
216
217
template<class Handler>
218
void
219
basic_parser<Handler>::
220
reserve()
221
13.8k
{
222
13.8k
    if(BOOST_JSON_LIKELY(
223
13.8k
        ! st_.empty()))
224
3.04k
        return;
225
    // Reserve the largest stack we need,
226
    // to avoid reallocation during suspend.
227
10.7k
    st_.reserve(
228
10.7k
        sizeof(state) + // document parsing state
229
10.7k
        (sizeof(state) +
230
10.7k
            sizeof(std::size_t)) * depth() + // array and object state + size
231
10.7k
        sizeof(state) + // value parsing state
232
10.7k
        sizeof(std::size_t) + // string size
233
10.7k
        sizeof(state)); // comment state
234
10.7k
}
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
10.3M
{
248
    // the "+1" ensures that the returned pointer is unique even if
249
    // the given input buffer borders on this object
250
10.3M
    return reinterpret_cast<
251
10.3M
        const char*>(this) + 1;
252
10.3M
}
253
254
template<class Handler>
255
bool
256
basic_parser<Handler>::
257
incomplete(
258
    const detail::const_stream_wrapper& cs)
259
10.3M
{
260
10.3M
    return cs.begin() == sentinel();
261
10.3M
}
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
6.94k
{
292
6.94k
    if(BOOST_JSON_LIKELY(
293
6.94k
        ! ec_ && more_))
294
2.99k
    {
295
        // suspend
296
2.99k
        reserve();
297
2.99k
        st_.push_unchecked(n);
298
2.99k
        st_.push_unchecked(st);
299
2.99k
    }
300
6.94k
    return sentinel();
301
6.94k
}
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
3.39k
{
322
3.39k
    BOOST_ASSERT( p != sentinel() );
323
3.39k
    end_ = p;
324
3.39k
    ec_.assign(ev, loc);
325
3.39k
    return sentinel();
326
3.39k
}
327
328
template<class Handler>
329
const char*
330
basic_parser<Handler>::
331
maybe_suspend(
332
    const char* p,
333
    state st)
334
1.06k
{
335
1.06k
    if( p != sentinel() )
336
972
        end_ = p;
337
1.06k
    if(BOOST_JSON_LIKELY(more_))
338
535
    {
339
        // suspend
340
535
        reserve();
341
535
        st_.push_unchecked(st);
342
535
    }
343
1.06k
    return sentinel();
344
1.06k
}
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
4.06k
{
354
4.06k
    BOOST_ASSERT( p != sentinel() );
355
4.06k
    end_ = p;
356
4.06k
    if(BOOST_JSON_LIKELY(more_))
357
1.50k
    {
358
        // suspend
359
1.50k
        reserve();
360
1.50k
        st_.push_unchecked(n);
361
1.50k
        st_.push_unchecked(st);
362
1.50k
    }
363
4.06k
    return sentinel();
364
4.06k
}
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
492
{
374
492
    BOOST_ASSERT( p != sentinel() );
375
492
    end_ = p;
376
492
    if(BOOST_JSON_LIKELY(more_))
377
246
    {
378
        // suspend
379
246
        num_ = num;
380
246
        reserve();
381
246
        st_.push_unchecked(st);;
382
246
    }
383
492
    return sentinel();
384
492
}
385
386
template<class Handler>
387
const char*
388
basic_parser<Handler>::
389
suspend(
390
    const char* p,
391
    state st)
392
1.95k
{
393
1.95k
    BOOST_ASSERT( p != sentinel() );
394
1.95k
    end_ = p;
395
    // suspend
396
1.95k
    reserve();
397
1.95k
    st_.push_unchecked(st);
398
1.95k
    return sentinel();
399
1.95k
}
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.59k
{
409
6.59k
    BOOST_ASSERT( p != sentinel() );
410
6.59k
    end_ = p;
411
    // suspend
412
6.59k
    num_ = num;
413
6.59k
    reserve();
414
6.59k
    st_.push_unchecked(st);
415
6.59k
    return sentinel();
416
6.59k
}
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
4.90k
{
428
4.90k
    detail::const_stream_wrapper cs(p, end_);
429
4.90k
    const char* start = cs.begin();
430
4.90k
    std::size_t remain;
431
4.90k
    if(! stack_empty && ! st_.empty())
432
118
    {
433
118
        state st;
434
118
        st_.pop(st);
435
118
        switch(st)
436
118
        {
437
0
            default: BOOST_JSON_UNREACHABLE();
438
79
            case state::com1: goto do_com1;
439
14
            case state::com2: goto do_com2;
440
19
            case state::com3: goto do_com3;
441
6
            case state::com4: goto do_com4;
442
118
        }
443
118
    }
444
4.78k
    BOOST_ASSERT(*cs == '/');
445
4.78k
    ++cs;
446
4.86k
do_com1:
447
4.86k
    if(BOOST_JSON_UNLIKELY(! cs))
448
158
        return maybe_suspend(cs.begin(), state::com1);
449
4.70k
    switch(*cs)
450
4.70k
    {
451
19
    default:
452
19
        {
453
19
            BOOST_STATIC_CONSTEXPR source_location loc
454
19
                = BOOST_CURRENT_LOCATION;
455
19
            return fail(cs.begin(), error::syntax, &loc);
456
0
        }
457
4.47k
    case '/':
458
4.47k
        ++cs;
459
4.48k
do_com2:
460
        // KRYSTIAN TODO: this is a mess, we have to fix this
461
4.48k
        remain = cs.remain();
462
4.48k
        cs = remain ? static_cast<const char*>(
463
4.46k
            std::memchr(cs.begin(), '\n', remain)) : sentinel();
464
4.48k
        if(! cs.begin())
465
6
            cs = sentinel();
466
4.48k
        if(BOOST_JSON_UNLIKELY(incomplete(cs)))
467
28
        {
468
            // if the doc does not terminate
469
            // with a newline, treat it as the
470
            // end of the comment
471
28
            if(terminal && ! more_)
472
2
            {
473
2
                if(BOOST_JSON_UNLIKELY(! h_.on_comment(
474
2
                    {start, cs.remain(start)}, ec_)))
475
0
                    return fail(cs.end());
476
2
                return cs.end();
477
2
            }
478
26
            if(BOOST_JSON_UNLIKELY(! h_.on_comment_part(
479
26
                {start, cs.remain(start)}, ec_)))
480
0
                return fail(cs.end());
481
26
            if(terminal)
482
2
                return suspend(cs.end(), state::com2);
483
24
            return maybe_suspend(cs.end(), state::com2);
484
26
        }
485
4.45k
        break;
486
4.45k
    case '*':
487
219
        do
488
767
        {
489
767
            ++cs;
490
786
do_com3:
491
            // KRYSTIAN TODO: this is a mess, we have to fix this
492
786
            remain = cs.remain();
493
786
            cs = remain ? static_cast<const char*>(
494
752
                std::memchr(cs.begin(), '*', remain)) : sentinel();
495
786
            if(! cs.begin())
496
4
                cs = sentinel();
497
            // stopped inside a c comment
498
786
            if(BOOST_JSON_UNLIKELY(incomplete(cs)))
499
38
            {
500
38
                if(BOOST_JSON_UNLIKELY(! h_.on_comment_part(
501
38
                    {start, cs.remain(start)}, ec_)))
502
0
                    return fail(cs.end());
503
38
                return maybe_suspend(cs.end(), state::com3);
504
38
            }
505
            // found a asterisk, check if the next char is a slash
506
748
            ++cs;
507
754
do_com4:
508
754
            if(BOOST_JSON_UNLIKELY(! cs))
509
12
            {
510
12
                if(BOOST_JSON_UNLIKELY(! h_.on_comment_part(
511
12
                    {start, cs.used(start)}, ec_)))
512
0
                    return fail(cs.begin());
513
12
                return maybe_suspend(cs.begin(), state::com4);
514
12
            }
515
754
        }
516
742
        while(*cs != '/');
517
4.70k
    }
518
4.65k
    ++cs;
519
4.65k
    if(BOOST_JSON_UNLIKELY(! h_.on_comment(
520
4.65k
        {start, cs.used(start)}, ec_)))
521
0
        return fail(cs.begin());
522
4.65k
    return cs.begin();
523
4.65k
}
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
4.78k
{
428
4.78k
    detail::const_stream_wrapper cs(p, end_);
429
4.78k
    const char* start = cs.begin();
430
4.78k
    std::size_t remain;
431
4.78k
    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
4.78k
    BOOST_ASSERT(*cs == '/');
445
4.78k
    ++cs;
446
4.78k
do_com1:
447
4.78k
    if(BOOST_JSON_UNLIKELY(! cs))
448
79
        return maybe_suspend(cs.begin(), state::com1);
449
4.70k
    switch(*cs)
450
4.70k
    {
451
19
    default:
452
19
        {
453
19
            BOOST_STATIC_CONSTEXPR source_location loc
454
19
                = BOOST_CURRENT_LOCATION;
455
19
            return fail(cs.begin(), error::syntax, &loc);
456
0
        }
457
4.47k
    case '/':
458
4.47k
        ++cs;
459
4.47k
do_com2:
460
        // KRYSTIAN TODO: this is a mess, we have to fix this
461
4.47k
        remain = cs.remain();
462
4.47k
        cs = remain ? static_cast<const char*>(
463
4.46k
            std::memchr(cs.begin(), '\n', remain)) : sentinel();
464
4.47k
        if(! cs.begin())
465
6
            cs = sentinel();
466
4.47k
        if(BOOST_JSON_UNLIKELY(incomplete(cs)))
467
14
        {
468
            // if the doc does not terminate
469
            // with a newline, treat it as the
470
            // end of the comment
471
14
            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
14
            if(BOOST_JSON_UNLIKELY(! h_.on_comment_part(
479
14
                {start, cs.remain(start)}, ec_)))
480
0
                return fail(cs.end());
481
14
            if(terminal)
482
2
                return suspend(cs.end(), state::com2);
483
12
            return maybe_suspend(cs.end(), state::com2);
484
14
        }
485
4.45k
        break;
486
4.45k
    case '*':
487
219
        do
488
767
        {
489
767
            ++cs;
490
767
do_com3:
491
            // KRYSTIAN TODO: this is a mess, we have to fix this
492
767
            remain = cs.remain();
493
767
            cs = remain ? static_cast<const char*>(
494
752
                std::memchr(cs.begin(), '*', remain)) : sentinel();
495
767
            if(! cs.begin())
496
4
                cs = sentinel();
497
            // stopped inside a c comment
498
767
            if(BOOST_JSON_UNLIKELY(incomplete(cs)))
499
19
            {
500
19
                if(BOOST_JSON_UNLIKELY(! h_.on_comment_part(
501
19
                    {start, cs.remain(start)}, ec_)))
502
0
                    return fail(cs.end());
503
19
                return maybe_suspend(cs.end(), state::com3);
504
19
            }
505
            // found a asterisk, check if the next char is a slash
506
748
            ++cs;
507
748
do_com4:
508
748
            if(BOOST_JSON_UNLIKELY(! cs))
509
6
            {
510
6
                if(BOOST_JSON_UNLIKELY(! h_.on_comment_part(
511
6
                    {start, cs.used(start)}, ec_)))
512
0
                    return fail(cs.begin());
513
6
                return maybe_suspend(cs.begin(), state::com4);
514
6
            }
515
748
        }
516
742
        while(*cs != '/');
517
4.70k
    }
518
4.65k
    ++cs;
519
4.65k
    if(BOOST_JSON_UNLIKELY(! h_.on_comment(
520
4.65k
        {start, cs.used(start)}, ec_)))
521
0
        return fail(cs.begin());
522
4.65k
    return cs.begin();
523
4.65k
}
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
118
{
428
118
    detail::const_stream_wrapper cs(p, end_);
429
118
    const char* start = cs.begin();
430
118
    std::size_t remain;
431
118
    if(! stack_empty && ! st_.empty())
432
118
    {
433
118
        state st;
434
118
        st_.pop(st);
435
118
        switch(st)
436
118
        {
437
0
            default: BOOST_JSON_UNREACHABLE();
438
79
            case state::com1: goto do_com1;
439
14
            case state::com2: goto do_com2;
440
19
            case state::com3: goto do_com3;
441
6
            case state::com4: goto do_com4;
442
118
        }
443
118
    }
444
0
    BOOST_ASSERT(*cs == '/');
445
0
    ++cs;
446
79
do_com1:
447
79
    if(BOOST_JSON_UNLIKELY(! cs))
448
79
        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
14
do_com2:
460
        // KRYSTIAN TODO: this is a mess, we have to fix this
461
14
        remain = cs.remain();
462
14
        cs = remain ? static_cast<const char*>(
463
14
            std::memchr(cs.begin(), '\n', remain)) : sentinel();
464
14
        if(! cs.begin())
465
0
            cs = sentinel();
466
14
        if(BOOST_JSON_UNLIKELY(incomplete(cs)))
467
14
        {
468
            // if the doc does not terminate
469
            // with a newline, treat it as the
470
            // end of the comment
471
14
            if(terminal && ! more_)
472
2
            {
473
2
                if(BOOST_JSON_UNLIKELY(! h_.on_comment(
474
2
                    {start, cs.remain(start)}, ec_)))
475
0
                    return fail(cs.end());
476
2
                return cs.end();
477
2
            }
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
0
                return suspend(cs.end(), state::com2);
483
12
            return maybe_suspend(cs.end(), state::com2);
484
12
        }
485
0
        break;
486
0
    case '*':
487
0
        do
488
0
        {
489
0
            ++cs;
490
19
do_com3:
491
            // KRYSTIAN TODO: this is a mess, we have to fix this
492
19
            remain = cs.remain();
493
19
            cs = remain ? static_cast<const char*>(
494
19
                std::memchr(cs.begin(), '*', remain)) : sentinel();
495
19
            if(! cs.begin())
496
0
                cs = sentinel();
497
            // stopped inside a c comment
498
19
            if(BOOST_JSON_UNLIKELY(incomplete(cs)))
499
19
            {
500
19
                if(BOOST_JSON_UNLIKELY(! h_.on_comment_part(
501
19
                    {start, cs.remain(start)}, ec_)))
502
0
                    return fail(cs.end());
503
19
                return maybe_suspend(cs.end(), state::com3);
504
19
            }
505
            // found a asterisk, check if the next char is a slash
506
0
            ++cs;
507
6
do_com4:
508
6
            if(BOOST_JSON_UNLIKELY(! cs))
509
6
            {
510
6
                if(BOOST_JSON_UNLIKELY(! h_.on_comment_part(
511
6
                    {start, cs.used(start)}, ec_)))
512
0
                    return fail(cs.begin());
513
6
                return maybe_suspend(cs.begin(), state::com4);
514
6
            }
515
6
        }
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
26.9k
{
532
26.9k
    detail::const_stream_wrapper cs(p, end_);
533
26.9k
    if(! stack_empty && ! st_.empty())
534
10.7k
    {
535
10.7k
        state st;
536
10.7k
        st_.peek(st);
537
10.7k
        switch(st)
538
10.7k
        {
539
8.76k
        default: goto do_doc2;
540
8.76k
        case state::doc1:
541
47
                 st_.pop(st);
542
47
                 goto do_doc1;
543
1.95k
        case state::doc3:
544
1.95k
                 st_.pop(st);
545
1.95k
                 goto do_doc3;
546
21
        case state::com1: case state::com2:
547
24
        case state::com3: case state::com4:
548
24
                 goto do_doc4;
549
10.7k
        }
550
10.7k
    }
551
16.2k
do_doc1:
552
16.2k
    cs = detail::count_whitespace(cs.begin(), cs.end());
553
16.2k
    if(BOOST_JSON_UNLIKELY(! cs))
554
94
        return maybe_suspend(cs.begin(), state::doc1);
555
24.8k
do_doc2:
556
24.8k
    switch(+opt_.allow_comments |
557
24.8k
        (opt_.allow_trailing_commas << 1) |
558
24.8k
        (opt_.allow_invalid_utf8 << 2))
559
24.8k
    {
560
    // no extensions
561
2.91k
    default:
562
2.91k
        cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::false_type(), std::false_type(), opt_.allow_invalid_utf16);
563
2.91k
        break;
564
    // comments
565
2.53k
    case 1:
566
2.53k
        cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::false_type(), std::false_type(), opt_.allow_invalid_utf16);
567
2.53k
        break;
568
    // trailing
569
1.82k
    case 2:
570
1.82k
        cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::true_type(), std::false_type(), opt_.allow_invalid_utf16);
571
1.82k
        break;
572
    // comments & trailing
573
3.15k
    case 3:
574
3.15k
        cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::true_type(), std::false_type(), opt_.allow_invalid_utf16);
575
3.15k
        break;
576
    // skip validation
577
2.35k
    case 4:
578
2.35k
        cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::false_type(), std::true_type(), opt_.allow_invalid_utf16);
579
2.35k
        break;
580
    // comments & skip validation
581
3.22k
    case 5:
582
3.22k
        cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::false_type(), std::true_type(), opt_.allow_invalid_utf16);
583
3.22k
        break;
584
    // trailing & skip validation
585
4.95k
    case 6:
586
4.95k
        cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::true_type(), std::true_type(), opt_.allow_invalid_utf16);
587
4.95k
        break;
588
    // comments & trailing & skip validation
589
3.91k
    case 7:
590
3.91k
        cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::true_type(), std::true_type(), opt_.allow_invalid_utf16);
591
3.91k
        break;
592
24.8k
    }
593
24.7k
    if(BOOST_JSON_UNLIKELY(incomplete(cs)))
594
        // the appropriate state has already been pushed into stack
595
15.3k
        return sentinel();
596
11.8k
do_doc3:
597
11.8k
    cs = detail::count_whitespace(cs.begin(), cs.end());
598
11.8k
    if(BOOST_JSON_UNLIKELY(! cs))
599
9.21k
    {
600
9.21k
        if(more_)
601
1.95k
            return suspend(cs.begin(), state::doc3);
602
9.21k
    }
603
2.65k
    else if(opt_.allow_comments && *cs == '/')
604
616
    {
605
640
do_doc4:
606
640
        cs = parse_comment(cs.begin(), stack_empty, std::true_type());
607
640
        if(BOOST_JSON_UNLIKELY(incomplete(cs)))
608
50
            return sentinel();
609
590
        goto do_doc3;
610
640
    }
611
9.30k
    return cs.begin();
612
11.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
16.1k
{
532
16.1k
    detail::const_stream_wrapper cs(p, end_);
533
16.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
16.1k
do_doc1:
552
16.1k
    cs = detail::count_whitespace(cs.begin(), cs.end());
553
16.1k
    if(BOOST_JSON_UNLIKELY(! cs))
554
47
        return maybe_suspend(cs.begin(), state::doc1);
555
16.1k
do_doc2:
556
16.1k
    switch(+opt_.allow_comments |
557
16.1k
        (opt_.allow_trailing_commas << 1) |
558
16.1k
        (opt_.allow_invalid_utf8 << 2))
559
16.1k
    {
560
    // no extensions
561
1.79k
    default:
562
1.79k
        cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::false_type(), std::false_type(), opt_.allow_invalid_utf16);
563
1.79k
        break;
564
    // comments
565
1.59k
    case 1:
566
1.59k
        cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::false_type(), std::false_type(), opt_.allow_invalid_utf16);
567
1.59k
        break;
568
    // trailing
569
1.16k
    case 2:
570
1.16k
        cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::true_type(), std::false_type(), opt_.allow_invalid_utf16);
571
1.16k
        break;
572
    // comments & trailing
573
2.02k
    case 3:
574
2.02k
        cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::true_type(), std::false_type(), opt_.allow_invalid_utf16);
575
2.02k
        break;
576
    // skip validation
577
1.46k
    case 4:
578
1.46k
        cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::false_type(), std::true_type(), opt_.allow_invalid_utf16);
579
1.46k
        break;
580
    // comments & skip validation
581
2.19k
    case 5:
582
2.19k
        cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::false_type(), std::true_type(), opt_.allow_invalid_utf16);
583
2.19k
        break;
584
    // trailing & skip validation
585
3.26k
    case 6:
586
3.26k
        cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::true_type(), std::true_type(), opt_.allow_invalid_utf16);
587
3.26k
        break;
588
    // comments & trailing & skip validation
589
2.61k
    case 7:
590
2.61k
        cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::true_type(), std::true_type(), opt_.allow_invalid_utf16);
591
2.61k
        break;
592
16.1k
    }
593
16.0k
    if(BOOST_JSON_UNLIKELY(incomplete(cs)))
594
        // the appropriate state has already been pushed into stack
595
12.0k
        return sentinel();
596
4.60k
do_doc3:
597
4.60k
    cs = detail::count_whitespace(cs.begin(), cs.end());
598
4.60k
    if(BOOST_JSON_UNLIKELY(! cs))
599
1.95k
    {
600
1.95k
        if(more_)
601
1.95k
            return suspend(cs.begin(), state::doc3);
602
1.95k
    }
603
2.65k
    else if(opt_.allow_comments && *cs == '/')
604
616
    {
605
616
do_doc4:
606
616
        cs = parse_comment(cs.begin(), stack_empty, std::true_type());
607
616
        if(BOOST_JSON_UNLIKELY(incomplete(cs)))
608
28
            return sentinel();
609
588
        goto do_doc3;
610
616
    }
611
2.04k
    return cs.begin();
612
4.60k
}
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.7k
{
532
10.7k
    detail::const_stream_wrapper cs(p, end_);
533
10.7k
    if(! stack_empty && ! st_.empty())
534
10.7k
    {
535
10.7k
        state st;
536
10.7k
        st_.peek(st);
537
10.7k
        switch(st)
538
10.7k
        {
539
8.76k
        default: goto do_doc2;
540
8.76k
        case state::doc1:
541
47
                 st_.pop(st);
542
47
                 goto do_doc1;
543
1.95k
        case state::doc3:
544
1.95k
                 st_.pop(st);
545
1.95k
                 goto do_doc3;
546
21
        case state::com1: case state::com2:
547
24
        case state::com3: case state::com4:
548
24
                 goto do_doc4;
549
10.7k
        }
550
10.7k
    }
551
47
do_doc1:
552
47
    cs = detail::count_whitespace(cs.begin(), cs.end());
553
47
    if(BOOST_JSON_UNLIKELY(! cs))
554
47
        return maybe_suspend(cs.begin(), state::doc1);
555
8.76k
do_doc2:
556
8.76k
    switch(+opt_.allow_comments |
557
8.76k
        (opt_.allow_trailing_commas << 1) |
558
8.76k
        (opt_.allow_invalid_utf8 << 2))
559
8.76k
    {
560
    // no extensions
561
1.12k
    default:
562
1.12k
        cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::false_type(), std::false_type(), opt_.allow_invalid_utf16);
563
1.12k
        break;
564
    // comments
565
946
    case 1:
566
946
        cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::false_type(), std::false_type(), opt_.allow_invalid_utf16);
567
946
        break;
568
    // trailing
569
659
    case 2:
570
659
        cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::true_type(), std::false_type(), opt_.allow_invalid_utf16);
571
659
        break;
572
    // comments & trailing
573
1.12k
    case 3:
574
1.12k
        cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::true_type(), std::false_type(), opt_.allow_invalid_utf16);
575
1.12k
        break;
576
    // skip validation
577
885
    case 4:
578
885
        cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::false_type(), std::true_type(), opt_.allow_invalid_utf16);
579
885
        break;
580
    // comments & skip validation
581
1.03k
    case 5:
582
1.03k
        cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::false_type(), std::true_type(), opt_.allow_invalid_utf16);
583
1.03k
        break;
584
    // trailing & skip validation
585
1.69k
    case 6:
586
1.69k
        cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::true_type(), std::true_type(), opt_.allow_invalid_utf16);
587
1.69k
        break;
588
    // comments & trailing & skip validation
589
1.30k
    case 7:
590
1.30k
        cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::true_type(), std::true_type(), opt_.allow_invalid_utf16);
591
1.30k
        break;
592
8.76k
    }
593
8.67k
    if(BOOST_JSON_UNLIKELY(incomplete(cs)))
594
        // the appropriate state has already been pushed into stack
595
3.36k
        return sentinel();
596
7.26k
do_doc3:
597
7.26k
    cs = detail::count_whitespace(cs.begin(), cs.end());
598
7.26k
    if(BOOST_JSON_UNLIKELY(! cs))
599
7.26k
    {
600
7.26k
        if(more_)
601
0
            return suspend(cs.begin(), state::doc3);
602
7.26k
    }
603
0
    else if(opt_.allow_comments && *cs == '/')
604
0
    {
605
24
do_doc4:
606
24
        cs = parse_comment(cs.begin(), stack_empty, std::true_type());
607
24
        if(BOOST_JSON_UNLIKELY(incomplete(cs)))
608
22
            return sentinel();
609
2
        goto do_doc3;
610
24
    }
611
7.26k
    return cs.begin();
612
7.26k
}
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
9.82M
{
629
9.82M
    if(stack_empty || st_.empty())
630
9.81M
    {
631
9.81M
loop:
632
9.81M
        switch(*p)
633
9.81M
        {
634
411k
        case '0':
635
411k
            return mp11::mp_with_index<3>(
636
411k
                static_cast<unsigned char>(opt_.numbers),
637
411k
                parse_number_helper<true, '0'>{ this, p });
638
51.2k
        case '-':
639
51.2k
            return mp11::mp_with_index<3>(
640
51.2k
                static_cast<unsigned char>(opt_.numbers),
641
51.2k
                parse_number_helper<true, '-'>{ this, p });
642
6.32M
        case '1': case '2': case '3':
643
6.45M
        case '4': case '5': case '6':
644
9.19M
        case '7': case '8': case '9':
645
9.19M
            return mp11::mp_with_index<3>(
646
9.19M
                static_cast<unsigned char>(opt_.numbers),
647
9.19M
                parse_number_helper<true, '+'>{ this, p });
648
7.93k
        case 'n':
649
7.93k
            return parse_literal( p, detail::literals_c<detail::literals::null>() );
650
38.7k
        case 't':
651
38.7k
            return parse_literal( p, detail::literals_c<detail::literals::true_>() );
652
15.4k
        case 'f':
653
15.4k
            return parse_literal( p, detail::literals_c<detail::literals::false_>() );
654
4
        case 'I':
655
4
            if( !opt_.allow_infinity_and_nan )
656
4
            {
657
4
                BOOST_STATIC_CONSTEXPR source_location loc
658
4
                    = BOOST_CURRENT_LOCATION;
659
4
                return fail(p, error::syntax, &loc);
660
4
            }
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
49.4k
        case '"':
671
49.4k
            return parse_string(p, std::true_type(), std::false_type(), allow_bad_utf8, allow_bad_utf16);
672
26.3k
        case '[':
673
26.3k
            return parse_array(p, std::true_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16);
674
17.1k
        case '{':
675
17.1k
            return parse_object(p, std::true_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16);
676
1.19k
        case '/':
677
1.19k
            if(! allow_comments)
678
1
            {
679
1
                BOOST_STATIC_CONSTEXPR source_location loc
680
1
                    = BOOST_CURRENT_LOCATION;
681
1
                return fail(p, error::syntax, &loc);
682
1
            }
683
1.19k
            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
1.19k
            if(BOOST_JSON_UNLIKELY(p == sentinel()))
688
49
                return maybe_suspend(p, state::val2);
689
1.14k
            BOOST_FALLTHROUGH;
690
1.14k
        case ' ':
691
1.14k
        case '\t':
692
1.14k
        case '\n':
693
1.14k
        case '\r':
694
1.14k
            p = detail::count_whitespace(p, end_);
695
1.14k
            if(BOOST_JSON_UNLIKELY(p == end_))
696
40
                return maybe_suspend(p, state::val1);
697
1.10k
            goto loop;
698
1.10k
        default:
699
409
            {
700
409
                BOOST_STATIC_CONSTEXPR source_location loc
701
409
                    = BOOST_CURRENT_LOCATION;
702
409
                return fail(p, error::syntax, &loc);
703
1.14k
            }
704
9.81M
        }
705
9.81M
    }
706
11.2k
    return resume_value(p, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16);
707
9.82M
}
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
5.41M
{
629
5.41M
    if(stack_empty || st_.empty())
630
5.41M
    {
631
5.41M
loop:
632
5.41M
        switch(*p)
633
5.41M
        {
634
365k
        case '0':
635
365k
            return mp11::mp_with_index<3>(
636
365k
                static_cast<unsigned char>(opt_.numbers),
637
365k
                parse_number_helper<true, '0'>{ this, p });
638
30.5k
        case '-':
639
30.5k
            return mp11::mp_with_index<3>(
640
30.5k
                static_cast<unsigned char>(opt_.numbers),
641
30.5k
                parse_number_helper<true, '-'>{ this, p });
642
3.35M
        case '1': case '2': case '3':
643
3.43M
        case '4': case '5': case '6':
644
4.94M
        case '7': case '8': case '9':
645
4.94M
            return mp11::mp_with_index<3>(
646
4.94M
                static_cast<unsigned char>(opt_.numbers),
647
4.94M
                parse_number_helper<true, '+'>{ this, p });
648
3.71k
        case 'n':
649
3.71k
            return parse_literal( p, detail::literals_c<detail::literals::null>() );
650
21.3k
        case 't':
651
21.3k
            return parse_literal( p, detail::literals_c<detail::literals::true_>() );
652
12.3k
        case 'f':
653
12.3k
            return parse_literal( p, detail::literals_c<detail::literals::false_>() );
654
1
        case 'I':
655
1
            if( !opt_.allow_infinity_and_nan )
656
1
            {
657
1
                BOOST_STATIC_CONSTEXPR source_location loc
658
1
                    = BOOST_CURRENT_LOCATION;
659
1
                return fail(p, error::syntax, &loc);
660
1
            }
661
0
            return parse_literal( p, detail::literals_c<detail::literals::infinity>() );
662
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
18.5k
        case '"':
671
18.5k
            return parse_string(p, std::true_type(), std::false_type(), allow_bad_utf8, allow_bad_utf16);
672
9.91k
        case '[':
673
9.91k
            return parse_array(p, std::true_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16);
674
10.1k
        case '{':
675
10.1k
            return parse_object(p, std::true_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16);
676
1
        case '/':
677
1
            if(! allow_comments)
678
1
            {
679
1
                BOOST_STATIC_CONSTEXPR source_location loc
680
1
                    = BOOST_CURRENT_LOCATION;
681
1
                return fail(p, error::syntax, &loc);
682
1
            }
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
177
        default:
699
177
            {
700
177
                BOOST_STATIC_CONSTEXPR source_location loc
701
177
                    = BOOST_CURRENT_LOCATION;
702
177
                return fail(p, error::syntax, &loc);
703
0
            }
704
5.41M
        }
705
5.41M
    }
706
0
    return resume_value(p, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16);
707
5.41M
}
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.39M
{
629
4.39M
    if(stack_empty || st_.empty())
630
4.39M
    {
631
4.40M
loop:
632
4.40M
        switch(*p)
633
4.40M
        {
634
45.8k
        case '0':
635
45.8k
            return mp11::mp_with_index<3>(
636
45.8k
                static_cast<unsigned char>(opt_.numbers),
637
45.8k
                parse_number_helper<true, '0'>{ this, p });
638
20.7k
        case '-':
639
20.7k
            return mp11::mp_with_index<3>(
640
20.7k
                static_cast<unsigned char>(opt_.numbers),
641
20.7k
                parse_number_helper<true, '-'>{ this, p });
642
2.96M
        case '1': case '2': case '3':
643
3.01M
        case '4': case '5': case '6':
644
4.25M
        case '7': case '8': case '9':
645
4.25M
            return mp11::mp_with_index<3>(
646
4.25M
                static_cast<unsigned char>(opt_.numbers),
647
4.25M
                parse_number_helper<true, '+'>{ this, p });
648
4.21k
        case 'n':
649
4.21k
            return parse_literal( p, detail::literals_c<detail::literals::null>() );
650
17.4k
        case 't':
651
17.4k
            return parse_literal( p, detail::literals_c<detail::literals::true_>() );
652
3.10k
        case 'f':
653
3.10k
            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
30.8k
        case '"':
671
30.8k
            return parse_string(p, std::true_type(), std::false_type(), allow_bad_utf8, allow_bad_utf16);
672
16.4k
        case '[':
673
16.4k
            return parse_array(p, std::true_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16);
674
7.03k
        case '{':
675
7.03k
            return parse_object(p, std::true_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16);
676
1.19k
        case '/':
677
1.19k
            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
1.19k
            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
1.19k
            if(BOOST_JSON_UNLIKELY(p == sentinel()))
688
49
                return maybe_suspend(p, state::val2);
689
1.14k
            BOOST_FALLTHROUGH;
690
1.14k
        case ' ':
691
1.14k
        case '\t':
692
1.14k
        case '\n':
693
1.14k
        case '\r':
694
1.14k
            p = detail::count_whitespace(p, end_);
695
1.14k
            if(BOOST_JSON_UNLIKELY(p == end_))
696
40
                return maybe_suspend(p, state::val1);
697
1.10k
            goto loop;
698
1.10k
        default:
699
232
            {
700
232
                BOOST_STATIC_CONSTEXPR source_location loc
701
232
                    = BOOST_CURRENT_LOCATION;
702
232
                return fail(p, error::syntax, &loc);
703
1.14k
            }
704
4.40M
        }
705
4.40M
    }
706
0
    return resume_value(p, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16);
707
4.39M
}
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.47k
{
629
5.47k
    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.47k
    return resume_value(p, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16);
707
5.47k
}
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.78k
{
629
5.78k
    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.78k
    return resume_value(p, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16);
707
5.78k
}
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
11.2k
{
722
11.2k
    state st;
723
11.2k
    st_.peek(st);
724
11.2k
    switch(st)
725
11.2k
    {
726
0
    default: BOOST_JSON_UNREACHABLE();
727
50
    case state::lit1:
728
50
        return parse_literal(p,  detail::literals_c<detail::literals::resume>() );
729
730
534
    case state::str1: case state::str2:
731
549
    case state::str8:
732
549
        return parse_string(p, std::false_type(), std::false_type(), allow_bad_utf8, allow_bad_utf16);
733
734
107
    case state::arr1: case state::arr2:
735
2.31k
    case state::arr3: case state::arr4:
736
2.59k
    case state::arr5: case state::arr6:
737
2.59k
        return parse_array(p, std::false_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16);
738
739
91
    case state::obj1: case state::obj2:
740
425
    case state::obj3: case state::obj4:
741
484
    case state::obj5: case state::obj6:
742
1.06k
    case state::obj7: case state::obj8:
743
1.13k
    case state::obj9: case state::obj10:
744
1.13k
    case state::obj11:
745
1.13k
        return parse_object(p, std::false_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16);
746
747
1.17k
    case state::num1: case state::num2:
748
1.74k
    case state::num3: case state::num4:
749
2.96k
    case state::num5: case state::num6:
750
4.43k
    case state::num7: case state::num8:
751
4.72k
    case state::exp1: case state::exp2:
752
6.84k
    case state::exp3:
753
6.84k
        return mp11::mp_with_index<3>(
754
6.84k
            static_cast<unsigned char>(opt_.numbers),
755
6.84k
            parse_number_helper<false, 0>{ this, p });
756
757
    // KRYSTIAN NOTE: these are special cases
758
40
    case state::val1:
759
40
    {
760
40
        st_.pop(st);
761
40
        BOOST_ASSERT(st_.empty());
762
40
        p = detail::count_whitespace(p, end_);
763
40
        if(BOOST_JSON_UNLIKELY(p == end_))
764
40
            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
40
    }
767
768
45
    case state::val2:
769
45
    {
770
45
        st_.pop(st);
771
45
        p = parse_comment(p, std::false_type(), std::false_type());
772
45
        if(BOOST_JSON_UNLIKELY(p == sentinel()))
773
45
            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
11.2k
    }
786
11.2k
}
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.47k
{
722
5.47k
    state st;
723
5.47k
    st_.peek(st);
724
5.47k
    switch(st)
725
5.47k
    {
726
0
    default: BOOST_JSON_UNREACHABLE();
727
24
    case state::lit1:
728
24
        return parse_literal(p,  detail::literals_c<detail::literals::resume>() );
729
730
211
    case state::str1: case state::str2:
731
218
    case state::str8:
732
218
        return parse_string(p, std::false_type(), std::false_type(), allow_bad_utf8, allow_bad_utf16);
733
734
41
    case state::arr1: case state::arr2:
735
1.06k
    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
37
    case state::obj1: case state::obj2:
740
206
    case state::obj3: case state::obj4:
741
235
    case state::obj5: case state::obj6:
742
448
    case state::obj7: case state::obj8:
743
478
    case state::obj9: case state::obj10:
744
478
    case state::obj11:
745
478
        return parse_object(p, std::false_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16);
746
747
606
    case state::num1: case state::num2:
748
922
    case state::num3: case state::num4:
749
1.59k
    case state::num5: case state::num6:
750
2.35k
    case state::num7: case state::num8:
751
2.50k
    case state::exp1: case state::exp2:
752
3.55k
    case state::exp3:
753
3.55k
        return mp11::mp_with_index<3>(
754
3.55k
            static_cast<unsigned char>(opt_.numbers),
755
3.55k
            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.47k
    }
786
5.47k
}
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.78k
{
722
5.78k
    state st;
723
5.78k
    st_.peek(st);
724
5.78k
    switch(st)
725
5.78k
    {
726
0
    default: BOOST_JSON_UNREACHABLE();
727
26
    case state::lit1:
728
26
        return parse_literal(p,  detail::literals_c<detail::literals::resume>() );
729
730
323
    case state::str1: case state::str2:
731
331
    case state::str8:
732
331
        return parse_string(p, std::false_type(), std::false_type(), allow_bad_utf8, allow_bad_utf16);
733
734
66
    case state::arr1: case state::arr2:
735
1.24k
    case state::arr3: case state::arr4:
736
1.40k
    case state::arr5: case state::arr6:
737
1.40k
        return parse_array(p, std::false_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16);
738
739
54
    case state::obj1: case state::obj2:
740
219
    case state::obj3: case state::obj4:
741
249
    case state::obj5: case state::obj6:
742
612
    case state::obj7: case state::obj8:
743
658
    case state::obj9: case state::obj10:
744
661
    case state::obj11:
745
661
        return parse_object(p, std::false_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16);
746
747
565
    case state::num1: case state::num2:
748
824
    case state::num3: case state::num4:
749
1.37k
    case state::num5: case state::num6:
750
2.07k
    case state::num7: case state::num8:
751
2.21k
    case state::exp1: case state::exp2:
752
3.28k
    case state::exp3:
753
3.28k
        return mp11::mp_with_index<3>(
754
3.28k
            static_cast<unsigned char>(opt_.numbers),
755
3.28k
            parse_number_helper<false, 0>{ this, p });
756
757
    // KRYSTIAN NOTE: these are special cases
758
40
    case state::val1:
759
40
    {
760
40
        st_.pop(st);
761
40
        BOOST_ASSERT(st_.empty());
762
40
        p = detail::count_whitespace(p, end_);
763
40
        if(BOOST_JSON_UNLIKELY(p == end_))
764
40
            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
40
    }
767
768
45
    case state::val2:
769
45
    {
770
45
        st_.pop(st);
771
45
        p = parse_comment(p, std::false_type(), std::false_type());
772
45
        if(BOOST_JSON_UNLIKELY(p == sentinel()))
773
45
            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.78k
    }
786
5.78k
}
787
788
template<class Handler>
789
template<class Literal>
790
const char*
791
basic_parser<Handler>::
792
parse_literal(const char* p, Literal)
793
62.1k
{
794
62.1k
    using L = detail::literals;
795
796
62.1k
    std::size_t cur_lit;
797
62.1k
    std::size_t offset;
798
799
62.1k
    detail::const_stream_wrapper cs(p, end_);
800
    BOOST_IF_CONSTEXPR( Literal::value != L::resume )
801
62.1k
    {
802
62.1k
        constexpr std::size_t index = literal_index(Literal::value);
803
62.1k
        constexpr char const* literal = detail::literal_strings[index];
804
62.1k
        constexpr std::size_t sz = detail::literal_sizes[index];
805
806
62.1k
        if(BOOST_JSON_LIKELY( cs.remain() >= sz ))
807
61.9k
        {
808
61.9k
            int const cmp = std::memcmp(cs.begin(), literal, sz);
809
61.9k
            if( cmp != 0 )
810
40
            {
811
40
                BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION;
812
40
                return fail(cs.begin(), error::syntax, &loc);
813
40
            }
814
815
61.9k
            BOOST_IF_CONSTEXPR( Literal::value == L::null )
816
61.9k
            {
817
7.87k
                if(BOOST_JSON_UNLIKELY(
818
7.87k
                    ! h_.on_null(ec_)))
819
0
                    return fail(cs.begin());
820
            }
821
54.0k
            else BOOST_IF_CONSTEXPR( Literal::value == L::true_ )
822
54.0k
            {
823
38.6k
                if(BOOST_JSON_UNLIKELY(
824
38.6k
                    ! h_.on_bool(true, ec_)))
825
0
                    return fail(cs.begin());
826
            }
827
15.3k
            else BOOST_IF_CONSTEXPR( Literal::value == L::false_ )
828
15.3k
            {
829
15.3k
                if(BOOST_JSON_UNLIKELY(
830
15.3k
                    ! 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
61.9k
            cs += sz;
866
61.9k
            return cs.begin();
867
61.9k
        }
868
869
169
        offset = 0;
870
169
        cur_lit = index;
871
    }
872
    else
873
50
    {
874
50
        state st;
875
50
        st_.pop(st);
876
50
        BOOST_ASSERT( st == state::lit1 );
877
878
50
        cur_lit = cur_lit_;
879
50
        offset = lit_offset_;
880
50
    }
881
882
0
    std::size_t const lit_size = detail::literal_sizes[cur_lit];
883
62.1k
    std::size_t const size = (std::min)( lit_size - offset, cs.remain() );
884
62.1k
    int cmp = 0;
885
62.1k
    if(BOOST_JSON_LIKELY( cs.begin() ))
886
169
        cmp = std::memcmp(
887
169
            cs.begin(), detail::literal_strings[cur_lit] + offset, size );
888
62.1k
    if( cmp != 0 )
889
119
    {
890
119
        BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION;
891
119
        return fail(cs.begin(), error::syntax, &loc);
892
119
    }
893
894
62.0k
    if(BOOST_JSON_UNLIKELY( offset + size < lit_size ))
895
100
    {
896
100
        BOOST_ASSERT( cur_lit < 256 );
897
100
        cur_lit_ = static_cast<unsigned char>( cur_lit );
898
100
        BOOST_ASSERT( offset + size < 256 );
899
100
        lit_offset_ = static_cast<unsigned char>( offset + size );
900
100
        return maybe_suspend(cs.begin() + size, state::lit1);
901
100
    }
902
903
61.9k
    switch( static_cast<L>(cur_lit) )
904
61.9k
    {
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
61.9k
    }
952
953
0
    cs += size;
954
0
    return cs.begin();
955
61.9k
}
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
50
{
794
50
    using L = detail::literals;
795
796
50
    std::size_t cur_lit;
797
50
    std::size_t offset;
798
799
50
    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
50
    {
874
50
        state st;
875
50
        st_.pop(st);
876
50
        BOOST_ASSERT( st == state::lit1 );
877
878
50
        cur_lit = cur_lit_;
879
50
        offset = lit_offset_;
880
50
    }
881
882
50
    std::size_t const lit_size = detail::literal_sizes[cur_lit];
883
50
    std::size_t const size = (std::min)( lit_size - offset, cs.remain() );
884
50
    int cmp = 0;
885
50
    if(BOOST_JSON_LIKELY( cs.begin() ))
886
0
        cmp = std::memcmp(
887
0
            cs.begin(), detail::literal_strings[cur_lit] + offset, size );
888
50
    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
50
    if(BOOST_JSON_UNLIKELY( offset + size < lit_size ))
895
50
    {
896
50
        BOOST_ASSERT( cur_lit < 256 );
897
50
        cur_lit_ = static_cast<unsigned char>( cur_lit );
898
50
        BOOST_ASSERT( offset + size < 256 );
899
50
        lit_offset_ = static_cast<unsigned char>( offset + size );
900
50
        return maybe_suspend(cs.begin() + size, state::lit1);
901
50
    }
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
7.93k
{
794
7.93k
    using L = detail::literals;
795
796
7.93k
    std::size_t cur_lit;
797
7.93k
    std::size_t offset;
798
799
7.93k
    detail::const_stream_wrapper cs(p, end_);
800
    BOOST_IF_CONSTEXPR( Literal::value != L::resume )
801
7.93k
    {
802
7.93k
        constexpr std::size_t index = literal_index(Literal::value);
803
7.93k
        constexpr char const* literal = detail::literal_strings[index];
804
7.93k
        constexpr std::size_t sz = detail::literal_sizes[index];
805
806
7.93k
        if(BOOST_JSON_LIKELY( cs.remain() >= sz ))
807
7.88k
        {
808
7.88k
            int const cmp = std::memcmp(cs.begin(), literal, sz);
809
7.88k
            if( cmp != 0 )
810
11
            {
811
11
                BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION;
812
11
                return fail(cs.begin(), error::syntax, &loc);
813
11
            }
814
815
7.87k
            BOOST_IF_CONSTEXPR( Literal::value == L::null )
816
7.87k
            {
817
7.87k
                if(BOOST_JSON_UNLIKELY(
818
7.87k
                    ! 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
7.87k
            cs += sz;
866
7.87k
            return cs.begin();
867
7.88k
        }
868
869
51
        offset = 0;
870
51
        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
7.93k
    std::size_t const size = (std::min)( lit_size - offset, cs.remain() );
884
7.93k
    int cmp = 0;
885
7.93k
    if(BOOST_JSON_LIKELY( cs.begin() ))
886
51
        cmp = std::memcmp(
887
51
            cs.begin(), detail::literal_strings[cur_lit] + offset, size );
888
7.93k
    if( cmp != 0 )
889
38
    {
890
38
        BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION;
891
38
        return fail(cs.begin(), error::syntax, &loc);
892
38
    }
893
894
7.89k
    if(BOOST_JSON_UNLIKELY( offset + size < lit_size ))
895
13
    {
896
13
        BOOST_ASSERT( cur_lit < 256 );
897
13
        cur_lit_ = static_cast<unsigned char>( cur_lit );
898
13
        BOOST_ASSERT( offset + size < 256 );
899
13
        lit_offset_ = static_cast<unsigned char>( offset + size );
900
13
        return maybe_suspend(cs.begin() + size, state::lit1);
901
13
    }
902
903
7.88k
    switch( static_cast<L>(cur_lit) )
904
7.88k
    {
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
7.88k
    }
952
953
0
    cs += size;
954
0
    return cs.begin();
955
7.88k
}
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
38.7k
{
794
38.7k
    using L = detail::literals;
795
796
38.7k
    std::size_t cur_lit;
797
38.7k
    std::size_t offset;
798
799
38.7k
    detail::const_stream_wrapper cs(p, end_);
800
    BOOST_IF_CONSTEXPR( Literal::value != L::resume )
801
38.7k
    {
802
38.7k
        constexpr std::size_t index = literal_index(Literal::value);
803
38.7k
        constexpr char const* literal = detail::literal_strings[index];
804
38.7k
        constexpr std::size_t sz = detail::literal_sizes[index];
805
806
38.7k
        if(BOOST_JSON_LIKELY( cs.remain() >= sz ))
807
38.6k
        {
808
38.6k
            int const cmp = std::memcmp(cs.begin(), literal, sz);
809
38.6k
            if( cmp != 0 )
810
12
            {
811
12
                BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION;
812
12
                return fail(cs.begin(), error::syntax, &loc);
813
12
            }
814
815
38.6k
            BOOST_IF_CONSTEXPR( Literal::value == L::null )
816
38.6k
            {
817
38.6k
                if(BOOST_JSON_UNLIKELY(
818
38.6k
                    ! h_.on_null(ec_)))
819
38.6k
                    return fail(cs.begin());
820
38.6k
            }
821
38.6k
            else BOOST_IF_CONSTEXPR( Literal::value == L::true_ )
822
38.6k
            {
823
38.6k
                if(BOOST_JSON_UNLIKELY(
824
38.6k
                    ! 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
38.6k
            cs += sz;
866
38.6k
            return cs.begin();
867
38.6k
        }
868
869
53
        offset = 0;
870
53
        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
38.7k
    std::size_t const size = (std::min)( lit_size - offset, cs.remain() );
884
38.7k
    int cmp = 0;
885
38.7k
    if(BOOST_JSON_LIKELY( cs.begin() ))
886
53
        cmp = std::memcmp(
887
53
            cs.begin(), detail::literal_strings[cur_lit] + offset, size );
888
38.7k
    if( cmp != 0 )
889
35
    {
890
35
        BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION;
891
35
        return fail(cs.begin(), error::syntax, &loc);
892
35
    }
893
894
38.6k
    if(BOOST_JSON_UNLIKELY( offset + size < lit_size ))
895
18
    {
896
18
        BOOST_ASSERT( cur_lit < 256 );
897
18
        cur_lit_ = static_cast<unsigned char>( cur_lit );
898
18
        BOOST_ASSERT( offset + size < 256 );
899
18
        lit_offset_ = static_cast<unsigned char>( offset + size );
900
18
        return maybe_suspend(cs.begin() + size, state::lit1);
901
18
    }
902
903
38.6k
    switch( static_cast<L>(cur_lit) )
904
38.6k
    {
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
38.6k
    }
952
953
0
    cs += size;
954
0
    return cs.begin();
955
38.6k
}
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
15.4k
{
794
15.4k
    using L = detail::literals;
795
796
15.4k
    std::size_t cur_lit;
797
15.4k
    std::size_t offset;
798
799
15.4k
    detail::const_stream_wrapper cs(p, end_);
800
    BOOST_IF_CONSTEXPR( Literal::value != L::resume )
801
15.4k
    {
802
15.4k
        constexpr std::size_t index = literal_index(Literal::value);
803
15.4k
        constexpr char const* literal = detail::literal_strings[index];
804
15.4k
        constexpr std::size_t sz = detail::literal_sizes[index];
805
806
15.4k
        if(BOOST_JSON_LIKELY( cs.remain() >= sz ))
807
15.4k
        {
808
15.4k
            int const cmp = std::memcmp(cs.begin(), literal, sz);
809
15.4k
            if( cmp != 0 )
810
17
            {
811
17
                BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION;
812
17
                return fail(cs.begin(), error::syntax, &loc);
813
17
            }
814
815
15.3k
            BOOST_IF_CONSTEXPR( Literal::value == L::null )
816
15.3k
            {
817
15.3k
                if(BOOST_JSON_UNLIKELY(
818
15.3k
                    ! h_.on_null(ec_)))
819
15.3k
                    return fail(cs.begin());
820
15.3k
            }
821
15.3k
            else BOOST_IF_CONSTEXPR( Literal::value == L::true_ )
822
15.3k
            {
823
15.3k
                if(BOOST_JSON_UNLIKELY(
824
15.3k
                    ! h_.on_bool(true, ec_)))
825
15.3k
                    return fail(cs.begin());
826
15.3k
            }
827
15.3k
            else BOOST_IF_CONSTEXPR( Literal::value == L::false_ )
828
15.3k
            {
829
15.3k
                if(BOOST_JSON_UNLIKELY(
830
15.3k
                    ! 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
15.3k
            cs += sz;
866
15.3k
            return cs.begin();
867
15.4k
        }
868
869
65
        offset = 0;
870
65
        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
15.4k
    std::size_t const size = (std::min)( lit_size - offset, cs.remain() );
884
15.4k
    int cmp = 0;
885
15.4k
    if(BOOST_JSON_LIKELY( cs.begin() ))
886
65
        cmp = std::memcmp(
887
65
            cs.begin(), detail::literal_strings[cur_lit] + offset, size );
888
15.4k
    if( cmp != 0 )
889
46
    {
890
46
        BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION;
891
46
        return fail(cs.begin(), error::syntax, &loc);
892
46
    }
893
894
15.4k
    if(BOOST_JSON_UNLIKELY( offset + size < lit_size ))
895
19
    {
896
19
        BOOST_ASSERT( cur_lit < 256 );
897
19
        cur_lit_ = static_cast<unsigned char>( cur_lit );
898
19
        BOOST_ASSERT( offset + size < 256 );
899
19
        lit_offset_ = static_cast<unsigned char>( offset + size );
900
19
        return maybe_suspend(cs.begin() + size, state::lit1);
901
19
    }
902
903
15.4k
    switch( static_cast<L>(cur_lit) )
904
15.4k
    {
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
15.4k
    }
952
953
0
    cs += size;
954
0
    return cs.begin();
955
15.4k
}
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
444k
{
969
444k
    detail::const_stream_wrapper cs(p, end_);
970
444k
    std::size_t total;
971
444k
    char const* start;
972
444k
    std::size_t size;
973
444k
    if(! stack_empty && ! st_.empty())
974
770
    {
975
770
        state st;
976
770
        st_.pop(st);
977
770
        st_.pop(total);
978
770
        switch(st)
979
770
        {
980
0
        default: BOOST_JSON_UNREACHABLE();
981
233
        case state::str2: goto do_str2;
982
24
        case state::str8: goto do_str8;
983
513
        case state::str1: break;
984
770
        }
985
770
    }
986
444k
    else
987
444k
    {
988
444k
        BOOST_ASSERT(*cs == '\x22'); // '"'
989
444k
        ++cs;
990
444k
        total = 0;
991
444k
    }
992
993
522k
do_str1:
994
522k
    start = cs.begin();
995
522k
    cs = allow_bad_utf8?
996
491k
        detail::count_valid<true>(cs.begin(), cs.end()):
997
522k
        detail::count_valid<false>(cs.begin(), cs.end());
998
522k
    size = cs.used(start);
999
522k
    if(is_key)
1000
398k
    {
1001
398k
        BOOST_ASSERT(total <= Handler::max_key_size);
1002
398k
        if(BOOST_JSON_UNLIKELY(size >
1003
398k
            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
398k
    }
1010
124k
    else
1011
124k
    {
1012
124k
        BOOST_ASSERT(total <= Handler::max_string_size);
1013
124k
        if(BOOST_JSON_UNLIKELY(size >
1014
124k
            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
124k
    }
1021
522k
    total += size;
1022
522k
    if(BOOST_JSON_UNLIKELY(! cs))
1023
1.03k
    {
1024
        // call handler if the string isn't empty
1025
1.03k
        if(BOOST_JSON_LIKELY(size))
1026
299
        {
1027
299
            {
1028
299
                bool r = is_key?
1029
130
                    h_.on_key_part( {start, size}, total, ec_ ):
1030
299
                    h_.on_string_part( {start, size}, total, ec_ );
1031
1032
299
                if(BOOST_JSON_UNLIKELY(!r))
1033
0
                {
1034
0
                    return fail(cs.begin());
1035
0
                }
1036
299
            }
1037
299
        }
1038
1.03k
        return maybe_suspend(cs.begin(), state::str1, total);
1039
1.03k
    }
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
521k
    if(BOOST_JSON_UNLIKELY(*cs != '\x22')) // '"'
1044
79.1k
    {
1045
        // sequence is invalid or incomplete
1046
79.1k
        if((*cs & 0x80) && !allow_bad_utf8)
1047
238
        {
1048
238
            seq_.save(cs.begin(), cs.remain());
1049
238
            if(BOOST_JSON_UNLIKELY(seq_.complete()))
1050
214
            {
1051
214
                BOOST_STATIC_CONSTEXPR source_location loc
1052
214
                    = BOOST_CURRENT_LOCATION;
1053
214
                return fail(cs.begin(), error::syntax, &loc);
1054
214
            }
1055
24
            if(BOOST_JSON_LIKELY(size))
1056
6
            {
1057
6
                bool const r = is_key?
1058
1
                    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
24
            return maybe_suspend(cs.end(), state::str8, total);
1064
24
        }
1065
78.8k
        else if(BOOST_JSON_LIKELY(*cs == '\\'))
1066
78.7k
        {
1067
            // flush unescaped run from input
1068
78.7k
            if(BOOST_JSON_LIKELY(size))
1069
72.9k
            {
1070
72.9k
                bool const r = is_key?
1071
3.22k
                    h_.on_key_part( {start, size}, total, ec_ ):
1072
72.9k
                    h_.on_string_part( {start, size}, total, ec_ );
1073
72.9k
                if(BOOST_JSON_UNLIKELY( !r ))
1074
0
                    return fail( cs.begin() );
1075
72.9k
            }
1076
79.0k
do_str2:
1077
79.0k
            cs = parse_escaped(cs.begin(), total, stack_empty, is_key, allow_bad_utf16);
1078
79.0k
            if(BOOST_JSON_UNLIKELY( incomplete(cs) ))
1079
823
                return suspend_or_fail(state::str2, total);
1080
1081
78.2k
            goto do_str1;
1082
79.0k
        }
1083
        // illegal control
1084
78
        BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION;
1085
78
        return fail(cs.begin(), error::syntax, &loc);
1086
79.1k
    }
1087
1088
442k
    {
1089
442k
        bool r = is_key?
1090
394k
            h_.on_key( {start, size}, total, ec_ ):
1091
442k
            h_.on_string( {start, size}, total, ec_ );
1092
1093
442k
        if(BOOST_JSON_UNLIKELY(!r))
1094
0
        {
1095
0
            return fail(cs.begin());
1096
0
        }
1097
442k
    }
1098
1099
442k
    ++cs;
1100
442k
    return cs.begin();
1101
1102
24
do_str8:
1103
24
    uint8_t needed = seq_.needed();
1104
24
    if(BOOST_JSON_UNLIKELY( !seq_.append(cs.begin(), cs.remain()) ))
1105
24
        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
49.4k
{
969
49.4k
    detail::const_stream_wrapper cs(p, end_);
970
49.4k
    std::size_t total;
971
49.4k
    char const* start;
972
49.4k
    std::size_t size;
973
49.4k
    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
49.4k
    else
987
49.4k
    {
988
49.4k
        BOOST_ASSERT(*cs == '\x22'); // '"'
989
49.4k
        ++cs;
990
49.4k
        total = 0;
991
49.4k
    }
992
993
123k
do_str1:
994
123k
    start = cs.begin();
995
123k
    cs = allow_bad_utf8?
996
96.1k
        detail::count_valid<true>(cs.begin(), cs.end()):
997
123k
        detail::count_valid<false>(cs.begin(), cs.end());
998
123k
    size = cs.used(start);
999
123k
    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
123k
    else
1011
123k
    {
1012
123k
        BOOST_ASSERT(total <= Handler::max_string_size);
1013
123k
        if(BOOST_JSON_UNLIKELY(size >
1014
123k
            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
123k
    }
1021
123k
    total += size;
1022
123k
    if(BOOST_JSON_UNLIKELY(! cs))
1023
352
    {
1024
        // call handler if the string isn't empty
1025
352
        if(BOOST_JSON_LIKELY(size))
1026
169
        {
1027
169
            {
1028
169
                bool r = is_key?
1029
0
                    h_.on_key_part( {start, size}, total, ec_ ):
1030
169
                    h_.on_string_part( {start, size}, total, ec_ );
1031
1032
169
                if(BOOST_JSON_UNLIKELY(!r))
1033
0
                {
1034
0
                    return fail(cs.begin());
1035
0
                }
1036
169
            }
1037
169
        }
1038
352
        return maybe_suspend(cs.begin(), state::str1, total);
1039
352
    }
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
123k
    if(BOOST_JSON_UNLIKELY(*cs != '\x22')) // '"'
1044
74.9k
    {
1045
        // sequence is invalid or incomplete
1046
74.9k
        if((*cs & 0x80) && !allow_bad_utf8)
1047
130
        {
1048
130
            seq_.save(cs.begin(), cs.remain());
1049
130
            if(BOOST_JSON_UNLIKELY(seq_.complete()))
1050
115
            {
1051
115
                BOOST_STATIC_CONSTEXPR source_location loc
1052
115
                    = BOOST_CURRENT_LOCATION;
1053
115
                return fail(cs.begin(), error::syntax, &loc);
1054
115
            }
1055
15
            if(BOOST_JSON_LIKELY(size))
1056
5
            {
1057
5
                bool const r = is_key?
1058
0
                    h_.on_key_part( {start, size}, total, ec_ ):
1059
5
                    h_.on_string_part( {start, size}, total, ec_ );
1060
5
                if(BOOST_JSON_UNLIKELY( !r ))
1061
0
                    return fail( cs.begin() );
1062
5
            }
1063
15
            return maybe_suspend(cs.end(), state::str8, total);
1064
15
        }
1065
74.8k
        else if(BOOST_JSON_LIKELY(*cs == '\\'))
1066
74.8k
        {
1067
            // flush unescaped run from input
1068
74.8k
            if(BOOST_JSON_LIKELY(size))
1069
69.6k
            {
1070
69.6k
                bool const r = is_key?
1071
0
                    h_.on_key_part( {start, size}, total, ec_ ):
1072
69.6k
                    h_.on_string_part( {start, size}, total, ec_ );
1073
69.6k
                if(BOOST_JSON_UNLIKELY( !r ))
1074
0
                    return fail( cs.begin() );
1075
69.6k
            }
1076
74.8k
do_str2:
1077
74.8k
            cs = parse_escaped(cs.begin(), total, stack_empty, is_key, allow_bad_utf16);
1078
74.8k
            if(BOOST_JSON_UNLIKELY( incomplete(cs) ))
1079
526
                return suspend_or_fail(state::str2, total);
1080
1081
74.2k
            goto do_str1;
1082
74.8k
        }
1083
        // illegal control
1084
43
        BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION;
1085
43
        return fail(cs.begin(), error::syntax, &loc);
1086
74.9k
    }
1087
1088
48.3k
    {
1089
48.3k
        bool r = is_key?
1090
0
            h_.on_key( {start, size}, total, ec_ ):
1091
48.3k
            h_.on_string( {start, size}, total, ec_ );
1092
1093
48.3k
        if(BOOST_JSON_UNLIKELY(!r))
1094
0
        {
1095
0
            return fail(cs.begin());
1096
0
        }
1097
48.3k
    }
1098
1099
48.3k
    ++cs;
1100
48.3k
    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
394k
{
969
394k
    detail::const_stream_wrapper cs(p, end_);
970
394k
    std::size_t total;
971
394k
    char const* start;
972
394k
    std::size_t size;
973
394k
    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
394k
    else
987
394k
    {
988
394k
        BOOST_ASSERT(*cs == '\x22'); // '"'
989
394k
        ++cs;
990
394k
        total = 0;
991
394k
    }
992
993
398k
do_str1:
994
398k
    start = cs.begin();
995
398k
    cs = allow_bad_utf8?
996
394k
        detail::count_valid<true>(cs.begin(), cs.end()):
997
398k
        detail::count_valid<false>(cs.begin(), cs.end());
998
398k
    size = cs.used(start);
999
398k
    if(is_key)
1000
398k
    {
1001
398k
        BOOST_ASSERT(total <= Handler::max_key_size);
1002
398k
        if(BOOST_JSON_UNLIKELY(size >
1003
398k
            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
398k
    }
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
398k
    total += size;
1022
398k
    if(BOOST_JSON_UNLIKELY(! cs))
1023
168
    {
1024
        // call handler if the string isn't empty
1025
168
        if(BOOST_JSON_LIKELY(size))
1026
130
        {
1027
130
            {
1028
130
                bool r = is_key?
1029
130
                    h_.on_key_part( {start, size}, total, ec_ ):
1030
130
                    h_.on_string_part( {start, size}, total, ec_ );
1031
1032
130
                if(BOOST_JSON_UNLIKELY(!r))
1033
0
                {
1034
0
                    return fail(cs.begin());
1035
0
                }
1036
130
            }
1037
130
        }
1038
168
        return maybe_suspend(cs.begin(), state::str1, total);
1039
168
    }
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
398k
    if(BOOST_JSON_UNLIKELY(*cs != '\x22')) // '"'
1044
4.12k
    {
1045
        // sequence is invalid or incomplete
1046
4.12k
        if((*cs & 0x80) && !allow_bad_utf8)
1047
108
        {
1048
108
            seq_.save(cs.begin(), cs.remain());
1049
108
            if(BOOST_JSON_UNLIKELY(seq_.complete()))
1050
99
            {
1051
99
                BOOST_STATIC_CONSTEXPR source_location loc
1052
99
                    = BOOST_CURRENT_LOCATION;
1053
99
                return fail(cs.begin(), error::syntax, &loc);
1054
99
            }
1055
9
            if(BOOST_JSON_LIKELY(size))
1056
1
            {
1057
1
                bool const r = is_key?
1058
1
                    h_.on_key_part( {start, size}, total, ec_ ):
1059
1
                    h_.on_string_part( {start, size}, total, ec_ );
1060
1
                if(BOOST_JSON_UNLIKELY( !r ))
1061
0
                    return fail( cs.begin() );
1062
1
            }
1063
9
            return maybe_suspend(cs.end(), state::str8, total);
1064
9
        }
1065
4.01k
        else if(BOOST_JSON_LIKELY(*cs == '\\'))
1066
3.97k
        {
1067
            // flush unescaped run from input
1068
3.97k
            if(BOOST_JSON_LIKELY(size))
1069
3.22k
            {
1070
3.22k
                bool const r = is_key?
1071
3.22k
                    h_.on_key_part( {start, size}, total, ec_ ):
1072
3.22k
                    h_.on_string_part( {start, size}, total, ec_ );
1073
3.22k
                if(BOOST_JSON_UNLIKELY( !r ))
1074
0
                    return fail( cs.begin() );
1075
3.22k
            }
1076
3.97k
do_str2:
1077
3.97k
            cs = parse_escaped(cs.begin(), total, stack_empty, is_key, allow_bad_utf16);
1078
3.97k
            if(BOOST_JSON_UNLIKELY( incomplete(cs) ))
1079
64
                return suspend_or_fail(state::str2, total);
1080
1081
3.91k
            goto do_str1;
1082
3.97k
        }
1083
        // illegal control
1084
35
        BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION;
1085
35
        return fail(cs.begin(), error::syntax, &loc);
1086
4.12k
    }
1087
1088
394k
    {
1089
394k
        bool r = is_key?
1090
394k
            h_.on_key( {start, size}, total, ec_ ):
1091
394k
            h_.on_string( {start, size}, total, ec_ );
1092
1093
394k
        if(BOOST_JSON_UNLIKELY(!r))
1094
0
        {
1095
0
            return fail(cs.begin());
1096
0
        }
1097
394k
    }
1098
1099
394k
    ++cs;
1100
394k
    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
549
{
969
549
    detail::const_stream_wrapper cs(p, end_);
970
549
    std::size_t total;
971
549
    char const* start;
972
549
    std::size_t size;
973
549
    if(! stack_empty && ! st_.empty())
974
549
    {
975
549
        state st;
976
549
        st_.pop(st);
977
549
        st_.pop(total);
978
549
        switch(st)
979
549
        {
980
0
        default: BOOST_JSON_UNREACHABLE();
981
186
        case state::str2: goto do_str2;
982
15
        case state::str8: goto do_str8;
983
348
        case state::str1: break;
984
549
        }
985
549
    }
986
0
    else
987
0
    {
988
0
        BOOST_ASSERT(*cs == '\x22'); // '"'
989
0
        ++cs;
990
0
        total = 0;
991
0
    }
992
993
348
do_str1:
994
348
    start = cs.begin();
995
348
    cs = allow_bad_utf8?
996
210
        detail::count_valid<true>(cs.begin(), cs.end()):
997
348
        detail::count_valid<false>(cs.begin(), cs.end());
998
348
    size = cs.used(start);
999
348
    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
348
    else
1011
348
    {
1012
348
        BOOST_ASSERT(total <= Handler::max_string_size);
1013
348
        if(BOOST_JSON_UNLIKELY(size >
1014
348
            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
348
    }
1021
348
    total += size;
1022
348
    if(BOOST_JSON_UNLIKELY(! cs))
1023
348
    {
1024
        // call handler if the string isn't empty
1025
348
        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
348
        return maybe_suspend(cs.begin(), state::str1, total);
1039
348
    }
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
186
do_str2:
1077
186
            cs = parse_escaped(cs.begin(), total, stack_empty, is_key, allow_bad_utf16);
1078
186
            if(BOOST_JSON_UNLIKELY( incomplete(cs) ))
1079
186
                return suspend_or_fail(state::str2, total);
1080
1081
0
            goto do_str1;
1082
186
        }
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
15
do_str8:
1103
15
    uint8_t needed = seq_.needed();
1104
15
    if(BOOST_JSON_UNLIKELY( !seq_.append(cs.begin(), cs.remain()) ))
1105
15
        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
221
{
969
221
    detail::const_stream_wrapper cs(p, end_);
970
221
    std::size_t total;
971
221
    char const* start;
972
221
    std::size_t size;
973
221
    if(! stack_empty && ! st_.empty())
974
221
    {
975
221
        state st;
976
221
        st_.pop(st);
977
221
        st_.pop(total);
978
221
        switch(st)
979
221
        {
980
0
        default: BOOST_JSON_UNREACHABLE();
981
47
        case state::str2: goto do_str2;
982
9
        case state::str8: goto do_str8;
983
165
        case state::str1: break;
984
221
        }
985
221
    }
986
0
    else
987
0
    {
988
0
        BOOST_ASSERT(*cs == '\x22'); // '"'
989
0
        ++cs;
990
0
        total = 0;
991
0
    }
992
993
165
do_str1:
994
165
    start = cs.begin();
995
165
    cs = allow_bad_utf8?
996
82
        detail::count_valid<true>(cs.begin(), cs.end()):
997
165
        detail::count_valid<false>(cs.begin(), cs.end());
998
165
    size = cs.used(start);
999
165
    if(is_key)
1000
165
    {
1001
165
        BOOST_ASSERT(total <= Handler::max_key_size);
1002
165
        if(BOOST_JSON_UNLIKELY(size >
1003
165
            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
165
    }
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
165
    total += size;
1022
165
    if(BOOST_JSON_UNLIKELY(! cs))
1023
165
    {
1024
        // call handler if the string isn't empty
1025
165
        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
165
        return maybe_suspend(cs.begin(), state::str1, total);
1039
165
    }
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
47
do_str2:
1077
47
            cs = parse_escaped(cs.begin(), total, stack_empty, is_key, allow_bad_utf16);
1078
47
            if(BOOST_JSON_UNLIKELY( incomplete(cs) ))
1079
47
                return suspend_or_fail(state::str2, total);
1080
1081
0
            goto do_str1;
1082
47
        }
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
9
do_str8:
1103
9
    uint8_t needed = seq_.needed();
1104
9
    if(BOOST_JSON_UNLIKELY( !seq_.append(cs.begin(), cs.remain()) ))
1105
9
        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
79.0k
{
1133
79.0k
    constexpr unsigned urc = 0xFFFD; // Unicode replacement character
1134
79.0k
    auto const ev_too_large = is_key?
1135
75.0k
        error::key_too_large : error::string_too_large;
1136
79.0k
    auto const max_size = is_key?
1137
75.0k
        Handler::max_key_size : Handler::max_string_size;
1138
79.0k
    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
79.0k
    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
79.0k
    detail::clipped_const_stream cs(p, end_);
1161
79.0k
    cs.clip(temp.max_size());
1162
1163
79.0k
    if(! stack_empty && ! st_.empty())
1164
233
    {
1165
233
        state st;
1166
233
        st_.pop(st);
1167
233
        switch(st)
1168
233
        {
1169
0
        default: BOOST_JSON_UNREACHABLE();
1170
123
        case state::str3: goto do_str3;
1171
18
        case state::str4: goto do_str4;
1172
14
        case state::str5: goto do_str5;
1173
17
        case state::str6: goto do_str6;
1174
19
        case state::str7: goto do_str7;
1175
14
        case state::sur1: goto do_sur1;
1176
2
        case state::sur2: goto do_sur2;
1177
2
        case state::sur3: goto do_sur3;
1178
9
        case state::sur4: goto do_sur4;
1179
8
        case state::sur5: goto do_sur5;
1180
7
        case state::sur6: goto do_sur6;
1181
233
        }
1182
233
    }
1183
1184
5.19M
    while(true)
1185
5.19M
    {
1186
5.19M
        BOOST_ASSERT( temp.capacity() );
1187
5.19M
        BOOST_ASSERT(*cs == '\\');
1188
5.19M
        ++cs;
1189
5.19M
do_str3:
1190
5.19M
        if(BOOST_JSON_UNLIKELY(! cs))
1191
798
        {
1192
798
            if(BOOST_JSON_LIKELY(! temp.empty()))
1193
612
            {
1194
612
                BOOST_ASSERT(total <= max_size);
1195
612
                if(BOOST_JSON_UNLIKELY(
1196
612
                    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
612
                total += temp.size();
1203
612
                {
1204
612
                    bool r = is_key
1205
612
                        ? h_.on_key_part(temp.get(), total, ec_)
1206
612
                        : h_.on_string_part(temp.get(), total, ec_);
1207
1208
612
                    if(BOOST_JSON_UNLIKELY(!r))
1209
0
                    {
1210
0
                        return fail(cs.begin());
1211
0
                    }
1212
612
                }
1213
612
                temp.clear();
1214
612
            }
1215
798
            cs.clip(temp.max_size());
1216
798
            if(BOOST_JSON_UNLIKELY(! cs))
1217
246
                return maybe_suspend(cs.begin(), state::str3);
1218
798
        }
1219
5.19M
        switch(*cs)
1220
5.19M
        {
1221
44
        default:
1222
44
            {
1223
44
                BOOST_STATIC_CONSTEXPR source_location loc
1224
44
                    = BOOST_CURRENT_LOCATION;
1225
44
                return fail(cs.begin(), error::syntax, &loc);
1226
0
            }
1227
3.47k
        case '\x22': // '"'
1228
3.47k
            temp.push_back('\x22');
1229
3.47k
            ++cs;
1230
3.47k
            break;
1231
4.89M
        case '\\':
1232
4.89M
            temp.push_back('\\');
1233
4.89M
            ++cs;
1234
4.89M
            break;
1235
1.80k
        case '/':
1236
1.80k
            temp.push_back('/');
1237
1.80k
            ++cs;
1238
1.80k
            break;
1239
835
        case 'b':
1240
835
            temp.push_back('\x08');
1241
835
            ++cs;
1242
835
            break;
1243
522
        case 'f':
1244
522
            temp.push_back('\x0c');
1245
522
            ++cs;
1246
522
            break;
1247
3.59k
        case 'n':
1248
3.59k
            temp.push_back('\x0a');
1249
3.59k
            ++cs;
1250
3.59k
            break;
1251
558
        case 'r':
1252
558
            temp.push_back('\x0d');
1253
558
            ++cs;
1254
558
            break;
1255
4.50k
        case 't':
1256
4.50k
            temp.push_back('\x09');
1257
4.50k
            ++cs;
1258
4.50k
            break;
1259
279k
        case 'u':
1260
            // utf16 escape
1261
            //
1262
            // fast path only when the buffer
1263
            // is large enough for 2 surrogates
1264
279k
            if(BOOST_JSON_LIKELY(cs.remain() > 10))
1265
277k
            {
1266
                // KRYSTIAN TODO: this could be done
1267
                // with fewer instructions
1268
277k
                digit = detail::load_little_endian<4>(
1269
277k
                    cs.begin() + 1);
1270
277k
                int d4 = detail::hex_digit(static_cast<
1271
277k
                    unsigned char>(digit >> 24));
1272
277k
                int d3 = detail::hex_digit(static_cast<
1273
277k
                    unsigned char>(digit >> 16));
1274
277k
                int d2 = detail::hex_digit(static_cast<
1275
277k
                    unsigned char>(digit >> 8));
1276
277k
                int d1 = detail::hex_digit(static_cast<
1277
277k
                    unsigned char>(digit));
1278
277k
                if(BOOST_JSON_UNLIKELY(
1279
277k
                    (d1 | d2 | d3 | d4) == -1))
1280
64
                {
1281
64
                    if(d1 != -1)
1282
38
                        ++cs;
1283
64
                    if(d2 != -1)
1284
29
                        ++cs;
1285
64
                    if(d3 != -1)
1286
29
                        ++cs;
1287
64
                    BOOST_STATIC_CONSTEXPR source_location loc
1288
64
                        = BOOST_CURRENT_LOCATION;
1289
64
                    return fail(cs.begin(), error::expected_hex_digit, &loc);
1290
64
                }
1291
                // 32 bit unicode scalar value
1292
277k
                unsigned u1 =
1293
277k
                    (d1 << 12) + (d2 << 8) +
1294
277k
                    (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
277k
                if(BOOST_JSON_LIKELY(
1300
277k
                    u1 < 0xd800 || u1 > 0xdfff))
1301
265k
                {
1302
265k
                    cs += 5;
1303
265k
                    temp.append_utf8(u1);
1304
265k
                    break;
1305
265k
                }
1306
12.6k
                if(BOOST_JSON_UNLIKELY(u1 > 0xdbff))
1307
11
                {
1308
                    // If it's an illegal leading surrogate and
1309
                    // the parser does not allow it, return an error.
1310
11
                    if(!allow_bad_utf16)
1311
11
                    {
1312
11
                        BOOST_STATIC_CONSTEXPR source_location loc
1313
11
                            = BOOST_CURRENT_LOCATION;
1314
11
                        return fail(cs.begin(), error::illegal_leading_surrogate,
1315
11
                            &loc);
1316
11
                    }
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
11
                }
1325
12.6k
                cs += 5;
1326
                // KRYSTIAN TODO: this can be a two byte load
1327
                // and a single comparison. We lose error information,
1328
                // but it's faster.
1329
12.6k
                if(BOOST_JSON_UNLIKELY(*cs != '\\'))
1330
5
                {
1331
                    // If the next character is not a backslash and
1332
                    // the parser does not allow it, return a syntax error.
1333
5
                    if(!allow_bad_utf16)
1334
5
                    {
1335
5
                        BOOST_STATIC_CONSTEXPR source_location loc
1336
5
                            = BOOST_CURRENT_LOCATION;
1337
5
                        return fail(cs.begin(), error::syntax, &loc);
1338
5
                    }
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
5
                }
1347
12.6k
                ++cs;
1348
12.6k
                if(BOOST_JSON_UNLIKELY(*cs != 'u'))
1349
6
                {
1350
6
                    if (!allow_bad_utf16)
1351
6
                    {
1352
6
                        BOOST_STATIC_CONSTEXPR source_location loc
1353
6
                            = BOOST_CURRENT_LOCATION;
1354
6
                        return fail(cs.begin(), error::syntax, &loc);
1355
6
                    }
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
6
                }
1364
12.6k
                ++cs;
1365
12.6k
                digit = detail::load_little_endian<4>(cs.begin());
1366
12.6k
                d4 = detail::hex_digit(static_cast<
1367
12.6k
                    unsigned char>(digit >> 24));
1368
12.6k
                d3 = detail::hex_digit(static_cast<
1369
12.6k
                    unsigned char>(digit >> 16));
1370
12.6k
                d2 = detail::hex_digit(static_cast<
1371
12.6k
                    unsigned char>(digit >> 8));
1372
12.6k
                d1 = detail::hex_digit(static_cast<
1373
12.6k
                    unsigned char>(digit));
1374
12.6k
                if(BOOST_JSON_UNLIKELY(
1375
12.6k
                    (d1 | d2 | d3 | d4) == -1))
1376
37
                {
1377
37
                    if(d1 != -1)
1378
18
                        ++cs;
1379
37
                    if(d2 != -1)
1380
15
                        ++cs;
1381
37
                    if(d3 != -1)
1382
11
                        ++cs;
1383
37
                    BOOST_STATIC_CONSTEXPR source_location loc
1384
37
                        = BOOST_CURRENT_LOCATION;
1385
37
                    return fail(cs.begin(), error::expected_hex_digit, &loc);
1386
37
                }
1387
12.6k
                unsigned u2 =
1388
12.6k
                    (d1 << 12) + (d2 << 8) +
1389
12.6k
                    (d3 << 4) + d4;
1390
                // Check if the second code point is a valid trailing surrogate.
1391
                // Valid trailing surrogates are [DC00, DFFF]
1392
12.6k
                if(BOOST_JSON_UNLIKELY(
1393
12.6k
                    u2 < 0xdc00 || u2 > 0xdfff))
1394
23
                {
1395
                    // If not valid and the parser does not allow it, return an error.
1396
23
                    if(!allow_bad_utf16)
1397
23
                    {
1398
23
                        BOOST_STATIC_CONSTEXPR source_location loc
1399
23
                            = BOOST_CURRENT_LOCATION;
1400
23
                        return fail(cs.begin(), error::illegal_trailing_surrogate,
1401
23
                            &loc);
1402
23
                    }
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
12.6k
                cs += 4;
1423
                // Calculate the Unicode code point from the surrogate pair and
1424
                // append the UTF-8 representation.
1425
12.6k
                unsigned cp =
1426
12.6k
                    ((u1 - 0xd800) << 10) +
1427
12.6k
                    ((u2 - 0xdc00)) +
1428
12.6k
                        0x10000;
1429
                // utf-16 surrogate pair
1430
12.6k
                temp.append_utf8(cp);
1431
12.6k
                break;
1432
12.6k
            }
1433
            // flush
1434
1.80k
            if(BOOST_JSON_LIKELY(! temp.empty()))
1435
1.50k
            {
1436
1.50k
                BOOST_ASSERT(total <= max_size);
1437
1.50k
                if(BOOST_JSON_UNLIKELY(
1438
1.50k
                    temp.size() > max_size - total))
1439
0
                {
1440
0
                    BOOST_STATIC_CONSTEXPR source_location loc
1441
0
                        = BOOST_CURRENT_LOCATION;
1442
0
                    return fail(cs.begin(), ev_too_large, &loc);
1443
0
                }
1444
1.50k
                total += temp.size();
1445
1.50k
                {
1446
1.50k
                    bool r = is_key
1447
1.50k
                        ? h_.on_key_part(temp.get(), total, ec_)
1448
1.50k
                        : h_.on_string_part(temp.get(), total, ec_);
1449
1450
1.50k
                    if(BOOST_JSON_UNLIKELY(!r))
1451
0
                    {
1452
0
                        return fail(cs.begin());
1453
0
                    }
1454
1.50k
                }
1455
1.50k
                temp.clear();
1456
1.50k
                cs.clip(temp.max_size());
1457
1.50k
            }
1458
1.80k
            ++cs;
1459
            // utf-16 escape
1460
1.82k
    do_str4:
1461
1.82k
            if(BOOST_JSON_UNLIKELY(! cs))
1462
36
                return maybe_suspend(cs.begin(), state::str4);
1463
1.79k
            digit = detail::hex_digit(*cs);
1464
1.79k
            if(BOOST_JSON_UNLIKELY(digit == -1))
1465
21
            {
1466
21
                BOOST_STATIC_CONSTEXPR source_location loc
1467
21
                    = BOOST_CURRENT_LOCATION;
1468
21
                return fail(cs.begin(), error::expected_hex_digit, &loc);
1469
21
            }
1470
1.76k
            ++cs;
1471
1.76k
            u1_ = digit << 12;
1472
1.78k
    do_str5:
1473
1.78k
            if(BOOST_JSON_UNLIKELY(! cs))
1474
28
                return maybe_suspend(cs.begin(), state::str5);
1475
1.75k
            digit = detail::hex_digit(*cs);
1476
1.75k
            if(BOOST_JSON_UNLIKELY(digit == -1))
1477
23
            {
1478
23
                BOOST_STATIC_CONSTEXPR source_location loc
1479
23
                    = BOOST_CURRENT_LOCATION;
1480
23
                return fail(cs.begin(), error::expected_hex_digit, &loc);
1481
23
            }
1482
1.73k
            ++cs;
1483
1.73k
            u1_ += digit << 8;
1484
1.74k
    do_str6:
1485
1.74k
            if(BOOST_JSON_UNLIKELY(! cs))
1486
34
                return maybe_suspend(cs.begin(), state::str6);
1487
1.71k
            digit = detail::hex_digit(*cs);
1488
1.71k
            if(BOOST_JSON_UNLIKELY(digit == -1))
1489
26
            {
1490
26
                BOOST_STATIC_CONSTEXPR source_location loc
1491
26
                    = BOOST_CURRENT_LOCATION;
1492
26
                return fail(cs.begin(), error::expected_hex_digit, &loc);
1493
26
            }
1494
1.68k
            ++cs;
1495
1.68k
            u1_ += digit << 4;
1496
1.70k
    do_str7:
1497
1.70k
            if(BOOST_JSON_UNLIKELY(! cs))
1498
38
                return maybe_suspend(cs.begin(), state::str7);
1499
1.67k
            digit = detail::hex_digit(*cs);
1500
1.67k
            if(BOOST_JSON_UNLIKELY(digit == -1))
1501
22
            {
1502
22
                BOOST_STATIC_CONSTEXPR source_location loc
1503
22
                    = BOOST_CURRENT_LOCATION;
1504
22
                return fail(cs.begin(), error::expected_hex_digit, &loc);
1505
22
            }
1506
1.64k
            ++cs;
1507
1.64k
            u1_ += digit;
1508
1.64k
            if(BOOST_JSON_LIKELY(
1509
1.64k
                u1_ < 0xd800 || u1_ > 0xdfff))
1510
1.04k
            {
1511
1.04k
                BOOST_ASSERT(temp.empty());
1512
                // utf-8 codepoint
1513
1.04k
                temp.append_utf8(u1_);
1514
1.04k
                break;
1515
1.04k
            }
1516
606
            if(BOOST_JSON_UNLIKELY(u1_ > 0xdbff))
1517
15
            {
1518
                // If it's an illegal leading surrogate and
1519
                // the parser does not allow it, return an error.
1520
15
                if(!allow_bad_utf16)
1521
15
                {
1522
15
                    BOOST_STATIC_CONSTEXPR source_location loc
1523
15
                        = BOOST_CURRENT_LOCATION;
1524
15
                    return fail(cs.begin(), error::illegal_leading_surrogate, &loc);
1525
15
                }
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
15
            }
1534
605
    do_sur1:
1535
605
            if(BOOST_JSON_UNLIKELY(! cs))
1536
28
                return maybe_suspend(cs.begin(), state::sur1);
1537
577
            if(BOOST_JSON_UNLIKELY(*cs != '\\'))
1538
3
            {
1539
                // If the next character is not a backslash and
1540
                // the parser does not allow it, return a syntax error.
1541
3
                if(!allow_bad_utf16)
1542
3
                {
1543
3
                    BOOST_STATIC_CONSTEXPR source_location loc
1544
3
                        = BOOST_CURRENT_LOCATION;
1545
3
                    return fail(cs.begin(), error::syntax, &loc);
1546
3
                }
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
3
            }
1555
574
            ++cs;
1556
576
    do_sur2:
1557
576
            if(BOOST_JSON_UNLIKELY(! cs))
1558
4
                return maybe_suspend(cs.begin(), state::sur2);
1559
572
            if(BOOST_JSON_UNLIKELY(*cs != 'u'))
1560
10
            {
1561
10
                if (!allow_bad_utf16)
1562
10
                {
1563
10
                    BOOST_STATIC_CONSTEXPR source_location loc
1564
10
                        = BOOST_CURRENT_LOCATION;
1565
10
                    return fail(cs.begin(), error::syntax, &loc);
1566
10
                }
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
10
            }
1575
562
            ++cs;
1576
564
    do_sur3:
1577
564
            if(BOOST_JSON_UNLIKELY(! cs))
1578
4
                return maybe_suspend(cs.begin(), state::sur3);
1579
560
            digit = detail::hex_digit(*cs);
1580
560
            if(BOOST_JSON_UNLIKELY(digit == -1))
1581
10
            {
1582
10
                BOOST_STATIC_CONSTEXPR source_location loc
1583
10
                    = BOOST_CURRENT_LOCATION;
1584
10
                return fail(cs.begin(), error::expected_hex_digit, &loc);
1585
10
            }
1586
550
            ++cs;
1587
550
            u2_ = digit << 12;
1588
559
    do_sur4:
1589
559
            if(BOOST_JSON_UNLIKELY(! cs))
1590
18
                return maybe_suspend(cs.begin(), state::sur4);
1591
541
            digit = detail::hex_digit(*cs);
1592
541
            if(BOOST_JSON_UNLIKELY(digit == -1))
1593
11
            {
1594
11
                BOOST_STATIC_CONSTEXPR source_location loc
1595
11
                    = BOOST_CURRENT_LOCATION;
1596
11
                return fail(cs.begin(), error::expected_hex_digit, &loc);
1597
11
            }
1598
530
            ++cs;
1599
530
            u2_ += digit << 8;
1600
538
    do_sur5:
1601
538
            if(BOOST_JSON_UNLIKELY(! cs))
1602
16
                return maybe_suspend(cs.begin(), state::sur5);
1603
522
            digit = detail::hex_digit(*cs);
1604
522
            if(BOOST_JSON_UNLIKELY(digit == -1))
1605
5
            {
1606
5
                BOOST_STATIC_CONSTEXPR source_location loc
1607
5
                    = BOOST_CURRENT_LOCATION;
1608
5
                return fail(cs.begin(), error::expected_hex_digit, &loc);
1609
5
            }
1610
517
            ++cs;
1611
517
            u2_ += digit << 4;
1612
524
    do_sur6:
1613
524
            if(BOOST_JSON_UNLIKELY(! cs))
1614
14
                return maybe_suspend(cs.begin(), state::sur6);
1615
510
            digit = detail::hex_digit(*cs);
1616
510
            if(BOOST_JSON_UNLIKELY(digit == -1))
1617
3
            {
1618
3
                BOOST_STATIC_CONSTEXPR source_location loc
1619
3
                    = BOOST_CURRENT_LOCATION;
1620
3
                return fail(cs.begin(), error::expected_hex_digit, &loc);
1621
3
            }
1622
507
            ++cs;
1623
507
            u2_ += digit;
1624
            // Check if the second code point is a valid trailing surrogate.
1625
            // Valid trailing surrogates are [DC00, DFFF]
1626
507
            if(BOOST_JSON_UNLIKELY(
1627
507
                u2_ < 0xdc00 || u2_ > 0xdfff))
1628
18
            {
1629
                // If not valid and the parser does not allow it, return an error.
1630
18
                if(!allow_bad_utf16)
1631
18
                {
1632
18
                    BOOST_STATIC_CONSTEXPR source_location loc
1633
18
                        = BOOST_CURRENT_LOCATION;
1634
18
                    return fail(cs.begin(), error::illegal_trailing_surrogate, &loc);
1635
18
                }
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
489
            unsigned cp =
1657
489
                ((u1_ - 0xd800) << 10) +
1658
489
                ((u2_ - 0xdc00)) +
1659
489
                    0x10000;
1660
            // utf-16 surrogate pair
1661
489
            temp.append_utf8(cp);
1662
5.19M
        }
1663
1664
        // flush
1665
5.19M
        if(BOOST_JSON_UNLIKELY( !cs ) || *cs != '\\')
1666
78.2k
            break;
1667
5.19M
    }
1668
1669
78.2k
    if(BOOST_JSON_LIKELY( temp.size() ))
1670
78.2k
    {
1671
78.2k
        BOOST_ASSERT(total <= max_size);
1672
78.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
78.2k
        total += temp.size();
1680
78.2k
        bool const r = is_key
1681
78.2k
            ? h_.on_key_part(temp.get(), total, ec_)
1682
78.2k
            : h_.on_string_part(temp.get(), total, ec_);
1683
78.2k
        if(BOOST_JSON_UNLIKELY( !r ))
1684
0
            return fail( cs.begin() );
1685
78.2k
    }
1686
1687
78.2k
    return cs.begin();
1688
78.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
78.7k
{
1133
78.7k
    constexpr unsigned urc = 0xFFFD; // Unicode replacement character
1134
78.7k
    auto const ev_too_large = is_key?
1135
74.8k
        error::key_too_large : error::string_too_large;
1136
78.7k
    auto const max_size = is_key?
1137
74.8k
        Handler::max_key_size : Handler::max_string_size;
1138
78.7k
    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
78.7k
    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
78.7k
    detail::clipped_const_stream cs(p, end_);
1161
78.7k
    cs.clip(temp.max_size());
1162
1163
78.7k
    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
5.19M
    while(true)
1185
5.19M
    {
1186
5.19M
        BOOST_ASSERT( temp.capacity() );
1187
5.19M
        BOOST_ASSERT(*cs == '\\');
1188
5.19M
        ++cs;
1189
5.19M
do_str3:
1190
5.19M
        if(BOOST_JSON_UNLIKELY(! cs))
1191
675
        {
1192
675
            if(BOOST_JSON_LIKELY(! temp.empty()))
1193
612
            {
1194
612
                BOOST_ASSERT(total <= max_size);
1195
612
                if(BOOST_JSON_UNLIKELY(
1196
612
                    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
612
                total += temp.size();
1203
612
                {
1204
612
                    bool r = is_key
1205
612
                        ? h_.on_key_part(temp.get(), total, ec_)
1206
612
                        : h_.on_string_part(temp.get(), total, ec_);
1207
1208
612
                    if(BOOST_JSON_UNLIKELY(!r))
1209
0
                    {
1210
0
                        return fail(cs.begin());
1211
0
                    }
1212
612
                }
1213
612
                temp.clear();
1214
612
            }
1215
675
            cs.clip(temp.max_size());
1216
675
            if(BOOST_JSON_UNLIKELY(! cs))
1217
123
                return maybe_suspend(cs.begin(), state::str3);
1218
675
        }
1219
5.19M
        switch(*cs)
1220
5.19M
        {
1221
44
        default:
1222
44
            {
1223
44
                BOOST_STATIC_CONSTEXPR source_location loc
1224
44
                    = BOOST_CURRENT_LOCATION;
1225
44
                return fail(cs.begin(), error::syntax, &loc);
1226
0
            }
1227
3.47k
        case '\x22': // '"'
1228
3.47k
            temp.push_back('\x22');
1229
3.47k
            ++cs;
1230
3.47k
            break;
1231
4.89M
        case '\\':
1232
4.89M
            temp.push_back('\\');
1233
4.89M
            ++cs;
1234
4.89M
            break;
1235
1.80k
        case '/':
1236
1.80k
            temp.push_back('/');
1237
1.80k
            ++cs;
1238
1.80k
            break;
1239
835
        case 'b':
1240
835
            temp.push_back('\x08');
1241
835
            ++cs;
1242
835
            break;
1243
522
        case 'f':
1244
522
            temp.push_back('\x0c');
1245
522
            ++cs;
1246
522
            break;
1247
3.59k
        case 'n':
1248
3.59k
            temp.push_back('\x0a');
1249
3.59k
            ++cs;
1250
3.59k
            break;
1251
558
        case 'r':
1252
558
            temp.push_back('\x0d');
1253
558
            ++cs;
1254
558
            break;
1255
4.50k
        case 't':
1256
4.50k
            temp.push_back('\x09');
1257
4.50k
            ++cs;
1258
4.50k
            break;
1259
279k
        case 'u':
1260
            // utf16 escape
1261
            //
1262
            // fast path only when the buffer
1263
            // is large enough for 2 surrogates
1264
279k
            if(BOOST_JSON_LIKELY(cs.remain() > 10))
1265
277k
            {
1266
                // KRYSTIAN TODO: this could be done
1267
                // with fewer instructions
1268
277k
                digit = detail::load_little_endian<4>(
1269
277k
                    cs.begin() + 1);
1270
277k
                int d4 = detail::hex_digit(static_cast<
1271
277k
                    unsigned char>(digit >> 24));
1272
277k
                int d3 = detail::hex_digit(static_cast<
1273
277k
                    unsigned char>(digit >> 16));
1274
277k
                int d2 = detail::hex_digit(static_cast<
1275
277k
                    unsigned char>(digit >> 8));
1276
277k
                int d1 = detail::hex_digit(static_cast<
1277
277k
                    unsigned char>(digit));
1278
277k
                if(BOOST_JSON_UNLIKELY(
1279
277k
                    (d1 | d2 | d3 | d4) == -1))
1280
64
                {
1281
64
                    if(d1 != -1)
1282
38
                        ++cs;
1283
64
                    if(d2 != -1)
1284
29
                        ++cs;
1285
64
                    if(d3 != -1)
1286
29
                        ++cs;
1287
64
                    BOOST_STATIC_CONSTEXPR source_location loc
1288
64
                        = BOOST_CURRENT_LOCATION;
1289
64
                    return fail(cs.begin(), error::expected_hex_digit, &loc);
1290
64
                }
1291
                // 32 bit unicode scalar value
1292
277k
                unsigned u1 =
1293
277k
                    (d1 << 12) + (d2 << 8) +
1294
277k
                    (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
277k
                if(BOOST_JSON_LIKELY(
1300
277k
                    u1 < 0xd800 || u1 > 0xdfff))
1301
265k
                {
1302
265k
                    cs += 5;
1303
265k
                    temp.append_utf8(u1);
1304
265k
                    break;
1305
265k
                }
1306
12.6k
                if(BOOST_JSON_UNLIKELY(u1 > 0xdbff))
1307
11
                {
1308
                    // If it's an illegal leading surrogate and
1309
                    // the parser does not allow it, return an error.
1310
11
                    if(!allow_bad_utf16)
1311
11
                    {
1312
11
                        BOOST_STATIC_CONSTEXPR source_location loc
1313
11
                            = BOOST_CURRENT_LOCATION;
1314
11
                        return fail(cs.begin(), error::illegal_leading_surrogate,
1315
11
                            &loc);
1316
11
                    }
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
11
                }
1325
12.6k
                cs += 5;
1326
                // KRYSTIAN TODO: this can be a two byte load
1327
                // and a single comparison. We lose error information,
1328
                // but it's faster.
1329
12.6k
                if(BOOST_JSON_UNLIKELY(*cs != '\\'))
1330
5
                {
1331
                    // If the next character is not a backslash and
1332
                    // the parser does not allow it, return a syntax error.
1333
5
                    if(!allow_bad_utf16)
1334
5
                    {
1335
5
                        BOOST_STATIC_CONSTEXPR source_location loc
1336
5
                            = BOOST_CURRENT_LOCATION;
1337
5
                        return fail(cs.begin(), error::syntax, &loc);
1338
5
                    }
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
5
                }
1347
12.6k
                ++cs;
1348
12.6k
                if(BOOST_JSON_UNLIKELY(*cs != 'u'))
1349
6
                {
1350
6
                    if (!allow_bad_utf16)
1351
6
                    {
1352
6
                        BOOST_STATIC_CONSTEXPR source_location loc
1353
6
                            = BOOST_CURRENT_LOCATION;
1354
6
                        return fail(cs.begin(), error::syntax, &loc);
1355
6
                    }
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
6
                }
1364
12.6k
                ++cs;
1365
12.6k
                digit = detail::load_little_endian<4>(cs.begin());
1366
12.6k
                d4 = detail::hex_digit(static_cast<
1367
12.6k
                    unsigned char>(digit >> 24));
1368
12.6k
                d3 = detail::hex_digit(static_cast<
1369
12.6k
                    unsigned char>(digit >> 16));
1370
12.6k
                d2 = detail::hex_digit(static_cast<
1371
12.6k
                    unsigned char>(digit >> 8));
1372
12.6k
                d1 = detail::hex_digit(static_cast<
1373
12.6k
                    unsigned char>(digit));
1374
12.6k
                if(BOOST_JSON_UNLIKELY(
1375
12.6k
                    (d1 | d2 | d3 | d4) == -1))
1376
37
                {
1377
37
                    if(d1 != -1)
1378
18
                        ++cs;
1379
37
                    if(d2 != -1)
1380
15
                        ++cs;
1381
37
                    if(d3 != -1)
1382
11
                        ++cs;
1383
37
                    BOOST_STATIC_CONSTEXPR source_location loc
1384
37
                        = BOOST_CURRENT_LOCATION;
1385
37
                    return fail(cs.begin(), error::expected_hex_digit, &loc);
1386
37
                }
1387
12.6k
                unsigned u2 =
1388
12.6k
                    (d1 << 12) + (d2 << 8) +
1389
12.6k
                    (d3 << 4) + d4;
1390
                // Check if the second code point is a valid trailing surrogate.
1391
                // Valid trailing surrogates are [DC00, DFFF]
1392
12.6k
                if(BOOST_JSON_UNLIKELY(
1393
12.6k
                    u2 < 0xdc00 || u2 > 0xdfff))
1394
23
                {
1395
                    // If not valid and the parser does not allow it, return an error.
1396
23
                    if(!allow_bad_utf16)
1397
23
                    {
1398
23
                        BOOST_STATIC_CONSTEXPR source_location loc
1399
23
                            = BOOST_CURRENT_LOCATION;
1400
23
                        return fail(cs.begin(), error::illegal_trailing_surrogate,
1401
23
                            &loc);
1402
23
                    }
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
12.6k
                cs += 4;
1423
                // Calculate the Unicode code point from the surrogate pair and
1424
                // append the UTF-8 representation.
1425
12.6k
                unsigned cp =
1426
12.6k
                    ((u1 - 0xd800) << 10) +
1427
12.6k
                    ((u2 - 0xdc00)) +
1428
12.6k
                        0x10000;
1429
                // utf-16 surrogate pair
1430
12.6k
                temp.append_utf8(cp);
1431
12.6k
                break;
1432
12.6k
            }
1433
            // flush
1434
1.80k
            if(BOOST_JSON_LIKELY(! temp.empty()))
1435
1.50k
            {
1436
1.50k
                BOOST_ASSERT(total <= max_size);
1437
1.50k
                if(BOOST_JSON_UNLIKELY(
1438
1.50k
                    temp.size() > max_size - total))
1439
0
                {
1440
0
                    BOOST_STATIC_CONSTEXPR source_location loc
1441
0
                        = BOOST_CURRENT_LOCATION;
1442
0
                    return fail(cs.begin(), ev_too_large, &loc);
1443
0
                }
1444
1.50k
                total += temp.size();
1445
1.50k
                {
1446
1.50k
                    bool r = is_key
1447
1.50k
                        ? h_.on_key_part(temp.get(), total, ec_)
1448
1.50k
                        : h_.on_string_part(temp.get(), total, ec_);
1449
1450
1.50k
                    if(BOOST_JSON_UNLIKELY(!r))
1451
0
                    {
1452
0
                        return fail(cs.begin());
1453
0
                    }
1454
1.50k
                }
1455
1.50k
                temp.clear();
1456
1.50k
                cs.clip(temp.max_size());
1457
1.50k
            }
1458
1.80k
            ++cs;
1459
            // utf-16 escape
1460
1.80k
    do_str4:
1461
1.80k
            if(BOOST_JSON_UNLIKELY(! cs))
1462
18
                return maybe_suspend(cs.begin(), state::str4);
1463
1.79k
            digit = detail::hex_digit(*cs);
1464
1.79k
            if(BOOST_JSON_UNLIKELY(digit == -1))
1465
21
            {
1466
21
                BOOST_STATIC_CONSTEXPR source_location loc
1467
21
                    = BOOST_CURRENT_LOCATION;
1468
21
                return fail(cs.begin(), error::expected_hex_digit, &loc);
1469
21
            }
1470
1.76k
            ++cs;
1471
1.76k
            u1_ = digit << 12;
1472
1.76k
    do_str5:
1473
1.76k
            if(BOOST_JSON_UNLIKELY(! cs))
1474
14
                return maybe_suspend(cs.begin(), state::str5);
1475
1.75k
            digit = detail::hex_digit(*cs);
1476
1.75k
            if(BOOST_JSON_UNLIKELY(digit == -1))
1477
23
            {
1478
23
                BOOST_STATIC_CONSTEXPR source_location loc
1479
23
                    = BOOST_CURRENT_LOCATION;
1480
23
                return fail(cs.begin(), error::expected_hex_digit, &loc);
1481
23
            }
1482
1.73k
            ++cs;
1483
1.73k
            u1_ += digit << 8;
1484
1.73k
    do_str6:
1485
1.73k
            if(BOOST_JSON_UNLIKELY(! cs))
1486
17
                return maybe_suspend(cs.begin(), state::str6);
1487
1.71k
            digit = detail::hex_digit(*cs);
1488
1.71k
            if(BOOST_JSON_UNLIKELY(digit == -1))
1489
26
            {
1490
26
                BOOST_STATIC_CONSTEXPR source_location loc
1491
26
                    = BOOST_CURRENT_LOCATION;
1492
26
                return fail(cs.begin(), error::expected_hex_digit, &loc);
1493
26
            }
1494
1.68k
            ++cs;
1495
1.68k
            u1_ += digit << 4;
1496
1.68k
    do_str7:
1497
1.68k
            if(BOOST_JSON_UNLIKELY(! cs))
1498
19
                return maybe_suspend(cs.begin(), state::str7);
1499
1.67k
            digit = detail::hex_digit(*cs);
1500
1.67k
            if(BOOST_JSON_UNLIKELY(digit == -1))
1501
22
            {
1502
22
                BOOST_STATIC_CONSTEXPR source_location loc
1503
22
                    = BOOST_CURRENT_LOCATION;
1504
22
                return fail(cs.begin(), error::expected_hex_digit, &loc);
1505
22
            }
1506
1.64k
            ++cs;
1507
1.64k
            u1_ += digit;
1508
1.64k
            if(BOOST_JSON_LIKELY(
1509
1.64k
                u1_ < 0xd800 || u1_ > 0xdfff))
1510
1.04k
            {
1511
1.04k
                BOOST_ASSERT(temp.empty());
1512
                // utf-8 codepoint
1513
1.04k
                temp.append_utf8(u1_);
1514
1.04k
                break;
1515
1.04k
            }
1516
606
            if(BOOST_JSON_UNLIKELY(u1_ > 0xdbff))
1517
15
            {
1518
                // If it's an illegal leading surrogate and
1519
                // the parser does not allow it, return an error.
1520
15
                if(!allow_bad_utf16)
1521
15
                {
1522
15
                    BOOST_STATIC_CONSTEXPR source_location loc
1523
15
                        = BOOST_CURRENT_LOCATION;
1524
15
                    return fail(cs.begin(), error::illegal_leading_surrogate, &loc);
1525
15
                }
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
15
            }
1534
591
    do_sur1:
1535
591
            if(BOOST_JSON_UNLIKELY(! cs))
1536
14
                return maybe_suspend(cs.begin(), state::sur1);
1537
577
            if(BOOST_JSON_UNLIKELY(*cs != '\\'))
1538
3
            {
1539
                // If the next character is not a backslash and
1540
                // the parser does not allow it, return a syntax error.
1541
3
                if(!allow_bad_utf16)
1542
3
                {
1543
3
                    BOOST_STATIC_CONSTEXPR source_location loc
1544
3
                        = BOOST_CURRENT_LOCATION;
1545
3
                    return fail(cs.begin(), error::syntax, &loc);
1546
3
                }
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
3
            }
1555
574
            ++cs;
1556
574
    do_sur2:
1557
574
            if(BOOST_JSON_UNLIKELY(! cs))
1558
2
                return maybe_suspend(cs.begin(), state::sur2);
1559
572
            if(BOOST_JSON_UNLIKELY(*cs != 'u'))
1560
10
            {
1561
10
                if (!allow_bad_utf16)
1562
10
                {
1563
10
                    BOOST_STATIC_CONSTEXPR source_location loc
1564
10
                        = BOOST_CURRENT_LOCATION;
1565
10
                    return fail(cs.begin(), error::syntax, &loc);
1566
10
                }
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
10
            }
1575
562
            ++cs;
1576
562
    do_sur3:
1577
562
            if(BOOST_JSON_UNLIKELY(! cs))
1578
2
                return maybe_suspend(cs.begin(), state::sur3);
1579
560
            digit = detail::hex_digit(*cs);
1580
560
            if(BOOST_JSON_UNLIKELY(digit == -1))
1581
10
            {
1582
10
                BOOST_STATIC_CONSTEXPR source_location loc
1583
10
                    = BOOST_CURRENT_LOCATION;
1584
10
                return fail(cs.begin(), error::expected_hex_digit, &loc);
1585
10
            }
1586
550
            ++cs;
1587
550
            u2_ = digit << 12;
1588
550
    do_sur4:
1589
550
            if(BOOST_JSON_UNLIKELY(! cs))
1590
9
                return maybe_suspend(cs.begin(), state::sur4);
1591
541
            digit = detail::hex_digit(*cs);
1592
541
            if(BOOST_JSON_UNLIKELY(digit == -1))
1593
11
            {
1594
11
                BOOST_STATIC_CONSTEXPR source_location loc
1595
11
                    = BOOST_CURRENT_LOCATION;
1596
11
                return fail(cs.begin(), error::expected_hex_digit, &loc);
1597
11
            }
1598
530
            ++cs;
1599
530
            u2_ += digit << 8;
1600
530
    do_sur5:
1601
530
            if(BOOST_JSON_UNLIKELY(! cs))
1602
8
                return maybe_suspend(cs.begin(), state::sur5);
1603
522
            digit = detail::hex_digit(*cs);
1604
522
            if(BOOST_JSON_UNLIKELY(digit == -1))
1605
5
            {
1606
5
                BOOST_STATIC_CONSTEXPR source_location loc
1607
5
                    = BOOST_CURRENT_LOCATION;
1608
5
                return fail(cs.begin(), error::expected_hex_digit, &loc);
1609
5
            }
1610
517
            ++cs;
1611
517
            u2_ += digit << 4;
1612
517
    do_sur6:
1613
517
            if(BOOST_JSON_UNLIKELY(! cs))
1614
7
                return maybe_suspend(cs.begin(), state::sur6);
1615
510
            digit = detail::hex_digit(*cs);
1616
510
            if(BOOST_JSON_UNLIKELY(digit == -1))
1617
3
            {
1618
3
                BOOST_STATIC_CONSTEXPR source_location loc
1619
3
                    = BOOST_CURRENT_LOCATION;
1620
3
                return fail(cs.begin(), error::expected_hex_digit, &loc);
1621
3
            }
1622
507
            ++cs;
1623
507
            u2_ += digit;
1624
            // Check if the second code point is a valid trailing surrogate.
1625
            // Valid trailing surrogates are [DC00, DFFF]
1626
507
            if(BOOST_JSON_UNLIKELY(
1627
507
                u2_ < 0xdc00 || u2_ > 0xdfff))
1628
18
            {
1629
                // If not valid and the parser does not allow it, return an error.
1630
18
                if(!allow_bad_utf16)
1631
18
                {
1632
18
                    BOOST_STATIC_CONSTEXPR source_location loc
1633
18
                        = BOOST_CURRENT_LOCATION;
1634
18
                    return fail(cs.begin(), error::illegal_trailing_surrogate, &loc);
1635
18
                }
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
489
            unsigned cp =
1657
489
                ((u1_ - 0xd800) << 10) +
1658
489
                ((u2_ - 0xdc00)) +
1659
489
                    0x10000;
1660
            // utf-16 surrogate pair
1661
489
            temp.append_utf8(cp);
1662
5.19M
        }
1663
1664
        // flush
1665
5.19M
        if(BOOST_JSON_UNLIKELY( !cs ) || *cs != '\\')
1666
78.2k
            break;
1667
5.19M
    }
1668
1669
78.2k
    if(BOOST_JSON_LIKELY( temp.size() ))
1670
78.2k
    {
1671
78.2k
        BOOST_ASSERT(total <= max_size);
1672
78.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
78.2k
        total += temp.size();
1680
78.2k
        bool const r = is_key
1681
78.2k
            ? h_.on_key_part(temp.get(), total, ec_)
1682
78.2k
            : h_.on_string_part(temp.get(), total, ec_);
1683
78.2k
        if(BOOST_JSON_UNLIKELY( !r ))
1684
0
            return fail( cs.begin() );
1685
78.2k
    }
1686
1687
78.2k
    return cs.begin();
1688
78.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
233
{
1133
233
    constexpr unsigned urc = 0xFFFD; // Unicode replacement character
1134
233
    auto const ev_too_large = is_key?
1135
186
        error::key_too_large : error::string_too_large;
1136
233
    auto const max_size = is_key?
1137
186
        Handler::max_key_size : Handler::max_string_size;
1138
233
    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
233
    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
233
    detail::clipped_const_stream cs(p, end_);
1161
233
    cs.clip(temp.max_size());
1162
1163
233
    if(! stack_empty && ! st_.empty())
1164
233
    {
1165
233
        state st;
1166
233
        st_.pop(st);
1167
233
        switch(st)
1168
233
        {
1169
0
        default: BOOST_JSON_UNREACHABLE();
1170
123
        case state::str3: goto do_str3;
1171
18
        case state::str4: goto do_str4;
1172
14
        case state::str5: goto do_str5;
1173
17
        case state::str6: goto do_str6;
1174
19
        case state::str7: goto do_str7;
1175
14
        case state::sur1: goto do_sur1;
1176
2
        case state::sur2: goto do_sur2;
1177
2
        case state::sur3: goto do_sur3;
1178
9
        case state::sur4: goto do_sur4;
1179
8
        case state::sur5: goto do_sur5;
1180
7
        case state::sur6: goto do_sur6;
1181
233
        }
1182
233
    }
1183
1184
0
    while(true)
1185
0
    {
1186
0
        BOOST_ASSERT( temp.capacity() );
1187
0
        BOOST_ASSERT(*cs == '\\');
1188
0
        ++cs;
1189
123
do_str3:
1190
123
        if(BOOST_JSON_UNLIKELY(! cs))
1191
123
        {
1192
123
            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
123
            cs.clip(temp.max_size());
1216
123
            if(BOOST_JSON_UNLIKELY(! cs))
1217
123
                return maybe_suspend(cs.begin(), state::str3);
1218
123
        }
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
18
    do_str4:
1461
18
            if(BOOST_JSON_UNLIKELY(! cs))
1462
18
                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
14
    do_str5:
1473
14
            if(BOOST_JSON_UNLIKELY(! cs))
1474
14
                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
17
    do_str6:
1485
17
            if(BOOST_JSON_UNLIKELY(! cs))
1486
17
                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
19
    do_str7:
1497
19
            if(BOOST_JSON_UNLIKELY(! cs))
1498
19
                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
14
    do_sur1:
1535
14
            if(BOOST_JSON_UNLIKELY(! cs))
1536
14
                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
2
    do_sur2:
1557
2
            if(BOOST_JSON_UNLIKELY(! cs))
1558
2
                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
2
    do_sur3:
1577
2
            if(BOOST_JSON_UNLIKELY(! cs))
1578
2
                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
9
    do_sur4:
1589
9
            if(BOOST_JSON_UNLIKELY(! cs))
1590
9
                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
8
    do_sur5:
1601
8
            if(BOOST_JSON_UNLIKELY(! cs))
1602
8
                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
7
    do_sur6:
1613
7
            if(BOOST_JSON_UNLIKELY(! cs))
1614
7
                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
18.3k
{
1707
18.3k
    detail::const_stream_wrapper cs(p, end_);
1708
18.3k
    std::size_t size;
1709
18.3k
    if(! stack_empty && ! st_.empty())
1710
1.13k
    {
1711
        // resume
1712
1.13k
        state st;
1713
1.13k
        st_.pop(st);
1714
1.13k
        st_.pop(size);
1715
1.13k
        switch(st)
1716
1.13k
        {
1717
0
        default: BOOST_JSON_UNREACHABLE();
1718
84
        case state::obj1: goto do_obj1;
1719
7
        case state::obj2: goto do_obj2;
1720
221
        case state::obj3: goto do_obj3;
1721
113
        case state::obj4: goto do_obj4;
1722
4
        case state::obj5: goto do_obj5;
1723
55
        case state::obj6: goto do_obj6;
1724
510
        case state::obj7: goto do_obj7;
1725
66
        case state::obj8: goto do_obj8;
1726
68
        case state::obj9: goto do_obj9;
1727
8
        case state::obj10: goto do_obj10;
1728
3
        case state::obj11: goto do_obj11;
1729
1.13k
        }
1730
1.13k
    }
1731
17.1k
    BOOST_ASSERT(*cs == '{');
1732
17.1k
    size = 0;
1733
17.1k
    if(BOOST_JSON_UNLIKELY(! depth_))
1734
7
    {
1735
7
        BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION;
1736
7
        return fail(cs.begin(), error::too_deep, &loc);
1737
7
    }
1738
17.1k
    --depth_;
1739
17.1k
    if(BOOST_JSON_UNLIKELY(
1740
17.1k
        ! h_.on_object_begin(ec_)))
1741
0
        return fail(cs.begin());
1742
17.1k
    ++cs;
1743
    // object:
1744
    //     '{' *ws '}'
1745
    //     '{' *ws string *ws ':' *ws value *ws *[ ',' *ws string *ws ':' *ws value *ws ] '}'
1746
17.6k
do_obj1:
1747
17.6k
    cs = detail::count_whitespace(cs.begin(), cs.end());
1748
17.6k
    if(BOOST_JSON_UNLIKELY(! cs))
1749
168
        return maybe_suspend(cs.begin(), state::obj1, size);
1750
17.5k
    if(BOOST_JSON_LIKELY(*cs != '}'))
1751
9.89k
    {
1752
9.89k
        if(BOOST_JSON_UNLIKELY(*cs != '\x22'))
1753
584
        {
1754
584
            if(allow_comments && *cs == '/')
1755
462
            {
1756
469
do_obj2:
1757
469
                cs = parse_comment(cs.begin(), stack_empty, std::false_type());
1758
469
                if(BOOST_JSON_UNLIKELY(incomplete(cs)))
1759
15
                    return suspend_or_fail(state::obj2, size);
1760
454
                goto do_obj1;
1761
469
            }
1762
122
            BOOST_STATIC_CONSTEXPR source_location loc
1763
122
                = BOOST_CURRENT_LOCATION;
1764
122
            return fail(cs.begin(), error::syntax, &loc);
1765
584
        }
1766
394k
loop:
1767
394k
        if(BOOST_JSON_UNLIKELY(++size >
1768
394k
            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
394k
do_obj3:
1775
394k
        cs = parse_string(cs.begin(), stack_empty, std::true_type(), allow_bad_utf8, allow_bad_utf16);
1776
394k
        if(BOOST_JSON_UNLIKELY(incomplete(cs)))
1777
593
            return suspend_or_fail(state::obj3, size);
1778
394k
do_obj4:
1779
394k
        cs = detail::count_whitespace(cs.begin(), cs.end());
1780
394k
        if(BOOST_JSON_UNLIKELY(! cs))
1781
226
            return maybe_suspend(cs.begin(), state::obj4, size);
1782
394k
        if(BOOST_JSON_UNLIKELY(*cs != ':'))
1783
679
        {
1784
679
            if(allow_comments && *cs == '/')
1785
549
            {
1786
553
do_obj5:
1787
553
                cs = parse_comment(cs.begin(), stack_empty, std::false_type());
1788
553
                if(BOOST_JSON_UNLIKELY(incomplete(cs)))
1789
8
                    return suspend_or_fail(state::obj5, size);
1790
545
                goto do_obj4;
1791
553
            }
1792
130
            BOOST_STATIC_CONSTEXPR source_location loc
1793
130
                = BOOST_CURRENT_LOCATION;
1794
130
            return fail(cs.begin(), error::syntax, &loc);
1795
679
        }
1796
393k
        ++cs;
1797
394k
do_obj6:
1798
394k
        cs = detail::count_whitespace(cs.begin(), cs.end());
1799
394k
        if(BOOST_JSON_UNLIKELY(! cs))
1800
110
            return maybe_suspend(cs.begin(), state::obj6, size);
1801
394k
do_obj7:
1802
394k
        cs = parse_value(cs.begin(), stack_empty, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16);
1803
394k
        if(BOOST_JSON_UNLIKELY(incomplete(cs)))
1804
1.44k
            return suspend_or_fail(state::obj7, size);
1805
393k
do_obj8:
1806
393k
        cs = detail::count_whitespace(cs.begin(), cs.end());
1807
393k
        if(BOOST_JSON_UNLIKELY(! cs))
1808
139
            return maybe_suspend(cs.begin(), state::obj8, size);
1809
393k
        if(BOOST_JSON_LIKELY(*cs == ','))
1810
385k
        {
1811
385k
            ++cs;
1812
386k
do_obj9:
1813
386k
            cs = detail::count_whitespace(cs.begin(), cs.end());
1814
386k
            if(BOOST_JSON_UNLIKELY(! cs))
1815
136
                return maybe_suspend(cs.begin(), state::obj9, size);
1816
1817
            // loop for next element
1818
386k
            if(BOOST_JSON_LIKELY(*cs == '\x22'))
1819
385k
                goto loop;
1820
1.33k
            if(! allow_trailing || *cs != '}')
1821
884
            {
1822
884
                if(allow_comments && *cs == '/')
1823
760
                {
1824
768
do_obj10:
1825
768
                    cs = parse_comment(cs.begin(), stack_empty, std::false_type());
1826
768
                    if(BOOST_JSON_UNLIKELY(incomplete(cs)))
1827
19
                        return suspend_or_fail(state::obj10, size);
1828
749
                    goto do_obj9;
1829
768
                }
1830
124
                BOOST_STATIC_CONSTEXPR source_location loc
1831
124
                    = BOOST_CURRENT_LOCATION;
1832
124
                return fail(cs.begin(), error::syntax, &loc);
1833
884
            }
1834
1.33k
        }
1835
7.37k
        else if(BOOST_JSON_UNLIKELY(*cs != '}'))
1836
521
        {
1837
521
            if(allow_comments && *cs == '/')
1838
411
            {
1839
414
do_obj11:
1840
414
                cs = parse_comment(cs.begin(), stack_empty, std::false_type());
1841
414
                if(BOOST_JSON_UNLIKELY(incomplete(cs)))
1842
9
                    return suspend_or_fail(state::obj11, size);
1843
405
                goto do_obj8;
1844
414
            }
1845
110
            BOOST_STATIC_CONSTEXPR source_location loc
1846
110
                = BOOST_CURRENT_LOCATION;
1847
110
            return fail(cs.begin(), error::syntax, &loc);
1848
521
        }
1849
        // got closing brace, fall through
1850
393k
    }
1851
14.9k
    if(BOOST_JSON_UNLIKELY(
1852
14.9k
        ! h_.on_object_end(size, ec_)))
1853
0
        return fail(cs.begin());
1854
14.9k
    ++depth_;
1855
14.9k
    ++cs;
1856
14.9k
    return cs.begin();
1857
14.9k
}
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
10.1k
{
1707
10.1k
    detail::const_stream_wrapper cs(p, end_);
1708
10.1k
    std::size_t size;
1709
10.1k
    if(! stack_empty && ! st_.empty())
1710
0
    {
1711
        // resume
1712
0
        state st;
1713
0
        st_.pop(st);
1714
0
        st_.pop(size);
1715
0
        switch(st)
1716
0
        {
1717
0
        default: BOOST_JSON_UNREACHABLE();
1718
0
        case state::obj1: goto do_obj1;
1719
0
        case state::obj2: goto do_obj2;
1720
0
        case state::obj3: goto do_obj3;
1721
0
        case state::obj4: goto do_obj4;
1722
0
        case state::obj5: goto do_obj5;
1723
0
        case state::obj6: goto do_obj6;
1724
0
        case state::obj7: goto do_obj7;
1725
0
        case state::obj8: goto do_obj8;
1726
0
        case state::obj9: goto do_obj9;
1727
0
        case state::obj10: goto do_obj10;
1728
0
        case state::obj11: goto do_obj11;
1729
0
        }
1730
0
    }
1731
10.1k
    BOOST_ASSERT(*cs == '{');
1732
10.1k
    size = 0;
1733
10.1k
    if(BOOST_JSON_UNLIKELY(! depth_))
1734
5
    {
1735
5
        BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION;
1736
5
        return fail(cs.begin(), error::too_deep, &loc);
1737
5
    }
1738
10.1k
    --depth_;
1739
10.1k
    if(BOOST_JSON_UNLIKELY(
1740
10.1k
        ! h_.on_object_begin(ec_)))
1741
0
        return fail(cs.begin());
1742
10.1k
    ++cs;
1743
    // object:
1744
    //     '{' *ws '}'
1745
    //     '{' *ws string *ws ':' *ws value *ws *[ ',' *ws string *ws ':' *ws value *ws ] '}'
1746
10.1k
do_obj1:
1747
10.1k
    cs = detail::count_whitespace(cs.begin(), cs.end());
1748
10.1k
    if(BOOST_JSON_UNLIKELY(! cs))
1749
37
        return maybe_suspend(cs.begin(), state::obj1, size);
1750
10.0k
    if(BOOST_JSON_LIKELY(*cs != '}'))
1751
4.54k
    {
1752
4.54k
        if(BOOST_JSON_UNLIKELY(*cs != '\x22'))
1753
58
        {
1754
58
            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
58
            BOOST_STATIC_CONSTEXPR source_location loc
1763
58
                = BOOST_CURRENT_LOCATION;
1764
58
            return fail(cs.begin(), error::syntax, &loc);
1765
58
        }
1766
376k
loop:
1767
376k
        if(BOOST_JSON_UNLIKELY(++size >
1768
376k
            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
376k
do_obj3:
1775
376k
        cs = parse_string(cs.begin(), stack_empty, std::true_type(), allow_bad_utf8, allow_bad_utf16);
1776
376k
        if(BOOST_JSON_UNLIKELY(incomplete(cs)))
1777
198
            return suspend_or_fail(state::obj3, size);
1778
375k
do_obj4:
1779
375k
        cs = detail::count_whitespace(cs.begin(), cs.end());
1780
375k
        if(BOOST_JSON_UNLIKELY(! cs))
1781
50
            return maybe_suspend(cs.begin(), state::obj4, size);
1782
375k
        if(BOOST_JSON_UNLIKELY(*cs != ':'))
1783
61
        {
1784
61
            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
61
            BOOST_STATIC_CONSTEXPR source_location loc
1793
61
                = BOOST_CURRENT_LOCATION;
1794
61
            return fail(cs.begin(), error::syntax, &loc);
1795
61
        }
1796
375k
        ++cs;
1797
375k
do_obj6:
1798
375k
        cs = detail::count_whitespace(cs.begin(), cs.end());
1799
375k
        if(BOOST_JSON_UNLIKELY(! cs))
1800
29
            return maybe_suspend(cs.begin(), state::obj6, size);
1801
375k
do_obj7:
1802
375k
        cs = parse_value(cs.begin(), stack_empty, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16);
1803
375k
        if(BOOST_JSON_UNLIKELY(incomplete(cs)))
1804
485
            return suspend_or_fail(state::obj7, size);
1805
375k
do_obj8:
1806
375k
        cs = detail::count_whitespace(cs.begin(), cs.end());
1807
375k
        if(BOOST_JSON_UNLIKELY(! cs))
1808
33
            return maybe_suspend(cs.begin(), state::obj8, size);
1809
375k
        if(BOOST_JSON_LIKELY(*cs == ','))
1810
371k
        {
1811
371k
            ++cs;
1812
371k
do_obj9:
1813
371k
            cs = detail::count_whitespace(cs.begin(), cs.end());
1814
371k
            if(BOOST_JSON_UNLIKELY(! cs))
1815
30
                return maybe_suspend(cs.begin(), state::obj9, size);
1816
1817
            // loop for next element
1818
371k
            if(BOOST_JSON_LIKELY(*cs == '\x22'))
1819
371k
                goto loop;
1820
263
            if(! allow_trailing || *cs != '}')
1821
54
            {
1822
54
                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
54
                BOOST_STATIC_CONSTEXPR source_location loc
1831
54
                    = BOOST_CURRENT_LOCATION;
1832
54
                return fail(cs.begin(), error::syntax, &loc);
1833
54
            }
1834
263
        }
1835
3.33k
        else if(BOOST_JSON_UNLIKELY(*cs != '}'))
1836
59
        {
1837
59
            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
59
            BOOST_STATIC_CONSTEXPR source_location loc
1846
59
                = BOOST_CURRENT_LOCATION;
1847
59
            return fail(cs.begin(), error::syntax, &loc);
1848
59
        }
1849
        // got closing brace, fall through
1850
375k
    }
1851
9.03k
    if(BOOST_JSON_UNLIKELY(
1852
9.03k
        ! h_.on_object_end(size, ec_)))
1853
0
        return fail(cs.begin());
1854
9.03k
    ++depth_;
1855
9.03k
    ++cs;
1856
9.03k
    return cs.begin();
1857
9.03k
}
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
7.03k
{
1707
7.03k
    detail::const_stream_wrapper cs(p, end_);
1708
7.03k
    std::size_t size;
1709
7.03k
    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
7.03k
    BOOST_ASSERT(*cs == '{');
1732
7.03k
    size = 0;
1733
7.03k
    if(BOOST_JSON_UNLIKELY(! depth_))
1734
2
    {
1735
2
        BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION;
1736
2
        return fail(cs.begin(), error::too_deep, &loc);
1737
2
    }
1738
7.03k
    --depth_;
1739
7.03k
    if(BOOST_JSON_UNLIKELY(
1740
7.03k
        ! h_.on_object_begin(ec_)))
1741
0
        return fail(cs.begin());
1742
7.03k
    ++cs;
1743
    // object:
1744
    //     '{' *ws '}'
1745
    //     '{' *ws string *ws ':' *ws value *ws *[ ',' *ws string *ws ':' *ws value *ws ] '}'
1746
7.48k
do_obj1:
1747
7.48k
    cs = detail::count_whitespace(cs.begin(), cs.end());
1748
7.48k
    if(BOOST_JSON_UNLIKELY(! cs))
1749
47
        return maybe_suspend(cs.begin(), state::obj1, size);
1750
7.43k
    if(BOOST_JSON_LIKELY(*cs != '}'))
1751
5.35k
    {
1752
5.35k
        if(BOOST_JSON_UNLIKELY(*cs != '\x22'))
1753
526
        {
1754
526
            if(allow_comments && *cs == '/')
1755
462
            {
1756
462
do_obj2:
1757
462
                cs = parse_comment(cs.begin(), stack_empty, std::false_type());
1758
462
                if(BOOST_JSON_UNLIKELY(incomplete(cs)))
1759
8
                    return suspend_or_fail(state::obj2, size);
1760
454
                goto do_obj1;
1761
462
            }
1762
64
            BOOST_STATIC_CONSTEXPR source_location loc
1763
64
                = BOOST_CURRENT_LOCATION;
1764
64
            return fail(cs.begin(), error::syntax, &loc);
1765
526
        }
1766
18.5k
loop:
1767
18.5k
        if(BOOST_JSON_UNLIKELY(++size >
1768
18.5k
            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
18.5k
do_obj3:
1775
18.5k
        cs = parse_string(cs.begin(), stack_empty, std::true_type(), allow_bad_utf8, allow_bad_utf16);
1776
18.5k
        if(BOOST_JSON_UNLIKELY(incomplete(cs)))
1777
174
            return suspend_or_fail(state::obj3, size);
1778
18.9k
do_obj4:
1779
18.9k
        cs = detail::count_whitespace(cs.begin(), cs.end());
1780
18.9k
        if(BOOST_JSON_UNLIKELY(! cs))
1781
63
            return maybe_suspend(cs.begin(), state::obj4, size);
1782
18.8k
        if(BOOST_JSON_UNLIKELY(*cs != ':'))
1783
618
        {
1784
618
            if(allow_comments && *cs == '/')
1785
549
            {
1786
549
do_obj5:
1787
549
                cs = parse_comment(cs.begin(), stack_empty, std::false_type());
1788
549
                if(BOOST_JSON_UNLIKELY(incomplete(cs)))
1789
4
                    return suspend_or_fail(state::obj5, size);
1790
545
                goto do_obj4;
1791
549
            }
1792
69
            BOOST_STATIC_CONSTEXPR source_location loc
1793
69
                = BOOST_CURRENT_LOCATION;
1794
69
            return fail(cs.begin(), error::syntax, &loc);
1795
618
        }
1796
18.2k
        ++cs;
1797
18.2k
do_obj6:
1798
18.2k
        cs = detail::count_whitespace(cs.begin(), cs.end());
1799
18.2k
        if(BOOST_JSON_UNLIKELY(! cs))
1800
26
            return maybe_suspend(cs.begin(), state::obj6, size);
1801
18.2k
do_obj7:
1802
18.2k
        cs = parse_value(cs.begin(), stack_empty, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16);
1803
18.2k
        if(BOOST_JSON_UNLIKELY(incomplete(cs)))
1804
457
            return suspend_or_fail(state::obj7, size);
1805
18.2k
do_obj8:
1806
18.2k
        cs = detail::count_whitespace(cs.begin(), cs.end());
1807
18.2k
        if(BOOST_JSON_UNLIKELY(! cs))
1808
33
            return maybe_suspend(cs.begin(), state::obj8, size);
1809
18.1k
        if(BOOST_JSON_LIKELY(*cs == ','))
1810
14.1k
        {
1811
14.1k
            ++cs;
1812
14.8k
do_obj9:
1813
14.8k
            cs = detail::count_whitespace(cs.begin(), cs.end());
1814
14.8k
            if(BOOST_JSON_UNLIKELY(! cs))
1815
38
                return maybe_suspend(cs.begin(), state::obj9, size);
1816
1817
            // loop for next element
1818
14.8k
            if(BOOST_JSON_LIKELY(*cs == '\x22'))
1819
13.7k
                goto loop;
1820
1.06k
            if(! allow_trailing || *cs != '}')
1821
830
            {
1822
830
                if(allow_comments && *cs == '/')
1823
760
                {
1824
760
do_obj10:
1825
760
                    cs = parse_comment(cs.begin(), stack_empty, std::false_type());
1826
760
                    if(BOOST_JSON_UNLIKELY(incomplete(cs)))
1827
11
                        return suspend_or_fail(state::obj10, size);
1828
749
                    goto do_obj9;
1829
760
                }
1830
70
                BOOST_STATIC_CONSTEXPR source_location loc
1831
70
                    = BOOST_CURRENT_LOCATION;
1832
70
                return fail(cs.begin(), error::syntax, &loc);
1833
830
            }
1834
1.06k
        }
1835
4.04k
        else if(BOOST_JSON_UNLIKELY(*cs != '}'))
1836
462
        {
1837
462
            if(allow_comments && *cs == '/')
1838
411
            {
1839
411
do_obj11:
1840
411
                cs = parse_comment(cs.begin(), stack_empty, std::false_type());
1841
411
                if(BOOST_JSON_UNLIKELY(incomplete(cs)))
1842
6
                    return suspend_or_fail(state::obj11, size);
1843
405
                goto do_obj8;
1844
411
            }
1845
51
            BOOST_STATIC_CONSTEXPR source_location loc
1846
51
                = BOOST_CURRENT_LOCATION;
1847
51
            return fail(cs.begin(), error::syntax, &loc);
1848
462
        }
1849
        // got closing brace, fall through
1850
18.1k
    }
1851
5.90k
    if(BOOST_JSON_UNLIKELY(
1852
5.90k
        ! h_.on_object_end(size, ec_)))
1853
0
        return fail(cs.begin());
1854
5.90k
    ++depth_;
1855
5.90k
    ++cs;
1856
5.90k
    return cs.begin();
1857
5.90k
}
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
478
{
1707
478
    detail::const_stream_wrapper cs(p, end_);
1708
478
    std::size_t size;
1709
478
    if(! stack_empty && ! st_.empty())
1710
478
    {
1711
        // resume
1712
478
        state st;
1713
478
        st_.pop(st);
1714
478
        st_.pop(size);
1715
478
        switch(st)
1716
478
        {
1717
0
        default: BOOST_JSON_UNREACHABLE();
1718
37
        case state::obj1: goto do_obj1;
1719
0
        case state::obj2: goto do_obj2;
1720
119
        case state::obj3: goto do_obj3;
1721
50
        case state::obj4: goto do_obj4;
1722
0
        case state::obj5: goto do_obj5;
1723
29
        case state::obj6: goto do_obj6;
1724
180
        case state::obj7: goto do_obj7;
1725
33
        case state::obj8: goto do_obj8;
1726
30
        case state::obj9: goto do_obj9;
1727
0
        case state::obj10: goto do_obj10;
1728
0
        case state::obj11: goto do_obj11;
1729
478
        }
1730
478
    }
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
37
do_obj1:
1747
37
    cs = detail::count_whitespace(cs.begin(), cs.end());
1748
37
    if(BOOST_JSON_UNLIKELY(! cs))
1749
37
        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
119
do_obj3:
1775
119
        cs = parse_string(cs.begin(), stack_empty, std::true_type(), allow_bad_utf8, allow_bad_utf16);
1776
119
        if(BOOST_JSON_UNLIKELY(incomplete(cs)))
1777
119
            return suspend_or_fail(state::obj3, size);
1778
50
do_obj4:
1779
50
        cs = detail::count_whitespace(cs.begin(), cs.end());
1780
50
        if(BOOST_JSON_UNLIKELY(! cs))
1781
50
            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
29
do_obj6:
1798
29
        cs = detail::count_whitespace(cs.begin(), cs.end());
1799
29
        if(BOOST_JSON_UNLIKELY(! cs))
1800
29
            return maybe_suspend(cs.begin(), state::obj6, size);
1801
180
do_obj7:
1802
180
        cs = parse_value(cs.begin(), stack_empty, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16);
1803
180
        if(BOOST_JSON_UNLIKELY(incomplete(cs)))
1804
176
            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
30
do_obj9:
1813
30
            cs = detail::count_whitespace(cs.begin(), cs.end());
1814
30
            if(BOOST_JSON_UNLIKELY(! cs))
1815
30
                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
661
{
1707
661
    detail::const_stream_wrapper cs(p, end_);
1708
661
    std::size_t size;
1709
661
    if(! stack_empty && ! st_.empty())
1710
661
    {
1711
        // resume
1712
661
        state st;
1713
661
        st_.pop(st);
1714
661
        st_.pop(size);
1715
661
        switch(st)
1716
661
        {
1717
0
        default: BOOST_JSON_UNREACHABLE();
1718
47
        case state::obj1: goto do_obj1;
1719
7
        case state::obj2: goto do_obj2;
1720
102
        case state::obj3: goto do_obj3;
1721
63
        case state::obj4: goto do_obj4;
1722
4
        case state::obj5: goto do_obj5;
1723
26
        case state::obj6: goto do_obj6;
1724
330
        case state::obj7: goto do_obj7;
1725
33
        case state::obj8: goto do_obj8;
1726
38
        case state::obj9: goto do_obj9;
1727
8
        case state::obj10: goto do_obj10;
1728
3
        case state::obj11: goto do_obj11;
1729
661
        }
1730
661
    }
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
47
do_obj1:
1747
47
    cs = detail::count_whitespace(cs.begin(), cs.end());
1748
47
    if(BOOST_JSON_UNLIKELY(! cs))
1749
47
        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
7
do_obj2:
1757
7
                cs = parse_comment(cs.begin(), stack_empty, std::false_type());
1758
7
                if(BOOST_JSON_UNLIKELY(incomplete(cs)))
1759
7
                    return suspend_or_fail(state::obj2, size);
1760
0
                goto do_obj1;
1761
7
            }
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
102
do_obj3:
1775
102
        cs = parse_string(cs.begin(), stack_empty, std::true_type(), allow_bad_utf8, allow_bad_utf16);
1776
102
        if(BOOST_JSON_UNLIKELY(incomplete(cs)))
1777
102
            return suspend_or_fail(state::obj3, size);
1778
63
do_obj4:
1779
63
        cs = detail::count_whitespace(cs.begin(), cs.end());
1780
63
        if(BOOST_JSON_UNLIKELY(! cs))
1781
63
            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
26
do_obj6:
1798
26
        cs = detail::count_whitespace(cs.begin(), cs.end());
1799
26
        if(BOOST_JSON_UNLIKELY(! cs))
1800
26
            return maybe_suspend(cs.begin(), state::obj6, size);
1801
330
do_obj7:
1802
330
        cs = parse_value(cs.begin(), stack_empty, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16);
1803
330
        if(BOOST_JSON_UNLIKELY(incomplete(cs)))
1804
327
            return suspend_or_fail(state::obj7, size);
1805
36
do_obj8:
1806
36
        cs = detail::count_whitespace(cs.begin(), cs.end());
1807
36
        if(BOOST_JSON_UNLIKELY(! cs))
1808
36
            return maybe_suspend(cs.begin(), state::obj8, size);
1809
0
        if(BOOST_JSON_LIKELY(*cs == ','))
1810
0
        {
1811
0
            ++cs;
1812
38
do_obj9:
1813
38
            cs = detail::count_whitespace(cs.begin(), cs.end());
1814
38
            if(BOOST_JSON_UNLIKELY(! cs))
1815
38
                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
8
do_obj10:
1825
8
                    cs = parse_comment(cs.begin(), stack_empty, std::false_type());
1826
8
                    if(BOOST_JSON_UNLIKELY(incomplete(cs)))
1827
8
                        return suspend_or_fail(state::obj10, size);
1828
0
                    goto do_obj9;
1829
8
                }
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
28.9k
{
1876
28.9k
    detail::const_stream_wrapper cs(p, end_);
1877
28.9k
    std::size_t size;
1878
28.9k
    if(! stack_empty && ! st_.empty())
1879
2.59k
    {
1880
        // resume
1881
2.59k
        state st;
1882
2.59k
        st_.pop(st);
1883
2.59k
        st_.pop(size);
1884
2.59k
        switch(st)
1885
2.59k
        {
1886
0
        default: BOOST_JSON_UNREACHABLE();
1887
91
        case state::arr1: goto do_arr1;
1888
16
        case state::arr2: goto do_arr2;
1889
1.98k
        case state::arr3: goto do_arr3;
1890
223
        case state::arr4: goto do_arr4;
1891
269
        case state::arr5: goto do_arr5;
1892
11
        case state::arr6: goto do_arr6;
1893
2.59k
        }
1894
2.59k
    }
1895
26.3k
    BOOST_ASSERT(*cs == '[');
1896
26.3k
    size = 0;
1897
26.3k
    if(BOOST_JSON_UNLIKELY(! depth_))
1898
13
    {
1899
13
        BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION;
1900
13
        return fail(cs.begin(), error::too_deep, &loc);
1901
13
    }
1902
26.3k
    --depth_;
1903
26.3k
    if(BOOST_JSON_UNLIKELY(
1904
26.3k
        ! h_.on_array_begin(ec_)))
1905
0
        return fail(cs.begin());
1906
26.3k
    ++cs;
1907
    // array:
1908
    //     '[' *ws ']'
1909
    //     '[' *ws value *ws *[ ',' *ws value *ws ] ']'
1910
26.9k
do_arr1:
1911
26.9k
    cs = detail::count_whitespace(cs.begin(), cs.end());
1912
26.9k
    if(BOOST_JSON_UNLIKELY(! cs))
1913
182
        return maybe_suspend(cs.begin(), state::arr1, size);
1914
26.8k
    if(BOOST_JSON_LIKELY(*cs != ']'))
1915
24.4k
    {
1916
9.40M
loop:
1917
9.40M
        if(allow_comments && *cs == '/')
1918
572
        {
1919
588
do_arr2:
1920
588
            cs = parse_comment(cs.begin(), stack_empty, std::false_type());
1921
588
            if(BOOST_JSON_UNLIKELY(incomplete(cs)))
1922
33
                return suspend_or_fail(state::arr2, size);
1923
555
            goto do_arr1;
1924
588
        }
1925
9.40M
        if(BOOST_JSON_UNLIKELY(++size >
1926
9.40M
            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
9.40M
do_arr3:
1933
        // array is not empty, value required
1934
9.40M
        cs = parse_value(cs.begin(), stack_empty, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16);
1935
9.40M
        if(BOOST_JSON_UNLIKELY(incomplete(cs)))
1936
3.97k
            return suspend_or_fail(state::arr3, size);
1937
9.40M
do_arr4:
1938
9.40M
        cs = detail::count_whitespace(cs.begin(), cs.end());
1939
9.40M
        if(BOOST_JSON_UNLIKELY(! cs))
1940
1.48k
            return maybe_suspend(cs.begin(), state::arr4, size);
1941
9.40M
        if(BOOST_JSON_LIKELY(*cs == ','))
1942
9.38M
        {
1943
9.38M
            ++cs;
1944
9.38M
do_arr5:
1945
9.38M
            cs = detail::count_whitespace(cs.begin(), cs.end());
1946
9.38M
            if(BOOST_JSON_UNLIKELY(! cs))
1947
538
                return maybe_suspend(cs.begin(), state::arr5, size);
1948
            // loop for next element
1949
9.38M
            if(! allow_trailing || *cs != ']')
1950
9.38M
                goto loop;
1951
9.38M
        }
1952
18.6k
        else if(BOOST_JSON_UNLIKELY(*cs != ']'))
1953
1.25k
        {
1954
1.25k
            if(allow_comments && *cs == '/')
1955
220
            {
1956
231
do_arr6:
1957
231
                cs = parse_comment(cs.begin(), stack_empty, std::false_type());
1958
231
                if(BOOST_JSON_UNLIKELY(incomplete(cs)))
1959
25
                    return suspend_or_fail(state::arr6, size);
1960
206
                goto do_arr4;
1961
231
            }
1962
1.03k
            BOOST_STATIC_CONSTEXPR source_location loc
1963
1.03k
                = BOOST_CURRENT_LOCATION;
1964
1.03k
            return fail(cs.begin(), error::syntax, &loc);
1965
1.25k
        }
1966
        // got closing bracket; fall through
1967
9.40M
    }
1968
21.6k
    if(BOOST_JSON_UNLIKELY(
1969
21.6k
        ! h_.on_array_end(size, ec_)))
1970
0
        return fail(cs.begin());
1971
21.6k
    ++depth_;
1972
21.6k
    ++cs;
1973
21.6k
    return cs.begin();
1974
21.6k
}
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
9.91k
{
1876
9.91k
    detail::const_stream_wrapper cs(p, end_);
1877
9.91k
    std::size_t size;
1878
9.91k
    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
9.91k
    BOOST_ASSERT(*cs == '[');
1896
9.91k
    size = 0;
1897
9.91k
    if(BOOST_JSON_UNLIKELY(! depth_))
1898
6
    {
1899
6
        BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION;
1900
6
        return fail(cs.begin(), error::too_deep, &loc);
1901
6
    }
1902
9.91k
    --depth_;
1903
9.91k
    if(BOOST_JSON_UNLIKELY(
1904
9.91k
        ! h_.on_array_begin(ec_)))
1905
0
        return fail(cs.begin());
1906
9.91k
    ++cs;
1907
    // array:
1908
    //     '[' *ws ']'
1909
    //     '[' *ws value *ws *[ ',' *ws value *ws ] ']'
1910
9.91k
do_arr1:
1911
9.91k
    cs = detail::count_whitespace(cs.begin(), cs.end());
1912
9.91k
    if(BOOST_JSON_UNLIKELY(! cs))
1913
41
        return maybe_suspend(cs.begin(), state::arr1, size);
1914
9.87k
    if(BOOST_JSON_LIKELY(*cs != ']'))
1915
8.60k
    {
1916
5.03M
loop:
1917
5.03M
        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
5.03M
        if(BOOST_JSON_UNLIKELY(++size >
1926
5.03M
            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
5.03M
do_arr3:
1933
        // array is not empty, value required
1934
5.03M
        cs = parse_value(cs.begin(), stack_empty, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16);
1935
5.03M
        if(BOOST_JSON_UNLIKELY(incomplete(cs)))
1936
1.39k
            return suspend_or_fail(state::arr3, size);
1937
5.02M
do_arr4:
1938
5.02M
        cs = detail::count_whitespace(cs.begin(), cs.end());
1939
5.02M
        if(BOOST_JSON_UNLIKELY(! cs))
1940
90
            return maybe_suspend(cs.begin(), state::arr4, size);
1941
5.02M
        if(BOOST_JSON_LIKELY(*cs == ','))
1942
5.02M
        {
1943
5.02M
            ++cs;
1944
5.02M
do_arr5:
1945
5.02M
            cs = detail::count_whitespace(cs.begin(), cs.end());
1946
5.02M
            if(BOOST_JSON_UNLIKELY(! cs))
1947
126
                return maybe_suspend(cs.begin(), state::arr5, size);
1948
            // loop for next element
1949
5.02M
            if(! allow_trailing || *cs != ']')
1950
5.02M
                goto loop;
1951
5.02M
        }
1952
5.80k
        else if(BOOST_JSON_UNLIKELY(*cs != ']'))
1953
519
        {
1954
519
            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
519
            BOOST_STATIC_CONSTEXPR source_location loc
1963
519
                = BOOST_CURRENT_LOCATION;
1964
519
            return fail(cs.begin(), error::syntax, &loc);
1965
519
        }
1966
        // got closing bracket; fall through
1967
5.02M
    }
1968
7.73k
    if(BOOST_JSON_UNLIKELY(
1969
7.73k
        ! h_.on_array_end(size, ec_)))
1970
0
        return fail(cs.begin());
1971
7.73k
    ++depth_;
1972
7.73k
    ++cs;
1973
7.73k
    return cs.begin();
1974
7.73k
}
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
16.4k
{
1876
16.4k
    detail::const_stream_wrapper cs(p, end_);
1877
16.4k
    std::size_t size;
1878
16.4k
    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
16.4k
    BOOST_ASSERT(*cs == '[');
1896
16.4k
    size = 0;
1897
16.4k
    if(BOOST_JSON_UNLIKELY(! depth_))
1898
7
    {
1899
7
        BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION;
1900
7
        return fail(cs.begin(), error::too_deep, &loc);
1901
7
    }
1902
16.4k
    --depth_;
1903
16.4k
    if(BOOST_JSON_UNLIKELY(
1904
16.4k
        ! h_.on_array_begin(ec_)))
1905
0
        return fail(cs.begin());
1906
16.4k
    ++cs;
1907
    // array:
1908
    //     '[' *ws ']'
1909
    //     '[' *ws value *ws *[ ',' *ws value *ws ] ']'
1910
16.9k
do_arr1:
1911
16.9k
    cs = detail::count_whitespace(cs.begin(), cs.end());
1912
16.9k
    if(BOOST_JSON_UNLIKELY(! cs))
1913
50
        return maybe_suspend(cs.begin(), state::arr1, size);
1914
16.9k
    if(BOOST_JSON_LIKELY(*cs != ']'))
1915
15.8k
    {
1916
4.37M
loop:
1917
4.37M
        if(allow_comments && *cs == '/')
1918
572
        {
1919
572
do_arr2:
1920
572
            cs = parse_comment(cs.begin(), stack_empty, std::false_type());
1921
572
            if(BOOST_JSON_UNLIKELY(incomplete(cs)))
1922
17
                return suspend_or_fail(state::arr2, size);
1923
555
            goto do_arr1;
1924
572
        }
1925
4.37M
        if(BOOST_JSON_UNLIKELY(++size >
1926
4.37M
            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.37M
do_arr3:
1933
        // array is not empty, value required
1934
4.37M
        cs = parse_value(cs.begin(), stack_empty, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16);
1935
4.37M
        if(BOOST_JSON_UNLIKELY(incomplete(cs)))
1936
1.63k
            return suspend_or_fail(state::arr3, size);
1937
4.37M
do_arr4:
1938
4.37M
        cs = detail::count_whitespace(cs.begin(), cs.end());
1939
4.37M
        if(BOOST_JSON_UNLIKELY(! cs))
1940
133
            return maybe_suspend(cs.begin(), state::arr4, size);
1941
4.37M
        if(BOOST_JSON_LIKELY(*cs == ','))
1942
4.35M
        {
1943
4.35M
            ++cs;
1944
4.35M
do_arr5:
1945
4.35M
            cs = detail::count_whitespace(cs.begin(), cs.end());
1946
4.35M
            if(BOOST_JSON_UNLIKELY(! cs))
1947
143
                return maybe_suspend(cs.begin(), state::arr5, size);
1948
            // loop for next element
1949
4.35M
            if(! allow_trailing || *cs != ']')
1950
4.35M
                goto loop;
1951
4.35M
        }
1952
12.8k
        else if(BOOST_JSON_UNLIKELY(*cs != ']'))
1953
736
        {
1954
736
            if(allow_comments && *cs == '/')
1955
220
            {
1956
220
do_arr6:
1957
220
                cs = parse_comment(cs.begin(), stack_empty, std::false_type());
1958
220
                if(BOOST_JSON_UNLIKELY(incomplete(cs)))
1959
14
                    return suspend_or_fail(state::arr6, size);
1960
206
                goto do_arr4;
1961
220
            }
1962
516
            BOOST_STATIC_CONSTEXPR source_location loc
1963
516
                = BOOST_CURRENT_LOCATION;
1964
516
            return fail(cs.begin(), error::syntax, &loc);
1965
736
        }
1966
        // got closing bracket; fall through
1967
4.37M
    }
1968
13.8k
    if(BOOST_JSON_UNLIKELY(
1969
13.8k
        ! h_.on_array_end(size, ec_)))
1970
0
        return fail(cs.begin());
1971
13.8k
    ++depth_;
1972
13.8k
    ++cs;
1973
13.8k
    return cs.begin();
1974
13.8k
}
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
41
        case state::arr1: goto do_arr1;
1888
0
        case state::arr2: goto do_arr2;
1889
934
        case state::arr3: goto do_arr3;
1890
90
        case state::arr4: goto do_arr4;
1891
126
        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
41
do_arr1:
1911
41
    cs = detail::count_whitespace(cs.begin(), cs.end());
1912
41
    if(BOOST_JSON_UNLIKELY(! cs))
1913
41
        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
934
do_arr3:
1933
        // array is not empty, value required
1934
934
        cs = parse_value(cs.begin(), stack_empty, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16);
1935
934
        if(BOOST_JSON_UNLIKELY(incomplete(cs)))
1936
379
            return suspend_or_fail(state::arr3, size);
1937
645
do_arr4:
1938
645
        cs = detail::count_whitespace(cs.begin(), cs.end());
1939
645
        if(BOOST_JSON_UNLIKELY(! cs))
1940
645
            return maybe_suspend(cs.begin(), state::arr4, size);
1941
0
        if(BOOST_JSON_LIKELY(*cs == ','))
1942
0
        {
1943
0
            ++cs;
1944
126
do_arr5:
1945
126
            cs = detail::count_whitespace(cs.begin(), cs.end());
1946
126
            if(BOOST_JSON_UNLIKELY(! cs))
1947
126
                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.40k
{
1876
1.40k
    detail::const_stream_wrapper cs(p, end_);
1877
1.40k
    std::size_t size;
1878
1.40k
    if(! stack_empty && ! st_.empty())
1879
1.40k
    {
1880
        // resume
1881
1.40k
        state st;
1882
1.40k
        st_.pop(st);
1883
1.40k
        st_.pop(size);
1884
1.40k
        switch(st)
1885
1.40k
        {
1886
0
        default: BOOST_JSON_UNREACHABLE();
1887
50
        case state::arr1: goto do_arr1;
1888
16
        case state::arr2: goto do_arr2;
1889
1.04k
        case state::arr3: goto do_arr3;
1890
133
        case state::arr4: goto do_arr4;
1891
143
        case state::arr5: goto do_arr5;
1892
11
        case state::arr6: goto do_arr6;
1893
1.40k
        }
1894
1.40k
    }
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
50
do_arr1:
1911
50
    cs = detail::count_whitespace(cs.begin(), cs.end());
1912
50
    if(BOOST_JSON_UNLIKELY(! cs))
1913
50
        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
16
do_arr2:
1920
16
            cs = parse_comment(cs.begin(), stack_empty, std::false_type());
1921
16
            if(BOOST_JSON_UNLIKELY(incomplete(cs)))
1922
16
                return suspend_or_fail(state::arr2, size);
1923
0
            goto do_arr1;
1924
16
        }
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.04k
do_arr3:
1933
        // array is not empty, value required
1934
1.04k
        cs = parse_value(cs.begin(), stack_empty, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16);
1935
1.04k
        if(BOOST_JSON_UNLIKELY(incomplete(cs)))
1936
560
            return suspend_or_fail(state::arr3, size);
1937
621
do_arr4:
1938
621
        cs = detail::count_whitespace(cs.begin(), cs.end());
1939
621
        if(BOOST_JSON_UNLIKELY(! cs))
1940
621
            return maybe_suspend(cs.begin(), state::arr4, size);
1941
0
        if(BOOST_JSON_LIKELY(*cs == ','))
1942
0
        {
1943
0
            ++cs;
1944
143
do_arr5:
1945
143
            cs = detail::count_whitespace(cs.begin(), cs.end());
1946
143
            if(BOOST_JSON_UNLIKELY(! cs))
1947
143
                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
11
do_arr6:
1957
11
                cs = parse_comment(cs.begin(), stack_empty, std::false_type());
1958
11
                if(BOOST_JSON_UNLIKELY(incomplete(cs)))
1959
11
                    return suspend_or_fail(state::arr6, size);
1960
0
                goto do_arr4;
1961
11
            }
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
9.66M
{
1987
9.66M
    constexpr bool precise_parsing = mode == number_precision::precise;
1988
9.66M
    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.66M
    bool const negative = first == '-';
1995
9.66M
    bool const zero_first = first == '0';
1996
9.66M
    bool const nonzero_first = first == '+';
1997
9.66M
    detail::const_stream_wrapper cs(p, end_);
1998
9.66M
    number num;
1999
9.66M
    const char* begin = cs.begin();
2000
9.66M
    if(stack_empty || st_.empty())
2001
9.65M
    {
2002
9.65M
        num.bias = 0;
2003
9.65M
        num.exp = 0;
2004
9.65M
        num.frac = false;
2005
9.65M
        num_buf_.clear();
2006
2007
        //----------------------------------
2008
        //
2009
        // '-'
2010
        // leading minus sign
2011
        //
2012
9.65M
        BOOST_ASSERT(cs);
2013
9.65M
        if(negative)
2014
51.2k
            ++cs;
2015
2016
9.65M
        num.neg = negative;
2017
9.65M
        num.frac = false;
2018
9.65M
        num.exp = 0;
2019
9.65M
        num.bias = 0;
2020
2021
        // fast path
2022
9.65M
        if( cs.remain() >= 16 + 1 + 16 ) // digits . digits
2023
9.63M
        {
2024
9.63M
            int n1;
2025
2026
9.63M
            if( nonzero_first ||
2027
9.63M
                (negative && *cs != '0') )
2028
9.21M
            {
2029
9.21M
                n1 = detail::count_digits( cs.begin() );
2030
9.21M
                BOOST_ASSERT(n1 >= 0 && n1 <= 16);
2031
2032
9.21M
                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.21M
                if( ! nonzero_first && n1 == 0 )
2040
26
                {
2041
                    // digit required
2042
26
                    BOOST_STATIC_CONSTEXPR source_location loc
2043
26
                        = BOOST_CURRENT_LOCATION;
2044
26
                    return fail(cs.begin(), error::syntax, &loc);
2045
26
                }
2046
2047
9.21M
                BOOST_IF_CONSTEXPR( !no_parsing )
2048
9.21M
                    num.mant = detail::parse_unsigned( 0, cs.begin(), n1 );
2049
                else
2050
604k
                    num.mant = 0;
2051
2052
9.21M
                cs += n1;
2053
2054
                // integer or floating-point with
2055
                // >= 16 leading digits
2056
9.21M
                if( n1 == 16 )
2057
142k
                {
2058
142k
                    goto do_num2;
2059
142k
                }
2060
9.21M
            }
2061
419k
            else
2062
419k
            {
2063
                // 0. floating-point or 0e integer
2064
419k
                num.mant = 0;
2065
419k
                n1 = 0;
2066
419k
                ++cs;
2067
419k
            }
2068
2069
9.49M
            {
2070
9.49M
                const char c = *cs;
2071
9.49M
                if(c != '.')
2072
9.45M
                {
2073
9.45M
                    if((c | 32) == 'e')
2074
5.77M
                    {
2075
5.77M
                        ++cs;
2076
5.77M
                        goto do_exp1;
2077
5.77M
                    }
2078
3.68M
                    BOOST_IF_CONSTEXPR( negative && !no_parsing )
2079
3.68M
                        num.mant = ~num.mant + 1;
2080
3.68M
                    goto finish_signed;
2081
9.45M
                }
2082
9.49M
            }
2083
2084
            // floating-point number
2085
2086
44.1k
            ++cs;
2087
2088
44.1k
            int n2 = detail::count_digits( cs.begin() );
2089
44.1k
            BOOST_ASSERT(n2 >= 0 && n2 <= 16);
2090
2091
44.1k
            if( n2 == 0 )
2092
28
            {
2093
                // digit required
2094
28
                BOOST_STATIC_CONSTEXPR source_location loc
2095
28
                    = BOOST_CURRENT_LOCATION;
2096
28
                return fail(cs.begin(), error::syntax, &loc);
2097
28
            }
2098
2099
            // floating-point mantissa overflow
2100
44.1k
            if( n1 + n2 >= 19 )
2101
4.42k
            {
2102
4.42k
                goto do_num7;
2103
4.42k
            }
2104
2105
39.6k
            BOOST_IF_CONSTEXPR( !no_parsing )
2106
39.6k
                num.mant = detail::parse_unsigned( num.mant, cs.begin(), n2 );
2107
2108
39.6k
            BOOST_ASSERT(num.bias == 0);
2109
2110
39.6k
            num.bias -= n2;
2111
2112
39.6k
            cs += n2;
2113
2114
39.6k
            char ch = *cs;
2115
2116
39.6k
            if( (ch | 32) == 'e' )
2117
7.42k
            {
2118
7.42k
                ++cs;
2119
7.42k
                goto do_exp1;
2120
7.42k
            }
2121
32.2k
            else if( ch >= '0' && ch <= '9' )
2122
10.3k
            {
2123
10.3k
                goto do_num8;
2124
10.3k
            }
2125
2126
21.9k
            goto finish_dub;
2127
39.6k
        }
2128
9.65M
    }
2129
6.84k
    else
2130
6.84k
    {
2131
6.84k
        num = num_;
2132
6.84k
        state st;
2133
6.84k
        st_.pop(st);
2134
6.84k
        switch(st)
2135
6.84k
        {
2136
0
        default: BOOST_JSON_UNREACHABLE();
2137
48
        case state::num1: goto do_num1;
2138
1.12k
        case state::num2: goto do_num2;
2139
566
        case state::num3: goto do_num3;
2140
9
        case state::num4: goto do_num4;
2141
1.13k
        case state::num5: goto do_num5;
2142
88
        case state::num6: goto do_num6;
2143
44
        case state::num7: goto do_num7;
2144
1.42k
        case state::num8: goto do_num8;
2145
189
        case state::exp1: goto do_exp1;
2146
100
        case state::exp2: goto do_exp2;
2147
2.12k
        case state::exp3: goto do_exp3;
2148
6.84k
        }
2149
6.84k
    }
2150
2151
    //----------------------------------
2152
    //
2153
    // DIGIT
2154
    // first digit
2155
    //
2156
20.4k
do_num1:
2157
20.4k
    if(zero_first || nonzero_first ||
2158
20.4k
        BOOST_JSON_LIKELY(cs))
2159
20.3k
    {
2160
20.3k
        char const c = *cs;
2161
20.3k
        if(zero_first)
2162
4.09k
        {
2163
4.09k
            ++cs;
2164
4.09k
            num.mant = 0;
2165
4.09k
            goto do_num6;
2166
4.09k
        }
2167
16.2k
        else if(nonzero_first || BOOST_JSON_LIKELY(
2168
16.2k
            c >= '1' && c <= '9'))
2169
15.4k
        {
2170
15.4k
            ++cs;
2171
15.4k
            num.mant = c - '0';
2172
15.4k
        }
2173
795
        else if(BOOST_JSON_UNLIKELY(
2174
795
            c == '0'))
2175
725
        {
2176
725
            ++cs;
2177
725
            num.mant = 0;
2178
725
            goto do_num6;
2179
725
        }
2180
70
        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
70
        else
2189
70
        {
2190
70
            BOOST_STATIC_CONSTEXPR source_location loc
2191
70
                = BOOST_CURRENT_LOCATION;
2192
70
            return fail(cs.begin(), error::syntax, &loc);
2193
70
        }
2194
20.3k
    }
2195
96
    else
2196
96
    {
2197
96
        if(BOOST_JSON_UNLIKELY(
2198
96
            ! h_.on_number_part(
2199
96
                {begin, cs.used(begin)}, ec_)))
2200
0
            return fail(cs.begin());
2201
2202
96
        BOOST_IF_CONSTEXPR( precise_parsing )
2203
96
            num_buf_.append( begin, cs.used(begin) );
2204
96
        return maybe_suspend(
2205
96
            cs.begin(), state::num1, num);
2206
96
    }
2207
2208
    //----------------------------------
2209
    //
2210
    // 1*DIGIT
2211
    // significant digits left of decimal
2212
    //
2213
158k
do_num2:
2214
158k
    if(negative || (!stack_empty && num.neg))
2215
15.6k
    {
2216
15.6k
        for(;;)
2217
46.4k
        {
2218
46.4k
            if(BOOST_JSON_UNLIKELY(! cs))
2219
748
            {
2220
748
                if(BOOST_JSON_UNLIKELY(more_))
2221
374
                {
2222
374
                    if(BOOST_JSON_UNLIKELY(
2223
374
                        ! h_.on_number_part(
2224
374
                            {begin, cs.used(begin)}, ec_)))
2225
0
                        return fail(cs.begin());
2226
2227
374
                    BOOST_IF_CONSTEXPR( precise_parsing )
2228
374
                        num_buf_.append( begin, cs.used(begin) );
2229
374
                    return suspend(cs.begin(), state::num2, num);
2230
374
                }
2231
374
                goto finish_int;
2232
748
            }
2233
45.7k
            char const c = *cs;
2234
45.7k
            if(BOOST_JSON_LIKELY(
2235
45.7k
                c >= '0' && c <= '9'))
2236
36.0k
            {
2237
36.0k
                ++cs;
2238
                //              9223372036854775808 INT64_MIN
2239
36.0k
                if( num.mant  > 922337203685477580 || (
2240
31.5k
                    num.mant == 922337203685477580 && c > '8'))
2241
5.25k
                    break;
2242
30.8k
                BOOST_IF_CONSTEXPR( !no_parsing )
2243
30.8k
                    num.mant = 10 * num.mant + ( c - '0' );
2244
30.8k
                continue;
2245
36.0k
            }
2246
9.64k
            goto do_num6; // [.eE]
2247
45.7k
        }
2248
15.6k
    }
2249
143k
    else
2250
143k
    {
2251
143k
        for(;;)
2252
591k
        {
2253
591k
            if(BOOST_JSON_UNLIKELY(! cs))
2254
1.49k
            {
2255
1.49k
                if(BOOST_JSON_UNLIKELY(more_))
2256
749
                {
2257
749
                    if(BOOST_JSON_UNLIKELY(
2258
749
                        ! h_.on_number_part(
2259
749
                            {begin, cs.used(begin)}, ec_)))
2260
0
                        return fail(cs.begin());
2261
2262
749
                    BOOST_IF_CONSTEXPR( precise_parsing )
2263
749
                        num_buf_.append( begin, cs.used(begin) );
2264
749
                    return suspend(cs.begin(), state::num2, num);
2265
749
                }
2266
749
                goto finish_int;
2267
1.49k
            }
2268
589k
            char const c = *cs;
2269
589k
            if(BOOST_JSON_LIKELY(
2270
589k
                c >= '0' && c <= '9'))
2271
489k
            {
2272
489k
                ++cs;
2273
                //              18446744073709551615 UINT64_MAX
2274
489k
                if( num.mant  > 1844674407370955161 || (
2275
469k
                    num.mant == 1844674407370955161 && c > '5'))
2276
41.9k
                    break;
2277
447k
                BOOST_IF_CONSTEXPR( !no_parsing )
2278
447k
                    num.mant = 10 * num.mant + ( c - '0' );
2279
447k
            }
2280
99.8k
            else
2281
99.8k
            {
2282
99.8k
                goto do_num6; // [.eE]
2283
99.8k
            }
2284
589k
        }
2285
143k
    }
2286
47.2k
    ++num.bias;
2287
2288
    //----------------------------------
2289
    //
2290
    // 1*DIGIT
2291
    // non-significant digits left of decimal
2292
    //
2293
47.7k
do_num3:
2294
47.7k
    for(;;)
2295
31.7M
    {
2296
31.7M
        if(BOOST_JSON_UNLIKELY(! cs))
2297
1.13k
        {
2298
1.13k
            if(BOOST_JSON_UNLIKELY(more_))
2299
566
            {
2300
566
                if(BOOST_JSON_UNLIKELY(
2301
566
                    ! h_.on_number_part(
2302
566
                        {begin, cs.used(begin)}, ec_)))
2303
0
                    return fail(cs.begin());
2304
2305
566
                BOOST_IF_CONSTEXPR( precise_parsing )
2306
566
                    num_buf_.append( begin, cs.used(begin) );
2307
566
                return suspend(cs.begin(), state::num3, num);
2308
566
            }
2309
566
            goto finish_dub;
2310
1.13k
        }
2311
31.7M
        char const c = *cs;
2312
31.7M
        if(BOOST_JSON_UNLIKELY(
2313
31.7M
            c >= '0' && c <= '9'))
2314
31.7M
        {
2315
31.7M
            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
31.7M
            ++cs;
2322
31.7M
            ++num.bias;
2323
31.7M
        }
2324
46.6k
        else if(BOOST_JSON_LIKELY(
2325
46.6k
            c == '.'))
2326
4.77k
        {
2327
4.77k
            ++cs;
2328
4.77k
            break;
2329
4.77k
        }
2330
41.8k
        else if((c | 32) == 'e')
2331
29.2k
        {
2332
29.2k
            ++cs;
2333
29.2k
            goto do_exp1;
2334
29.2k
        }
2335
12.6k
        else
2336
12.6k
        {
2337
12.6k
            goto finish_dub;
2338
12.6k
        }
2339
31.7M
    }
2340
2341
    //----------------------------------
2342
    //
2343
    // DIGIT
2344
    // first non-significant digit
2345
    // to the right of decimal
2346
    //
2347
4.78k
do_num4:
2348
4.78k
    {
2349
4.78k
        if(BOOST_JSON_UNLIKELY(! cs))
2350
18
        {
2351
18
            if(BOOST_JSON_UNLIKELY(
2352
18
                ! h_.on_number_part(
2353
18
                    {begin, cs.used(begin)}, ec_)))
2354
0
                return fail(cs.begin());
2355
2356
18
            BOOST_IF_CONSTEXPR( precise_parsing )
2357
18
                num_buf_.append( begin, cs.used(begin) );
2358
18
            return maybe_suspend(
2359
18
                cs.begin(), state::num4, num);
2360
18
        }
2361
4.76k
        char const c = *cs;
2362
4.76k
        if(BOOST_JSON_LIKELY(
2363
            //static_cast<unsigned char>(c - '0') < 10))
2364
4.76k
            c >= '0' && c <= '9'))
2365
4.73k
        {
2366
4.73k
            ++cs;
2367
4.73k
        }
2368
33
        else
2369
33
        {
2370
            // digit required
2371
33
            BOOST_STATIC_CONSTEXPR source_location loc
2372
33
                = BOOST_CURRENT_LOCATION;
2373
33
            return fail(cs.begin(), error::syntax, &loc);
2374
33
        }
2375
4.76k
    }
2376
2377
    //----------------------------------
2378
    //
2379
    // 1*DIGIT
2380
    // non-significant digits
2381
    // to the right of decimal
2382
    //
2383
24.7k
do_num5:
2384
24.7k
    for(;;)
2385
4.82M
    {
2386
4.82M
        if(BOOST_JSON_UNLIKELY(! cs))
2387
2.26k
        {
2388
2.26k
            if(BOOST_JSON_UNLIKELY(more_))
2389
1.13k
            {
2390
1.13k
                if(BOOST_JSON_UNLIKELY(
2391
1.13k
                    ! h_.on_number_part(
2392
1.13k
                        {begin, cs.used(begin)}, ec_)))
2393
0
                    return fail(cs.begin());
2394
2395
1.13k
                BOOST_IF_CONSTEXPR( precise_parsing )
2396
1.13k
                    num_buf_.append( begin, cs.used(begin) );
2397
1.13k
                return suspend(cs.begin(), state::num5, num);
2398
1.13k
            }
2399
1.13k
            goto finish_dub;
2400
2.26k
        }
2401
4.81M
        char const c = *cs;
2402
4.81M
        if(BOOST_JSON_LIKELY(
2403
4.81M
            c >= '0' && c <= '9'))
2404
4.79M
        {
2405
4.79M
            ++cs;
2406
4.79M
        }
2407
22.5k
        else if((c | 32) == 'e')
2408
5.66k
        {
2409
5.66k
            ++cs;
2410
5.66k
            goto do_exp1;
2411
5.66k
        }
2412
16.8k
        else
2413
16.8k
        {
2414
16.8k
            goto finish_dub;
2415
16.8k
        }
2416
4.81M
    }
2417
2418
    //----------------------------------
2419
    //
2420
    // [.eE]
2421
    //
2422
114k
do_num6:
2423
114k
    {
2424
114k
        if(BOOST_JSON_UNLIKELY(! cs))
2425
176
        {
2426
176
            if(BOOST_JSON_UNLIKELY(more_))
2427
88
            {
2428
88
                if(BOOST_JSON_UNLIKELY(
2429
88
                    ! h_.on_number_part(
2430
88
                        {begin, cs.used(begin)}, ec_)))
2431
0
                    return fail(cs.begin());
2432
2433
88
                BOOST_IF_CONSTEXPR( precise_parsing )
2434
88
                    num_buf_.append( begin, cs.used(begin) );
2435
88
                return suspend(cs.begin(), state::num6, num);
2436
88
            }
2437
88
            goto finish_int;
2438
176
        }
2439
114k
        char const c = *cs;
2440
114k
        if(BOOST_JSON_LIKELY(
2441
114k
            c == '.'))
2442
11.8k
        {
2443
11.8k
            ++cs;
2444
11.8k
        }
2445
102k
        else if((c | 32) == 'e')
2446
8.93k
        {
2447
8.93k
            ++cs;
2448
8.93k
            goto do_exp1;
2449
8.93k
        }
2450
93.4k
        else
2451
93.4k
        {
2452
93.4k
            goto finish_int;
2453
93.4k
        }
2454
114k
    }
2455
2456
    //----------------------------------
2457
    //
2458
    // DIGIT
2459
    // first significant digit
2460
    // to the right of decimal
2461
    //
2462
16.2k
do_num7:
2463
16.2k
    {
2464
16.2k
        if(BOOST_JSON_UNLIKELY(! cs))
2465
88
        {
2466
88
            if(BOOST_JSON_UNLIKELY(more_))
2467
44
            {
2468
44
                if(BOOST_JSON_UNLIKELY(
2469
44
                    ! h_.on_number_part(
2470
44
                        {begin, cs.used(begin)}, ec_)))
2471
0
                    return fail(cs.begin());
2472
2473
44
                BOOST_IF_CONSTEXPR( precise_parsing )
2474
44
                    num_buf_.append( begin, cs.used(begin) );
2475
44
                return suspend(cs.begin(), state::num7, num);
2476
44
            }
2477
            // digit required
2478
44
            BOOST_STATIC_CONSTEXPR source_location loc
2479
44
                = BOOST_CURRENT_LOCATION;
2480
44
            return fail(cs.begin(), error::syntax, &loc);
2481
88
        }
2482
16.2k
        char const c = *cs;
2483
16.2k
        if(BOOST_JSON_UNLIKELY(
2484
16.2k
            c < '0' || c > '9'))
2485
118
        {
2486
            // digit required
2487
118
            BOOST_STATIC_CONSTEXPR source_location loc
2488
118
                = BOOST_CURRENT_LOCATION;
2489
118
            return fail(cs.begin(), error::syntax, &loc);
2490
118
        }
2491
16.2k
    }
2492
2493
    //----------------------------------
2494
    //
2495
    // 1*DIGIT
2496
    // significant digits
2497
    // to the right of decimal
2498
    //
2499
27.8k
do_num8:
2500
27.8k
    for(;;)
2501
24.0M
    {
2502
24.0M
        if(BOOST_JSON_UNLIKELY(! cs))
2503
2.84k
        {
2504
2.84k
            if(BOOST_JSON_UNLIKELY(more_))
2505
1.42k
            {
2506
1.42k
                if(BOOST_JSON_UNLIKELY(
2507
1.42k
                    ! h_.on_number_part(
2508
1.42k
                        {begin, cs.used(begin)}, ec_)))
2509
0
                    return fail(cs.begin());
2510
2511
1.42k
                BOOST_IF_CONSTEXPR( precise_parsing )
2512
1.42k
                    num_buf_.append( begin, cs.used(begin) );
2513
1.42k
                return suspend(cs.begin(), state::num8, num);
2514
1.42k
            }
2515
1.42k
            goto finish_dub;
2516
2.84k
        }
2517
24.0M
        char const c = *cs;
2518
24.0M
        if(BOOST_JSON_LIKELY(
2519
24.0M
            c >= '0' && c <= '9'))
2520
23.9M
        {
2521
23.9M
            ++cs;
2522
23.9M
            if(!no_parsing && BOOST_JSON_LIKELY(
2523
23.9M
                num.mant <= 9007199254740991)) // 2^53-1
2524
23.9M
            {
2525
23.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
23.9M
                --num.bias;
2532
23.9M
                num.mant = 10 * num.mant + ( c - '0' );
2533
23.9M
            }
2534
18.9k
            else
2535
18.9k
            {
2536
18.9k
                goto do_num5;
2537
18.9k
            }
2538
23.9M
        }
2539
6.07k
        else if((c | 32) == 'e')
2540
2.27k
        {
2541
2.27k
            ++cs;
2542
2.27k
            goto do_exp1;
2543
2.27k
        }
2544
3.80k
        else
2545
3.80k
        {
2546
3.80k
            goto finish_dub;
2547
3.80k
        }
2548
24.0M
    }
2549
2550
    //----------------------------------
2551
    //
2552
    // *[+-]
2553
    //
2554
5.82M
do_exp1:
2555
5.82M
    if(BOOST_JSON_UNLIKELY(! cs))
2556
378
    {
2557
378
        if(BOOST_JSON_UNLIKELY(
2558
378
            ! h_.on_number_part(
2559
378
                {begin, cs.used(begin)}, ec_)))
2560
0
            return fail(cs.begin());
2561
2562
378
        BOOST_IF_CONSTEXPR( precise_parsing )
2563
378
            num_buf_.append( begin, cs.used(begin) );
2564
378
        return maybe_suspend(
2565
378
            cs.begin(), state::exp1, num);
2566
378
    }
2567
5.82M
    if(*cs == '+')
2568
2.79k
    {
2569
2.79k
        ++cs;
2570
2.79k
    }
2571
5.82M
    else if(*cs == '-')
2572
77.0k
    {
2573
77.0k
        ++cs;
2574
77.0k
        num.frac = true;
2575
77.0k
    }
2576
2577
    //----------------------------------
2578
    //
2579
    // DIGIT
2580
    // first digit of the exponent
2581
    //
2582
5.82M
do_exp2:
2583
5.82M
    {
2584
5.82M
        if(BOOST_JSON_UNLIKELY(! cs))
2585
200
        {
2586
200
            if(BOOST_JSON_UNLIKELY(more_))
2587
100
            {
2588
100
                if(BOOST_JSON_UNLIKELY(
2589
100
                    ! h_.on_number_part(
2590
100
                        {begin, cs.used(begin)}, ec_)))
2591
0
                    return fail(cs.begin());
2592
2593
100
                BOOST_IF_CONSTEXPR( precise_parsing )
2594
100
                    num_buf_.append( begin, cs.used(begin) );
2595
100
                return suspend(cs.begin(), state::exp2, num);
2596
100
            }
2597
            // digit required
2598
100
            BOOST_STATIC_CONSTEXPR source_location loc
2599
100
                = BOOST_CURRENT_LOCATION;
2600
100
            return fail(cs.begin(), error::syntax, &loc);
2601
200
        }
2602
5.82M
        char const c = *cs;
2603
5.82M
        if(BOOST_JSON_UNLIKELY(
2604
5.82M
            c < '0' || c > '9'))
2605
191
        {
2606
            // digit required
2607
191
            BOOST_STATIC_CONSTEXPR source_location loc
2608
191
                = BOOST_CURRENT_LOCATION;
2609
191
            return fail(cs.begin(), error::syntax, &loc);
2610
191
        }
2611
5.82M
        ++cs;
2612
5.82M
        num.exp = c - '0';
2613
5.82M
    }
2614
2615
    //----------------------------------
2616
    //
2617
    // 1*DIGIT
2618
    // subsequent digits in the exponent
2619
    //
2620
5.82M
do_exp3:
2621
5.82M
    for(;;)
2622
12.0M
    {
2623
12.0M
        if(BOOST_JSON_UNLIKELY(! cs))
2624
4.24k
        {
2625
4.24k
            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
4.24k
        }
2637
12.0M
        else
2638
12.0M
        {
2639
12.0M
            char const c = *cs;
2640
12.0M
            if(BOOST_JSON_LIKELY( c >= '0' && c <= '9' ))
2641
6.18M
            {
2642
6.18M
                if(BOOST_JSON_UNLIKELY(
2643
                //              2147483647 INT_MAX
2644
6.18M
                    num.exp  >  214748364 ||
2645
6.18M
                    (num.exp == 214748364 && c > '7')
2646
6.18M
                ))
2647
186k
                    num.exp = INT_MAX;
2648
5.99M
                else BOOST_IF_CONSTEXPR( !no_parsing )
2649
5.99M
                    num.exp = 10 * num.exp + ( c - '0' );
2650
2651
6.18M
                ++cs;
2652
6.18M
                continue;
2653
6.18M
            }
2654
12.0M
        }
2655
5.82M
        BOOST_ASSERT(num.exp >= 0);
2656
5.82M
        if ( num.frac )
2657
76.9k
        {
2658
76.9k
            if(BOOST_JSON_UNLIKELY( num.bias < (INT_MIN + num.exp) ))
2659
3.83k
            {
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.83k
                if(BOOST_JSON_UNLIKELY(
2664
3.83k
                    (num.exp == INT_MAX) &&
2665
3.83k
                    (num.bias < 0) &&
2666
3.83k
                    (num.exp + num.bias < 308) &&
2667
3.83k
                    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.83k
                num.bias = 0;
2675
3.83k
                num.exp = INT_MAX;
2676
3.83k
            }
2677
76.9k
        }
2678
5.74M
        else if (BOOST_JSON_UNLIKELY( num.bias > (INT_MAX - num.exp) ))
2679
2.19k
        {
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.19k
            if(BOOST_JSON_UNLIKELY(
2684
2.19k
                (num.exp == INT_MAX) &&
2685
2.19k
                (num.bias > 0) &&
2686
2.19k
                (num.exp - num.bias < 308) &&
2687
2.19k
                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.19k
            num.bias = 0;
2695
2.19k
            num.exp = INT_MAX;
2696
2.19k
        }
2697
5.82M
        goto finish_dub;
2698
5.82M
    }
2699
2700
94.7k
finish_int:
2701
94.7k
    if(negative || (!stack_empty && num.neg))
2702
6.77k
    {
2703
6.77k
        if(BOOST_JSON_UNLIKELY(
2704
6.77k
            ! h_.on_int64(static_cast<
2705
6.77k
                int64_t>(~num.mant + 1), {begin, cs.used(begin)}, ec_)))
2706
0
            return fail(cs.begin());
2707
6.77k
        return cs.begin();
2708
6.77k
    }
2709
87.9k
    if(num.mant <= INT64_MAX)
2710
13.2k
    {
2711
3.69M
finish_signed:
2712
3.69M
        if(BOOST_JSON_UNLIKELY(
2713
3.69M
            ! h_.on_int64(static_cast<
2714
3.69M
                int64_t>(num.mant), {begin, cs.used(begin)}, ec_)))
2715
0
            return fail(cs.begin());
2716
3.69M
        return cs.begin();
2717
3.69M
    }
2718
74.6k
    if(BOOST_JSON_UNLIKELY(
2719
74.6k
        ! h_.on_uint64(num.mant, {begin, cs.used(begin)}, ec_)))
2720
0
        return fail(cs.begin());
2721
74.6k
    return cs.begin();
2722
5.88M
finish_dub:
2723
5.88M
    double d;
2724
5.88M
    std::size_t const size = cs.used(begin);
2725
5.88M
    BOOST_ASSERT( !num_buf_.size() || precise_parsing );
2726
    BOOST_IF_CONSTEXPR( precise_parsing )
2727
220k
    {
2728
220k
        char const* data = begin;
2729
220k
        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
220k
        if(BOOST_JSON_UNLIKELY( num_buf_.size() ))
2734
3.64k
        {
2735
3.64k
            data = num_buf_.append( begin, size );
2736
3.64k
            full_size = num_buf_.size();
2737
3.64k
        }
2738
220k
        auto const err = detail::charconv::from_chars(
2739
220k
            data, data + full_size, d );
2740
220k
        BOOST_ASSERT( err.ec != std::errc::invalid_argument );
2741
220k
        BOOST_ASSERT( err.ptr == data + full_size );
2742
220k
        (void)err;
2743
    }
2744
5.66M
    else BOOST_IF_CONSTEXPR( no_parsing )
2745
5.66M
        d = 0;
2746
    else
2747
5.61M
        d = detail::dec_to_float(
2748
5.61M
            num.mant,
2749
5.61M
            num.bias + (num.frac ?
2750
5.55M
                -num.exp : num.exp),
2751
5.61M
            num.neg);
2752
5.88M
    if(BOOST_JSON_UNLIKELY(
2753
5.88M
        ! h_.on_double(d, {begin, size}, ec_)))
2754
0
        return fail(cs.begin());
2755
5.88M
    return cs.begin();
2756
5.88M
}
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
63.9k
{
1987
63.9k
    constexpr bool precise_parsing = mode == number_precision::precise;
1988
63.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
63.9k
    bool const negative = first == '-';
1995
63.9k
    bool const zero_first = first == '0';
1996
63.9k
    bool const nonzero_first = first == '+';
1997
63.9k
    detail::const_stream_wrapper cs(p, end_);
1998
63.9k
    number num;
1999
63.9k
    const char* begin = cs.begin();
2000
63.9k
    if(stack_empty || st_.empty())
2001
63.9k
    {
2002
63.9k
        num.bias = 0;
2003
63.9k
        num.exp = 0;
2004
63.9k
        num.frac = false;
2005
63.9k
        num_buf_.clear();
2006
2007
        //----------------------------------
2008
        //
2009
        // '-'
2010
        // leading minus sign
2011
        //
2012
63.9k
        BOOST_ASSERT(cs);
2013
63.9k
        if(negative)
2014
0
            ++cs;
2015
2016
63.9k
        num.neg = negative;
2017
63.9k
        num.frac = false;
2018
63.9k
        num.exp = 0;
2019
63.9k
        num.bias = 0;
2020
2021
        // fast path
2022
63.9k
        if( cs.remain() >= 16 + 1 + 16 ) // digits . digits
2023
62.0k
        {
2024
62.0k
            int n1;
2025
2026
62.0k
            if( nonzero_first ||
2027
62.0k
                (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
62.0k
            else
2062
62.0k
            {
2063
                // 0. floating-point or 0e integer
2064
62.0k
                num.mant = 0;
2065
62.0k
                n1 = 0;
2066
62.0k
                ++cs;
2067
62.0k
            }
2068
2069
62.0k
            {
2070
62.0k
                const char c = *cs;
2071
62.0k
                if(c != '.')
2072
56.7k
                {
2073
56.7k
                    if((c | 32) == 'e')
2074
2.12k
                    {
2075
2.12k
                        ++cs;
2076
2.12k
                        goto do_exp1;
2077
2.12k
                    }
2078
54.6k
                    BOOST_IF_CONSTEXPR( negative && !no_parsing )
2079
54.6k
                        num.mant = ~num.mant + 1;
2080
54.6k
                    goto finish_signed;
2081
56.7k
                }
2082
62.0k
            }
2083
2084
            // floating-point number
2085
2086
5.30k
            ++cs;
2087
2088
5.30k
            int n2 = detail::count_digits( cs.begin() );
2089
5.30k
            BOOST_ASSERT(n2 >= 0 && n2 <= 16);
2090
2091
5.30k
            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
5.29k
            if( n1 + n2 >= 19 )
2101
0
            {
2102
0
                goto do_num7;
2103
0
            }
2104
2105
5.29k
            BOOST_IF_CONSTEXPR( !no_parsing )
2106
5.29k
                num.mant = detail::parse_unsigned( num.mant, cs.begin(), n2 );
2107
2108
5.29k
            BOOST_ASSERT(num.bias == 0);
2109
2110
5.29k
            num.bias -= n2;
2111
2112
5.29k
            cs += n2;
2113
2114
5.29k
            char ch = *cs;
2115
2116
5.29k
            if( (ch | 32) == 'e' )
2117
792
            {
2118
792
                ++cs;
2119
792
                goto do_exp1;
2120
792
            }
2121
4.50k
            else if( ch >= '0' && ch <= '9' )
2122
2.48k
            {
2123
2.48k
                goto do_num8;
2124
2.48k
            }
2125
2126
2.02k
            goto finish_dub;
2127
5.29k
        }
2128
63.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
1.83k
do_num1:
2157
1.83k
    if(zero_first || nonzero_first ||
2158
1.83k
        BOOST_JSON_LIKELY(cs))
2159
1.83k
    {
2160
1.83k
        char const c = *cs;
2161
1.83k
        if(zero_first)
2162
1.83k
        {
2163
1.83k
            ++cs;
2164
1.83k
            num.mant = 0;
2165
1.83k
            goto do_num6;
2166
1.83k
        }
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.83k
    }
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.26k
do_num5:
2384
1.26k
    for(;;)
2385
313k
    {
2386
313k
        if(BOOST_JSON_UNLIKELY(! cs))
2387
17
        {
2388
17
            if(BOOST_JSON_UNLIKELY(more_))
2389
17
            {
2390
17
                if(BOOST_JSON_UNLIKELY(
2391
17
                    ! h_.on_number_part(
2392
17
                        {begin, cs.used(begin)}, ec_)))
2393
0
                    return fail(cs.begin());
2394
2395
17
                BOOST_IF_CONSTEXPR( precise_parsing )
2396
17
                    num_buf_.append( begin, cs.used(begin) );
2397
17
                return suspend(cs.begin(), state::num5, num);
2398
17
            }
2399
0
            goto finish_dub;
2400
17
        }
2401
313k
        char const c = *cs;
2402
313k
        if(BOOST_JSON_LIKELY(
2403
313k
            c >= '0' && c <= '9'))
2404
312k
        {
2405
312k
            ++cs;
2406
312k
        }
2407
1.24k
        else if((c | 32) == 'e')
2408
582
        {
2409
582
            ++cs;
2410
582
            goto do_exp1;
2411
582
        }
2412
661
        else
2413
661
        {
2414
661
            goto finish_dub;
2415
661
        }
2416
313k
    }
2417
2418
    //----------------------------------
2419
    //
2420
    // [.eE]
2421
    //
2422
1.83k
do_num6:
2423
1.83k
    {
2424
1.83k
        if(BOOST_JSON_UNLIKELY(! cs))
2425
20
        {
2426
20
            if(BOOST_JSON_UNLIKELY(more_))
2427
20
            {
2428
20
                if(BOOST_JSON_UNLIKELY(
2429
20
                    ! h_.on_number_part(
2430
20
                        {begin, cs.used(begin)}, ec_)))
2431
0
                    return fail(cs.begin());
2432
2433
20
                BOOST_IF_CONSTEXPR( precise_parsing )
2434
20
                    num_buf_.append( begin, cs.used(begin) );
2435
20
                return suspend(cs.begin(), state::num6, num);
2436
20
            }
2437
0
            goto finish_int;
2438
20
        }
2439
1.81k
        char const c = *cs;
2440
1.81k
        if(BOOST_JSON_LIKELY(
2441
1.81k
            c == '.'))
2442
334
        {
2443
334
            ++cs;
2444
334
        }
2445
1.48k
        else if((c | 32) == 'e')
2446
493
        {
2447
493
            ++cs;
2448
493
            goto do_exp1;
2449
493
        }
2450
988
        else
2451
988
        {
2452
988
            goto finish_int;
2453
988
        }
2454
1.81k
    }
2455
2456
    //----------------------------------
2457
    //
2458
    // DIGIT
2459
    // first significant digit
2460
    // to the right of decimal
2461
    //
2462
334
do_num7:
2463
334
    {
2464
334
        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
0
            BOOST_STATIC_CONSTEXPR source_location loc
2479
0
                = BOOST_CURRENT_LOCATION;
2480
0
            return fail(cs.begin(), error::syntax, &loc);
2481
5
        }
2482
329
        char const c = *cs;
2483
329
        if(BOOST_JSON_UNLIKELY(
2484
329
            c < '0' || c > '9'))
2485
13
        {
2486
            // digit required
2487
13
            BOOST_STATIC_CONSTEXPR source_location loc
2488
13
                = BOOST_CURRENT_LOCATION;
2489
13
            return fail(cs.begin(), error::syntax, &loc);
2490
13
        }
2491
329
    }
2492
2493
    //----------------------------------
2494
    //
2495
    // 1*DIGIT
2496
    // significant digits
2497
    // to the right of decimal
2498
    //
2499
2.80k
do_num8:
2500
2.80k
    for(;;)
2501
9.75M
    {
2502
9.75M
        if(BOOST_JSON_UNLIKELY(! cs))
2503
84
        {
2504
84
            if(BOOST_JSON_UNLIKELY(more_))
2505
84
            {
2506
84
                if(BOOST_JSON_UNLIKELY(
2507
84
                    ! h_.on_number_part(
2508
84
                        {begin, cs.used(begin)}, ec_)))
2509
0
                    return fail(cs.begin());
2510
2511
84
                BOOST_IF_CONSTEXPR( precise_parsing )
2512
84
                    num_buf_.append( begin, cs.used(begin) );
2513
84
                return suspend(cs.begin(), state::num8, num);
2514
84
            }
2515
0
            goto finish_dub;
2516
84
        }
2517
9.75M
        char const c = *cs;
2518
9.75M
        if(BOOST_JSON_LIKELY(
2519
9.75M
            c >= '0' && c <= '9'))
2520
9.75M
        {
2521
9.75M
            ++cs;
2522
9.75M
            if(!no_parsing && BOOST_JSON_LIKELY(
2523
9.75M
                num.mant <= 9007199254740991)) // 2^53-1
2524
9.75M
            {
2525
9.75M
                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
9.75M
                --num.bias;
2532
9.75M
                num.mant = 10 * num.mant + ( c - '0' );
2533
9.75M
            }
2534
1.26k
            else
2535
1.26k
            {
2536
1.26k
                goto do_num5;
2537
1.26k
            }
2538
9.75M
        }
2539
1.45k
        else if((c | 32) == 'e')
2540
706
        {
2541
706
            ++cs;
2542
706
            goto do_exp1;
2543
706
        }
2544
752
        else
2545
752
        {
2546
752
            goto finish_dub;
2547
752
        }
2548
9.75M
    }
2549
2550
    //----------------------------------
2551
    //
2552
    // *[+-]
2553
    //
2554
4.69k
do_exp1:
2555
4.69k
    if(BOOST_JSON_UNLIKELY(! cs))
2556
21
    {
2557
21
        if(BOOST_JSON_UNLIKELY(
2558
21
            ! h_.on_number_part(
2559
21
                {begin, cs.used(begin)}, ec_)))
2560
0
            return fail(cs.begin());
2561
2562
21
        BOOST_IF_CONSTEXPR( precise_parsing )
2563
21
            num_buf_.append( begin, cs.used(begin) );
2564
21
        return maybe_suspend(
2565
21
            cs.begin(), state::exp1, num);
2566
21
    }
2567
4.67k
    if(*cs == '+')
2568
399
    {
2569
399
        ++cs;
2570
399
    }
2571
4.27k
    else if(*cs == '-')
2572
1.40k
    {
2573
1.40k
        ++cs;
2574
1.40k
        num.frac = true;
2575
1.40k
    }
2576
2577
    //----------------------------------
2578
    //
2579
    // DIGIT
2580
    // first digit of the exponent
2581
    //
2582
4.67k
do_exp2:
2583
4.67k
    {
2584
4.67k
        if(BOOST_JSON_UNLIKELY(! cs))
2585
12
        {
2586
12
            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
0
            BOOST_STATIC_CONSTEXPR source_location loc
2599
0
                = BOOST_CURRENT_LOCATION;
2600
0
            return fail(cs.begin(), error::syntax, &loc);
2601
12
        }
2602
4.66k
        char const c = *cs;
2603
4.66k
        if(BOOST_JSON_UNLIKELY(
2604
4.66k
            c < '0' || c > '9'))
2605
28
        {
2606
            // digit required
2607
28
            BOOST_STATIC_CONSTEXPR source_location loc
2608
28
                = BOOST_CURRENT_LOCATION;
2609
28
            return fail(cs.begin(), error::syntax, &loc);
2610
28
        }
2611
4.63k
        ++cs;
2612
4.63k
        num.exp = c - '0';
2613
4.63k
    }
2614
2615
    //----------------------------------
2616
    //
2617
    // 1*DIGIT
2618
    // subsequent digits in the exponent
2619
    //
2620
4.63k
do_exp3:
2621
4.63k
    for(;;)
2622
59.0k
    {
2623
59.0k
        if(BOOST_JSON_UNLIKELY(! cs))
2624
139
        {
2625
139
            if(BOOST_JSON_UNLIKELY(more_))
2626
139
            {
2627
139
                if(BOOST_JSON_UNLIKELY(
2628
139
                    ! h_.on_number_part(
2629
139
                        {begin, cs.used(begin)}, ec_)))
2630
0
                    return fail(cs.begin());
2631
2632
139
                BOOST_IF_CONSTEXPR( precise_parsing )
2633
139
                    num_buf_.append( begin, cs.used(begin) );
2634
139
                return suspend(cs.begin(), state::exp3, num);
2635
139
            }
2636
139
        }
2637
58.9k
        else
2638
58.9k
        {
2639
58.9k
            char const c = *cs;
2640
58.9k
            if(BOOST_JSON_LIKELY( c >= '0' && c <= '9' ))
2641
54.4k
            {
2642
54.4k
                if(BOOST_JSON_UNLIKELY(
2643
                //              2147483647 INT_MAX
2644
54.4k
                    num.exp  >  214748364 ||
2645
54.4k
                    (num.exp == 214748364 && c > '7')
2646
54.4k
                ))
2647
42.5k
                    num.exp = INT_MAX;
2648
11.8k
                else BOOST_IF_CONSTEXPR( !no_parsing )
2649
11.8k
                    num.exp = 10 * num.exp + ( c - '0' );
2650
2651
54.4k
                ++cs;
2652
54.4k
                continue;
2653
54.4k
            }
2654
58.9k
        }
2655
4.49k
        BOOST_ASSERT(num.exp >= 0);
2656
4.49k
        if ( num.frac )
2657
1.34k
        {
2658
1.34k
            if(BOOST_JSON_UNLIKELY( num.bias < (INT_MIN + num.exp) ))
2659
475
            {
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
475
                if(BOOST_JSON_UNLIKELY(
2664
475
                    (num.exp == INT_MAX) &&
2665
475
                    (num.bias < 0) &&
2666
475
                    (num.exp + num.bias < 308) &&
2667
475
                    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
475
                num.bias = 0;
2675
475
                num.exp = INT_MAX;
2676
475
            }
2677
1.34k
        }
2678
3.14k
        else if (BOOST_JSON_UNLIKELY( num.bias > (INT_MAX - num.exp) ))
2679
0
        {
2680
            // if exponent overflowed, bias is a very large positive number,
2681
            // and mantissa isn't zero, then we cannot parse the
2682
            // number correctly
2683
0
            if(BOOST_JSON_UNLIKELY(
2684
0
                (num.exp == INT_MAX) &&
2685
0
                (num.bias > 0) &&
2686
0
                (num.exp - num.bias < 308) &&
2687
0
                num.mant ))
2688
0
            {
2689
0
                BOOST_STATIC_CONSTEXPR source_location loc
2690
0
                    = BOOST_CURRENT_LOCATION;
2691
0
                return fail(cs.begin(), error::exponent_overflow, &loc);
2692
0
            }
2693
2694
0
            num.bias = 0;
2695
0
            num.exp = INT_MAX;
2696
0
        }
2697
4.49k
        goto finish_dub;
2698
4.49k
    }
2699
2700
988
finish_int:
2701
988
    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
988
    if(num.mant <= INT64_MAX)
2710
988
    {
2711
55.6k
finish_signed:
2712
55.6k
        if(BOOST_JSON_UNLIKELY(
2713
55.6k
            ! h_.on_int64(static_cast<
2714
55.6k
                int64_t>(num.mant), {begin, cs.used(begin)}, ec_)))
2715
0
            return fail(cs.begin());
2716
55.6k
        return cs.begin();
2717
55.6k
    }
2718
0
    if(BOOST_JSON_UNLIKELY(
2719
0
        ! h_.on_uint64(num.mant, {begin, cs.used(begin)}, ec_)))
2720
0
        return fail(cs.begin());
2721
0
    return cs.begin();
2722
7.92k
finish_dub:
2723
7.92k
    double d;
2724
7.92k
    std::size_t const size = cs.used(begin);
2725
7.92k
    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
7.92k
    else BOOST_IF_CONSTEXPR( no_parsing )
2745
7.92k
        d = 0;
2746
7.92k
    else
2747
7.92k
        d = detail::dec_to_float(
2748
7.92k
            num.mant,
2749
7.92k
            num.bias + (num.frac ?
2750
6.58k
                -num.exp : num.exp),
2751
7.92k
            num.neg);
2752
7.92k
    if(BOOST_JSON_UNLIKELY(
2753
7.92k
        ! h_.on_double(d, {begin, size}, ec_)))
2754
0
        return fail(cs.begin());
2755
7.92k
    return cs.begin();
2756
7.92k
}
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
302k
{
1987
302k
    constexpr bool precise_parsing = mode == number_precision::precise;
1988
302k
    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
302k
    bool const negative = first == '-';
1995
302k
    bool const zero_first = first == '0';
1996
302k
    bool const nonzero_first = first == '+';
1997
302k
    detail::const_stream_wrapper cs(p, end_);
1998
302k
    number num;
1999
302k
    const char* begin = cs.begin();
2000
302k
    if(stack_empty || st_.empty())
2001
302k
    {
2002
302k
        num.bias = 0;
2003
302k
        num.exp = 0;
2004
302k
        num.frac = false;
2005
302k
        num_buf_.clear();
2006
2007
        //----------------------------------
2008
        //
2009
        // '-'
2010
        // leading minus sign
2011
        //
2012
302k
        BOOST_ASSERT(cs);
2013
302k
        if(negative)
2014
0
            ++cs;
2015
2016
302k
        num.neg = negative;
2017
302k
        num.frac = false;
2018
302k
        num.exp = 0;
2019
302k
        num.bias = 0;
2020
2021
        // fast path
2022
302k
        if( cs.remain() >= 16 + 1 + 16 ) // digits . digits
2023
300k
        {
2024
300k
            int n1;
2025
2026
300k
            if( nonzero_first ||
2027
300k
                (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
300k
            else
2062
300k
            {
2063
                // 0. floating-point or 0e integer
2064
300k
                num.mant = 0;
2065
300k
                n1 = 0;
2066
300k
                ++cs;
2067
300k
            }
2068
2069
300k
            {
2070
300k
                const char c = *cs;
2071
300k
                if(c != '.')
2072
296k
                {
2073
296k
                    if((c | 32) == 'e')
2074
1.12k
                    {
2075
1.12k
                        ++cs;
2076
1.12k
                        goto do_exp1;
2077
1.12k
                    }
2078
295k
                    BOOST_IF_CONSTEXPR( negative && !no_parsing )
2079
295k
                        num.mant = ~num.mant + 1;
2080
295k
                    goto finish_signed;
2081
296k
                }
2082
300k
            }
2083
2084
            // floating-point number
2085
2086
4.41k
            ++cs;
2087
2088
4.41k
            int n2 = detail::count_digits( cs.begin() );
2089
4.41k
            BOOST_ASSERT(n2 >= 0 && n2 <= 16);
2090
2091
4.41k
            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
4.41k
            if( n1 + n2 >= 19 )
2101
0
            {
2102
0
                goto do_num7;
2103
0
            }
2104
2105
4.41k
            BOOST_IF_CONSTEXPR( !no_parsing )
2106
4.41k
                num.mant = detail::parse_unsigned( num.mant, cs.begin(), n2 );
2107
2108
4.41k
            BOOST_ASSERT(num.bias == 0);
2109
2110
4.41k
            num.bias -= n2;
2111
2112
4.41k
            cs += n2;
2113
2114
4.41k
            char ch = *cs;
2115
2116
4.41k
            if( (ch | 32) == 'e' )
2117
733
            {
2118
733
                ++cs;
2119
733
                goto do_exp1;
2120
733
            }
2121
3.67k
            else if( ch >= '0' && ch <= '9' )
2122
2.34k
            {
2123
2.34k
                goto do_num8;
2124
2.34k
            }
2125
2126
1.33k
            goto finish_dub;
2127
4.41k
        }
2128
302k
    }
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.35k
do_num1:
2157
1.35k
    if(zero_first || nonzero_first ||
2158
1.35k
        BOOST_JSON_LIKELY(cs))
2159
1.35k
    {
2160
1.35k
        char const c = *cs;
2161
1.35k
        if(zero_first)
2162
1.35k
        {
2163
1.35k
            ++cs;
2164
1.35k
            num.mant = 0;
2165
1.35k
            goto do_num6;
2166
1.35k
        }
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.35k
    }
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.66k
do_num5:
2384
1.66k
    for(;;)
2385
754k
    {
2386
754k
        if(BOOST_JSON_UNLIKELY(! cs))
2387
112
        {
2388
112
            if(BOOST_JSON_UNLIKELY(more_))
2389
112
            {
2390
112
                if(BOOST_JSON_UNLIKELY(
2391
112
                    ! h_.on_number_part(
2392
112
                        {begin, cs.used(begin)}, ec_)))
2393
0
                    return fail(cs.begin());
2394
2395
112
                BOOST_IF_CONSTEXPR( precise_parsing )
2396
112
                    num_buf_.append( begin, cs.used(begin) );
2397
112
                return suspend(cs.begin(), state::num5, num);
2398
112
            }
2399
0
            goto finish_dub;
2400
112
        }
2401
754k
        char const c = *cs;
2402
754k
        if(BOOST_JSON_LIKELY(
2403
754k
            c >= '0' && c <= '9'))
2404
752k
        {
2405
752k
            ++cs;
2406
752k
        }
2407
1.55k
        else if((c | 32) == 'e')
2408
360
        {
2409
360
            ++cs;
2410
360
            goto do_exp1;
2411
360
        }
2412
1.19k
        else
2413
1.19k
        {
2414
1.19k
            goto finish_dub;
2415
1.19k
        }
2416
754k
    }
2417
2418
    //----------------------------------
2419
    //
2420
    // [.eE]
2421
    //
2422
1.35k
do_num6:
2423
1.35k
    {
2424
1.35k
        if(BOOST_JSON_UNLIKELY(! cs))
2425
27
        {
2426
27
            if(BOOST_JSON_UNLIKELY(more_))
2427
27
            {
2428
27
                if(BOOST_JSON_UNLIKELY(
2429
27
                    ! h_.on_number_part(
2430
27
                        {begin, cs.used(begin)}, ec_)))
2431
0
                    return fail(cs.begin());
2432
2433
27
                BOOST_IF_CONSTEXPR( precise_parsing )
2434
27
                    num_buf_.append( begin, cs.used(begin) );
2435
27
                return suspend(cs.begin(), state::num6, num);
2436
27
            }
2437
0
            goto finish_int;
2438
27
        }
2439
1.32k
        char const c = *cs;
2440
1.32k
        if(BOOST_JSON_LIKELY(
2441
1.32k
            c == '.'))
2442
509
        {
2443
509
            ++cs;
2444
509
        }
2445
818
        else if((c | 32) == 'e')
2446
370
        {
2447
370
            ++cs;
2448
370
            goto do_exp1;
2449
370
        }
2450
448
        else
2451
448
        {
2452
448
            goto finish_int;
2453
448
        }
2454
1.32k
    }
2455
2456
    //----------------------------------
2457
    //
2458
    // DIGIT
2459
    // first significant digit
2460
    // to the right of decimal
2461
    //
2462
509
do_num7:
2463
509
    {
2464
509
        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
0
            BOOST_STATIC_CONSTEXPR source_location loc
2479
0
                = BOOST_CURRENT_LOCATION;
2480
0
            return fail(cs.begin(), error::syntax, &loc);
2481
5
        }
2482
504
        char const c = *cs;
2483
504
        if(BOOST_JSON_UNLIKELY(
2484
504
            c < '0' || c > '9'))
2485
10
        {
2486
            // digit required
2487
10
            BOOST_STATIC_CONSTEXPR source_location loc
2488
10
                = BOOST_CURRENT_LOCATION;
2489
10
            return fail(cs.begin(), error::syntax, &loc);
2490
10
        }
2491
504
    }
2492
2493
    //----------------------------------
2494
    //
2495
    // 1*DIGIT
2496
    // significant digits
2497
    // to the right of decimal
2498
    //
2499
2.83k
do_num8:
2500
2.83k
    for(;;)
2501
8.93M
    {
2502
8.93M
        if(BOOST_JSON_UNLIKELY(! cs))
2503
154
        {
2504
154
            if(BOOST_JSON_UNLIKELY(more_))
2505
154
            {
2506
154
                if(BOOST_JSON_UNLIKELY(
2507
154
                    ! h_.on_number_part(
2508
154
                        {begin, cs.used(begin)}, ec_)))
2509
0
                    return fail(cs.begin());
2510
2511
154
                BOOST_IF_CONSTEXPR( precise_parsing )
2512
154
                    num_buf_.append( begin, cs.used(begin) );
2513
154
                return suspend(cs.begin(), state::num8, num);
2514
154
            }
2515
0
            goto finish_dub;
2516
154
        }
2517
8.93M
        char const c = *cs;
2518
8.93M
        if(BOOST_JSON_LIKELY(
2519
8.93M
            c >= '0' && c <= '9'))
2520
8.93M
        {
2521
8.93M
            ++cs;
2522
8.93M
            if(!no_parsing && BOOST_JSON_LIKELY(
2523
8.93M
                num.mant <= 9007199254740991)) // 2^53-1
2524
8.93M
            {
2525
8.93M
                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
8.93M
                --num.bias;
2532
8.93M
                num.mant = 10 * num.mant + ( c - '0' );
2533
8.93M
            }
2534
1.66k
            else
2535
1.66k
            {
2536
1.66k
                goto do_num5;
2537
1.66k
            }
2538
8.93M
        }
2539
1.01k
        else if((c | 32) == 'e')
2540
349
        {
2541
349
            ++cs;
2542
349
            goto do_exp1;
2543
349
        }
2544
667
        else
2545
667
        {
2546
667
            goto finish_dub;
2547
667
        }
2548
8.93M
    }
2549
2550
    //----------------------------------
2551
    //
2552
    // *[+-]
2553
    //
2554
2.93k
do_exp1:
2555
2.93k
    if(BOOST_JSON_UNLIKELY(! cs))
2556
19
    {
2557
19
        if(BOOST_JSON_UNLIKELY(
2558
19
            ! h_.on_number_part(
2559
19
                {begin, cs.used(begin)}, ec_)))
2560
0
            return fail(cs.begin());
2561
2562
19
        BOOST_IF_CONSTEXPR( precise_parsing )
2563
19
            num_buf_.append( begin, cs.used(begin) );
2564
19
        return maybe_suspend(
2565
19
            cs.begin(), state::exp1, num);
2566
19
    }
2567
2.92k
    if(*cs == '+')
2568
282
    {
2569
282
        ++cs;
2570
282
    }
2571
2.63k
    else if(*cs == '-')
2572
884
    {
2573
884
        ++cs;
2574
884
        num.frac = true;
2575
884
    }
2576
2577
    //----------------------------------
2578
    //
2579
    // DIGIT
2580
    // first digit of the exponent
2581
    //
2582
2.92k
do_exp2:
2583
2.92k
    {
2584
2.92k
        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
0
            BOOST_STATIC_CONSTEXPR source_location loc
2599
0
                = BOOST_CURRENT_LOCATION;
2600
0
            return fail(cs.begin(), error::syntax, &loc);
2601
9
        }
2602
2.91k
        char const c = *cs;
2603
2.91k
        if(BOOST_JSON_UNLIKELY(
2604
2.91k
            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.89k
        ++cs;
2612
2.89k
        num.exp = c - '0';
2613
2.89k
    }
2614
2615
    //----------------------------------
2616
    //
2617
    // 1*DIGIT
2618
    // subsequent digits in the exponent
2619
    //
2620
2.89k
do_exp3:
2621
2.89k
    for(;;)
2622
14.6k
    {
2623
14.6k
        if(BOOST_JSON_UNLIKELY(! cs))
2624
148
        {
2625
148
            if(BOOST_JSON_UNLIKELY(more_))
2626
148
            {
2627
148
                if(BOOST_JSON_UNLIKELY(
2628
148
                    ! h_.on_number_part(
2629
148
                        {begin, cs.used(begin)}, ec_)))
2630
0
                    return fail(cs.begin());
2631
2632
148
                BOOST_IF_CONSTEXPR( precise_parsing )
2633
148
                    num_buf_.append( begin, cs.used(begin) );
2634
148
                return suspend(cs.begin(), state::exp3, num);
2635
148
            }
2636
148
        }
2637
14.4k
        else
2638
14.4k
        {
2639
14.4k
            char const c = *cs;
2640
14.4k
            if(BOOST_JSON_LIKELY( c >= '0' && c <= '9' ))
2641
11.7k
            {
2642
11.7k
                if(BOOST_JSON_UNLIKELY(
2643
                //              2147483647 INT_MAX
2644
11.7k
                    num.exp  >  214748364 ||
2645
11.7k
                    (num.exp == 214748364 && c > '7')
2646
11.7k
                ))
2647
3.69k
                    num.exp = INT_MAX;
2648
8.02k
                else BOOST_IF_CONSTEXPR( !no_parsing )
2649
8.02k
                    num.exp = 10 * num.exp + ( c - '0' );
2650
2651
11.7k
                ++cs;
2652
11.7k
                continue;
2653
11.7k
            }
2654
14.4k
        }
2655
2.74k
        BOOST_ASSERT(num.exp >= 0);
2656
2.74k
        if ( num.frac )
2657
821
        {
2658
821
            if(BOOST_JSON_UNLIKELY( num.bias < (INT_MIN + num.exp) ))
2659
456
            {
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
456
                if(BOOST_JSON_UNLIKELY(
2664
456
                    (num.exp == INT_MAX) &&
2665
456
                    (num.bias < 0) &&
2666
456
                    (num.exp + num.bias < 308) &&
2667
456
                    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
456
                num.bias = 0;
2675
456
                num.exp = INT_MAX;
2676
456
            }
2677
821
        }
2678
1.92k
        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.74k
        goto finish_dub;
2698
2.74k
    }
2699
2700
448
finish_int:
2701
448
    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
448
    if(num.mant <= INT64_MAX)
2710
448
    {
2711
295k
finish_signed:
2712
295k
        if(BOOST_JSON_UNLIKELY(
2713
295k
            ! h_.on_int64(static_cast<
2714
295k
                int64_t>(num.mant), {begin, cs.used(begin)}, ec_)))
2715
0
            return fail(cs.begin());
2716
295k
        return cs.begin();
2717
295k
    }
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.94k
finish_dub:
2723
5.94k
    double d;
2724
5.94k
    std::size_t const size = cs.used(begin);
2725
5.94k
    BOOST_ASSERT( !num_buf_.size() || precise_parsing );
2726
    BOOST_IF_CONSTEXPR( precise_parsing )
2727
5.94k
    {
2728
5.94k
        char const* data = begin;
2729
5.94k
        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.94k
        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.94k
        auto const err = detail::charconv::from_chars(
2739
5.94k
            data, data + full_size, d );
2740
5.94k
        BOOST_ASSERT( err.ec != std::errc::invalid_argument );
2741
5.94k
        BOOST_ASSERT( err.ptr == data + full_size );
2742
5.94k
        (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.94k
    if(BOOST_JSON_UNLIKELY(
2753
5.94k
        ! h_.on_double(d, {begin, size}, ec_)))
2754
0
        return fail(cs.begin());
2755
5.94k
    return cs.begin();
2756
5.94k
}
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
45.5k
{
1987
45.5k
    constexpr bool precise_parsing = mode == number_precision::precise;
1988
45.5k
    constexpr bool no_parsing = mode == number_precision::none;
1989
1990
    // only one of these will be true if we are not resuming
1991
    // if negative then !zero_first && !nonzero_first
1992
    // if zero_first then !nonzero_first && !negative
1993
    // if nonzero_first then !zero_first && !negative
1994
45.5k
    bool const negative = first == '-';
1995
45.5k
    bool const zero_first = first == '0';
1996
45.5k
    bool const nonzero_first = first == '+';
1997
45.5k
    detail::const_stream_wrapper cs(p, end_);
1998
45.5k
    number num;
1999
45.5k
    const char* begin = cs.begin();
2000
45.5k
    if(stack_empty || st_.empty())
2001
45.5k
    {
2002
45.5k
        num.bias = 0;
2003
45.5k
        num.exp = 0;
2004
45.5k
        num.frac = false;
2005
45.5k
        num_buf_.clear();
2006
2007
        //----------------------------------
2008
        //
2009
        // '-'
2010
        // leading minus sign
2011
        //
2012
45.5k
        BOOST_ASSERT(cs);
2013
45.5k
        if(negative)
2014
0
            ++cs;
2015
2016
45.5k
        num.neg = negative;
2017
45.5k
        num.frac = false;
2018
45.5k
        num.exp = 0;
2019
45.5k
        num.bias = 0;
2020
2021
        // fast path
2022
45.5k
        if( cs.remain() >= 16 + 1 + 16 ) // digits . digits
2023
44.6k
        {
2024
44.6k
            int n1;
2025
2026
44.6k
            if( nonzero_first ||
2027
44.6k
                (negative && *cs != '0') )
2028
0
            {
2029
0
                n1 = detail::count_digits( cs.begin() );
2030
0
                BOOST_ASSERT(n1 >= 0 && n1 <= 16);
2031
2032
0
                if( negative && n1 == 0 && opt_.allow_infinity_and_nan )
2033
0
                {
2034
0
                    return parse_literal(
2035
0
                        p - 1,
2036
0
                        detail::literals_c<detail::literals::neg_infinity>());
2037
0
                }
2038
2039
0
                if( ! nonzero_first && n1 == 0 )
2040
0
                {
2041
                    // digit required
2042
0
                    BOOST_STATIC_CONSTEXPR source_location loc
2043
0
                        = BOOST_CURRENT_LOCATION;
2044
0
                    return fail(cs.begin(), error::syntax, &loc);
2045
0
                }
2046
2047
0
                BOOST_IF_CONSTEXPR( !no_parsing )
2048
0
                    num.mant = detail::parse_unsigned( 0, cs.begin(), n1 );
2049
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
44.6k
            else
2062
44.6k
            {
2063
                // 0. floating-point or 0e integer
2064
44.6k
                num.mant = 0;
2065
44.6k
                n1 = 0;
2066
44.6k
                ++cs;
2067
44.6k
            }
2068
2069
44.6k
            {
2070
44.6k
                const char c = *cs;
2071
44.6k
                if(c != '.')
2072
43.5k
                {
2073
43.5k
                    if((c | 32) == 'e')
2074
723
                    {
2075
723
                        ++cs;
2076
723
                        goto do_exp1;
2077
723
                    }
2078
42.8k
                    BOOST_IF_CONSTEXPR( negative && !no_parsing )
2079
42.8k
                        num.mant = ~num.mant + 1;
2080
42.8k
                    goto finish_signed;
2081
43.5k
                }
2082
44.6k
            }
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.06k
            if( n1 + n2 >= 19 )
2101
0
            {
2102
0
                goto do_num7;
2103
0
            }
2104
2105
1.06k
            BOOST_IF_CONSTEXPR( !no_parsing )
2106
1.06k
                num.mant = detail::parse_unsigned( num.mant, cs.begin(), n2 );
2107
2108
1.06k
            BOOST_ASSERT(num.bias == 0);
2109
2110
1.06k
            num.bias -= n2;
2111
2112
1.06k
            cs += n2;
2113
2114
1.06k
            char ch = *cs;
2115
2116
1.06k
            if( (ch | 32) == 'e' )
2117
204
            {
2118
204
                ++cs;
2119
204
                goto do_exp1;
2120
204
            }
2121
864
            else if( ch >= '0' && ch <= '9' )
2122
417
            {
2123
417
                goto do_num8;
2124
417
            }
2125
2126
447
            goto finish_dub;
2127
1.06k
        }
2128
45.5k
    }
2129
0
    else
2130
0
    {
2131
0
        num = num_;
2132
0
        state st;
2133
0
        st_.pop(st);
2134
0
        switch(st)
2135
0
        {
2136
0
        default: BOOST_JSON_UNREACHABLE();
2137
0
        case state::num1: goto do_num1;
2138
0
        case state::num2: goto do_num2;
2139
0
        case state::num3: goto do_num3;
2140
0
        case state::num4: goto do_num4;
2141
0
        case state::num5: goto do_num5;
2142
0
        case state::num6: goto do_num6;
2143
0
        case state::num7: goto do_num7;
2144
0
        case state::num8: goto do_num8;
2145
0
        case state::exp1: goto do_exp1;
2146
0
        case state::exp2: goto do_exp2;
2147
0
        case state::exp3: goto do_exp3;
2148
0
        }
2149
0
    }
2150
2151
    //----------------------------------
2152
    //
2153
    // DIGIT
2154
    // first digit
2155
    //
2156
908
do_num1:
2157
908
    if(zero_first || nonzero_first ||
2158
908
        BOOST_JSON_LIKELY(cs))
2159
908
    {
2160
908
        char const c = *cs;
2161
908
        if(zero_first)
2162
908
        {
2163
908
            ++cs;
2164
908
            num.mant = 0;
2165
908
            goto do_num6;
2166
908
        }
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
908
    }
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
549
do_num5:
2384
549
    for(;;)
2385
2.81k
    {
2386
2.81k
        if(BOOST_JSON_UNLIKELY(! cs))
2387
23
        {
2388
23
            if(BOOST_JSON_UNLIKELY(more_))
2389
23
            {
2390
23
                if(BOOST_JSON_UNLIKELY(
2391
23
                    ! h_.on_number_part(
2392
23
                        {begin, cs.used(begin)}, ec_)))
2393
0
                    return fail(cs.begin());
2394
2395
23
                BOOST_IF_CONSTEXPR( precise_parsing )
2396
23
                    num_buf_.append( begin, cs.used(begin) );
2397
23
                return suspend(cs.begin(), state::num5, num);
2398
23
            }
2399
0
            goto finish_dub;
2400
23
        }
2401
2.79k
        char const c = *cs;
2402
2.79k
        if(BOOST_JSON_LIKELY(
2403
2.79k
            c >= '0' && c <= '9'))
2404
2.26k
        {
2405
2.26k
            ++cs;
2406
2.26k
        }
2407
526
        else if((c | 32) == 'e')
2408
203
        {
2409
203
            ++cs;
2410
203
            goto do_exp1;
2411
203
        }
2412
323
        else
2413
323
        {
2414
323
            goto finish_dub;
2415
323
        }
2416
2.79k
    }
2417
2418
    //----------------------------------
2419
    //
2420
    // [.eE]
2421
    //
2422
908
do_num6:
2423
908
    {
2424
908
        if(BOOST_JSON_UNLIKELY(! cs))
2425
23
        {
2426
23
            if(BOOST_JSON_UNLIKELY(more_))
2427
23
            {
2428
23
                if(BOOST_JSON_UNLIKELY(
2429
23
                    ! h_.on_number_part(
2430
23
                        {begin, cs.used(begin)}, ec_)))
2431
0
                    return fail(cs.begin());
2432
2433
23
                BOOST_IF_CONSTEXPR( precise_parsing )
2434
23
                    num_buf_.append( begin, cs.used(begin) );
2435
23
                return suspend(cs.begin(), state::num6, num);
2436
23
            }
2437
0
            goto finish_int;
2438
23
        }
2439
885
        char const c = *cs;
2440
885
        if(BOOST_JSON_LIKELY(
2441
885
            c == '.'))
2442
148
        {
2443
148
            ++cs;
2444
148
        }
2445
737
        else if((c | 32) == 'e')
2446
214
        {
2447
214
            ++cs;
2448
214
            goto do_exp1;
2449
214
        }
2450
523
        else
2451
523
        {
2452
523
            goto finish_int;
2453
523
        }
2454
885
    }
2455
2456
    //----------------------------------
2457
    //
2458
    // DIGIT
2459
    // first significant digit
2460
    // to the right of decimal
2461
    //
2462
148
do_num7:
2463
148
    {
2464
148
        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
0
            BOOST_STATIC_CONSTEXPR source_location loc
2479
0
                = BOOST_CURRENT_LOCATION;
2480
0
            return fail(cs.begin(), error::syntax, &loc);
2481
5
        }
2482
143
        char const c = *cs;
2483
143
        if(BOOST_JSON_UNLIKELY(
2484
143
            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
143
    }
2492
2493
    //----------------------------------
2494
    //
2495
    // 1*DIGIT
2496
    // significant digits
2497
    // to the right of decimal
2498
    //
2499
549
do_num8:
2500
549
    for(;;)
2501
549
    {
2502
549
        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
549
        char const c = *cs;
2518
549
        if(BOOST_JSON_LIKELY(
2519
549
            c >= '0' && c <= '9'))
2520
549
        {
2521
549
            ++cs;
2522
549
            if(!no_parsing && BOOST_JSON_LIKELY(
2523
549
                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
549
            else
2535
549
            {
2536
549
                goto do_num5;
2537
549
            }
2538
549
        }
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
549
    }
2549
2550
    //----------------------------------
2551
    //
2552
    // *[+-]
2553
    //
2554
1.34k
do_exp1:
2555
1.34k
    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.33k
    if(*cs == '+')
2568
194
    {
2569
194
        ++cs;
2570
194
    }
2571
1.13k
    else if(*cs == '-')
2572
260
    {
2573
260
        ++cs;
2574
260
        num.frac = true;
2575
260
    }
2576
2577
    //----------------------------------
2578
    //
2579
    // DIGIT
2580
    // first digit of the exponent
2581
    //
2582
1.33k
do_exp2:
2583
1.33k
    {
2584
1.33k
        if(BOOST_JSON_UNLIKELY(! cs))
2585
14
        {
2586
14
            if(BOOST_JSON_UNLIKELY(more_))
2587
14
            {
2588
14
                if(BOOST_JSON_UNLIKELY(
2589
14
                    ! h_.on_number_part(
2590
14
                        {begin, cs.used(begin)}, ec_)))
2591
0
                    return fail(cs.begin());
2592
2593
14
                BOOST_IF_CONSTEXPR( precise_parsing )
2594
14
                    num_buf_.append( begin, cs.used(begin) );
2595
14
                return suspend(cs.begin(), state::exp2, num);
2596
14
            }
2597
            // digit required
2598
0
            BOOST_STATIC_CONSTEXPR source_location loc
2599
0
                = BOOST_CURRENT_LOCATION;
2600
0
            return fail(cs.begin(), error::syntax, &loc);
2601
14
        }
2602
1.31k
        char const c = *cs;
2603
1.31k
        if(BOOST_JSON_UNLIKELY(
2604
1.31k
            c < '0' || c > '9'))
2605
21
        {
2606
            // digit required
2607
21
            BOOST_STATIC_CONSTEXPR source_location loc
2608
21
                = BOOST_CURRENT_LOCATION;
2609
21
            return fail(cs.begin(), error::syntax, &loc);
2610
21
        }
2611
1.29k
        ++cs;
2612
1.29k
        num.exp = c - '0';
2613
1.29k
    }
2614
2615
    //----------------------------------
2616
    //
2617
    // 1*DIGIT
2618
    // subsequent digits in the exponent
2619
    //
2620
1.29k
do_exp3:
2621
1.29k
    for(;;)
2622
1.57k
    {
2623
1.57k
        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
1.55k
        else
2638
1.55k
        {
2639
1.55k
            char const c = *cs;
2640
1.55k
            if(BOOST_JSON_LIKELY( c >= '0' && c <= '9' ))
2641
281
            {
2642
281
                if(BOOST_JSON_UNLIKELY(
2643
                //              2147483647 INT_MAX
2644
281
                    num.exp  >  214748364 ||
2645
281
                    (num.exp == 214748364 && c > '7')
2646
281
                ))
2647
0
                    num.exp = INT_MAX;
2648
281
                else BOOST_IF_CONSTEXPR( !no_parsing )
2649
281
                    num.exp = 10 * num.exp + ( c - '0' );
2650
2651
281
                ++cs;
2652
281
                continue;
2653
281
            }
2654
1.55k
        }
2655
1.27k
        BOOST_ASSERT(num.exp >= 0);
2656
1.27k
        if ( num.frac )
2657
253
        {
2658
253
            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
253
        }
2678
1.02k
        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.27k
        goto finish_dub;
2698
1.27k
    }
2699
2700
523
finish_int:
2701
523
    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
523
    if(num.mant <= INT64_MAX)
2710
523
    {
2711
43.3k
finish_signed:
2712
43.3k
        if(BOOST_JSON_UNLIKELY(
2713
43.3k
            ! h_.on_int64(static_cast<
2714
43.3k
                int64_t>(num.mant), {begin, cs.used(begin)}, ec_)))
2715
0
            return fail(cs.begin());
2716
43.3k
        return cs.begin();
2717
43.3k
    }
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.04k
finish_dub:
2723
2.04k
    double d;
2724
2.04k
    std::size_t const size = cs.used(begin);
2725
2.04k
    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.04k
    else BOOST_IF_CONSTEXPR( no_parsing )
2745
2.04k
        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.04k
    if(BOOST_JSON_UNLIKELY(
2753
2.04k
        ! h_.on_double(d, {begin, size}, ec_)))
2754
0
        return fail(cs.begin());
2755
2.04k
    return cs.begin();
2756
2.04k
}
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
29.6k
{
1987
29.6k
    constexpr bool precise_parsing = mode == number_precision::precise;
1988
29.6k
    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
29.6k
    bool const negative = first == '-';
1995
29.6k
    bool const zero_first = first == '0';
1996
29.6k
    bool const nonzero_first = first == '+';
1997
29.6k
    detail::const_stream_wrapper cs(p, end_);
1998
29.6k
    number num;
1999
29.6k
    const char* begin = cs.begin();
2000
29.6k
    if(stack_empty || st_.empty())
2001
29.6k
    {
2002
29.6k
        num.bias = 0;
2003
29.6k
        num.exp = 0;
2004
29.6k
        num.frac = false;
2005
29.6k
        num_buf_.clear();
2006
2007
        //----------------------------------
2008
        //
2009
        // '-'
2010
        // leading minus sign
2011
        //
2012
29.6k
        BOOST_ASSERT(cs);
2013
29.6k
        if(negative)
2014
29.6k
            ++cs;
2015
2016
29.6k
        num.neg = negative;
2017
29.6k
        num.frac = false;
2018
29.6k
        num.exp = 0;
2019
29.6k
        num.bias = 0;
2020
2021
        // fast path
2022
29.6k
        if( cs.remain() >= 16 + 1 + 16 ) // digits . digits
2023
28.1k
        {
2024
28.1k
            int n1;
2025
2026
28.1k
            if( nonzero_first ||
2027
28.1k
                (negative && *cs != '0') )
2028
24.0k
            {
2029
24.0k
                n1 = detail::count_digits( cs.begin() );
2030
24.0k
                BOOST_ASSERT(n1 >= 0 && n1 <= 16);
2031
2032
24.0k
                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
24.0k
                if( ! nonzero_first && n1 == 0 )
2040
9
                {
2041
                    // digit required
2042
9
                    BOOST_STATIC_CONSTEXPR source_location loc
2043
9
                        = BOOST_CURRENT_LOCATION;
2044
9
                    return fail(cs.begin(), error::syntax, &loc);
2045
9
                }
2046
2047
24.0k
                BOOST_IF_CONSTEXPR( !no_parsing )
2048
24.0k
                    num.mant = detail::parse_unsigned( 0, cs.begin(), n1 );
2049
                else
2050
                    num.mant = 0;
2051
2052
24.0k
                cs += n1;
2053
2054
                // integer or floating-point with
2055
                // >= 16 leading digits
2056
24.0k
                if( n1 == 16 )
2057
7.44k
                {
2058
7.44k
                    goto do_num2;
2059
7.44k
                }
2060
24.0k
            }
2061
4.09k
            else
2062
4.09k
            {
2063
                // 0. floating-point or 0e integer
2064
4.09k
                num.mant = 0;
2065
4.09k
                n1 = 0;
2066
4.09k
                ++cs;
2067
4.09k
            }
2068
2069
20.7k
            {
2070
20.7k
                const char c = *cs;
2071
20.7k
                if(c != '.')
2072
13.8k
                {
2073
13.8k
                    if((c | 32) == 'e')
2074
8.99k
                    {
2075
8.99k
                        ++cs;
2076
8.99k
                        goto do_exp1;
2077
8.99k
                    }
2078
4.81k
                    BOOST_IF_CONSTEXPR( negative && !no_parsing )
2079
4.81k
                        num.mant = ~num.mant + 1;
2080
4.81k
                    goto finish_signed;
2081
13.8k
                }
2082
20.7k
            }
2083
2084
            // floating-point number
2085
2086
6.90k
            ++cs;
2087
2088
6.90k
            int n2 = detail::count_digits( cs.begin() );
2089
6.90k
            BOOST_ASSERT(n2 >= 0 && n2 <= 16);
2090
2091
6.90k
            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
6.90k
            if( n1 + n2 >= 19 )
2101
278
            {
2102
278
                goto do_num7;
2103
278
            }
2104
2105
6.62k
            BOOST_IF_CONSTEXPR( !no_parsing )
2106
6.62k
                num.mant = detail::parse_unsigned( num.mant, cs.begin(), n2 );
2107
2108
6.62k
            BOOST_ASSERT(num.bias == 0);
2109
2110
6.62k
            num.bias -= n2;
2111
2112
6.62k
            cs += n2;
2113
2114
6.62k
            char ch = *cs;
2115
2116
6.62k
            if( (ch | 32) == 'e' )
2117
2.18k
            {
2118
2.18k
                ++cs;
2119
2.18k
                goto do_exp1;
2120
2.18k
            }
2121
4.44k
            else if( ch >= '0' && ch <= '9' )
2122
1.23k
            {
2123
1.23k
                goto do_num8;
2124
1.23k
            }
2125
2126
3.21k
            goto finish_dub;
2127
6.62k
        }
2128
29.6k
    }
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.49k
do_num1:
2157
1.49k
    if(zero_first || nonzero_first ||
2158
1.49k
        BOOST_JSON_LIKELY(cs))
2159
1.47k
    {
2160
1.47k
        char const c = *cs;
2161
1.47k
        if(zero_first)
2162
0
        {
2163
0
            ++cs;
2164
0
            num.mant = 0;
2165
0
            goto do_num6;
2166
0
        }
2167
1.47k
        else if(nonzero_first || BOOST_JSON_LIKELY(
2168
1.47k
            c >= '1' && c <= '9'))
2169
1.14k
        {
2170
1.14k
            ++cs;
2171
1.14k
            num.mant = c - '0';
2172
1.14k
        }
2173
333
        else if(BOOST_JSON_UNLIKELY(
2174
333
            c == '0'))
2175
304
        {
2176
304
            ++cs;
2177
304
            num.mant = 0;
2178
304
            goto do_num6;
2179
304
        }
2180
29
        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
29
        else
2189
29
        {
2190
29
            BOOST_STATIC_CONSTEXPR source_location loc
2191
29
                = BOOST_CURRENT_LOCATION;
2192
29
            return fail(cs.begin(), error::syntax, &loc);
2193
29
        }
2194
1.47k
    }
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
8.59k
do_num2:
2214
8.59k
    if(negative || (!stack_empty && num.neg))
2215
8.59k
    {
2216
8.59k
        for(;;)
2217
25.9k
        {
2218
25.9k
            if(BOOST_JSON_UNLIKELY(! cs))
2219
175
            {
2220
175
                if(BOOST_JSON_UNLIKELY(more_))
2221
175
                {
2222
175
                    if(BOOST_JSON_UNLIKELY(
2223
175
                        ! h_.on_number_part(
2224
175
                            {begin, cs.used(begin)}, ec_)))
2225
0
                        return fail(cs.begin());
2226
2227
175
                    BOOST_IF_CONSTEXPR( precise_parsing )
2228
175
                        num_buf_.append( begin, cs.used(begin) );
2229
175
                    return suspend(cs.begin(), state::num2, num);
2230
175
                }
2231
0
                goto finish_int;
2232
175
            }
2233
25.7k
            char const c = *cs;
2234
25.7k
            if(BOOST_JSON_LIKELY(
2235
25.7k
                c >= '0' && c <= '9'))
2236
20.1k
            {
2237
20.1k
                ++cs;
2238
                //              9223372036854775808 INT64_MIN
2239
20.1k
                if( num.mant  > 922337203685477580 || (
2240
17.8k
                    num.mant == 922337203685477580 && c > '8'))
2241
2.79k
                    break;
2242
17.3k
                BOOST_IF_CONSTEXPR( !no_parsing )
2243
17.3k
                    num.mant = 10 * num.mant + ( c - '0' );
2244
17.3k
                continue;
2245
20.1k
            }
2246
5.62k
            goto do_num6; // [.eE]
2247
25.7k
        }
2248
8.59k
    }
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.79k
    ++num.bias;
2287
2288
    //----------------------------------
2289
    //
2290
    // 1*DIGIT
2291
    // non-significant digits left of decimal
2292
    //
2293
2.79k
do_num3:
2294
2.79k
    for(;;)
2295
7.45M
    {
2296
7.45M
        if(BOOST_JSON_UNLIKELY(! cs))
2297
38
        {
2298
38
            if(BOOST_JSON_UNLIKELY(more_))
2299
38
            {
2300
38
                if(BOOST_JSON_UNLIKELY(
2301
38
                    ! h_.on_number_part(
2302
38
                        {begin, cs.used(begin)}, ec_)))
2303
0
                    return fail(cs.begin());
2304
2305
38
                BOOST_IF_CONSTEXPR( precise_parsing )
2306
38
                    num_buf_.append( begin, cs.used(begin) );
2307
38
                return suspend(cs.begin(), state::num3, num);
2308
38
            }
2309
0
            goto finish_dub;
2310
38
        }
2311
7.45M
        char const c = *cs;
2312
7.45M
        if(BOOST_JSON_UNLIKELY(
2313
7.45M
            c >= '0' && c <= '9'))
2314
7.45M
        {
2315
7.45M
            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
7.45M
            ++cs;
2322
7.45M
            ++num.bias;
2323
7.45M
        }
2324
2.75k
        else if(BOOST_JSON_LIKELY(
2325
2.75k
            c == '.'))
2326
303
        {
2327
303
            ++cs;
2328
303
            break;
2329
303
        }
2330
2.44k
        else if((c | 32) == 'e')
2331
657
        {
2332
657
            ++cs;
2333
657
            goto do_exp1;
2334
657
        }
2335
1.79k
        else
2336
1.79k
        {
2337
1.79k
            goto finish_dub;
2338
1.79k
        }
2339
7.45M
    }
2340
2341
    //----------------------------------
2342
    //
2343
    // DIGIT
2344
    // first non-significant digit
2345
    // to the right of decimal
2346
    //
2347
303
do_num4:
2348
303
    {
2349
303
        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
299
        char const c = *cs;
2362
299
        if(BOOST_JSON_LIKELY(
2363
            //static_cast<unsigned char>(c - '0') < 10))
2364
299
            c >= '0' && c <= '9'))
2365
295
        {
2366
295
            ++cs;
2367
295
        }
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
299
    }
2376
2377
    //----------------------------------
2378
    //
2379
    // 1*DIGIT
2380
    // non-significant digits
2381
    // to the right of decimal
2382
    //
2383
1.25k
do_num5:
2384
1.25k
    for(;;)
2385
7.37k
    {
2386
7.37k
        if(BOOST_JSON_UNLIKELY(! cs))
2387
27
        {
2388
27
            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
0
            goto finish_dub;
2400
27
        }
2401
7.34k
        char const c = *cs;
2402
7.34k
        if(BOOST_JSON_LIKELY(
2403
7.34k
            c >= '0' && c <= '9'))
2404
6.11k
        {
2405
6.11k
            ++cs;
2406
6.11k
        }
2407
1.23k
        else if((c | 32) == 'e')
2408
273
        {
2409
273
            ++cs;
2410
273
            goto do_exp1;
2411
273
        }
2412
959
        else
2413
959
        {
2414
959
            goto finish_dub;
2415
959
        }
2416
7.34k
    }
2417
2418
    //----------------------------------
2419
    //
2420
    // [.eE]
2421
    //
2422
5.93k
do_num6:
2423
5.93k
    {
2424
5.93k
        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
5.92k
        char const c = *cs;
2440
5.92k
        if(BOOST_JSON_LIKELY(
2441
5.92k
            c == '.'))
2442
835
        {
2443
835
            ++cs;
2444
835
        }
2445
5.09k
        else if((c | 32) == 'e')
2446
657
        {
2447
657
            ++cs;
2448
657
            goto do_exp1;
2449
657
        }
2450
4.43k
        else
2451
4.43k
        {
2452
4.43k
            goto finish_int;
2453
4.43k
        }
2454
5.92k
    }
2455
2456
    //----------------------------------
2457
    //
2458
    // DIGIT
2459
    // first significant digit
2460
    // to the right of decimal
2461
    //
2462
1.11k
do_num7:
2463
1.11k
    {
2464
1.11k
        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
0
            BOOST_STATIC_CONSTEXPR source_location loc
2479
0
                = BOOST_CURRENT_LOCATION;
2480
0
            return fail(cs.begin(), error::syntax, &loc);
2481
3
        }
2482
1.11k
        char const c = *cs;
2483
1.11k
        if(BOOST_JSON_UNLIKELY(
2484
1.11k
            c < '0' || c > '9'))
2485
12
        {
2486
            // digit required
2487
12
            BOOST_STATIC_CONSTEXPR source_location loc
2488
12
                = BOOST_CURRENT_LOCATION;
2489
12
            return fail(cs.begin(), error::syntax, &loc);
2490
12
        }
2491
1.11k
    }
2492
2493
    //----------------------------------
2494
    //
2495
    // 1*DIGIT
2496
    // significant digits
2497
    // to the right of decimal
2498
    //
2499
2.33k
do_num8:
2500
2.33k
    for(;;)
2501
3.22M
    {
2502
3.22M
        if(BOOST_JSON_UNLIKELY(! cs))
2503
116
        {
2504
116
            if(BOOST_JSON_UNLIKELY(more_))
2505
116
            {
2506
116
                if(BOOST_JSON_UNLIKELY(
2507
116
                    ! h_.on_number_part(
2508
116
                        {begin, cs.used(begin)}, ec_)))
2509
0
                    return fail(cs.begin());
2510
2511
116
                BOOST_IF_CONSTEXPR( precise_parsing )
2512
116
                    num_buf_.append( begin, cs.used(begin) );
2513
116
                return suspend(cs.begin(), state::num8, num);
2514
116
            }
2515
0
            goto finish_dub;
2516
116
        }
2517
3.22M
        char const c = *cs;
2518
3.22M
        if(BOOST_JSON_LIKELY(
2519
3.22M
            c >= '0' && c <= '9'))
2520
3.22M
        {
2521
3.22M
            ++cs;
2522
3.22M
            if(!no_parsing && BOOST_JSON_LIKELY(
2523
3.22M
                num.mant <= 9007199254740991)) // 2^53-1
2524
3.22M
            {
2525
3.22M
                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
3.22M
                --num.bias;
2532
3.22M
                num.mant = 10 * num.mant + ( c - '0' );
2533
3.22M
            }
2534
964
            else
2535
964
            {
2536
964
                goto do_num5;
2537
964
            }
2538
3.22M
        }
2539
1.25k
        else if((c | 32) == 'e')
2540
390
        {
2541
390
            ++cs;
2542
390
            goto do_exp1;
2543
390
        }
2544
862
        else
2545
862
        {
2546
862
            goto finish_dub;
2547
862
        }
2548
3.22M
    }
2549
2550
    //----------------------------------
2551
    //
2552
    // *[+-]
2553
    //
2554
13.1k
do_exp1:
2555
13.1k
    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
13.1k
    if(*cs == '+')
2568
240
    {
2569
240
        ++cs;
2570
240
    }
2571
12.8k
    else if(*cs == '-')
2572
3.99k
    {
2573
3.99k
        ++cs;
2574
3.99k
        num.frac = true;
2575
3.99k
    }
2576
2577
    //----------------------------------
2578
    //
2579
    // DIGIT
2580
    // first digit of the exponent
2581
    //
2582
13.1k
do_exp2:
2583
13.1k
    {
2584
13.1k
        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
0
            BOOST_STATIC_CONSTEXPR source_location loc
2599
0
                = BOOST_CURRENT_LOCATION;
2600
0
            return fail(cs.begin(), error::syntax, &loc);
2601
11
        }
2602
13.1k
        char const c = *cs;
2603
13.1k
        if(BOOST_JSON_UNLIKELY(
2604
13.1k
            c < '0' || c > '9'))
2605
17
        {
2606
            // digit required
2607
17
            BOOST_STATIC_CONSTEXPR source_location loc
2608
17
                = BOOST_CURRENT_LOCATION;
2609
17
            return fail(cs.begin(), error::syntax, &loc);
2610
17
        }
2611
13.0k
        ++cs;
2612
13.0k
        num.exp = c - '0';
2613
13.0k
    }
2614
2615
    //----------------------------------
2616
    //
2617
    // 1*DIGIT
2618
    // subsequent digits in the exponent
2619
    //
2620
13.0k
do_exp3:
2621
13.0k
    for(;;)
2622
49.9k
    {
2623
49.9k
        if(BOOST_JSON_UNLIKELY(! cs))
2624
106
        {
2625
106
            if(BOOST_JSON_UNLIKELY(more_))
2626
106
            {
2627
106
                if(BOOST_JSON_UNLIKELY(
2628
106
                    ! h_.on_number_part(
2629
106
                        {begin, cs.used(begin)}, ec_)))
2630
0
                    return fail(cs.begin());
2631
2632
106
                BOOST_IF_CONSTEXPR( precise_parsing )
2633
106
                    num_buf_.append( begin, cs.used(begin) );
2634
106
                return suspend(cs.begin(), state::exp3, num);
2635
106
            }
2636
106
        }
2637
49.8k
        else
2638
49.8k
        {
2639
49.8k
            char const c = *cs;
2640
49.8k
            if(BOOST_JSON_LIKELY( c >= '0' && c <= '9' ))
2641
36.8k
            {
2642
36.8k
                if(BOOST_JSON_UNLIKELY(
2643
                //              2147483647 INT_MAX
2644
36.8k
                    num.exp  >  214748364 ||
2645
36.8k
                    (num.exp == 214748364 && c > '7')
2646
36.8k
                ))
2647
6.63k
                    num.exp = INT_MAX;
2648
30.2k
                else BOOST_IF_CONSTEXPR( !no_parsing )
2649
30.2k
                    num.exp = 10 * num.exp + ( c - '0' );
2650
2651
36.8k
                ++cs;
2652
36.8k
                continue;
2653
36.8k
            }
2654
49.8k
        }
2655
12.9k
        BOOST_ASSERT(num.exp >= 0);
2656
12.9k
        if ( num.frac )
2657
3.97k
        {
2658
3.97k
            if(BOOST_JSON_UNLIKELY( num.bias < (INT_MIN + num.exp) ))
2659
1.37k
            {
2660
                // if exponent overflowed, bias is a very large negative
2661
                // number, and mantissa isn't zero, then we cannot parse the
2662
                // number correctly
2663
1.37k
                if(BOOST_JSON_UNLIKELY(
2664
1.37k
                    (num.exp == INT_MAX) &&
2665
1.37k
                    (num.bias < 0) &&
2666
1.37k
                    (num.exp + num.bias < 308) &&
2667
1.37k
                    num.mant ))
2668
0
                {
2669
0
                    BOOST_STATIC_CONSTEXPR source_location loc
2670
0
                        = BOOST_CURRENT_LOCATION;
2671
0
                    return fail(cs.begin(), error::exponent_overflow, &loc);
2672
0
                }
2673
2674
1.37k
                num.bias = 0;
2675
1.37k
                num.exp = INT_MAX;
2676
1.37k
            }
2677
3.97k
        }
2678
9.00k
        else if (BOOST_JSON_UNLIKELY( num.bias > (INT_MAX - num.exp) ))
2679
476
        {
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
476
            if(BOOST_JSON_UNLIKELY(
2684
476
                (num.exp == INT_MAX) &&
2685
476
                (num.bias > 0) &&
2686
476
                (num.exp - num.bias < 308) &&
2687
476
                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
476
            num.bias = 0;
2695
476
            num.exp = INT_MAX;
2696
476
        }
2697
12.9k
        goto finish_dub;
2698
12.9k
    }
2699
2700
4.43k
finish_int:
2701
4.43k
    if(negative || (!stack_empty && num.neg))
2702
4.43k
    {
2703
4.43k
        if(BOOST_JSON_UNLIKELY(
2704
4.43k
            ! h_.on_int64(static_cast<
2705
4.43k
                int64_t>(~num.mant + 1), {begin, cs.used(begin)}, ec_)))
2706
0
            return fail(cs.begin());
2707
4.43k
        return cs.begin();
2708
4.43k
    }
2709
0
    if(num.mant <= INT64_MAX)
2710
0
    {
2711
4.81k
finish_signed:
2712
4.81k
        if(BOOST_JSON_UNLIKELY(
2713
4.81k
            ! h_.on_int64(static_cast<
2714
4.81k
                int64_t>(num.mant), {begin, cs.used(begin)}, ec_)))
2715
0
            return fail(cs.begin());
2716
4.81k
        return cs.begin();
2717
4.81k
    }
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
19.8k
finish_dub:
2723
19.8k
    double d;
2724
19.8k
    std::size_t const size = cs.used(begin);
2725
19.8k
    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
19.8k
    else BOOST_IF_CONSTEXPR( no_parsing )
2745
19.8k
        d = 0;
2746
19.8k
    else
2747
19.8k
        d = detail::dec_to_float(
2748
19.8k
            num.mant,
2749
19.8k
            num.bias + (num.frac ?
2750
15.8k
                -num.exp : num.exp),
2751
19.8k
            num.neg);
2752
19.8k
    if(BOOST_JSON_UNLIKELY(
2753
19.8k
        ! h_.on_double(d, {begin, size}, ec_)))
2754
0
        return fail(cs.begin());
2755
19.8k
    return cs.begin();
2756
19.8k
}
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
16.9k
{
1987
16.9k
    constexpr bool precise_parsing = mode == number_precision::precise;
1988
16.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
16.9k
    bool const negative = first == '-';
1995
16.9k
    bool const zero_first = first == '0';
1996
16.9k
    bool const nonzero_first = first == '+';
1997
16.9k
    detail::const_stream_wrapper cs(p, end_);
1998
16.9k
    number num;
1999
16.9k
    const char* begin = cs.begin();
2000
16.9k
    if(stack_empty || st_.empty())
2001
16.9k
    {
2002
16.9k
        num.bias = 0;
2003
16.9k
        num.exp = 0;
2004
16.9k
        num.frac = false;
2005
16.9k
        num_buf_.clear();
2006
2007
        //----------------------------------
2008
        //
2009
        // '-'
2010
        // leading minus sign
2011
        //
2012
16.9k
        BOOST_ASSERT(cs);
2013
16.9k
        if(negative)
2014
16.9k
            ++cs;
2015
2016
16.9k
        num.neg = negative;
2017
16.9k
        num.frac = false;
2018
16.9k
        num.exp = 0;
2019
16.9k
        num.bias = 0;
2020
2021
        // fast path
2022
16.9k
        if( cs.remain() >= 16 + 1 + 16 ) // digits . digits
2023
15.7k
        {
2024
15.7k
            int n1;
2025
2026
15.7k
            if( nonzero_first ||
2027
15.7k
                (negative && *cs != '0') )
2028
9.69k
            {
2029
9.69k
                n1 = detail::count_digits( cs.begin() );
2030
9.69k
                BOOST_ASSERT(n1 >= 0 && n1 <= 16);
2031
2032
9.69k
                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.69k
                if( ! nonzero_first && n1 == 0 )
2040
10
                {
2041
                    // digit required
2042
10
                    BOOST_STATIC_CONSTEXPR source_location loc
2043
10
                        = BOOST_CURRENT_LOCATION;
2044
10
                    return fail(cs.begin(), error::syntax, &loc);
2045
10
                }
2046
2047
9.68k
                BOOST_IF_CONSTEXPR( !no_parsing )
2048
9.68k
                    num.mant = detail::parse_unsigned( 0, cs.begin(), n1 );
2049
                else
2050
                    num.mant = 0;
2051
2052
9.68k
                cs += n1;
2053
2054
                // integer or floating-point with
2055
                // >= 16 leading digits
2056
9.68k
                if( n1 == 16 )
2057
4.58k
                {
2058
4.58k
                    goto do_num2;
2059
4.58k
                }
2060
9.68k
            }
2061
6.04k
            else
2062
6.04k
            {
2063
                // 0. floating-point or 0e integer
2064
6.04k
                num.mant = 0;
2065
6.04k
                n1 = 0;
2066
6.04k
                ++cs;
2067
6.04k
            }
2068
2069
11.1k
            {
2070
11.1k
                const char c = *cs;
2071
11.1k
                if(c != '.')
2072
7.51k
                {
2073
7.51k
                    if((c | 32) == 'e')
2074
1.40k
                    {
2075
1.40k
                        ++cs;
2076
1.40k
                        goto do_exp1;
2077
1.40k
                    }
2078
6.10k
                    BOOST_IF_CONSTEXPR( negative && !no_parsing )
2079
6.10k
                        num.mant = ~num.mant + 1;
2080
6.10k
                    goto finish_signed;
2081
7.51k
                }
2082
11.1k
            }
2083
2084
            // floating-point number
2085
2086
3.63k
            ++cs;
2087
2088
3.63k
            int n2 = detail::count_digits( cs.begin() );
2089
3.63k
            BOOST_ASSERT(n2 >= 0 && n2 <= 16);
2090
2091
3.63k
            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
3.62k
            if( n1 + n2 >= 19 )
2101
213
            {
2102
213
                goto do_num7;
2103
213
            }
2104
2105
3.41k
            BOOST_IF_CONSTEXPR( !no_parsing )
2106
3.41k
                num.mant = detail::parse_unsigned( num.mant, cs.begin(), n2 );
2107
2108
3.41k
            BOOST_ASSERT(num.bias == 0);
2109
2110
3.41k
            num.bias -= n2;
2111
2112
3.41k
            cs += n2;
2113
2114
3.41k
            char ch = *cs;
2115
2116
3.41k
            if( (ch | 32) == 'e' )
2117
1.13k
            {
2118
1.13k
                ++cs;
2119
1.13k
                goto do_exp1;
2120
1.13k
            }
2121
2.28k
            else if( ch >= '0' && ch <= '9' )
2122
560
            {
2123
560
                goto do_num8;
2124
560
            }
2125
2126
1.72k
            goto finish_dub;
2127
3.41k
        }
2128
16.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
1.25k
do_num1:
2157
1.25k
    if(zero_first || nonzero_first ||
2158
1.25k
        BOOST_JSON_LIKELY(cs))
2159
1.24k
    {
2160
1.24k
        char const c = *cs;
2161
1.24k
        if(zero_first)
2162
0
        {
2163
0
            ++cs;
2164
0
            num.mant = 0;
2165
0
            goto do_num6;
2166
0
        }
2167
1.24k
        else if(nonzero_first || BOOST_JSON_LIKELY(
2168
1.24k
            c >= '1' && c <= '9'))
2169
956
        {
2170
956
            ++cs;
2171
956
            num.mant = c - '0';
2172
956
        }
2173
285
        else if(BOOST_JSON_UNLIKELY(
2174
285
            c == '0'))
2175
262
        {
2176
262
            ++cs;
2177
262
            num.mant = 0;
2178
262
            goto do_num6;
2179
262
        }
2180
23
        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
23
        else
2189
23
        {
2190
23
            BOOST_STATIC_CONSTEXPR source_location loc
2191
23
                = BOOST_CURRENT_LOCATION;
2192
23
            return fail(cs.begin(), error::syntax, &loc);
2193
23
        }
2194
1.24k
    }
2195
15
    else
2196
15
    {
2197
15
        if(BOOST_JSON_UNLIKELY(
2198
15
            ! h_.on_number_part(
2199
15
                {begin, cs.used(begin)}, ec_)))
2200
0
            return fail(cs.begin());
2201
2202
15
        BOOST_IF_CONSTEXPR( precise_parsing )
2203
15
            num_buf_.append( begin, cs.used(begin) );
2204
15
        return maybe_suspend(
2205
15
            cs.begin(), state::num1, num);
2206
15
    }
2207
2208
    //----------------------------------
2209
    //
2210
    // 1*DIGIT
2211
    // significant digits left of decimal
2212
    //
2213
5.54k
do_num2:
2214
5.54k
    if(negative || (!stack_empty && num.neg))
2215
5.54k
    {
2216
5.54k
        for(;;)
2217
18.4k
        {
2218
18.4k
            if(BOOST_JSON_UNLIKELY(! cs))
2219
173
            {
2220
173
                if(BOOST_JSON_UNLIKELY(more_))
2221
173
                {
2222
173
                    if(BOOST_JSON_UNLIKELY(
2223
173
                        ! h_.on_number_part(
2224
173
                            {begin, cs.used(begin)}, ec_)))
2225
0
                        return fail(cs.begin());
2226
2227
173
                    BOOST_IF_CONSTEXPR( precise_parsing )
2228
173
                        num_buf_.append( begin, cs.used(begin) );
2229
173
                    return suspend(cs.begin(), state::num2, num);
2230
173
                }
2231
0
                goto finish_int;
2232
173
            }
2233
18.2k
            char const c = *cs;
2234
18.2k
            if(BOOST_JSON_LIKELY(
2235
18.2k
                c >= '0' && c <= '9'))
2236
15.3k
            {
2237
15.3k
                ++cs;
2238
                //              9223372036854775808 INT64_MIN
2239
15.3k
                if( num.mant  > 922337203685477580 || (
2240
13.1k
                    num.mant == 922337203685477580 && c > '8'))
2241
2.46k
                    break;
2242
12.8k
                BOOST_IF_CONSTEXPR( !no_parsing )
2243
12.8k
                    num.mant = 10 * num.mant + ( c - '0' );
2244
12.8k
                continue;
2245
15.3k
            }
2246
2.90k
            goto do_num6; // [.eE]
2247
18.2k
        }
2248
5.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
2.46k
    ++num.bias;
2287
2288
    //----------------------------------
2289
    //
2290
    // 1*DIGIT
2291
    // non-significant digits left of decimal
2292
    //
2293
2.46k
do_num3:
2294
2.46k
    for(;;)
2295
6.75M
    {
2296
6.75M
        if(BOOST_JSON_UNLIKELY(! cs))
2297
41
        {
2298
41
            if(BOOST_JSON_UNLIKELY(more_))
2299
41
            {
2300
41
                if(BOOST_JSON_UNLIKELY(
2301
41
                    ! h_.on_number_part(
2302
41
                        {begin, cs.used(begin)}, ec_)))
2303
0
                    return fail(cs.begin());
2304
2305
41
                BOOST_IF_CONSTEXPR( precise_parsing )
2306
41
                    num_buf_.append( begin, cs.used(begin) );
2307
41
                return suspend(cs.begin(), state::num3, num);
2308
41
            }
2309
0
            goto finish_dub;
2310
41
        }
2311
6.75M
        char const c = *cs;
2312
6.75M
        if(BOOST_JSON_UNLIKELY(
2313
6.75M
            c >= '0' && c <= '9'))
2314
6.74M
        {
2315
6.74M
            if(BOOST_JSON_UNLIKELY( num.bias + 1 == INT_MAX ))
2316
0
            {
2317
0
                BOOST_STATIC_CONSTEXPR source_location loc
2318
0
                    = BOOST_CURRENT_LOCATION;
2319
0
                return fail(cs.begin(), error::exponent_overflow, &loc);
2320
0
            }
2321
6.74M
            ++cs;
2322
6.74M
            ++num.bias;
2323
6.74M
        }
2324
2.42k
        else if(BOOST_JSON_LIKELY(
2325
2.42k
            c == '.'))
2326
755
        {
2327
755
            ++cs;
2328
755
            break;
2329
755
        }
2330
1.66k
        else if((c | 32) == 'e')
2331
837
        {
2332
837
            ++cs;
2333
837
            goto do_exp1;
2334
837
        }
2335
832
        else
2336
832
        {
2337
832
            goto finish_dub;
2338
832
        }
2339
6.75M
    }
2340
2341
    //----------------------------------
2342
    //
2343
    // DIGIT
2344
    // first non-significant digit
2345
    // to the right of decimal
2346
    //
2347
755
do_num4:
2348
755
    {
2349
755
        if(BOOST_JSON_UNLIKELY(! cs))
2350
2
        {
2351
2
            if(BOOST_JSON_UNLIKELY(
2352
2
                ! h_.on_number_part(
2353
2
                    {begin, cs.used(begin)}, ec_)))
2354
0
                return fail(cs.begin());
2355
2356
2
            BOOST_IF_CONSTEXPR( precise_parsing )
2357
2
                num_buf_.append( begin, cs.used(begin) );
2358
2
            return maybe_suspend(
2359
2
                cs.begin(), state::num4, num);
2360
2
        }
2361
753
        char const c = *cs;
2362
753
        if(BOOST_JSON_LIKELY(
2363
            //static_cast<unsigned char>(c - '0') < 10))
2364
753
            c >= '0' && c <= '9'))
2365
739
        {
2366
739
            ++cs;
2367
739
        }
2368
14
        else
2369
14
        {
2370
            // digit required
2371
14
            BOOST_STATIC_CONSTEXPR source_location loc
2372
14
                = BOOST_CURRENT_LOCATION;
2373
14
            return fail(cs.begin(), error::syntax, &loc);
2374
14
        }
2375
753
    }
2376
2377
    //----------------------------------
2378
    //
2379
    // 1*DIGIT
2380
    // non-significant digits
2381
    // to the right of decimal
2382
    //
2383
1.84k
do_num5:
2384
1.84k
    for(;;)
2385
772k
    {
2386
772k
        if(BOOST_JSON_UNLIKELY(! cs))
2387
49
        {
2388
49
            if(BOOST_JSON_UNLIKELY(more_))
2389
49
            {
2390
49
                if(BOOST_JSON_UNLIKELY(
2391
49
                    ! h_.on_number_part(
2392
49
                        {begin, cs.used(begin)}, ec_)))
2393
0
                    return fail(cs.begin());
2394
2395
49
                BOOST_IF_CONSTEXPR( precise_parsing )
2396
49
                    num_buf_.append( begin, cs.used(begin) );
2397
49
                return suspend(cs.begin(), state::num5, num);
2398
49
            }
2399
0
            goto finish_dub;
2400
49
        }
2401
772k
        char const c = *cs;
2402
772k
        if(BOOST_JSON_LIKELY(
2403
772k
            c >= '0' && c <= '9'))
2404
770k
        {
2405
770k
            ++cs;
2406
770k
        }
2407
1.79k
        else if((c | 32) == 'e')
2408
377
        {
2409
377
            ++cs;
2410
377
            goto do_exp1;
2411
377
        }
2412
1.41k
        else
2413
1.41k
        {
2414
1.41k
            goto finish_dub;
2415
1.41k
        }
2416
772k
    }
2417
2418
    //----------------------------------
2419
    //
2420
    // [.eE]
2421
    //
2422
3.16k
do_num6:
2423
3.16k
    {
2424
3.16k
        if(BOOST_JSON_UNLIKELY(! cs))
2425
7
        {
2426
7
            if(BOOST_JSON_UNLIKELY(more_))
2427
7
            {
2428
7
                if(BOOST_JSON_UNLIKELY(
2429
7
                    ! h_.on_number_part(
2430
7
                        {begin, cs.used(begin)}, ec_)))
2431
0
                    return fail(cs.begin());
2432
2433
7
                BOOST_IF_CONSTEXPR( precise_parsing )
2434
7
                    num_buf_.append( begin, cs.used(begin) );
2435
7
                return suspend(cs.begin(), state::num6, num);
2436
7
            }
2437
0
            goto finish_int;
2438
7
        }
2439
3.15k
        char const c = *cs;
2440
3.15k
        if(BOOST_JSON_LIKELY(
2441
3.15k
            c == '.'))
2442
1.14k
        {
2443
1.14k
            ++cs;
2444
1.14k
        }
2445
2.01k
        else if((c | 32) == 'e')
2446
648
        {
2447
648
            ++cs;
2448
648
            goto do_exp1;
2449
648
        }
2450
1.36k
        else
2451
1.36k
        {
2452
1.36k
            goto finish_int;
2453
1.36k
        }
2454
3.15k
    }
2455
2456
    //----------------------------------
2457
    //
2458
    // DIGIT
2459
    // first significant digit
2460
    // to the right of decimal
2461
    //
2462
1.35k
do_num7:
2463
1.35k
    {
2464
1.35k
        if(BOOST_JSON_UNLIKELY(! cs))
2465
6
        {
2466
6
            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
0
            BOOST_STATIC_CONSTEXPR source_location loc
2479
0
                = BOOST_CURRENT_LOCATION;
2480
0
            return fail(cs.begin(), error::syntax, &loc);
2481
6
        }
2482
1.34k
        char const c = *cs;
2483
1.34k
        if(BOOST_JSON_UNLIKELY(
2484
1.34k
            c < '0' || c > '9'))
2485
16
        {
2486
            // digit required
2487
16
            BOOST_STATIC_CONSTEXPR source_location loc
2488
16
                = BOOST_CURRENT_LOCATION;
2489
16
            return fail(cs.begin(), error::syntax, &loc);
2490
16
        }
2491
1.34k
    }
2492
2493
    //----------------------------------
2494
    //
2495
    // 1*DIGIT
2496
    // significant digits
2497
    // to the right of decimal
2498
    //
2499
1.89k
do_num8:
2500
1.89k
    for(;;)
2501
2.03M
    {
2502
2.03M
        if(BOOST_JSON_UNLIKELY(! cs))
2503
120
        {
2504
120
            if(BOOST_JSON_UNLIKELY(more_))
2505
120
            {
2506
120
                if(BOOST_JSON_UNLIKELY(
2507
120
                    ! h_.on_number_part(
2508
120
                        {begin, cs.used(begin)}, ec_)))
2509
0
                    return fail(cs.begin());
2510
2511
120
                BOOST_IF_CONSTEXPR( precise_parsing )
2512
120
                    num_buf_.append( begin, cs.used(begin) );
2513
120
                return suspend(cs.begin(), state::num8, num);
2514
120
            }
2515
0
            goto finish_dub;
2516
120
        }
2517
2.03M
        char const c = *cs;
2518
2.03M
        if(BOOST_JSON_LIKELY(
2519
2.03M
            c >= '0' && c <= '9'))
2520
2.03M
        {
2521
2.03M
            ++cs;
2522
2.03M
            if(!no_parsing && BOOST_JSON_LIKELY(
2523
2.03M
                num.mant <= 9007199254740991)) // 2^53-1
2524
2.03M
            {
2525
2.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
2.03M
                --num.bias;
2532
2.03M
                num.mant = 10 * num.mant + ( c - '0' );
2533
2.03M
            }
2534
1.10k
            else
2535
1.10k
            {
2536
1.10k
                goto do_num5;
2537
1.10k
            }
2538
2.03M
        }
2539
668
        else if((c | 32) == 'e')
2540
269
        {
2541
269
            ++cs;
2542
269
            goto do_exp1;
2543
269
        }
2544
399
        else
2545
399
        {
2546
399
            goto finish_dub;
2547
399
        }
2548
2.03M
    }
2549
2550
    //----------------------------------
2551
    //
2552
    // *[+-]
2553
    //
2554
4.67k
do_exp1:
2555
4.67k
    if(BOOST_JSON_UNLIKELY(! cs))
2556
25
    {
2557
25
        if(BOOST_JSON_UNLIKELY(
2558
25
            ! h_.on_number_part(
2559
25
                {begin, cs.used(begin)}, ec_)))
2560
0
            return fail(cs.begin());
2561
2562
25
        BOOST_IF_CONSTEXPR( precise_parsing )
2563
25
            num_buf_.append( begin, cs.used(begin) );
2564
25
        return maybe_suspend(
2565
25
            cs.begin(), state::exp1, num);
2566
25
    }
2567
4.64k
    if(*cs == '+')
2568
230
    {
2569
230
        ++cs;
2570
230
    }
2571
4.41k
    else if(*cs == '-')
2572
1.31k
    {
2573
1.31k
        ++cs;
2574
1.31k
        num.frac = true;
2575
1.31k
    }
2576
2577
    //----------------------------------
2578
    //
2579
    // DIGIT
2580
    // first digit of the exponent
2581
    //
2582
4.64k
do_exp2:
2583
4.64k
    {
2584
4.64k
        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
0
            BOOST_STATIC_CONSTEXPR source_location loc
2599
0
                = BOOST_CURRENT_LOCATION;
2600
0
            return fail(cs.begin(), error::syntax, &loc);
2601
10
        }
2602
4.63k
        char const c = *cs;
2603
4.63k
        if(BOOST_JSON_UNLIKELY(
2604
4.63k
            c < '0' || c > '9'))
2605
17
        {
2606
            // digit required
2607
17
            BOOST_STATIC_CONSTEXPR source_location loc
2608
17
                = BOOST_CURRENT_LOCATION;
2609
17
            return fail(cs.begin(), error::syntax, &loc);
2610
17
        }
2611
4.62k
        ++cs;
2612
4.62k
        num.exp = c - '0';
2613
4.62k
    }
2614
2615
    //----------------------------------
2616
    //
2617
    // 1*DIGIT
2618
    // subsequent digits in the exponent
2619
    //
2620
4.62k
do_exp3:
2621
4.62k
    for(;;)
2622
62.1k
    {
2623
62.1k
        if(BOOST_JSON_UNLIKELY(! cs))
2624
86
        {
2625
86
            if(BOOST_JSON_UNLIKELY(more_))
2626
86
            {
2627
86
                if(BOOST_JSON_UNLIKELY(
2628
86
                    ! h_.on_number_part(
2629
86
                        {begin, cs.used(begin)}, ec_)))
2630
0
                    return fail(cs.begin());
2631
2632
86
                BOOST_IF_CONSTEXPR( precise_parsing )
2633
86
                    num_buf_.append( begin, cs.used(begin) );
2634
86
                return suspend(cs.begin(), state::exp3, num);
2635
86
            }
2636
86
        }
2637
62.0k
        else
2638
62.0k
        {
2639
62.0k
            char const c = *cs;
2640
62.0k
            if(BOOST_JSON_LIKELY( c >= '0' && c <= '9' ))
2641
57.5k
            {
2642
57.5k
                if(BOOST_JSON_UNLIKELY(
2643
                //              2147483647 INT_MAX
2644
57.5k
                    num.exp  >  214748364 ||
2645
57.5k
                    (num.exp == 214748364 && c > '7')
2646
57.5k
                ))
2647
13.7k
                    num.exp = INT_MAX;
2648
43.8k
                else BOOST_IF_CONSTEXPR( !no_parsing )
2649
43.8k
                    num.exp = 10 * num.exp + ( c - '0' );
2650
2651
57.5k
                ++cs;
2652
57.5k
                continue;
2653
57.5k
            }
2654
62.0k
        }
2655
4.53k
        BOOST_ASSERT(num.exp >= 0);
2656
4.53k
        if ( num.frac )
2657
1.30k
        {
2658
1.30k
            if(BOOST_JSON_UNLIKELY( num.bias < (INT_MIN + num.exp) ))
2659
631
            {
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
631
                if(BOOST_JSON_UNLIKELY(
2664
631
                    (num.exp == INT_MAX) &&
2665
631
                    (num.bias < 0) &&
2666
631
                    (num.exp + num.bias < 308) &&
2667
631
                    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
631
                num.bias = 0;
2675
631
                num.exp = INT_MAX;
2676
631
            }
2677
1.30k
        }
2678
3.23k
        else if (BOOST_JSON_UNLIKELY( num.bias > (INT_MAX - num.exp) ))
2679
488
        {
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
488
            if(BOOST_JSON_UNLIKELY(
2684
488
                (num.exp == INT_MAX) &&
2685
488
                (num.bias > 0) &&
2686
488
                (num.exp - num.bias < 308) &&
2687
488
                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
488
            num.bias = 0;
2695
488
            num.exp = INT_MAX;
2696
488
        }
2697
4.53k
        goto finish_dub;
2698
4.53k
    }
2699
2700
1.36k
finish_int:
2701
1.36k
    if(negative || (!stack_empty && num.neg))
2702
1.36k
    {
2703
1.36k
        if(BOOST_JSON_UNLIKELY(
2704
1.36k
            ! h_.on_int64(static_cast<
2705
1.36k
                int64_t>(~num.mant + 1), {begin, cs.used(begin)}, ec_)))
2706
0
            return fail(cs.begin());
2707
1.36k
        return cs.begin();
2708
1.36k
    }
2709
0
    if(num.mant <= INT64_MAX)
2710
0
    {
2711
6.10k
finish_signed:
2712
6.10k
        if(BOOST_JSON_UNLIKELY(
2713
6.10k
            ! h_.on_int64(static_cast<
2714
6.10k
                int64_t>(num.mant), {begin, cs.used(begin)}, ec_)))
2715
0
            return fail(cs.begin());
2716
6.10k
        return cs.begin();
2717
6.10k
    }
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
8.90k
finish_dub:
2723
8.90k
    double d;
2724
8.90k
    std::size_t const size = cs.used(begin);
2725
8.90k
    BOOST_ASSERT( !num_buf_.size() || precise_parsing );
2726
    BOOST_IF_CONSTEXPR( precise_parsing )
2727
8.90k
    {
2728
8.90k
        char const* data = begin;
2729
8.90k
        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
8.90k
        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
8.90k
        auto const err = detail::charconv::from_chars(
2739
8.90k
            data, data + full_size, d );
2740
8.90k
        BOOST_ASSERT( err.ec != std::errc::invalid_argument );
2741
8.90k
        BOOST_ASSERT( err.ptr == data + full_size );
2742
8.90k
        (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
8.90k
    if(BOOST_JSON_UNLIKELY(
2753
8.90k
        ! h_.on_double(d, {begin, size}, ec_)))
2754
0
        return fail(cs.begin());
2755
8.90k
    return cs.begin();
2756
8.90k
}
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.63k
{
1987
4.63k
    constexpr bool precise_parsing = mode == number_precision::precise;
1988
4.63k
    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.63k
    bool const negative = first == '-';
1995
4.63k
    bool const zero_first = first == '0';
1996
4.63k
    bool const nonzero_first = first == '+';
1997
4.63k
    detail::const_stream_wrapper cs(p, end_);
1998
4.63k
    number num;
1999
4.63k
    const char* begin = cs.begin();
2000
4.63k
    if(stack_empty || st_.empty())
2001
4.63k
    {
2002
4.63k
        num.bias = 0;
2003
4.63k
        num.exp = 0;
2004
4.63k
        num.frac = false;
2005
4.63k
        num_buf_.clear();
2006
2007
        //----------------------------------
2008
        //
2009
        // '-'
2010
        // leading minus sign
2011
        //
2012
4.63k
        BOOST_ASSERT(cs);
2013
4.63k
        if(negative)
2014
4.63k
            ++cs;
2015
2016
4.63k
        num.neg = negative;
2017
4.63k
        num.frac = false;
2018
4.63k
        num.exp = 0;
2019
4.63k
        num.bias = 0;
2020
2021
        // fast path
2022
4.63k
        if( cs.remain() >= 16 + 1 + 16 ) // digits . digits
2023
4.06k
        {
2024
4.06k
            int n1;
2025
2026
4.06k
            if( nonzero_first ||
2027
4.06k
                (negative && *cs != '0') )
2028
2.42k
            {
2029
2.42k
                n1 = detail::count_digits( cs.begin() );
2030
2.42k
                BOOST_ASSERT(n1 >= 0 && n1 <= 16);
2031
2032
2.42k
                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.42k
                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
2.41k
                BOOST_IF_CONSTEXPR( !no_parsing )
2048
2.41k
                    num.mant = detail::parse_unsigned( 0, cs.begin(), n1 );
2049
2.41k
                else
2050
2.41k
                    num.mant = 0;
2051
2052
2.41k
                cs += n1;
2053
2054
                // integer or floating-point with
2055
                // >= 16 leading digits
2056
2.41k
                if( n1 == 16 )
2057
761
                {
2058
761
                    goto do_num2;
2059
761
                }
2060
2.41k
            }
2061
1.64k
            else
2062
1.64k
            {
2063
                // 0. floating-point or 0e integer
2064
1.64k
                num.mant = 0;
2065
1.64k
                n1 = 0;
2066
1.64k
                ++cs;
2067
1.64k
            }
2068
2069
3.30k
            {
2070
3.30k
                const char c = *cs;
2071
3.30k
                if(c != '.')
2072
2.05k
                {
2073
2.05k
                    if((c | 32) == 'e')
2074
830
                    {
2075
830
                        ++cs;
2076
830
                        goto do_exp1;
2077
830
                    }
2078
1.22k
                    BOOST_IF_CONSTEXPR( negative && !no_parsing )
2079
1.22k
                        num.mant = ~num.mant + 1;
2080
1.22k
                    goto finish_signed;
2081
2.05k
                }
2082
3.30k
            }
2083
2084
            // floating-point number
2085
2086
1.24k
            ++cs;
2087
2088
1.24k
            int n2 = detail::count_digits( cs.begin() );
2089
1.24k
            BOOST_ASSERT(n2 >= 0 && n2 <= 16);
2090
2091
1.24k
            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.24k
            if( n1 + n2 >= 19 )
2101
198
            {
2102
198
                goto do_num7;
2103
198
            }
2104
2105
1.04k
            BOOST_IF_CONSTEXPR( !no_parsing )
2106
1.04k
                num.mant = detail::parse_unsigned( num.mant, cs.begin(), n2 );
2107
2108
1.04k
            BOOST_ASSERT(num.bias == 0);
2109
2110
1.04k
            num.bias -= n2;
2111
2112
1.04k
            cs += n2;
2113
2114
1.04k
            char ch = *cs;
2115
2116
1.04k
            if( (ch | 32) == 'e' )
2117
213
            {
2118
213
                ++cs;
2119
213
                goto do_exp1;
2120
213
            }
2121
833
            else if( ch >= '0' && ch <= '9' )
2122
218
            {
2123
218
                goto do_num8;
2124
218
            }
2125
2126
615
            goto finish_dub;
2127
1.04k
        }
2128
4.63k
    }
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
566
do_num1:
2157
566
    if(zero_first || nonzero_first ||
2158
566
        BOOST_JSON_LIKELY(cs))
2159
550
    {
2160
550
        char const c = *cs;
2161
550
        if(zero_first)
2162
0
        {
2163
0
            ++cs;
2164
0
            num.mant = 0;
2165
0
            goto do_num6;
2166
0
        }
2167
550
        else if(nonzero_first || BOOST_JSON_LIKELY(
2168
550
            c >= '1' && c <= '9'))
2169
373
        {
2170
373
            ++cs;
2171
373
            num.mant = c - '0';
2172
373
        }
2173
177
        else if(BOOST_JSON_UNLIKELY(
2174
177
            c == '0'))
2175
159
        {
2176
159
            ++cs;
2177
159
            num.mant = 0;
2178
159
            goto do_num6;
2179
159
        }
2180
18
        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
18
        else
2189
18
        {
2190
18
            BOOST_STATIC_CONSTEXPR source_location loc
2191
18
                = BOOST_CURRENT_LOCATION;
2192
18
            return fail(cs.begin(), error::syntax, &loc);
2193
18
        }
2194
550
    }
2195
16
    else
2196
16
    {
2197
16
        if(BOOST_JSON_UNLIKELY(
2198
16
            ! h_.on_number_part(
2199
16
                {begin, cs.used(begin)}, ec_)))
2200
0
            return fail(cs.begin());
2201
2202
16
        BOOST_IF_CONSTEXPR( precise_parsing )
2203
16
            num_buf_.append( begin, cs.used(begin) );
2204
16
        return maybe_suspend(
2205
16
            cs.begin(), state::num1, num);
2206
16
    }
2207
2208
    //----------------------------------
2209
    //
2210
    // 1*DIGIT
2211
    // significant digits left of decimal
2212
    //
2213
1.13k
do_num2:
2214
1.13k
    if(negative || (!stack_empty && num.neg))
2215
1.13k
    {
2216
1.13k
        for(;;)
2217
1.70k
        {
2218
1.70k
            if(BOOST_JSON_UNLIKELY(! cs))
2219
26
            {
2220
26
                if(BOOST_JSON_UNLIKELY(more_))
2221
26
                {
2222
26
                    if(BOOST_JSON_UNLIKELY(
2223
26
                        ! h_.on_number_part(
2224
26
                            {begin, cs.used(begin)}, ec_)))
2225
0
                        return fail(cs.begin());
2226
2227
26
                    BOOST_IF_CONSTEXPR( precise_parsing )
2228
26
                        num_buf_.append( begin, cs.used(begin) );
2229
26
                    return suspend(cs.begin(), state::num2, num);
2230
26
                }
2231
0
                goto finish_int;
2232
26
            }
2233
1.67k
            char const c = *cs;
2234
1.67k
            if(BOOST_JSON_LIKELY(
2235
1.67k
                c >= '0' && c <= '9'))
2236
571
            {
2237
571
                ++cs;
2238
                //              9223372036854775808 INT64_MIN
2239
571
                if( num.mant  > 922337203685477580 || (
2240
571
                    num.mant == 922337203685477580 && c > '8'))
2241
0
                    break;
2242
571
                BOOST_IF_CONSTEXPR( !no_parsing )
2243
571
                    num.mant = 10 * num.mant + ( c - '0' );
2244
571
                continue;
2245
571
            }
2246
1.10k
            goto do_num6; // [.eE]
2247
1.67k
        }
2248
1.13k
    }
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
729
do_num5:
2384
729
    for(;;)
2385
3.55k
    {
2386
3.55k
        if(BOOST_JSON_UNLIKELY(! cs))
2387
18
        {
2388
18
            if(BOOST_JSON_UNLIKELY(more_))
2389
18
            {
2390
18
                if(BOOST_JSON_UNLIKELY(
2391
18
                    ! h_.on_number_part(
2392
18
                        {begin, cs.used(begin)}, ec_)))
2393
0
                    return fail(cs.begin());
2394
2395
18
                BOOST_IF_CONSTEXPR( precise_parsing )
2396
18
                    num_buf_.append( begin, cs.used(begin) );
2397
18
                return suspend(cs.begin(), state::num5, num);
2398
18
            }
2399
0
            goto finish_dub;
2400
18
        }
2401
3.53k
        char const c = *cs;
2402
3.53k
        if(BOOST_JSON_LIKELY(
2403
3.53k
            c >= '0' && c <= '9'))
2404
2.82k
        {
2405
2.82k
            ++cs;
2406
2.82k
        }
2407
711
        else if((c | 32) == 'e')
2408
329
        {
2409
329
            ++cs;
2410
329
            goto do_exp1;
2411
329
        }
2412
382
        else
2413
382
        {
2414
382
            goto finish_dub;
2415
382
        }
2416
3.53k
    }
2417
2418
    //----------------------------------
2419
    //
2420
    // [.eE]
2421
    //
2422
1.26k
do_num6:
2423
1.26k
    {
2424
1.26k
        if(BOOST_JSON_UNLIKELY(! cs))
2425
6
        {
2426
6
            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
0
            goto finish_int;
2438
6
        }
2439
1.26k
        char const c = *cs;
2440
1.26k
        if(BOOST_JSON_LIKELY(
2441
1.26k
            c == '.'))
2442
332
        {
2443
332
            ++cs;
2444
332
        }
2445
929
        else if((c | 32) == 'e')
2446
347
        {
2447
347
            ++cs;
2448
347
            goto do_exp1;
2449
347
        }
2450
582
        else
2451
582
        {
2452
582
            goto finish_int;
2453
582
        }
2454
1.26k
    }
2455
2456
    //----------------------------------
2457
    //
2458
    // DIGIT
2459
    // first significant digit
2460
    // to the right of decimal
2461
    //
2462
530
do_num7:
2463
530
    {
2464
530
        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
0
            BOOST_STATIC_CONSTEXPR source_location loc
2479
0
                = BOOST_CURRENT_LOCATION;
2480
0
            return fail(cs.begin(), error::syntax, &loc);
2481
4
        }
2482
526
        char const c = *cs;
2483
526
        if(BOOST_JSON_UNLIKELY(
2484
526
            c < '0' || c > '9'))
2485
15
        {
2486
            // digit required
2487
15
            BOOST_STATIC_CONSTEXPR source_location loc
2488
15
                = BOOST_CURRENT_LOCATION;
2489
15
            return fail(cs.begin(), error::syntax, &loc);
2490
15
        }
2491
526
    }
2492
2493
    //----------------------------------
2494
    //
2495
    // 1*DIGIT
2496
    // significant digits
2497
    // to the right of decimal
2498
    //
2499
729
do_num8:
2500
729
    for(;;)
2501
729
    {
2502
729
        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
729
        char const c = *cs;
2518
729
        if(BOOST_JSON_LIKELY(
2519
729
            c >= '0' && c <= '9'))
2520
729
        {
2521
729
            ++cs;
2522
729
            if(!no_parsing && BOOST_JSON_LIKELY(
2523
729
                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
729
            else
2535
729
            {
2536
729
                goto do_num5;
2537
729
            }
2538
729
        }
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
729
    }
2549
2550
    //----------------------------------
2551
    //
2552
    // *[+-]
2553
    //
2554
1.71k
do_exp1:
2555
1.71k
    if(BOOST_JSON_UNLIKELY(! cs))
2556
16
    {
2557
16
        if(BOOST_JSON_UNLIKELY(
2558
16
            ! h_.on_number_part(
2559
16
                {begin, cs.used(begin)}, ec_)))
2560
0
            return fail(cs.begin());
2561
2562
16
        BOOST_IF_CONSTEXPR( precise_parsing )
2563
16
            num_buf_.append( begin, cs.used(begin) );
2564
16
        return maybe_suspend(
2565
16
            cs.begin(), state::exp1, num);
2566
16
    }
2567
1.70k
    if(*cs == '+')
2568
195
    {
2569
195
        ++cs;
2570
195
    }
2571
1.50k
    else if(*cs == '-')
2572
247
    {
2573
247
        ++cs;
2574
247
        num.frac = true;
2575
247
    }
2576
2577
    //----------------------------------
2578
    //
2579
    // DIGIT
2580
    // first digit of the exponent
2581
    //
2582
1.70k
do_exp2:
2583
1.70k
    {
2584
1.70k
        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
0
            BOOST_STATIC_CONSTEXPR source_location loc
2599
0
                = BOOST_CURRENT_LOCATION;
2600
0
            return fail(cs.begin(), error::syntax, &loc);
2601
10
        }
2602
1.69k
        char const c = *cs;
2603
1.69k
        if(BOOST_JSON_UNLIKELY(
2604
1.69k
            c < '0' || c > '9'))
2605
17
        {
2606
            // digit required
2607
17
            BOOST_STATIC_CONSTEXPR source_location loc
2608
17
                = BOOST_CURRENT_LOCATION;
2609
17
            return fail(cs.begin(), error::syntax, &loc);
2610
17
        }
2611
1.67k
        ++cs;
2612
1.67k
        num.exp = c - '0';
2613
1.67k
    }
2614
2615
    //----------------------------------
2616
    //
2617
    // 1*DIGIT
2618
    // subsequent digits in the exponent
2619
    //
2620
1.67k
do_exp3:
2621
1.67k
    for(;;)
2622
2.25k
    {
2623
2.25k
        if(BOOST_JSON_UNLIKELY(! cs))
2624
14
        {
2625
14
            if(BOOST_JSON_UNLIKELY(more_))
2626
14
            {
2627
14
                if(BOOST_JSON_UNLIKELY(
2628
14
                    ! h_.on_number_part(
2629
14
                        {begin, cs.used(begin)}, ec_)))
2630
0
                    return fail(cs.begin());
2631
2632
14
                BOOST_IF_CONSTEXPR( precise_parsing )
2633
14
                    num_buf_.append( begin, cs.used(begin) );
2634
14
                return suspend(cs.begin(), state::exp3, num);
2635
14
            }
2636
14
        }
2637
2.23k
        else
2638
2.23k
        {
2639
2.23k
            char const c = *cs;
2640
2.23k
            if(BOOST_JSON_LIKELY( c >= '0' && c <= '9' ))
2641
575
            {
2642
575
                if(BOOST_JSON_UNLIKELY(
2643
                //              2147483647 INT_MAX
2644
575
                    num.exp  >  214748364 ||
2645
575
                    (num.exp == 214748364 && c > '7')
2646
575
                ))
2647
0
                    num.exp = INT_MAX;
2648
575
                else BOOST_IF_CONSTEXPR( !no_parsing )
2649
575
                    num.exp = 10 * num.exp + ( c - '0' );
2650
2651
575
                ++cs;
2652
575
                continue;
2653
575
            }
2654
2.23k
        }
2655
1.66k
        BOOST_ASSERT(num.exp >= 0);
2656
1.66k
        if ( num.frac )
2657
243
        {
2658
243
            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
243
        }
2678
1.41k
        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.66k
        goto finish_dub;
2698
1.66k
    }
2699
2700
582
finish_int:
2701
582
    if(negative || (!stack_empty && num.neg))
2702
582
    {
2703
582
        if(BOOST_JSON_UNLIKELY(
2704
582
            ! h_.on_int64(static_cast<
2705
582
                int64_t>(~num.mant + 1), {begin, cs.used(begin)}, ec_)))
2706
0
            return fail(cs.begin());
2707
582
        return cs.begin();
2708
582
    }
2709
0
    if(num.mant <= INT64_MAX)
2710
0
    {
2711
1.22k
finish_signed:
2712
1.22k
        if(BOOST_JSON_UNLIKELY(
2713
1.22k
            ! h_.on_int64(static_cast<
2714
1.22k
                int64_t>(num.mant), {begin, cs.used(begin)}, ec_)))
2715
0
            return fail(cs.begin());
2716
1.22k
        return cs.begin();
2717
1.22k
    }
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.65k
finish_dub:
2723
2.65k
    double d;
2724
2.65k
    std::size_t const size = cs.used(begin);
2725
2.65k
    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.65k
    else BOOST_IF_CONSTEXPR( no_parsing )
2745
2.65k
        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.65k
    if(BOOST_JSON_UNLIKELY(
2753
2.65k
        ! h_.on_double(d, {begin, size}, ec_)))
2754
0
        return fail(cs.begin());
2755
2.65k
    return cs.begin();
2756
2.65k
}
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
8.31M
{
1987
8.31M
    constexpr bool precise_parsing = mode == number_precision::precise;
1988
8.31M
    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
8.31M
    bool const negative = first == '-';
1995
8.31M
    bool const zero_first = first == '0';
1996
8.31M
    bool const nonzero_first = first == '+';
1997
8.31M
    detail::const_stream_wrapper cs(p, end_);
1998
8.31M
    number num;
1999
8.31M
    const char* begin = cs.begin();
2000
8.31M
    if(stack_empty || st_.empty())
2001
8.31M
    {
2002
8.31M
        num.bias = 0;
2003
8.31M
        num.exp = 0;
2004
8.31M
        num.frac = false;
2005
8.31M
        num_buf_.clear();
2006
2007
        //----------------------------------
2008
        //
2009
        // '-'
2010
        // leading minus sign
2011
        //
2012
8.31M
        BOOST_ASSERT(cs);
2013
8.31M
        if(negative)
2014
0
            ++cs;
2015
2016
8.31M
        num.neg = negative;
2017
8.31M
        num.frac = false;
2018
8.31M
        num.exp = 0;
2019
8.31M
        num.bias = 0;
2020
2021
        // fast path
2022
8.31M
        if( cs.remain() >= 16 + 1 + 16 ) // digits . digits
2023
8.30M
        {
2024
8.30M
            int n1;
2025
2026
8.30M
            if( nonzero_first ||
2027
8.30M
                (negative && *cs != '0') )
2028
8.30M
            {
2029
8.30M
                n1 = detail::count_digits( cs.begin() );
2030
8.30M
                BOOST_ASSERT(n1 >= 0 && n1 <= 16);
2031
2032
8.30M
                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
8.30M
                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
8.30M
                BOOST_IF_CONSTEXPR( !no_parsing )
2048
8.30M
                    num.mant = detail::parse_unsigned( 0, cs.begin(), n1 );
2049
                else
2050
                    num.mant = 0;
2051
2052
8.30M
                cs += n1;
2053
2054
                // integer or floating-point with
2055
                // >= 16 leading digits
2056
8.30M
                if( n1 == 16 )
2057
87.3k
                {
2058
87.3k
                    goto do_num2;
2059
87.3k
                }
2060
8.30M
            }
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.21M
            {
2070
8.21M
                const char c = *cs;
2071
8.21M
                if(c != '.')
2072
8.20M
                {
2073
8.20M
                    if((c | 32) == 'e')
2074
5.55M
                    {
2075
5.55M
                        ++cs;
2076
5.55M
                        goto do_exp1;
2077
5.55M
                    }
2078
2.64M
                    BOOST_IF_CONSTEXPR( negative && !no_parsing )
2079
2.64M
                        num.mant = ~num.mant + 1;
2080
2.64M
                    goto finish_signed;
2081
8.20M
                }
2082
8.21M
            }
2083
2084
            // floating-point number
2085
2086
12.8k
            ++cs;
2087
2088
12.8k
            int n2 = detail::count_digits( cs.begin() );
2089
12.8k
            BOOST_ASSERT(n2 >= 0 && n2 <= 16);
2090
2091
12.8k
            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
12.8k
            if( n1 + n2 >= 19 )
2101
1.97k
            {
2102
1.97k
                goto do_num7;
2103
1.97k
            }
2104
2105
10.8k
            BOOST_IF_CONSTEXPR( !no_parsing )
2106
10.8k
                num.mant = detail::parse_unsigned( num.mant, cs.begin(), n2 );
2107
2108
10.8k
            BOOST_ASSERT(num.bias == 0);
2109
2110
10.8k
            num.bias -= n2;
2111
2112
10.8k
            cs += n2;
2113
2114
10.8k
            char ch = *cs;
2115
2116
10.8k
            if( (ch | 32) == 'e' )
2117
998
            {
2118
998
                ++cs;
2119
998
                goto do_exp1;
2120
998
            }
2121
9.84k
            else if( ch >= '0' && ch <= '9' )
2122
966
            {
2123
966
                goto do_num8;
2124
966
            }
2125
2126
8.87k
            goto finish_dub;
2127
10.8k
        }
2128
8.31M
    }
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
6.62k
do_num1:
2157
6.62k
    if(zero_first || nonzero_first ||
2158
6.62k
        BOOST_JSON_LIKELY(cs))
2159
6.62k
    {
2160
6.62k
        char const c = *cs;
2161
6.62k
        if(zero_first)
2162
0
        {
2163
0
            ++cs;
2164
0
            num.mant = 0;
2165
0
            goto do_num6;
2166
0
        }
2167
6.62k
        else if(nonzero_first || BOOST_JSON_LIKELY(
2168
6.62k
            c >= '1' && c <= '9'))
2169
6.62k
        {
2170
6.62k
            ++cs;
2171
6.62k
            num.mant = c - '0';
2172
6.62k
        }
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
6.62k
    }
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
93.9k
do_num2:
2214
93.9k
    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
93.9k
    else
2250
93.9k
    {
2251
93.9k
        for(;;)
2252
383k
        {
2253
383k
            if(BOOST_JSON_UNLIKELY(! cs))
2254
323
            {
2255
323
                if(BOOST_JSON_UNLIKELY(more_))
2256
323
                {
2257
323
                    if(BOOST_JSON_UNLIKELY(
2258
323
                        ! h_.on_number_part(
2259
323
                            {begin, cs.used(begin)}, ec_)))
2260
0
                        return fail(cs.begin());
2261
2262
323
                    BOOST_IF_CONSTEXPR( precise_parsing )
2263
323
                        num_buf_.append( begin, cs.used(begin) );
2264
323
                    return suspend(cs.begin(), state::num2, num);
2265
323
                }
2266
0
                goto finish_int;
2267
323
            }
2268
382k
            char const c = *cs;
2269
382k
            if(BOOST_JSON_LIKELY(
2270
382k
                c >= '0' && c <= '9'))
2271
299k
            {
2272
299k
                ++cs;
2273
                //              18446744073709551615 UINT64_MAX
2274
299k
                if( num.mant  > 1844674407370955161 || (
2275
289k
                    num.mant == 1844674407370955161 && c > '5'))
2276
10.7k
                    break;
2277
289k
                BOOST_IF_CONSTEXPR( !no_parsing )
2278
289k
                    num.mant = 10 * num.mant + ( c - '0' );
2279
289k
            }
2280
82.9k
            else
2281
82.9k
            {
2282
82.9k
                goto do_num6; // [.eE]
2283
82.9k
            }
2284
382k
        }
2285
93.9k
    }
2286
10.7k
    ++num.bias;
2287
2288
    //----------------------------------
2289
    //
2290
    // 1*DIGIT
2291
    // non-significant digits left of decimal
2292
    //
2293
10.7k
do_num3:
2294
10.7k
    for(;;)
2295
6.96M
    {
2296
6.96M
        if(BOOST_JSON_UNLIKELY(! cs))
2297
32
        {
2298
32
            if(BOOST_JSON_UNLIKELY(more_))
2299
32
            {
2300
32
                if(BOOST_JSON_UNLIKELY(
2301
32
                    ! h_.on_number_part(
2302
32
                        {begin, cs.used(begin)}, ec_)))
2303
0
                    return fail(cs.begin());
2304
2305
32
                BOOST_IF_CONSTEXPR( precise_parsing )
2306
32
                    num_buf_.append( begin, cs.used(begin) );
2307
32
                return suspend(cs.begin(), state::num3, num);
2308
32
            }
2309
0
            goto finish_dub;
2310
32
        }
2311
6.96M
        char const c = *cs;
2312
6.96M
        if(BOOST_JSON_UNLIKELY(
2313
6.96M
            c >= '0' && c <= '9'))
2314
6.95M
        {
2315
6.95M
            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.95M
            ++cs;
2322
6.95M
            ++num.bias;
2323
6.95M
        }
2324
10.7k
        else if(BOOST_JSON_LIKELY(
2325
10.7k
            c == '.'))
2326
958
        {
2327
958
            ++cs;
2328
958
            break;
2329
958
        }
2330
9.74k
        else if((c | 32) == 'e')
2331
2.31k
        {
2332
2.31k
            ++cs;
2333
2.31k
            goto do_exp1;
2334
2.31k
        }
2335
7.43k
        else
2336
7.43k
        {
2337
7.43k
            goto finish_dub;
2338
7.43k
        }
2339
6.96M
    }
2340
2341
    //----------------------------------
2342
    //
2343
    // DIGIT
2344
    // first non-significant digit
2345
    // to the right of decimal
2346
    //
2347
958
do_num4:
2348
958
    {
2349
958
        if(BOOST_JSON_UNLIKELY(! cs))
2350
2
        {
2351
2
            if(BOOST_JSON_UNLIKELY(
2352
2
                ! h_.on_number_part(
2353
2
                    {begin, cs.used(begin)}, ec_)))
2354
0
                return fail(cs.begin());
2355
2356
2
            BOOST_IF_CONSTEXPR( precise_parsing )
2357
2
                num_buf_.append( begin, cs.used(begin) );
2358
2
            return maybe_suspend(
2359
2
                cs.begin(), state::num4, num);
2360
2
        }
2361
956
        char const c = *cs;
2362
956
        if(BOOST_JSON_LIKELY(
2363
            //static_cast<unsigned char>(c - '0') < 10))
2364
956
            c >= '0' && c <= '9'))
2365
943
        {
2366
943
            ++cs;
2367
943
        }
2368
13
        else
2369
13
        {
2370
            // digit required
2371
13
            BOOST_STATIC_CONSTEXPR source_location loc
2372
13
                = BOOST_CURRENT_LOCATION;
2373
13
            return fail(cs.begin(), error::syntax, &loc);
2374
13
        }
2375
956
    }
2376
2377
    //----------------------------------
2378
    //
2379
    // 1*DIGIT
2380
    // non-significant digits
2381
    // to the right of decimal
2382
    //
2383
7.25k
do_num5:
2384
7.25k
    for(;;)
2385
36.7k
    {
2386
36.7k
        if(BOOST_JSON_UNLIKELY(! cs))
2387
48
        {
2388
48
            if(BOOST_JSON_UNLIKELY(more_))
2389
48
            {
2390
48
                if(BOOST_JSON_UNLIKELY(
2391
48
                    ! h_.on_number_part(
2392
48
                        {begin, cs.used(begin)}, ec_)))
2393
0
                    return fail(cs.begin());
2394
2395
48
                BOOST_IF_CONSTEXPR( precise_parsing )
2396
48
                    num_buf_.append( begin, cs.used(begin) );
2397
48
                return suspend(cs.begin(), state::num5, num);
2398
48
            }
2399
0
            goto finish_dub;
2400
48
        }
2401
36.7k
        char const c = *cs;
2402
36.7k
        if(BOOST_JSON_LIKELY(
2403
36.7k
            c >= '0' && c <= '9'))
2404
29.4k
        {
2405
29.4k
            ++cs;
2406
29.4k
        }
2407
7.20k
        else if((c | 32) == 'e')
2408
475
        {
2409
475
            ++cs;
2410
475
            goto do_exp1;
2411
475
        }
2412
6.73k
        else
2413
6.73k
        {
2414
6.73k
            goto finish_dub;
2415
6.73k
        }
2416
36.7k
    }
2417
2418
    //----------------------------------
2419
    //
2420
    // [.eE]
2421
    //
2422
82.9k
do_num6:
2423
82.9k
    {
2424
82.9k
        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
82.9k
        char const c = *cs;
2440
82.9k
        if(BOOST_JSON_LIKELY(
2441
82.9k
            c == '.'))
2442
4.80k
        {
2443
4.80k
            ++cs;
2444
4.80k
        }
2445
78.1k
        else if((c | 32) == 'e')
2446
2.81k
        {
2447
2.81k
            ++cs;
2448
2.81k
            goto do_exp1;
2449
2.81k
        }
2450
75.2k
        else
2451
75.2k
        {
2452
75.2k
            goto finish_int;
2453
75.2k
        }
2454
82.9k
    }
2455
2456
    //----------------------------------
2457
    //
2458
    // DIGIT
2459
    // first significant digit
2460
    // to the right of decimal
2461
    //
2462
6.77k
do_num7:
2463
6.77k
    {
2464
6.77k
        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
0
            BOOST_STATIC_CONSTEXPR source_location loc
2479
0
                = BOOST_CURRENT_LOCATION;
2480
0
            return fail(cs.begin(), error::syntax, &loc);
2481
5
        }
2482
6.77k
        char const c = *cs;
2483
6.77k
        if(BOOST_JSON_UNLIKELY(
2484
6.77k
            c < '0' || c > '9'))
2485
16
        {
2486
            // digit required
2487
16
            BOOST_STATIC_CONSTEXPR source_location loc
2488
16
                = BOOST_CURRENT_LOCATION;
2489
16
            return fail(cs.begin(), error::syntax, &loc);
2490
16
        }
2491
6.77k
    }
2492
2493
    //----------------------------------
2494
    //
2495
    // 1*DIGIT
2496
    // significant digits
2497
    // to the right of decimal
2498
    //
2499
7.72k
do_num8:
2500
7.72k
    for(;;)
2501
19.3k
    {
2502
19.3k
        if(BOOST_JSON_UNLIKELY(! cs))
2503
431
        {
2504
431
            if(BOOST_JSON_UNLIKELY(more_))
2505
431
            {
2506
431
                if(BOOST_JSON_UNLIKELY(
2507
431
                    ! h_.on_number_part(
2508
431
                        {begin, cs.used(begin)}, ec_)))
2509
0
                    return fail(cs.begin());
2510
2511
431
                BOOST_IF_CONSTEXPR( precise_parsing )
2512
431
                    num_buf_.append( begin, cs.used(begin) );
2513
431
                return suspend(cs.begin(), state::num8, num);
2514
431
            }
2515
0
            goto finish_dub;
2516
431
        }
2517
18.9k
        char const c = *cs;
2518
18.9k
        if(BOOST_JSON_LIKELY(
2519
18.9k
            c >= '0' && c <= '9'))
2520
17.9k
        {
2521
17.9k
            ++cs;
2522
17.9k
            if(!no_parsing && BOOST_JSON_LIKELY(
2523
17.9k
                num.mant <= 9007199254740991)) // 2^53-1
2524
11.6k
            {
2525
11.6k
                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.6k
                --num.bias;
2532
11.6k
                num.mant = 10 * num.mant + ( c - '0' );
2533
11.6k
            }
2534
6.31k
            else
2535
6.31k
            {
2536
6.31k
                goto do_num5;
2537
6.31k
            }
2538
17.9k
        }
2539
978
        else if((c | 32) == 'e')
2540
248
        {
2541
248
            ++cs;
2542
248
            goto do_exp1;
2543
248
        }
2544
730
        else
2545
730
        {
2546
730
            goto finish_dub;
2547
730
        }
2548
18.9k
    }
2549
2550
    //----------------------------------
2551
    //
2552
    // *[+-]
2553
    //
2554
5.56M
do_exp1:
2555
5.56M
    if(BOOST_JSON_UNLIKELY(! cs))
2556
23
    {
2557
23
        if(BOOST_JSON_UNLIKELY(
2558
23
            ! h_.on_number_part(
2559
23
                {begin, cs.used(begin)}, ec_)))
2560
0
            return fail(cs.begin());
2561
2562
23
        BOOST_IF_CONSTEXPR( precise_parsing )
2563
23
            num_buf_.append( begin, cs.used(begin) );
2564
23
        return maybe_suspend(
2565
23
            cs.begin(), state::exp1, num);
2566
23
    }
2567
5.56M
    if(*cs == '+')
2568
506
    {
2569
506
        ++cs;
2570
506
    }
2571
5.56M
    else if(*cs == '-')
2572
61.5k
    {
2573
61.5k
        ++cs;
2574
61.5k
        num.frac = true;
2575
61.5k
    }
2576
2577
    //----------------------------------
2578
    //
2579
    // DIGIT
2580
    // first digit of the exponent
2581
    //
2582
5.56M
do_exp2:
2583
5.56M
    {
2584
5.56M
        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
0
            BOOST_STATIC_CONSTEXPR source_location loc
2599
0
                = BOOST_CURRENT_LOCATION;
2600
0
            return fail(cs.begin(), error::syntax, &loc);
2601
11
        }
2602
5.56M
        char const c = *cs;
2603
5.56M
        if(BOOST_JSON_UNLIKELY(
2604
5.56M
            c < '0' || c > '9'))
2605
29
        {
2606
            // digit required
2607
29
            BOOST_STATIC_CONSTEXPR source_location loc
2608
29
                = BOOST_CURRENT_LOCATION;
2609
29
            return fail(cs.begin(), error::syntax, &loc);
2610
29
        }
2611
5.56M
        ++cs;
2612
5.56M
        num.exp = c - '0';
2613
5.56M
    }
2614
2615
    //----------------------------------
2616
    //
2617
    // 1*DIGIT
2618
    // subsequent digits in the exponent
2619
    //
2620
5.56M
do_exp3:
2621
5.56M
    for(;;)
2622
11.3M
    {
2623
11.3M
        if(BOOST_JSON_UNLIKELY(! cs))
2624
424
        {
2625
424
            if(BOOST_JSON_UNLIKELY(more_))
2626
424
            {
2627
424
                if(BOOST_JSON_UNLIKELY(
2628
424
                    ! h_.on_number_part(
2629
424
                        {begin, cs.used(begin)}, ec_)))
2630
0
                    return fail(cs.begin());
2631
2632
424
                BOOST_IF_CONSTEXPR( precise_parsing )
2633
424
                    num_buf_.append( begin, cs.used(begin) );
2634
424
                return suspend(cs.begin(), state::exp3, num);
2635
424
            }
2636
424
        }
2637
11.3M
        else
2638
11.3M
        {
2639
11.3M
            char const c = *cs;
2640
11.3M
            if(BOOST_JSON_LIKELY( c >= '0' && c <= '9' ))
2641
5.74M
            {
2642
5.74M
                if(BOOST_JSON_UNLIKELY(
2643
                //              2147483647 INT_MAX
2644
5.74M
                    num.exp  >  214748364 ||
2645
5.74M
                    (num.exp == 214748364 && c > '7')
2646
5.74M
                ))
2647
99.3k
                    num.exp = INT_MAX;
2648
5.64M
                else BOOST_IF_CONSTEXPR( !no_parsing )
2649
5.64M
                    num.exp = 10 * num.exp + ( c - '0' );
2650
2651
5.74M
                ++cs;
2652
5.74M
                continue;
2653
5.74M
            }
2654
11.3M
        }
2655
5.56M
        BOOST_ASSERT(num.exp >= 0);
2656
5.56M
        if ( num.frac )
2657
61.4k
        {
2658
61.4k
            if(BOOST_JSON_UNLIKELY( num.bias < (INT_MIN + num.exp) ))
2659
399
            {
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
399
                if(BOOST_JSON_UNLIKELY(
2664
399
                    (num.exp == INT_MAX) &&
2665
399
                    (num.bias < 0) &&
2666
399
                    (num.exp + num.bias < 308) &&
2667
399
                    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
399
                num.bias = 0;
2675
399
                num.exp = INT_MAX;
2676
399
            }
2677
61.4k
        }
2678
5.50M
        else if (BOOST_JSON_UNLIKELY( num.bias > (INT_MAX - num.exp) ))
2679
530
        {
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
530
            if(BOOST_JSON_UNLIKELY(
2684
530
                (num.exp == INT_MAX) &&
2685
530
                (num.bias > 0) &&
2686
530
                (num.exp - num.bias < 308) &&
2687
530
                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
530
            num.bias = 0;
2695
530
            num.exp = INT_MAX;
2696
530
        }
2697
5.56M
        goto finish_dub;
2698
5.56M
    }
2699
2700
75.2k
finish_int:
2701
75.2k
    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
75.2k
    if(num.mant <= INT64_MAX)
2710
7.54k
    {
2711
2.65M
finish_signed:
2712
2.65M
        if(BOOST_JSON_UNLIKELY(
2713
2.65M
            ! h_.on_int64(static_cast<
2714
2.65M
                int64_t>(num.mant), {begin, cs.used(begin)}, ec_)))
2715
0
            return fail(cs.begin());
2716
2.65M
        return cs.begin();
2717
2.65M
    }
2718
67.7k
    if(BOOST_JSON_UNLIKELY(
2719
67.7k
        ! h_.on_uint64(num.mant, {begin, cs.used(begin)}, ec_)))
2720
0
        return fail(cs.begin());
2721
67.7k
    return cs.begin();
2722
5.58M
finish_dub:
2723
5.58M
    double d;
2724
5.58M
    std::size_t const size = cs.used(begin);
2725
5.58M
    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
5.58M
    else BOOST_IF_CONSTEXPR( no_parsing )
2745
5.58M
        d = 0;
2746
5.58M
    else
2747
5.58M
        d = detail::dec_to_float(
2748
5.58M
            num.mant,
2749
5.58M
            num.bias + (num.frac ?
2750
5.52M
                -num.exp : num.exp),
2751
5.58M
            num.neg);
2752
5.58M
    if(BOOST_JSON_UNLIKELY(
2753
5.58M
        ! h_.on_double(d, {begin, size}, ec_)))
2754
0
        return fail(cs.begin());
2755
5.58M
    return cs.begin();
2756
5.58M
}
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
280k
{
1987
280k
    constexpr bool precise_parsing = mode == number_precision::precise;
1988
280k
    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
280k
    bool const negative = first == '-';
1995
280k
    bool const zero_first = first == '0';
1996
280k
    bool const nonzero_first = first == '+';
1997
280k
    detail::const_stream_wrapper cs(p, end_);
1998
280k
    number num;
1999
280k
    const char* begin = cs.begin();
2000
280k
    if(stack_empty || st_.empty())
2001
280k
    {
2002
280k
        num.bias = 0;
2003
280k
        num.exp = 0;
2004
280k
        num.frac = false;
2005
280k
        num_buf_.clear();
2006
2007
        //----------------------------------
2008
        //
2009
        // '-'
2010
        // leading minus sign
2011
        //
2012
280k
        BOOST_ASSERT(cs);
2013
280k
        if(negative)
2014
0
            ++cs;
2015
2016
280k
        num.neg = negative;
2017
280k
        num.frac = false;
2018
280k
        num.exp = 0;
2019
280k
        num.bias = 0;
2020
2021
        // fast path
2022
280k
        if( cs.remain() >= 16 + 1 + 16 ) // digits . digits
2023
274k
        {
2024
274k
            int n1;
2025
2026
274k
            if( nonzero_first ||
2027
274k
                (negative && *cs != '0') )
2028
274k
            {
2029
274k
                n1 = detail::count_digits( cs.begin() );
2030
274k
                BOOST_ASSERT(n1 >= 0 && n1 <= 16);
2031
2032
274k
                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
274k
                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
274k
                BOOST_IF_CONSTEXPR( !no_parsing )
2048
274k
                    num.mant = detail::parse_unsigned( 0, cs.begin(), n1 );
2049
                else
2050
                    num.mant = 0;
2051
2052
274k
                cs += n1;
2053
2054
                // integer or floating-point with
2055
                // >= 16 leading digits
2056
274k
                if( n1 == 16 )
2057
41.4k
                {
2058
41.4k
                    goto do_num2;
2059
41.4k
                }
2060
274k
            }
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
233k
            {
2070
233k
                const char c = *cs;
2071
233k
                if(c != '.')
2072
226k
                {
2073
226k
                    if((c | 32) == 'e')
2074
160k
                    {
2075
160k
                        ++cs;
2076
160k
                        goto do_exp1;
2077
160k
                    }
2078
66.3k
                    BOOST_IF_CONSTEXPR( negative && !no_parsing )
2079
66.3k
                        num.mant = ~num.mant + 1;
2080
66.3k
                    goto finish_signed;
2081
226k
                }
2082
233k
            }
2083
2084
            // floating-point number
2085
2086
6.99k
            ++cs;
2087
2088
6.99k
            int n2 = detail::count_digits( cs.begin() );
2089
6.99k
            BOOST_ASSERT(n2 >= 0 && n2 <= 16);
2090
2091
6.99k
            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
6.99k
            if( n1 + n2 >= 19 )
2101
1.55k
            {
2102
1.55k
                goto do_num7;
2103
1.55k
            }
2104
2105
5.43k
            BOOST_IF_CONSTEXPR( !no_parsing )
2106
5.43k
                num.mant = detail::parse_unsigned( num.mant, cs.begin(), n2 );
2107
2108
5.43k
            BOOST_ASSERT(num.bias == 0);
2109
2110
5.43k
            num.bias -= n2;
2111
2112
5.43k
            cs += n2;
2113
2114
5.43k
            char ch = *cs;
2115
2116
5.43k
            if( (ch | 32) == 'e' )
2117
967
            {
2118
967
                ++cs;
2119
967
                goto do_exp1;
2120
967
            }
2121
4.47k
            else if( ch >= '0' && ch <= '9' )
2122
1.82k
            {
2123
1.82k
                goto do_num8;
2124
1.82k
            }
2125
2126
2.64k
            goto finish_dub;
2127
5.43k
        }
2128
280k
    }
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
5.08k
do_num1:
2157
5.08k
    if(zero_first || nonzero_first ||
2158
5.08k
        BOOST_JSON_LIKELY(cs))
2159
5.08k
    {
2160
5.08k
        char const c = *cs;
2161
5.08k
        if(zero_first)
2162
0
        {
2163
0
            ++cs;
2164
0
            num.mant = 0;
2165
0
            goto do_num6;
2166
0
        }
2167
5.08k
        else if(nonzero_first || BOOST_JSON_LIKELY(
2168
5.08k
            c >= '1' && c <= '9'))
2169
5.08k
        {
2170
5.08k
            ++cs;
2171
5.08k
            num.mant = c - '0';
2172
5.08k
        }
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
5.08k
    }
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
46.5k
do_num2:
2214
46.5k
    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
46.5k
    else
2250
46.5k
    {
2251
46.5k
        for(;;)
2252
203k
        {
2253
203k
            if(BOOST_JSON_UNLIKELY(! cs))
2254
359
            {
2255
359
                if(BOOST_JSON_UNLIKELY(more_))
2256
359
                {
2257
359
                    if(BOOST_JSON_UNLIKELY(
2258
359
                        ! h_.on_number_part(
2259
359
                            {begin, cs.used(begin)}, ec_)))
2260
0
                        return fail(cs.begin());
2261
2262
359
                    BOOST_IF_CONSTEXPR( precise_parsing )
2263
359
                        num_buf_.append( begin, cs.used(begin) );
2264
359
                    return suspend(cs.begin(), state::num2, num);
2265
359
                }
2266
0
                goto finish_int;
2267
359
            }
2268
203k
            char const c = *cs;
2269
203k
            if(BOOST_JSON_LIKELY(
2270
203k
                c >= '0' && c <= '9'))
2271
188k
            {
2272
188k
                ++cs;
2273
                //              18446744073709551615 UINT64_MAX
2274
188k
                if( num.mant  > 1844674407370955161 || (
2275
177k
                    num.mant == 1844674407370955161 && c > '5'))
2276
31.2k
                    break;
2277
157k
                BOOST_IF_CONSTEXPR( !no_parsing )
2278
157k
                    num.mant = 10 * num.mant + ( c - '0' );
2279
157k
            }
2280
14.9k
            else
2281
14.9k
            {
2282
14.9k
                goto do_num6; // [.eE]
2283
14.9k
            }
2284
203k
        }
2285
46.5k
    }
2286
31.2k
    ++num.bias;
2287
2288
    //----------------------------------
2289
    //
2290
    // 1*DIGIT
2291
    // non-significant digits left of decimal
2292
    //
2293
31.2k
do_num3:
2294
31.2k
    for(;;)
2295
10.6M
    {
2296
10.6M
        if(BOOST_JSON_UNLIKELY(! cs))
2297
455
        {
2298
455
            if(BOOST_JSON_UNLIKELY(more_))
2299
455
            {
2300
455
                if(BOOST_JSON_UNLIKELY(
2301
455
                    ! h_.on_number_part(
2302
455
                        {begin, cs.used(begin)}, ec_)))
2303
0
                    return fail(cs.begin());
2304
2305
455
                BOOST_IF_CONSTEXPR( precise_parsing )
2306
455
                    num_buf_.append( begin, cs.used(begin) );
2307
455
                return suspend(cs.begin(), state::num3, num);
2308
455
            }
2309
0
            goto finish_dub;
2310
455
        }
2311
10.6M
        char const c = *cs;
2312
10.6M
        if(BOOST_JSON_UNLIKELY(
2313
10.6M
            c >= '0' && c <= '9'))
2314
10.5M
        {
2315
10.5M
            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
10.5M
            ++cs;
2322
10.5M
            ++num.bias;
2323
10.5M
        }
2324
30.7k
        else if(BOOST_JSON_LIKELY(
2325
30.7k
            c == '.'))
2326
2.75k
        {
2327
2.75k
            ++cs;
2328
2.75k
            break;
2329
2.75k
        }
2330
28.0k
        else if((c | 32) == 'e')
2331
25.4k
        {
2332
25.4k
            ++cs;
2333
25.4k
            goto do_exp1;
2334
25.4k
        }
2335
2.54k
        else
2336
2.54k
        {
2337
2.54k
            goto finish_dub;
2338
2.54k
        }
2339
10.6M
    }
2340
2341
    //----------------------------------
2342
    //
2343
    // DIGIT
2344
    // first non-significant digit
2345
    // to the right of decimal
2346
    //
2347
2.75k
do_num4:
2348
2.75k
    {
2349
2.75k
        if(BOOST_JSON_UNLIKELY(! cs))
2350
1
        {
2351
1
            if(BOOST_JSON_UNLIKELY(
2352
1
                ! h_.on_number_part(
2353
1
                    {begin, cs.used(begin)}, ec_)))
2354
0
                return fail(cs.begin());
2355
2356
1
            BOOST_IF_CONSTEXPR( precise_parsing )
2357
1
                num_buf_.append( begin, cs.used(begin) );
2358
1
            return maybe_suspend(
2359
1
                cs.begin(), state::num4, num);
2360
1
        }
2361
2.75k
        char const c = *cs;
2362
2.75k
        if(BOOST_JSON_LIKELY(
2363
            //static_cast<unsigned char>(c - '0') < 10))
2364
2.75k
            c >= '0' && c <= '9'))
2365
2.75k
        {
2366
2.75k
            ++cs;
2367
2.75k
        }
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
2.75k
    }
2376
2377
    //----------------------------------
2378
    //
2379
    // 1*DIGIT
2380
    // non-significant digits
2381
    // to the right of decimal
2382
    //
2383
8.10k
do_num5:
2384
8.10k
    for(;;)
2385
2.92M
    {
2386
2.92M
        if(BOOST_JSON_UNLIKELY(! cs))
2387
809
        {
2388
809
            if(BOOST_JSON_UNLIKELY(more_))
2389
809
            {
2390
809
                if(BOOST_JSON_UNLIKELY(
2391
809
                    ! h_.on_number_part(
2392
809
                        {begin, cs.used(begin)}, ec_)))
2393
0
                    return fail(cs.begin());
2394
2395
809
                BOOST_IF_CONSTEXPR( precise_parsing )
2396
809
                    num_buf_.append( begin, cs.used(begin) );
2397
809
                return suspend(cs.begin(), state::num5, num);
2398
809
            }
2399
0
            goto finish_dub;
2400
809
        }
2401
2.92M
        char const c = *cs;
2402
2.92M
        if(BOOST_JSON_LIKELY(
2403
2.92M
            c >= '0' && c <= '9'))
2404
2.91M
        {
2405
2.91M
            ++cs;
2406
2.91M
        }
2407
7.29k
        else if((c | 32) == 'e')
2408
2.86k
        {
2409
2.86k
            ++cs;
2410
2.86k
            goto do_exp1;
2411
2.86k
        }
2412
4.43k
        else
2413
4.43k
        {
2414
4.43k
            goto finish_dub;
2415
4.43k
        }
2416
2.92M
    }
2417
2418
    //----------------------------------
2419
    //
2420
    // [.eE]
2421
    //
2422
14.9k
do_num6:
2423
14.9k
    {
2424
14.9k
        if(BOOST_JSON_UNLIKELY(! cs))
2425
0
        {
2426
0
            if(BOOST_JSON_UNLIKELY(more_))
2427
0
            {
2428
0
                if(BOOST_JSON_UNLIKELY(
2429
0
                    ! h_.on_number_part(
2430
0
                        {begin, cs.used(begin)}, ec_)))
2431
0
                    return fail(cs.begin());
2432
2433
0
                BOOST_IF_CONSTEXPR( precise_parsing )
2434
0
                    num_buf_.append( begin, cs.used(begin) );
2435
0
                return suspend(cs.begin(), state::num6, num);
2436
0
            }
2437
0
            goto finish_int;
2438
0
        }
2439
14.9k
        char const c = *cs;
2440
14.9k
        if(BOOST_JSON_LIKELY(
2441
14.9k
            c == '.'))
2442
3.21k
        {
2443
3.21k
            ++cs;
2444
3.21k
        }
2445
11.7k
        else if((c | 32) == 'e')
2446
2.98k
        {
2447
2.98k
            ++cs;
2448
2.98k
            goto do_exp1;
2449
2.98k
        }
2450
8.72k
        else
2451
8.72k
        {
2452
8.72k
            goto finish_int;
2453
8.72k
        }
2454
14.9k
    }
2455
2456
    //----------------------------------
2457
    //
2458
    // DIGIT
2459
    // first significant digit
2460
    // to the right of decimal
2461
    //
2462
4.76k
do_num7:
2463
4.76k
    {
2464
4.76k
        if(BOOST_JSON_UNLIKELY(! cs))
2465
7
        {
2466
7
            if(BOOST_JSON_UNLIKELY(more_))
2467
7
            {
2468
7
                if(BOOST_JSON_UNLIKELY(
2469
7
                    ! h_.on_number_part(
2470
7
                        {begin, cs.used(begin)}, ec_)))
2471
0
                    return fail(cs.begin());
2472
2473
7
                BOOST_IF_CONSTEXPR( precise_parsing )
2474
7
                    num_buf_.append( begin, cs.used(begin) );
2475
7
                return suspend(cs.begin(), state::num7, num);
2476
7
            }
2477
            // digit required
2478
0
            BOOST_STATIC_CONSTEXPR source_location loc
2479
0
                = BOOST_CURRENT_LOCATION;
2480
0
            return fail(cs.begin(), error::syntax, &loc);
2481
7
        }
2482
4.75k
        char const c = *cs;
2483
4.75k
        if(BOOST_JSON_UNLIKELY(
2484
4.75k
            c < '0' || c > '9'))
2485
12
        {
2486
            // digit required
2487
12
            BOOST_STATIC_CONSTEXPR source_location loc
2488
12
                = BOOST_CURRENT_LOCATION;
2489
12
            return fail(cs.begin(), error::syntax, &loc);
2490
12
        }
2491
4.75k
    }
2492
2493
    //----------------------------------
2494
    //
2495
    // 1*DIGIT
2496
    // significant digits
2497
    // to the right of decimal
2498
    //
2499
6.57k
do_num8:
2500
6.57k
    for(;;)
2501
26.0k
    {
2502
26.0k
        if(BOOST_JSON_UNLIKELY(! cs))
2503
518
        {
2504
518
            if(BOOST_JSON_UNLIKELY(more_))
2505
518
            {
2506
518
                if(BOOST_JSON_UNLIKELY(
2507
518
                    ! h_.on_number_part(
2508
518
                        {begin, cs.used(begin)}, ec_)))
2509
0
                    return fail(cs.begin());
2510
2511
518
                BOOST_IF_CONSTEXPR( precise_parsing )
2512
518
                    num_buf_.append( begin, cs.used(begin) );
2513
518
                return suspend(cs.begin(), state::num8, num);
2514
518
            }
2515
0
            goto finish_dub;
2516
518
        }
2517
25.5k
        char const c = *cs;
2518
25.5k
        if(BOOST_JSON_LIKELY(
2519
25.5k
            c >= '0' && c <= '9'))
2520
24.8k
        {
2521
24.8k
            ++cs;
2522
24.8k
            if(!no_parsing && BOOST_JSON_LIKELY(
2523
24.8k
                num.mant <= 9007199254740991)) // 2^53-1
2524
19.5k
            {
2525
19.5k
                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
19.5k
                --num.bias;
2532
19.5k
                num.mant = 10 * num.mant + ( c - '0' );
2533
19.5k
            }
2534
5.35k
            else
2535
5.35k
            {
2536
5.35k
                goto do_num5;
2537
5.35k
            }
2538
24.8k
        }
2539
701
        else if((c | 32) == 'e')
2540
309
        {
2541
309
            ++cs;
2542
309
            goto do_exp1;
2543
309
        }
2544
392
        else
2545
392
        {
2546
392
            goto finish_dub;
2547
392
        }
2548
25.5k
    }
2549
2550
    //----------------------------------
2551
    //
2552
    // *[+-]
2553
    //
2554
192k
do_exp1:
2555
192k
    if(BOOST_JSON_UNLIKELY(! cs))
2556
29
    {
2557
29
        if(BOOST_JSON_UNLIKELY(
2558
29
            ! h_.on_number_part(
2559
29
                {begin, cs.used(begin)}, ec_)))
2560
0
            return fail(cs.begin());
2561
2562
29
        BOOST_IF_CONSTEXPR( precise_parsing )
2563
29
            num_buf_.append( begin, cs.used(begin) );
2564
29
        return maybe_suspend(
2565
29
            cs.begin(), state::exp1, num);
2566
29
    }
2567
192k
    if(*cs == '+')
2568
536
    {
2569
536
        ++cs;
2570
536
    }
2571
192k
    else if(*cs == '-')
2572
6.93k
    {
2573
6.93k
        ++cs;
2574
6.93k
        num.frac = true;
2575
6.93k
    }
2576
2577
    //----------------------------------
2578
    //
2579
    // DIGIT
2580
    // first digit of the exponent
2581
    //
2582
192k
do_exp2:
2583
192k
    {
2584
192k
        if(BOOST_JSON_UNLIKELY(! cs))
2585
12
        {
2586
12
            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
0
            BOOST_STATIC_CONSTEXPR source_location loc
2599
0
                = BOOST_CURRENT_LOCATION;
2600
0
            return fail(cs.begin(), error::syntax, &loc);
2601
12
        }
2602
192k
        char const c = *cs;
2603
192k
        if(BOOST_JSON_UNLIKELY(
2604
192k
            c < '0' || c > '9'))
2605
23
        {
2606
            // digit required
2607
23
            BOOST_STATIC_CONSTEXPR source_location loc
2608
23
                = BOOST_CURRENT_LOCATION;
2609
23
            return fail(cs.begin(), error::syntax, &loc);
2610
23
        }
2611
192k
        ++cs;
2612
192k
        num.exp = c - '0';
2613
192k
    }
2614
2615
    //----------------------------------
2616
    //
2617
    // 1*DIGIT
2618
    // subsequent digits in the exponent
2619
    //
2620
192k
do_exp3:
2621
192k
    for(;;)
2622
435k
    {
2623
435k
        if(BOOST_JSON_UNLIKELY(! cs))
2624
1.15k
        {
2625
1.15k
            if(BOOST_JSON_UNLIKELY(more_))
2626
1.15k
            {
2627
1.15k
                if(BOOST_JSON_UNLIKELY(
2628
1.15k
                    ! h_.on_number_part(
2629
1.15k
                        {begin, cs.used(begin)}, ec_)))
2630
0
                    return fail(cs.begin());
2631
2632
1.15k
                BOOST_IF_CONSTEXPR( precise_parsing )
2633
1.15k
                    num_buf_.append( begin, cs.used(begin) );
2634
1.15k
                return suspend(cs.begin(), state::exp3, num);
2635
1.15k
            }
2636
1.15k
        }
2637
434k
        else
2638
434k
        {
2639
434k
            char const c = *cs;
2640
434k
            if(BOOST_JSON_LIKELY( c >= '0' && c <= '9' ))
2641
243k
            {
2642
243k
                if(BOOST_JSON_UNLIKELY(
2643
                //              2147483647 INT_MAX
2644
243k
                    num.exp  >  214748364 ||
2645
243k
                    (num.exp == 214748364 && c > '7')
2646
243k
                ))
2647
20.2k
                    num.exp = INT_MAX;
2648
222k
                else BOOST_IF_CONSTEXPR( !no_parsing )
2649
222k
                    num.exp = 10 * num.exp + ( c - '0' );
2650
2651
243k
                ++cs;
2652
243k
                continue;
2653
243k
            }
2654
434k
        }
2655
191k
        BOOST_ASSERT(num.exp >= 0);
2656
191k
        if ( num.frac )
2657
6.46k
        {
2658
6.46k
            if(BOOST_JSON_UNLIKELY( num.bias < (INT_MIN + num.exp) ))
2659
421
            {
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
421
                if(BOOST_JSON_UNLIKELY(
2664
421
                    (num.exp == INT_MAX) &&
2665
421
                    (num.bias < 0) &&
2666
421
                    (num.exp + num.bias < 308) &&
2667
421
                    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
421
                num.bias = 0;
2675
421
                num.exp = INT_MAX;
2676
421
            }
2677
6.46k
        }
2678
185k
        else if (BOOST_JSON_UNLIKELY( num.bias > (INT_MAX - num.exp) ))
2679
598
        {
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
598
            if(BOOST_JSON_UNLIKELY(
2684
598
                (num.exp == INT_MAX) &&
2685
598
                (num.bias > 0) &&
2686
598
                (num.exp - num.bias < 308) &&
2687
598
                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
598
            num.bias = 0;
2695
598
            num.exp = INT_MAX;
2696
598
        }
2697
191k
        goto finish_dub;
2698
191k
    }
2699
2700
8.72k
finish_int:
2701
8.72k
    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
8.72k
    if(num.mant <= INT64_MAX)
2710
2.05k
    {
2711
68.3k
finish_signed:
2712
68.3k
        if(BOOST_JSON_UNLIKELY(
2713
68.3k
            ! h_.on_int64(static_cast<
2714
68.3k
                int64_t>(num.mant), {begin, cs.used(begin)}, ec_)))
2715
0
            return fail(cs.begin());
2716
68.3k
        return cs.begin();
2717
68.3k
    }
2718
6.66k
    if(BOOST_JSON_UNLIKELY(
2719
6.66k
        ! h_.on_uint64(num.mant, {begin, cs.used(begin)}, ec_)))
2720
0
        return fail(cs.begin());
2721
6.66k
    return cs.begin();
2722
201k
finish_dub:
2723
201k
    double d;
2724
201k
    std::size_t const size = cs.used(begin);
2725
201k
    BOOST_ASSERT( !num_buf_.size() || precise_parsing );
2726
    BOOST_IF_CONSTEXPR( precise_parsing )
2727
201k
    {
2728
201k
        char const* data = begin;
2729
201k
        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
201k
        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
201k
        auto const err = detail::charconv::from_chars(
2739
201k
            data, data + full_size, d );
2740
201k
        BOOST_ASSERT( err.ec != std::errc::invalid_argument );
2741
201k
        BOOST_ASSERT( err.ptr == data + full_size );
2742
201k
        (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
201k
    if(BOOST_JSON_UNLIKELY(
2753
201k
        ! h_.on_double(d, {begin, size}, ec_)))
2754
0
        return fail(cs.begin());
2755
201k
    return cs.begin();
2756
201k
}
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
603k
{
1987
603k
    constexpr bool precise_parsing = mode == number_precision::precise;
1988
603k
    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
603k
    bool const negative = first == '-';
1995
603k
    bool const zero_first = first == '0';
1996
603k
    bool const nonzero_first = first == '+';
1997
603k
    detail::const_stream_wrapper cs(p, end_);
1998
603k
    number num;
1999
603k
    const char* begin = cs.begin();
2000
603k
    if(stack_empty || st_.empty())
2001
603k
    {
2002
603k
        num.bias = 0;
2003
603k
        num.exp = 0;
2004
603k
        num.frac = false;
2005
603k
        num_buf_.clear();
2006
2007
        //----------------------------------
2008
        //
2009
        // '-'
2010
        // leading minus sign
2011
        //
2012
603k
        BOOST_ASSERT(cs);
2013
603k
        if(negative)
2014
0
            ++cs;
2015
2016
603k
        num.neg = negative;
2017
603k
        num.frac = false;
2018
603k
        num.exp = 0;
2019
603k
        num.bias = 0;
2020
2021
        // fast path
2022
603k
        if( cs.remain() >= 16 + 1 + 16 ) // digits . digits
2023
602k
        {
2024
602k
            int n1;
2025
2026
602k
            if( nonzero_first ||
2027
602k
                (negative && *cs != '0') )
2028
602k
            {
2029
602k
                n1 = detail::count_digits( cs.begin() );
2030
602k
                BOOST_ASSERT(n1 >= 0 && n1 <= 16);
2031
2032
602k
                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
602k
                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
602k
                BOOST_IF_CONSTEXPR( !no_parsing )
2048
602k
                    num.mant = detail::parse_unsigned( 0, cs.begin(), n1 );
2049
602k
                else
2050
602k
                    num.mant = 0;
2051
2052
602k
                cs += n1;
2053
2054
                // integer or floating-point with
2055
                // >= 16 leading digits
2056
602k
                if( n1 == 16 )
2057
815
                {
2058
815
                    goto do_num2;
2059
815
                }
2060
602k
            }
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
601k
            {
2070
601k
                const char c = *cs;
2071
601k
                if(c != '.')
2072
599k
                {
2073
599k
                    if((c | 32) == 'e')
2074
38.3k
                    {
2075
38.3k
                        ++cs;
2076
38.3k
                        goto do_exp1;
2077
38.3k
                    }
2078
561k
                    BOOST_IF_CONSTEXPR( negative && !no_parsing )
2079
561k
                        num.mant = ~num.mant + 1;
2080
561k
                    goto finish_signed;
2081
599k
                }
2082
601k
            }
2083
2084
            // floating-point number
2085
2086
1.75k
            ++cs;
2087
2088
1.75k
            int n2 = detail::count_digits( cs.begin() );
2089
1.75k
            BOOST_ASSERT(n2 >= 0 && n2 <= 16);
2090
2091
1.75k
            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
1.75k
            if( n1 + n2 >= 19 )
2101
209
            {
2102
209
                goto do_num7;
2103
209
            }
2104
2105
1.54k
            BOOST_IF_CONSTEXPR( !no_parsing )
2106
1.54k
                num.mant = detail::parse_unsigned( num.mant, cs.begin(), n2 );
2107
2108
1.54k
            BOOST_ASSERT(num.bias == 0);
2109
2110
1.54k
            num.bias -= n2;
2111
2112
1.54k
            cs += n2;
2113
2114
1.54k
            char ch = *cs;
2115
2116
1.54k
            if( (ch | 32) == 'e' )
2117
202
            {
2118
202
                ++cs;
2119
202
                goto do_exp1;
2120
202
            }
2121
1.33k
            else if( ch >= '0' && ch <= '9' )
2122
283
            {
2123
283
                goto do_num8;
2124
283
            }
2125
2126
1.05k
            goto finish_dub;
2127
1.54k
        }
2128
603k
    }
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.29k
do_num1:
2157
1.29k
    if(zero_first || nonzero_first ||
2158
1.29k
        BOOST_JSON_LIKELY(cs))
2159
1.29k
    {
2160
1.29k
        char const c = *cs;
2161
1.29k
        if(zero_first)
2162
0
        {
2163
0
            ++cs;
2164
0
            num.mant = 0;
2165
0
            goto do_num6;
2166
0
        }
2167
1.29k
        else if(nonzero_first || BOOST_JSON_LIKELY(
2168
1.29k
            c >= '1' && c <= '9'))
2169
1.29k
        {
2170
1.29k
            ++cs;
2171
1.29k
            num.mant = c - '0';
2172
1.29k
        }
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.29k
    }
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.10k
do_num2:
2214
2.10k
    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.10k
    else
2250
2.10k
    {
2251
2.10k
        for(;;)
2252
3.84k
        {
2253
3.84k
            if(BOOST_JSON_UNLIKELY(! cs))
2254
67
            {
2255
67
                if(BOOST_JSON_UNLIKELY(more_))
2256
67
                {
2257
67
                    if(BOOST_JSON_UNLIKELY(
2258
67
                        ! h_.on_number_part(
2259
67
                            {begin, cs.used(begin)}, ec_)))
2260
0
                        return fail(cs.begin());
2261
2262
67
                    BOOST_IF_CONSTEXPR( precise_parsing )
2263
67
                        num_buf_.append( begin, cs.used(begin) );
2264
67
                    return suspend(cs.begin(), state::num2, num);
2265
67
                }
2266
0
                goto finish_int;
2267
67
            }
2268
3.77k
            char const c = *cs;
2269
3.77k
            if(BOOST_JSON_LIKELY(
2270
3.77k
                c >= '0' && c <= '9'))
2271
1.73k
            {
2272
1.73k
                ++cs;
2273
                //              18446744073709551615 UINT64_MAX
2274
1.73k
                if( num.mant  > 1844674407370955161 || (
2275
1.73k
                    num.mant == 1844674407370955161 && c > '5'))
2276
0
                    break;
2277
1.73k
                BOOST_IF_CONSTEXPR( !no_parsing )
2278
1.73k
                    num.mant = 10 * num.mant + ( c - '0' );
2279
1.73k
            }
2280
2.03k
            else
2281
2.03k
            {
2282
2.03k
                goto do_num6; // [.eE]
2283
2.03k
            }
2284
3.77k
        }
2285
2.10k
    }
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
989
do_num5:
2384
989
    for(;;)
2385
5.78k
    {
2386
5.78k
        if(BOOST_JSON_UNLIKELY(! cs))
2387
27
        {
2388
27
            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
0
            goto finish_dub;
2400
27
        }
2401
5.75k
        char const c = *cs;
2402
5.75k
        if(BOOST_JSON_LIKELY(
2403
5.75k
            c >= '0' && c <= '9'))
2404
4.79k
        {
2405
4.79k
            ++cs;
2406
4.79k
        }
2407
962
        else if((c | 32) == 'e')
2408
209
        {
2409
209
            ++cs;
2410
209
            goto do_exp1;
2411
209
        }
2412
753
        else
2413
753
        {
2414
753
            goto finish_dub;
2415
753
        }
2416
5.75k
    }
2417
2418
    //----------------------------------
2419
    //
2420
    // [.eE]
2421
    //
2422
2.03k
do_num6:
2423
2.03k
    {
2424
2.03k
        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.03k
        char const c = *cs;
2440
2.03k
        if(BOOST_JSON_LIKELY(
2441
2.03k
            c == '.'))
2442
514
        {
2443
514
            ++cs;
2444
514
        }
2445
1.52k
        else if((c | 32) == 'e')
2446
402
        {
2447
402
            ++cs;
2448
402
            goto do_exp1;
2449
402
        }
2450
1.12k
        else
2451
1.12k
        {
2452
1.12k
            goto finish_int;
2453
1.12k
        }
2454
2.03k
    }
2455
2456
    //----------------------------------
2457
    //
2458
    // DIGIT
2459
    // first significant digit
2460
    // to the right of decimal
2461
    //
2462
723
do_num7:
2463
723
    {
2464
723
        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
0
            BOOST_STATIC_CONSTEXPR source_location loc
2479
0
                = BOOST_CURRENT_LOCATION;
2480
0
            return fail(cs.begin(), error::syntax, &loc);
2481
4
        }
2482
719
        char const c = *cs;
2483
719
        if(BOOST_JSON_UNLIKELY(
2484
719
            c < '0' || c > '9'))
2485
13
        {
2486
            // digit required
2487
13
            BOOST_STATIC_CONSTEXPR source_location loc
2488
13
                = BOOST_CURRENT_LOCATION;
2489
13
            return fail(cs.begin(), error::syntax, &loc);
2490
13
        }
2491
719
    }
2492
2493
    //----------------------------------
2494
    //
2495
    // 1*DIGIT
2496
    // significant digits
2497
    // to the right of decimal
2498
    //
2499
989
do_num8:
2500
989
    for(;;)
2501
989
    {
2502
989
        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
989
        char const c = *cs;
2518
989
        if(BOOST_JSON_LIKELY(
2519
989
            c >= '0' && c <= '9'))
2520
989
        {
2521
989
            ++cs;
2522
989
            if(!no_parsing && BOOST_JSON_LIKELY(
2523
989
                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
989
            else
2535
989
            {
2536
989
                goto do_num5;
2537
989
            }
2538
989
        }
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
989
    }
2549
2550
    //----------------------------------
2551
    //
2552
    // *[+-]
2553
    //
2554
39.2k
do_exp1:
2555
39.2k
    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
39.1k
    if(*cs == '+')
2568
208
    {
2569
208
        ++cs;
2570
208
    }
2571
38.9k
    else if(*cs == '-')
2572
389
    {
2573
389
        ++cs;
2574
389
        num.frac = true;
2575
389
    }
2576
2577
    //----------------------------------
2578
    //
2579
    // DIGIT
2580
    // first digit of the exponent
2581
    //
2582
39.1k
do_exp2:
2583
39.1k
    {
2584
39.1k
        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
0
            BOOST_STATIC_CONSTEXPR source_location loc
2599
0
                = BOOST_CURRENT_LOCATION;
2600
0
            return fail(cs.begin(), error::syntax, &loc);
2601
11
        }
2602
39.1k
        char const c = *cs;
2603
39.1k
        if(BOOST_JSON_UNLIKELY(
2604
39.1k
            c < '0' || c > '9'))
2605
20
        {
2606
            // digit required
2607
20
            BOOST_STATIC_CONSTEXPR source_location loc
2608
20
                = BOOST_CURRENT_LOCATION;
2609
20
            return fail(cs.begin(), error::syntax, &loc);
2610
20
        }
2611
39.1k
        ++cs;
2612
39.1k
        num.exp = c - '0';
2613
39.1k
    }
2614
2615
    //----------------------------------
2616
    //
2617
    // 1*DIGIT
2618
    // subsequent digits in the exponent
2619
    //
2620
39.1k
do_exp3:
2621
39.1k
    for(;;)
2622
79.1k
    {
2623
79.1k
        if(BOOST_JSON_UNLIKELY(! cs))
2624
26
        {
2625
26
            if(BOOST_JSON_UNLIKELY(more_))
2626
26
            {
2627
26
                if(BOOST_JSON_UNLIKELY(
2628
26
                    ! h_.on_number_part(
2629
26
                        {begin, cs.used(begin)}, ec_)))
2630
0
                    return fail(cs.begin());
2631
2632
26
                BOOST_IF_CONSTEXPR( precise_parsing )
2633
26
                    num_buf_.append( begin, cs.used(begin) );
2634
26
                return suspend(cs.begin(), state::exp3, num);
2635
26
            }
2636
26
        }
2637
79.0k
        else
2638
79.0k
        {
2639
79.0k
            char const c = *cs;
2640
79.0k
            if(BOOST_JSON_LIKELY( c >= '0' && c <= '9' ))
2641
39.9k
            {
2642
39.9k
                if(BOOST_JSON_UNLIKELY(
2643
                //              2147483647 INT_MAX
2644
39.9k
                    num.exp  >  214748364 ||
2645
39.9k
                    (num.exp == 214748364 && c > '7')
2646
39.9k
                ))
2647
0
                    num.exp = INT_MAX;
2648
39.9k
                else BOOST_IF_CONSTEXPR( !no_parsing )
2649
39.9k
                    num.exp = 10 * num.exp + ( c - '0' );
2650
2651
39.9k
                ++cs;
2652
39.9k
                continue;
2653
39.9k
            }
2654
79.0k
        }
2655
39.1k
        BOOST_ASSERT(num.exp >= 0);
2656
39.1k
        if ( num.frac )
2657
377
        {
2658
377
            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
377
        }
2678
38.7k
        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
39.1k
        goto finish_dub;
2698
39.1k
    }
2699
2700
1.12k
finish_int:
2701
1.12k
    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.12k
    if(num.mant <= INT64_MAX)
2710
1.12k
    {
2711
562k
finish_signed:
2712
562k
        if(BOOST_JSON_UNLIKELY(
2713
562k
            ! h_.on_int64(static_cast<
2714
562k
                int64_t>(num.mant), {begin, cs.used(begin)}, ec_)))
2715
0
            return fail(cs.begin());
2716
562k
        return cs.begin();
2717
562k
    }
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
40.9k
finish_dub:
2723
40.9k
    double d;
2724
40.9k
    std::size_t const size = cs.used(begin);
2725
40.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
40.9k
    else BOOST_IF_CONSTEXPR( no_parsing )
2745
40.9k
        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
40.9k
    if(BOOST_JSON_UNLIKELY(
2753
40.9k
        ! h_.on_double(d, {begin, size}, ec_)))
2754
0
        return fail(cs.begin());
2755
40.9k
    return cs.begin();
2756
40.9k
}
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.12k
{
1987
2.12k
    constexpr bool precise_parsing = mode == number_precision::precise;
1988
2.12k
    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.12k
    bool const negative = first == '-';
1995
2.12k
    bool const zero_first = first == '0';
1996
2.12k
    bool const nonzero_first = first == '+';
1997
2.12k
    detail::const_stream_wrapper cs(p, end_);
1998
2.12k
    number num;
1999
2.12k
    const char* begin = cs.begin();
2000
2.12k
    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.12k
    else
2130
2.12k
    {
2131
2.12k
        num = num_;
2132
2.12k
        state st;
2133
2.12k
        st_.pop(st);
2134
2.12k
        switch(st)
2135
2.12k
        {
2136
0
        default: BOOST_JSON_UNREACHABLE();
2137
17
        case state::num1: goto do_num1;
2138
498
        case state::num2: goto do_num2;
2139
70
        case state::num3: goto do_num3;
2140
6
        case state::num4: goto do_num4;
2141
92
        case state::num5: goto do_num5;
2142
25
        case state::num6: goto do_num6;
2143
13
        case state::num7: goto do_num7;
2144
631
        case state::num8: goto do_num8;
2145
74
        case state::exp1: goto do_exp1;
2146
34
        case state::exp2: goto do_exp2;
2147
669
        case state::exp3: goto do_exp3;
2148
2.12k
        }
2149
2.12k
    }
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
498
do_num2:
2214
498
    if(negative || (!stack_empty && num.neg))
2215
175
    {
2216
175
        for(;;)
2217
175
        {
2218
175
            if(BOOST_JSON_UNLIKELY(! cs))
2219
175
            {
2220
175
                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
175
                goto finish_int;
2232
175
            }
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
175
    }
2249
323
    else
2250
323
    {
2251
323
        for(;;)
2252
323
        {
2253
323
            if(BOOST_JSON_UNLIKELY(! cs))
2254
323
            {
2255
323
                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
323
                goto finish_int;
2267
323
            }
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
323
    }
2286
0
    ++num.bias;
2287
2288
    //----------------------------------
2289
    //
2290
    // 1*DIGIT
2291
    // non-significant digits left of decimal
2292
    //
2293
70
do_num3:
2294
70
    for(;;)
2295
70
    {
2296
70
        if(BOOST_JSON_UNLIKELY(! cs))
2297
70
        {
2298
70
            if(BOOST_JSON_UNLIKELY(more_))
2299
0
            {
2300
0
                if(BOOST_JSON_UNLIKELY(
2301
0
                    ! h_.on_number_part(
2302
0
                        {begin, cs.used(begin)}, ec_)))
2303
0
                    return fail(cs.begin());
2304
2305
0
                BOOST_IF_CONSTEXPR( precise_parsing )
2306
0
                    num_buf_.append( begin, cs.used(begin) );
2307
0
                return suspend(cs.begin(), state::num3, num);
2308
0
            }
2309
70
            goto finish_dub;
2310
70
        }
2311
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
92
do_num5:
2384
92
    for(;;)
2385
92
    {
2386
92
        if(BOOST_JSON_UNLIKELY(! cs))
2387
92
        {
2388
92
            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
92
            goto finish_dub;
2400
92
        }
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
25
do_num6:
2423
25
    {
2424
25
        if(BOOST_JSON_UNLIKELY(! cs))
2425
25
        {
2426
25
            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
25
            goto finish_int;
2438
25
        }
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
631
do_num8:
2500
631
    for(;;)
2501
631
    {
2502
631
        if(BOOST_JSON_UNLIKELY(! cs))
2503
631
        {
2504
631
            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
631
            goto finish_dub;
2516
631
        }
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
74
do_exp1:
2555
74
    if(BOOST_JSON_UNLIKELY(! cs))
2556
74
    {
2557
74
        if(BOOST_JSON_UNLIKELY(
2558
74
            ! h_.on_number_part(
2559
74
                {begin, cs.used(begin)}, ec_)))
2560
0
            return fail(cs.begin());
2561
2562
74
        BOOST_IF_CONSTEXPR( precise_parsing )
2563
74
            num_buf_.append( begin, cs.used(begin) );
2564
74
        return maybe_suspend(
2565
74
            cs.begin(), state::exp1, num);
2566
74
    }
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
34
do_exp2:
2583
34
    {
2584
34
        if(BOOST_JSON_UNLIKELY(! cs))
2585
34
        {
2586
34
            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
34
            BOOST_STATIC_CONSTEXPR source_location loc
2599
34
                = BOOST_CURRENT_LOCATION;
2600
34
            return fail(cs.begin(), error::syntax, &loc);
2601
34
        }
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
669
do_exp3:
2621
669
    for(;;)
2622
669
    {
2623
669
        if(BOOST_JSON_UNLIKELY(! cs))
2624
669
        {
2625
669
            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
669
        }
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
669
        BOOST_ASSERT(num.exp >= 0);
2656
669
        if ( num.frac )
2657
158
        {
2658
158
            if(BOOST_JSON_UNLIKELY( num.bias < (INT_MIN + num.exp) ))
2659
40
            {
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
40
                if(BOOST_JSON_UNLIKELY(
2664
40
                    (num.exp == INT_MAX) &&
2665
40
                    (num.bias < 0) &&
2666
40
                    (num.exp + num.bias < 308) &&
2667
40
                    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
40
                num.bias = 0;
2675
40
                num.exp = INT_MAX;
2676
40
            }
2677
158
        }
2678
511
        else if (BOOST_JSON_UNLIKELY( num.bias > (INT_MAX - num.exp) ))
2679
57
        {
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
57
            if(BOOST_JSON_UNLIKELY(
2684
57
                (num.exp == INT_MAX) &&
2685
57
                (num.bias > 0) &&
2686
57
                (num.exp - num.bias < 308) &&
2687
57
                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
57
            num.bias = 0;
2695
57
            num.exp = INT_MAX;
2696
57
        }
2697
669
        goto finish_dub;
2698
669
    }
2699
2700
523
finish_int:
2701
523
    if(negative || (!stack_empty && num.neg))
2702
180
    {
2703
180
        if(BOOST_JSON_UNLIKELY(
2704
180
            ! h_.on_int64(static_cast<
2705
180
                int64_t>(~num.mant + 1), {begin, cs.used(begin)}, ec_)))
2706
0
            return fail(cs.begin());
2707
180
        return cs.begin();
2708
180
    }
2709
343
    if(num.mant <= INT64_MAX)
2710
227
    {
2711
227
finish_signed:
2712
227
        if(BOOST_JSON_UNLIKELY(
2713
227
            ! h_.on_int64(static_cast<
2714
227
                int64_t>(num.mant), {begin, cs.used(begin)}, ec_)))
2715
0
            return fail(cs.begin());
2716
227
        return cs.begin();
2717
227
    }
2718
116
    if(BOOST_JSON_UNLIKELY(
2719
116
        ! h_.on_uint64(num.mant, {begin, cs.used(begin)}, ec_)))
2720
0
        return fail(cs.begin());
2721
116
    return cs.begin();
2722
1.46k
finish_dub:
2723
1.46k
    double d;
2724
1.46k
    std::size_t const size = cs.used(begin);
2725
1.46k
    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.46k
    else BOOST_IF_CONSTEXPR( no_parsing )
2745
1.46k
        d = 0;
2746
1.46k
    else
2747
1.46k
        d = detail::dec_to_float(
2748
1.46k
            num.mant,
2749
1.46k
            num.bias + (num.frac ?
2750
1.30k
                -num.exp : num.exp),
2751
1.46k
            num.neg);
2752
1.46k
    if(BOOST_JSON_UNLIKELY(
2753
1.46k
        ! h_.on_double(d, {begin, size}, ec_)))
2754
0
        return fail(cs.begin());
2755
1.46k
    return cs.begin();
2756
1.46k
}
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.35k
{
1987
4.35k
    constexpr bool precise_parsing = mode == number_precision::precise;
1988
4.35k
    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.35k
    bool const negative = first == '-';
1995
4.35k
    bool const zero_first = first == '0';
1996
4.35k
    bool const nonzero_first = first == '+';
1997
4.35k
    detail::const_stream_wrapper cs(p, end_);
1998
4.35k
    number num;
1999
4.35k
    const char* begin = cs.begin();
2000
4.35k
    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.35k
    else
2130
4.35k
    {
2131
4.35k
        num = num_;
2132
4.35k
        state st;
2133
4.35k
        st_.pop(st);
2134
4.35k
        switch(st)
2135
4.35k
        {
2136
0
        default: BOOST_JSON_UNREACHABLE();
2137
15
        case state::num1: goto do_num1;
2138
532
        case state::num2: goto do_num2;
2139
496
        case state::num3: goto do_num3;
2140
3
        case state::num4: goto do_num4;
2141
970
        case state::num5: goto do_num5;
2142
34
        case state::num6: goto do_num6;
2143
18
        case state::num7: goto do_num7;
2144
792
        case state::num8: goto do_num8;
2145
73
        case state::exp1: goto do_exp1;
2146
31
        case state::exp2: goto do_exp2;
2147
1.39k
        case state::exp3: goto do_exp3;
2148
4.35k
        }
2149
4.35k
    }
2150
2151
    //----------------------------------
2152
    //
2153
    // DIGIT
2154
    // first digit
2155
    //
2156
15
do_num1:
2157
15
    if(zero_first || nonzero_first ||
2158
15
        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
15
    else
2196
15
    {
2197
15
        if(BOOST_JSON_UNLIKELY(
2198
15
            ! h_.on_number_part(
2199
15
                {begin, cs.used(begin)}, ec_)))
2200
0
            return fail(cs.begin());
2201
2202
15
        BOOST_IF_CONSTEXPR( precise_parsing )
2203
15
            num_buf_.append( begin, cs.used(begin) );
2204
15
        return maybe_suspend(
2205
15
            cs.begin(), state::num1, num);
2206
15
    }
2207
2208
    //----------------------------------
2209
    //
2210
    // 1*DIGIT
2211
    // significant digits left of decimal
2212
    //
2213
532
do_num2:
2214
532
    if(negative || (!stack_empty && num.neg))
2215
173
    {
2216
173
        for(;;)
2217
173
        {
2218
173
            if(BOOST_JSON_UNLIKELY(! cs))
2219
173
            {
2220
173
                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
173
                goto finish_int;
2232
173
            }
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
173
    }
2249
359
    else
2250
359
    {
2251
359
        for(;;)
2252
359
        {
2253
359
            if(BOOST_JSON_UNLIKELY(! cs))
2254
359
            {
2255
359
                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
359
                goto finish_int;
2267
359
            }
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
359
    }
2286
0
    ++num.bias;
2287
2288
    //----------------------------------
2289
    //
2290
    // 1*DIGIT
2291
    // non-significant digits left of decimal
2292
    //
2293
496
do_num3:
2294
496
    for(;;)
2295
496
    {
2296
496
        if(BOOST_JSON_UNLIKELY(! cs))
2297
496
        {
2298
496
            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
496
            goto finish_dub;
2310
496
        }
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
970
do_num5:
2384
970
    for(;;)
2385
970
    {
2386
970
        if(BOOST_JSON_UNLIKELY(! cs))
2387
970
        {
2388
970
            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
970
            goto finish_dub;
2400
970
        }
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
34
do_num6:
2423
34
    {
2424
34
        if(BOOST_JSON_UNLIKELY(! cs))
2425
34
        {
2426
34
            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
34
            goto finish_int;
2438
34
        }
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
18
do_num7:
2463
18
    {
2464
18
        if(BOOST_JSON_UNLIKELY(! cs))
2465
18
        {
2466
18
            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
18
            BOOST_STATIC_CONSTEXPR source_location loc
2479
18
                = BOOST_CURRENT_LOCATION;
2480
18
            return fail(cs.begin(), error::syntax, &loc);
2481
18
        }
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
792
do_num8:
2500
792
    for(;;)
2501
792
    {
2502
792
        if(BOOST_JSON_UNLIKELY(! cs))
2503
792
        {
2504
792
            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
792
            goto finish_dub;
2516
792
        }
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
73
do_exp1:
2555
73
    if(BOOST_JSON_UNLIKELY(! cs))
2556
73
    {
2557
73
        if(BOOST_JSON_UNLIKELY(
2558
73
            ! h_.on_number_part(
2559
73
                {begin, cs.used(begin)}, ec_)))
2560
0
            return fail(cs.begin());
2561
2562
73
        BOOST_IF_CONSTEXPR( precise_parsing )
2563
73
            num_buf_.append( begin, cs.used(begin) );
2564
73
        return maybe_suspend(
2565
73
            cs.begin(), state::exp1, num);
2566
73
    }
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
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
533
        {
2658
533
            if(BOOST_JSON_UNLIKELY( num.bias < (INT_MIN + num.exp) ))
2659
41
            {
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
41
                if(BOOST_JSON_UNLIKELY(
2664
41
                    (num.exp == INT_MAX) &&
2665
41
                    (num.bias < 0) &&
2666
41
                    (num.exp + num.bias < 308) &&
2667
41
                    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
41
                num.bias = 0;
2675
41
                num.exp = INT_MAX;
2676
41
            }
2677
533
        }
2678
857
        else if (BOOST_JSON_UNLIKELY( num.bias > (INT_MAX - num.exp) ))
2679
48
        {
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
48
            if(BOOST_JSON_UNLIKELY(
2684
48
                (num.exp == INT_MAX) &&
2685
48
                (num.bias > 0) &&
2686
48
                (num.exp - num.bias < 308) &&
2687
48
                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
48
            num.bias = 0;
2695
48
            num.exp = INT_MAX;
2696
48
        }
2697
1.39k
        goto finish_dub;
2698
1.39k
    }
2699
2700
566
finish_int:
2701
566
    if(negative || (!stack_empty && num.neg))
2702
180
    {
2703
180
        if(BOOST_JSON_UNLIKELY(
2704
180
            ! h_.on_int64(static_cast<
2705
180
                int64_t>(~num.mant + 1), {begin, cs.used(begin)}, ec_)))
2706
0
            return fail(cs.begin());
2707
180
        return cs.begin();
2708
180
    }
2709
386
    if(num.mant <= INT64_MAX)
2710
278
    {
2711
278
finish_signed:
2712
278
        if(BOOST_JSON_UNLIKELY(
2713
278
            ! h_.on_int64(static_cast<
2714
278
                int64_t>(num.mant), {begin, cs.used(begin)}, ec_)))
2715
0
            return fail(cs.begin());
2716
278
        return cs.begin();
2717
278
    }
2718
108
    if(BOOST_JSON_UNLIKELY(
2719
108
        ! h_.on_uint64(num.mant, {begin, cs.used(begin)}, ec_)))
2720
0
        return fail(cs.begin());
2721
108
    return cs.begin();
2722
3.64k
finish_dub:
2723
3.64k
    double d;
2724
3.64k
    std::size_t const size = cs.used(begin);
2725
3.64k
    BOOST_ASSERT( !num_buf_.size() || precise_parsing );
2726
    BOOST_IF_CONSTEXPR( precise_parsing )
2727
3.64k
    {
2728
3.64k
        char const* data = begin;
2729
3.64k
        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.64k
        if(BOOST_JSON_UNLIKELY( num_buf_.size() ))
2734
3.64k
        {
2735
3.64k
            data = num_buf_.append( begin, size );
2736
3.64k
            full_size = num_buf_.size();
2737
3.64k
        }
2738
3.64k
        auto const err = detail::charconv::from_chars(
2739
3.64k
            data, data + full_size, d );
2740
3.64k
        BOOST_ASSERT( err.ec != std::errc::invalid_argument );
2741
3.64k
        BOOST_ASSERT( err.ptr == data + full_size );
2742
3.64k
        (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.64k
    if(BOOST_JSON_UNLIKELY(
2753
3.64k
        ! h_.on_double(d, {begin, size}, ec_)))
2754
0
        return fail(cs.begin());
2755
3.64k
    return cs.begin();
2756
3.64k
}
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
360
{
1987
360
    constexpr bool precise_parsing = mode == number_precision::precise;
1988
360
    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
360
    bool const negative = first == '-';
1995
360
    bool const zero_first = first == '0';
1996
360
    bool const nonzero_first = first == '+';
1997
360
    detail::const_stream_wrapper cs(p, end_);
1998
360
    number num;
1999
360
    const char* begin = cs.begin();
2000
360
    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
360
    else
2130
360
    {
2131
360
        num = num_;
2132
360
        state st;
2133
360
        st_.pop(st);
2134
360
        switch(st)
2135
360
        {
2136
0
        default: BOOST_JSON_UNREACHABLE();
2137
16
        case state::num1: goto do_num1;
2138
93
        case state::num2: goto do_num2;
2139
0
        case state::num3: goto do_num3;
2140
0
        case state::num4: goto do_num4;
2141
68
        case state::num5: goto do_num5;
2142
29
        case state::num6: goto do_num6;
2143
13
        case state::num7: goto do_num7;
2144
0
        case state::num8: goto do_num8;
2145
42
        case state::exp1: goto do_exp1;
2146
35
        case state::exp2: goto do_exp2;
2147
64
        case state::exp3: goto do_exp3;
2148
360
        }
2149
360
    }
2150
2151
    //----------------------------------
2152
    //
2153
    // DIGIT
2154
    // first digit
2155
    //
2156
16
do_num1:
2157
16
    if(zero_first || nonzero_first ||
2158
16
        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
16
    else
2196
16
    {
2197
16
        if(BOOST_JSON_UNLIKELY(
2198
16
            ! h_.on_number_part(
2199
16
                {begin, cs.used(begin)}, ec_)))
2200
0
            return fail(cs.begin());
2201
2202
16
        BOOST_IF_CONSTEXPR( precise_parsing )
2203
16
            num_buf_.append( begin, cs.used(begin) );
2204
16
        return maybe_suspend(
2205
16
            cs.begin(), state::num1, num);
2206
16
    }
2207
2208
    //----------------------------------
2209
    //
2210
    // 1*DIGIT
2211
    // significant digits left of decimal
2212
    //
2213
93
do_num2:
2214
93
    if(negative || (!stack_empty && num.neg))
2215
26
    {
2216
26
        for(;;)
2217
26
        {
2218
26
            if(BOOST_JSON_UNLIKELY(! cs))
2219
26
            {
2220
26
                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
26
                goto finish_int;
2232
26
            }
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
26
    }
2249
67
    else
2250
67
    {
2251
67
        for(;;)
2252
67
        {
2253
67
            if(BOOST_JSON_UNLIKELY(! cs))
2254
67
            {
2255
67
                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
67
                goto finish_int;
2267
67
            }
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
67
    }
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
68
do_num5:
2384
68
    for(;;)
2385
68
    {
2386
68
        if(BOOST_JSON_UNLIKELY(! cs))
2387
68
        {
2388
68
            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
68
            goto finish_dub;
2400
68
        }
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
29
do_num6:
2423
29
    {
2424
29
        if(BOOST_JSON_UNLIKELY(! cs))
2425
29
        {
2426
29
            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
29
            goto finish_int;
2438
29
        }
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
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
42
do_exp1:
2555
42
    if(BOOST_JSON_UNLIKELY(! cs))
2556
42
    {
2557
42
        if(BOOST_JSON_UNLIKELY(
2558
42
            ! h_.on_number_part(
2559
42
                {begin, cs.used(begin)}, ec_)))
2560
0
            return fail(cs.begin());
2561
2562
42
        BOOST_IF_CONSTEXPR( precise_parsing )
2563
42
            num_buf_.append( begin, cs.used(begin) );
2564
42
        return maybe_suspend(
2565
42
            cs.begin(), state::exp1, num);
2566
42
    }
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
35
do_exp2:
2583
35
    {
2584
35
        if(BOOST_JSON_UNLIKELY(! cs))
2585
35
        {
2586
35
            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
35
            BOOST_STATIC_CONSTEXPR source_location loc
2599
35
                = BOOST_CURRENT_LOCATION;
2600
35
            return fail(cs.begin(), error::syntax, &loc);
2601
35
        }
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
64
do_exp3:
2621
64
    for(;;)
2622
64
    {
2623
64
        if(BOOST_JSON_UNLIKELY(! cs))
2624
64
        {
2625
64
            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
64
        }
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
64
        BOOST_ASSERT(num.exp >= 0);
2656
64
        if ( num.frac )
2657
10
        {
2658
10
            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
10
        }
2678
54
        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
64
        goto finish_dub;
2698
64
    }
2699
2700
122
finish_int:
2701
122
    if(negative || (!stack_empty && num.neg))
2702
32
    {
2703
32
        if(BOOST_JSON_UNLIKELY(
2704
32
            ! h_.on_int64(static_cast<
2705
32
                int64_t>(~num.mant + 1), {begin, cs.used(begin)}, ec_)))
2706
0
            return fail(cs.begin());
2707
32
        return cs.begin();
2708
32
    }
2709
90
    if(num.mant <= INT64_MAX)
2710
90
    {
2711
90
finish_signed:
2712
90
        if(BOOST_JSON_UNLIKELY(
2713
90
            ! h_.on_int64(static_cast<
2714
90
                int64_t>(num.mant), {begin, cs.used(begin)}, ec_)))
2715
0
            return fail(cs.begin());
2716
90
        return cs.begin();
2717
90
    }
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
132
finish_dub:
2723
132
    double d;
2724
132
    std::size_t const size = cs.used(begin);
2725
132
    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
132
    else BOOST_IF_CONSTEXPR( no_parsing )
2745
132
        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
132
    if(BOOST_JSON_UNLIKELY(
2753
132
        ! h_.on_double(d, {begin, size}, ec_)))
2754
0
        return fail(cs.begin());
2755
132
    return cs.begin();
2756
132
}
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
16.1k
    : h_(std::forward<Args>(args)...)
2767
16.1k
    , opt_(opt)
2768
16.1k
{
2769
16.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
6.88k
    : h_(std::forward<Args>(args)...)
2767
6.88k
    , opt_(opt)
2768
6.88k
{
2769
6.88k
}
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
9.27k
    : h_(std::forward<Args>(args)...)
2767
9.27k
    , opt_(opt)
2768
9.27k
{
2769
9.27k
}
2770
2771
//----------------------------------------------------------
2772
2773
template<class Handler>
2774
void
2775
basic_parser<Handler>::
2776
reset() noexcept
2777
23.6k
{
2778
23.6k
    ec_ = {};
2779
23.6k
    st_.clear();
2780
23.6k
    more_ = true;
2781
23.6k
    done_ = false;
2782
23.6k
    clean_ = true;
2783
23.6k
    num_buf_.clear();
2784
23.6k
}
2785
2786
template<class Handler>
2787
void
2788
basic_parser<Handler>::
2789
fail(system::error_code ec) noexcept
2790
2.04k
{
2791
2.04k
    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.04k
    else
2798
2.04k
    {
2799
2.04k
        ec_ = ec;
2800
2.04k
    }
2801
2.04k
    done_ = false;
2802
2.04k
}
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
26.9k
{
2815
    // see if we exited via exception
2816
    // on the last call to write_some
2817
26.9k
    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
26.9k
    if(ec_)
2826
0
    {
2827
        // error is sticky
2828
0
        ec = ec_;
2829
0
        return 0;
2830
0
    }
2831
26.9k
    clean_ = false;
2832
26.9k
    more_ = more;
2833
26.9k
    end_ = data + size;
2834
26.9k
    const char* p;
2835
26.9k
    if(BOOST_JSON_LIKELY(st_.empty()))
2836
16.1k
    {
2837
        // first time
2838
16.1k
        depth_ = opt_.max_depth;
2839
16.1k
        if(BOOST_JSON_UNLIKELY(
2840
16.1k
            ! h_.on_document_begin(ec_)))
2841
0
        {
2842
0
            ec = ec_;
2843
0
            return 0;
2844
0
        }
2845
16.1k
        p = parse_document(data, std::true_type());
2846
16.1k
    }
2847
10.7k
    else
2848
10.7k
    {
2849
10.7k
        p = parse_document(data, std::false_type());
2850
10.7k
    }
2851
2852
26.9k
    if(BOOST_JSON_LIKELY(p != sentinel()))
2853
9.30k
    {
2854
9.30k
        BOOST_ASSERT(! ec_);
2855
9.30k
        if(! done_)
2856
7.35k
        {
2857
7.35k
            done_ = true;
2858
7.35k
            h_.on_document_end(ec_);
2859
7.35k
        }
2860
9.30k
    }
2861
17.6k
    else
2862
17.6k
    {
2863
17.6k
        if(! ec_)
2864
14.0k
        {
2865
14.0k
            if(! more_)
2866
3.28k
            {
2867
3.28k
                BOOST_JSON_FAIL(ec_, error::incomplete);
2868
3.28k
            }
2869
10.7k
            else if(! st_.empty())
2870
10.7k
            {
2871
                // consume as much trailing whitespace in
2872
                // the JSON document as possible, but still
2873
                // consider the parse complete
2874
10.7k
                state st;
2875
10.7k
                st_.peek(st);
2876
10.7k
                if( st == state::doc3 &&
2877
10.7k
                    ! done_)
2878
1.95k
                {
2879
1.95k
                    done_ = true;
2880
1.95k
                    h_.on_document_end(ec_);
2881
1.95k
                }
2882
10.7k
            }
2883
14.0k
        }
2884
17.6k
        p = end_;
2885
17.6k
    }
2886
26.9k
    ec = ec_;
2887
26.9k
    clean_ = true;
2888
26.9k
    return p - data;
2889
26.9k
}
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