100.00% Lines (1655/1655)
100.00% Functions (34/34)
| TLA | Baseline | Branch | ||||||
|---|---|---|---|---|---|---|---|---|
| Line | Hits | Code | Line | Hits | Code | |||
| 1 | // | 1 | // | |||||
| 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) | 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) | |||||
| 3 | // Copyright (c) 2020 Krystian Stasiowski (sdkrystian@gmail.com) | 3 | // Copyright (c) 2020 Krystian Stasiowski (sdkrystian@gmail.com) | |||||
| 4 | // | 4 | // | |||||
| 5 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | 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) | 6 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |||||
| 7 | // | 7 | // | |||||
| 8 | // Official repository: https://github.com/boostorg/json | 8 | // Official repository: https://github.com/boostorg/json | |||||
| 9 | // | 9 | // | |||||
| 10 | 10 | |||||||
| 11 | #ifndef BOOST_JSON_BASIC_PARSER_IMPL_HPP | 11 | #ifndef BOOST_JSON_BASIC_PARSER_IMPL_HPP | |||||
| 12 | #define BOOST_JSON_BASIC_PARSER_IMPL_HPP | 12 | #define BOOST_JSON_BASIC_PARSER_IMPL_HPP | |||||
| 13 | 13 | |||||||
| 14 | #include <boost/json/detail/config.hpp> | 14 | #include <boost/json/detail/config.hpp> | |||||
| 15 | #include <boost/json/detail/literals.hpp> | 15 | #include <boost/json/detail/literals.hpp> | |||||
| 16 | #include <boost/json/basic_parser.hpp> | 16 | #include <boost/json/basic_parser.hpp> | |||||
| 17 | #include <boost/json/error.hpp> | 17 | #include <boost/json/error.hpp> | |||||
| 18 | #include <boost/json/detail/buffer.hpp> | 18 | #include <boost/json/detail/buffer.hpp> | |||||
| 19 | #include <boost/json/detail/charconv/from_chars.hpp> | 19 | #include <boost/json/detail/charconv/from_chars.hpp> | |||||
| 20 | #include <boost/json/detail/sse2.hpp> | 20 | #include <boost/json/detail/sse2.hpp> | |||||
| 21 | #include <boost/mp11/algorithm.hpp> | 21 | #include <boost/mp11/algorithm.hpp> | |||||
| 22 | #include <boost/mp11/integral.hpp> | 22 | #include <boost/mp11/integral.hpp> | |||||
| 23 | #include <cmath> | 23 | #include <cmath> | |||||
| 24 | #include <limits> | 24 | #include <limits> | |||||
| 25 | #include <cstring> | 25 | #include <cstring> | |||||
| 26 | 26 | |||||||
| 27 | #ifdef _MSC_VER | 27 | #ifdef _MSC_VER | |||||
| 28 | #pragma warning(push) | 28 | #pragma warning(push) | |||||
| 29 | #pragma warning(disable: 4702) // unreachable code | 29 | #pragma warning(disable: 4702) // unreachable code | |||||
| 30 | #pragma warning(disable: 4127) // conditional expression is constant | 30 | #pragma warning(disable: 4127) // conditional expression is constant | |||||
| 31 | #endif | 31 | #endif | |||||
| 32 | 32 | |||||||
| 33 | /* This file must be manually included to get the | 33 | /* This file must be manually included to get the | |||||
| 34 | function template definitions for basic_parser. | 34 | function template definitions for basic_parser. | |||||
| 35 | */ | 35 | */ | |||||
| 36 | 36 | |||||||
| 37 | /* Reference: | 37 | /* Reference: | |||||
| 38 | 38 | |||||||
| 39 | https://www.json.org/ | 39 | https://www.json.org/ | |||||
| 40 | 40 | |||||||
| 41 | RFC 7159: The JavaScript Object Notation (JSON) Data Interchange Format | 41 | RFC 7159: The JavaScript Object Notation (JSON) Data Interchange Format | |||||
| 42 | https://tools.ietf.org/html/rfc7159 | 42 | https://tools.ietf.org/html/rfc7159 | |||||
| 43 | 43 | |||||||
| 44 | https://ampl.com/netlib/fp/dtoa.c | 44 | https://ampl.com/netlib/fp/dtoa.c | |||||
| 45 | */ | 45 | */ | |||||
| 46 | 46 | |||||||
| 47 | #ifndef BOOST_JSON_DOCS | 47 | #ifndef BOOST_JSON_DOCS | |||||
| 48 | 48 | |||||||
| 49 | namespace boost { | 49 | namespace boost { | |||||
| 50 | namespace json { | 50 | namespace json { | |||||
| 51 | namespace detail { | 51 | namespace detail { | |||||
| 52 | 52 | |||||||
| 53 | inline | 53 | inline | |||||
| 54 | double | 54 | double | |||||
| HITCBC | 55 | 1035607 | pow10(int exp) noexcept | 55 | 1027645 | pow10(int exp) noexcept | ||
| 56 | { | 56 | { | |||||
| 57 | static double const tab[618] = { | 57 | static double const tab[618] = { | |||||
| 58 | 1e-308, 1e-307, 1e-306, 1e-305, 1e-304, 1e-303, 1e-302, 1e-301, | 58 | 1e-308, 1e-307, 1e-306, 1e-305, 1e-304, 1e-303, 1e-302, 1e-301, | |||||
| 59 | 59 | |||||||
| 60 | 1e-300, 1e-299, 1e-298, 1e-297, 1e-296, 1e-295, 1e-294, 1e-293, 1e-292, 1e-291, | 60 | 1e-300, 1e-299, 1e-298, 1e-297, 1e-296, 1e-295, 1e-294, 1e-293, 1e-292, 1e-291, | |||||
| 61 | 1e-290, 1e-289, 1e-288, 1e-287, 1e-286, 1e-285, 1e-284, 1e-283, 1e-282, 1e-281, | 61 | 1e-290, 1e-289, 1e-288, 1e-287, 1e-286, 1e-285, 1e-284, 1e-283, 1e-282, 1e-281, | |||||
| 62 | 1e-280, 1e-279, 1e-278, 1e-277, 1e-276, 1e-275, 1e-274, 1e-273, 1e-272, 1e-271, | 62 | 1e-280, 1e-279, 1e-278, 1e-277, 1e-276, 1e-275, 1e-274, 1e-273, 1e-272, 1e-271, | |||||
| 63 | 1e-270, 1e-269, 1e-268, 1e-267, 1e-266, 1e-265, 1e-264, 1e-263, 1e-262, 1e-261, | 63 | 1e-270, 1e-269, 1e-268, 1e-267, 1e-266, 1e-265, 1e-264, 1e-263, 1e-262, 1e-261, | |||||
| 64 | 1e-260, 1e-259, 1e-258, 1e-257, 1e-256, 1e-255, 1e-254, 1e-253, 1e-252, 1e-251, | 64 | 1e-260, 1e-259, 1e-258, 1e-257, 1e-256, 1e-255, 1e-254, 1e-253, 1e-252, 1e-251, | |||||
| 65 | 1e-250, 1e-249, 1e-248, 1e-247, 1e-246, 1e-245, 1e-244, 1e-243, 1e-242, 1e-241, | 65 | 1e-250, 1e-249, 1e-248, 1e-247, 1e-246, 1e-245, 1e-244, 1e-243, 1e-242, 1e-241, | |||||
| 66 | 1e-240, 1e-239, 1e-238, 1e-237, 1e-236, 1e-235, 1e-234, 1e-233, 1e-232, 1e-231, | 66 | 1e-240, 1e-239, 1e-238, 1e-237, 1e-236, 1e-235, 1e-234, 1e-233, 1e-232, 1e-231, | |||||
| 67 | 1e-230, 1e-229, 1e-228, 1e-227, 1e-226, 1e-225, 1e-224, 1e-223, 1e-222, 1e-221, | 67 | 1e-230, 1e-229, 1e-228, 1e-227, 1e-226, 1e-225, 1e-224, 1e-223, 1e-222, 1e-221, | |||||
| 68 | 1e-220, 1e-219, 1e-218, 1e-217, 1e-216, 1e-215, 1e-214, 1e-213, 1e-212, 1e-211, | 68 | 1e-220, 1e-219, 1e-218, 1e-217, 1e-216, 1e-215, 1e-214, 1e-213, 1e-212, 1e-211, | |||||
| 69 | 1e-210, 1e-209, 1e-208, 1e-207, 1e-206, 1e-205, 1e-204, 1e-203, 1e-202, 1e-201, | 69 | 1e-210, 1e-209, 1e-208, 1e-207, 1e-206, 1e-205, 1e-204, 1e-203, 1e-202, 1e-201, | |||||
| 70 | 70 | |||||||
| 71 | 1e-200, 1e-199, 1e-198, 1e-197, 1e-196, 1e-195, 1e-194, 1e-193, 1e-192, 1e-191, | 71 | 1e-200, 1e-199, 1e-198, 1e-197, 1e-196, 1e-195, 1e-194, 1e-193, 1e-192, 1e-191, | |||||
| 72 | 1e-190, 1e-189, 1e-188, 1e-187, 1e-186, 1e-185, 1e-184, 1e-183, 1e-182, 1e-181, | 72 | 1e-190, 1e-189, 1e-188, 1e-187, 1e-186, 1e-185, 1e-184, 1e-183, 1e-182, 1e-181, | |||||
| 73 | 1e-180, 1e-179, 1e-178, 1e-177, 1e-176, 1e-175, 1e-174, 1e-173, 1e-172, 1e-171, | 73 | 1e-180, 1e-179, 1e-178, 1e-177, 1e-176, 1e-175, 1e-174, 1e-173, 1e-172, 1e-171, | |||||
| 74 | 1e-170, 1e-169, 1e-168, 1e-167, 1e-166, 1e-165, 1e-164, 1e-163, 1e-162, 1e-161, | 74 | 1e-170, 1e-169, 1e-168, 1e-167, 1e-166, 1e-165, 1e-164, 1e-163, 1e-162, 1e-161, | |||||
| 75 | 1e-160, 1e-159, 1e-158, 1e-157, 1e-156, 1e-155, 1e-154, 1e-153, 1e-152, 1e-151, | 75 | 1e-160, 1e-159, 1e-158, 1e-157, 1e-156, 1e-155, 1e-154, 1e-153, 1e-152, 1e-151, | |||||
| 76 | 1e-150, 1e-149, 1e-148, 1e-147, 1e-146, 1e-145, 1e-144, 1e-143, 1e-142, 1e-141, | 76 | 1e-150, 1e-149, 1e-148, 1e-147, 1e-146, 1e-145, 1e-144, 1e-143, 1e-142, 1e-141, | |||||
| 77 | 1e-140, 1e-139, 1e-138, 1e-137, 1e-136, 1e-135, 1e-134, 1e-133, 1e-132, 1e-131, | 77 | 1e-140, 1e-139, 1e-138, 1e-137, 1e-136, 1e-135, 1e-134, 1e-133, 1e-132, 1e-131, | |||||
| 78 | 1e-130, 1e-129, 1e-128, 1e-127, 1e-126, 1e-125, 1e-124, 1e-123, 1e-122, 1e-121, | 78 | 1e-130, 1e-129, 1e-128, 1e-127, 1e-126, 1e-125, 1e-124, 1e-123, 1e-122, 1e-121, | |||||
| 79 | 1e-120, 1e-119, 1e-118, 1e-117, 1e-116, 1e-115, 1e-114, 1e-113, 1e-112, 1e-111, | 79 | 1e-120, 1e-119, 1e-118, 1e-117, 1e-116, 1e-115, 1e-114, 1e-113, 1e-112, 1e-111, | |||||
| 80 | 1e-110, 1e-109, 1e-108, 1e-107, 1e-106, 1e-105, 1e-104, 1e-103, 1e-102, 1e-101, | 80 | 1e-110, 1e-109, 1e-108, 1e-107, 1e-106, 1e-105, 1e-104, 1e-103, 1e-102, 1e-101, | |||||
| 81 | 81 | |||||||
| 82 | 1e-100, 1e-099, 1e-098, 1e-097, 1e-096, 1e-095, 1e-094, 1e-093, 1e-092, 1e-091, | 82 | 1e-100, 1e-099, 1e-098, 1e-097, 1e-096, 1e-095, 1e-094, 1e-093, 1e-092, 1e-091, | |||||
| 83 | 1e-090, 1e-089, 1e-088, 1e-087, 1e-086, 1e-085, 1e-084, 1e-083, 1e-082, 1e-081, | 83 | 1e-090, 1e-089, 1e-088, 1e-087, 1e-086, 1e-085, 1e-084, 1e-083, 1e-082, 1e-081, | |||||
| 84 | 1e-080, 1e-079, 1e-078, 1e-077, 1e-076, 1e-075, 1e-074, 1e-073, 1e-072, 1e-071, | 84 | 1e-080, 1e-079, 1e-078, 1e-077, 1e-076, 1e-075, 1e-074, 1e-073, 1e-072, 1e-071, | |||||
| 85 | 1e-070, 1e-069, 1e-068, 1e-067, 1e-066, 1e-065, 1e-064, 1e-063, 1e-062, 1e-061, | 85 | 1e-070, 1e-069, 1e-068, 1e-067, 1e-066, 1e-065, 1e-064, 1e-063, 1e-062, 1e-061, | |||||
| 86 | 1e-060, 1e-059, 1e-058, 1e-057, 1e-056, 1e-055, 1e-054, 1e-053, 1e-052, 1e-051, | 86 | 1e-060, 1e-059, 1e-058, 1e-057, 1e-056, 1e-055, 1e-054, 1e-053, 1e-052, 1e-051, | |||||
| 87 | 1e-050, 1e-049, 1e-048, 1e-047, 1e-046, 1e-045, 1e-044, 1e-043, 1e-042, 1e-041, | 87 | 1e-050, 1e-049, 1e-048, 1e-047, 1e-046, 1e-045, 1e-044, 1e-043, 1e-042, 1e-041, | |||||
| 88 | 1e-040, 1e-039, 1e-038, 1e-037, 1e-036, 1e-035, 1e-034, 1e-033, 1e-032, 1e-031, | 88 | 1e-040, 1e-039, 1e-038, 1e-037, 1e-036, 1e-035, 1e-034, 1e-033, 1e-032, 1e-031, | |||||
| 89 | 1e-030, 1e-029, 1e-028, 1e-027, 1e-026, 1e-025, 1e-024, 1e-023, 1e-022, 1e-021, | 89 | 1e-030, 1e-029, 1e-028, 1e-027, 1e-026, 1e-025, 1e-024, 1e-023, 1e-022, 1e-021, | |||||
| 90 | 1e-020, 1e-019, 1e-018, 1e-017, 1e-016, 1e-015, 1e-014, 1e-013, 1e-012, 1e-011, | 90 | 1e-020, 1e-019, 1e-018, 1e-017, 1e-016, 1e-015, 1e-014, 1e-013, 1e-012, 1e-011, | |||||
| 91 | 1e-010, 1e-009, 1e-008, 1e-007, 1e-006, 1e-005, 1e-004, 1e-003, 1e-002, 1e-001, | 91 | 1e-010, 1e-009, 1e-008, 1e-007, 1e-006, 1e-005, 1e-004, 1e-003, 1e-002, 1e-001, | |||||
| 92 | 92 | |||||||
| 93 | 1e+000, 1e+001, 1e+002, 1e+003, 1e+004, 1e+005, 1e+006, 1e+007, 1e+008, 1e+009, | 93 | 1e+000, 1e+001, 1e+002, 1e+003, 1e+004, 1e+005, 1e+006, 1e+007, 1e+008, 1e+009, | |||||
| 94 | 1e+010, 1e+011, 1e+012, 1e+013, 1e+014, 1e+015, 1e+016, 1e+017, 1e+018, 1e+019, | 94 | 1e+010, 1e+011, 1e+012, 1e+013, 1e+014, 1e+015, 1e+016, 1e+017, 1e+018, 1e+019, | |||||
| 95 | 1e+020, 1e+021, 1e+022, 1e+023, 1e+024, 1e+025, 1e+026, 1e+027, 1e+028, 1e+029, | 95 | 1e+020, 1e+021, 1e+022, 1e+023, 1e+024, 1e+025, 1e+026, 1e+027, 1e+028, 1e+029, | |||||
| 96 | 1e+030, 1e+031, 1e+032, 1e+033, 1e+034, 1e+035, 1e+036, 1e+037, 1e+038, 1e+039, | 96 | 1e+030, 1e+031, 1e+032, 1e+033, 1e+034, 1e+035, 1e+036, 1e+037, 1e+038, 1e+039, | |||||
| 97 | 1e+040, 1e+041, 1e+042, 1e+043, 1e+044, 1e+045, 1e+046, 1e+047, 1e+048, 1e+049, | 97 | 1e+040, 1e+041, 1e+042, 1e+043, 1e+044, 1e+045, 1e+046, 1e+047, 1e+048, 1e+049, | |||||
| 98 | 1e+050, 1e+051, 1e+052, 1e+053, 1e+054, 1e+055, 1e+056, 1e+057, 1e+058, 1e+059, | 98 | 1e+050, 1e+051, 1e+052, 1e+053, 1e+054, 1e+055, 1e+056, 1e+057, 1e+058, 1e+059, | |||||
| 99 | 1e+060, 1e+061, 1e+062, 1e+063, 1e+064, 1e+065, 1e+066, 1e+067, 1e+068, 1e+069, | 99 | 1e+060, 1e+061, 1e+062, 1e+063, 1e+064, 1e+065, 1e+066, 1e+067, 1e+068, 1e+069, | |||||
| 100 | 1e+070, 1e+071, 1e+072, 1e+073, 1e+074, 1e+075, 1e+076, 1e+077, 1e+078, 1e+079, | 100 | 1e+070, 1e+071, 1e+072, 1e+073, 1e+074, 1e+075, 1e+076, 1e+077, 1e+078, 1e+079, | |||||
| 101 | 1e+080, 1e+081, 1e+082, 1e+083, 1e+084, 1e+085, 1e+086, 1e+087, 1e+088, 1e+089, | 101 | 1e+080, 1e+081, 1e+082, 1e+083, 1e+084, 1e+085, 1e+086, 1e+087, 1e+088, 1e+089, | |||||
| 102 | 1e+090, 1e+091, 1e+092, 1e+093, 1e+094, 1e+095, 1e+096, 1e+097, 1e+098, 1e+099, | 102 | 1e+090, 1e+091, 1e+092, 1e+093, 1e+094, 1e+095, 1e+096, 1e+097, 1e+098, 1e+099, | |||||
| 103 | 103 | |||||||
| 104 | 1e+100, 1e+101, 1e+102, 1e+103, 1e+104, 1e+105, 1e+106, 1e+107, 1e+108, 1e+109, | 104 | 1e+100, 1e+101, 1e+102, 1e+103, 1e+104, 1e+105, 1e+106, 1e+107, 1e+108, 1e+109, | |||||
| 105 | 1e+110, 1e+111, 1e+112, 1e+113, 1e+114, 1e+115, 1e+116, 1e+117, 1e+118, 1e+119, | 105 | 1e+110, 1e+111, 1e+112, 1e+113, 1e+114, 1e+115, 1e+116, 1e+117, 1e+118, 1e+119, | |||||
| 106 | 1e+120, 1e+121, 1e+122, 1e+123, 1e+124, 1e+125, 1e+126, 1e+127, 1e+128, 1e+129, | 106 | 1e+120, 1e+121, 1e+122, 1e+123, 1e+124, 1e+125, 1e+126, 1e+127, 1e+128, 1e+129, | |||||
| 107 | 1e+130, 1e+131, 1e+132, 1e+133, 1e+134, 1e+135, 1e+136, 1e+137, 1e+138, 1e+139, | 107 | 1e+130, 1e+131, 1e+132, 1e+133, 1e+134, 1e+135, 1e+136, 1e+137, 1e+138, 1e+139, | |||||
| 108 | 1e+140, 1e+141, 1e+142, 1e+143, 1e+144, 1e+145, 1e+146, 1e+147, 1e+148, 1e+149, | 108 | 1e+140, 1e+141, 1e+142, 1e+143, 1e+144, 1e+145, 1e+146, 1e+147, 1e+148, 1e+149, | |||||
| 109 | 1e+150, 1e+151, 1e+152, 1e+153, 1e+154, 1e+155, 1e+156, 1e+157, 1e+158, 1e+159, | 109 | 1e+150, 1e+151, 1e+152, 1e+153, 1e+154, 1e+155, 1e+156, 1e+157, 1e+158, 1e+159, | |||||
| 110 | 1e+160, 1e+161, 1e+162, 1e+163, 1e+164, 1e+165, 1e+166, 1e+167, 1e+168, 1e+169, | 110 | 1e+160, 1e+161, 1e+162, 1e+163, 1e+164, 1e+165, 1e+166, 1e+167, 1e+168, 1e+169, | |||||
| 111 | 1e+170, 1e+171, 1e+172, 1e+173, 1e+174, 1e+175, 1e+176, 1e+177, 1e+178, 1e+179, | 111 | 1e+170, 1e+171, 1e+172, 1e+173, 1e+174, 1e+175, 1e+176, 1e+177, 1e+178, 1e+179, | |||||
| 112 | 1e+180, 1e+181, 1e+182, 1e+183, 1e+184, 1e+185, 1e+186, 1e+187, 1e+188, 1e+189, | 112 | 1e+180, 1e+181, 1e+182, 1e+183, 1e+184, 1e+185, 1e+186, 1e+187, 1e+188, 1e+189, | |||||
| 113 | 1e+190, 1e+191, 1e+192, 1e+193, 1e+194, 1e+195, 1e+196, 1e+197, 1e+198, 1e+199, | 113 | 1e+190, 1e+191, 1e+192, 1e+193, 1e+194, 1e+195, 1e+196, 1e+197, 1e+198, 1e+199, | |||||
| 114 | 114 | |||||||
| 115 | 1e+200, 1e+201, 1e+202, 1e+203, 1e+204, 1e+205, 1e+206, 1e+207, 1e+208, 1e+209, | 115 | 1e+200, 1e+201, 1e+202, 1e+203, 1e+204, 1e+205, 1e+206, 1e+207, 1e+208, 1e+209, | |||||
| 116 | 1e+210, 1e+211, 1e+212, 1e+213, 1e+214, 1e+215, 1e+216, 1e+217, 1e+218, 1e+219, | 116 | 1e+210, 1e+211, 1e+212, 1e+213, 1e+214, 1e+215, 1e+216, 1e+217, 1e+218, 1e+219, | |||||
| 117 | 1e+220, 1e+221, 1e+222, 1e+223, 1e+224, 1e+225, 1e+226, 1e+227, 1e+228, 1e+229, | 117 | 1e+220, 1e+221, 1e+222, 1e+223, 1e+224, 1e+225, 1e+226, 1e+227, 1e+228, 1e+229, | |||||
| 118 | 1e+230, 1e+231, 1e+232, 1e+233, 1e+234, 1e+235, 1e+236, 1e+237, 1e+238, 1e+239, | 118 | 1e+230, 1e+231, 1e+232, 1e+233, 1e+234, 1e+235, 1e+236, 1e+237, 1e+238, 1e+239, | |||||
| 119 | 1e+240, 1e+241, 1e+242, 1e+243, 1e+244, 1e+245, 1e+246, 1e+247, 1e+248, 1e+249, | 119 | 1e+240, 1e+241, 1e+242, 1e+243, 1e+244, 1e+245, 1e+246, 1e+247, 1e+248, 1e+249, | |||||
| 120 | 1e+250, 1e+251, 1e+252, 1e+253, 1e+254, 1e+255, 1e+256, 1e+257, 1e+258, 1e+259, | 120 | 1e+250, 1e+251, 1e+252, 1e+253, 1e+254, 1e+255, 1e+256, 1e+257, 1e+258, 1e+259, | |||||
| 121 | 1e+260, 1e+261, 1e+262, 1e+263, 1e+264, 1e+265, 1e+266, 1e+267, 1e+268, 1e+269, | 121 | 1e+260, 1e+261, 1e+262, 1e+263, 1e+264, 1e+265, 1e+266, 1e+267, 1e+268, 1e+269, | |||||
| 122 | 1e+270, 1e+271, 1e+272, 1e+273, 1e+274, 1e+275, 1e+276, 1e+277, 1e+278, 1e+279, | 122 | 1e+270, 1e+271, 1e+272, 1e+273, 1e+274, 1e+275, 1e+276, 1e+277, 1e+278, 1e+279, | |||||
| 123 | 1e+280, 1e+281, 1e+282, 1e+283, 1e+284, 1e+285, 1e+286, 1e+287, 1e+288, 1e+289, | 123 | 1e+280, 1e+281, 1e+282, 1e+283, 1e+284, 1e+285, 1e+286, 1e+287, 1e+288, 1e+289, | |||||
| 124 | 1e+290, 1e+291, 1e+292, 1e+293, 1e+294, 1e+295, 1e+296, 1e+297, 1e+298, 1e+299, | 124 | 1e+290, 1e+291, 1e+292, 1e+293, 1e+294, 1e+295, 1e+296, 1e+297, 1e+298, 1e+299, | |||||
| 125 | 125 | |||||||
| 126 | 1e+300, 1e+301, 1e+302, 1e+303, 1e+304, 1e+305, 1e+306, 1e+307, 1e+308 }; | 126 | 1e+300, 1e+301, 1e+302, 1e+303, 1e+304, 1e+305, 1e+306, 1e+307, 1e+308 }; | |||||
| 127 | 127 | |||||||
| HITCBC | 128 | 1035607 | if( exp > 308 ) | 128 | 1027645 | if( exp > 308 ) | ||
| 129 | { | 129 | { | |||||
| HITCBC | 130 | 455 | return std::numeric_limits<double>::infinity(); | 130 | 455 | return std::numeric_limits<double>::infinity(); | ||
| 131 | } | 131 | } | |||||
| HITCBC | 132 | 1035152 | else if( exp < -308 ) | 132 | 1027190 | else if( exp < -308 ) | ||
| 133 | { | 133 | { | |||||
| 134 | // due to the way pow10 is used by dec_to_float, | 134 | // due to the way pow10 is used by dec_to_float, | |||||
| 135 | // we can afford to return 0.0 here | 135 | // we can afford to return 0.0 here | |||||
| HITCBC | 136 | 151 | return 0.0; | 136 | 151 | return 0.0; | ||
| 137 | } | 137 | } | |||||
| 138 | else | 138 | else | |||||
| 139 | { | 139 | { | |||||
| HITCBC | 140 | 1035001 | exp += 308; | 140 | 1027039 | exp += 308; | ||
| HITCBC | 141 | 1035001 | BOOST_ASSERT(exp >= 0 && exp < 618); | 141 | 1027039 | BOOST_ASSERT(exp >= 0 && exp < 618); | ||
| HITCBC | 142 | 1035001 | return tab[exp]; | 142 | 1027039 | return tab[exp]; | ||
| 143 | } | 143 | } | |||||
| 144 | } | 144 | } | |||||
| 145 | 145 | |||||||
| 146 | inline | 146 | inline | |||||
| 147 | double | 147 | double | |||||
| HITCBC | 148 | 1043157 | dec_to_float( | 148 | 1033899 | dec_to_float( | ||
| 149 | std::uint64_t m, | 149 | std::uint64_t m, | |||||
| 150 | std::int32_t e, | 150 | std::int32_t e, | |||||
| 151 | bool neg) noexcept | 151 | bool neg) noexcept | |||||
| 152 | { | 152 | { | |||||
| 153 | // convert to double explicitly to silence warnings | 153 | // convert to double explicitly to silence warnings | |||||
| HITCBC | 154 | 1043157 | double x = static_cast<double>(m); | 154 | 1033899 | double x = static_cast<double>(m); | ||
| HITCBC | 155 | 1043157 | if(neg) | 155 | 1033899 | if(neg) | ||
| HITCBC | 156 | 17069 | x = -x; | 156 | 13171 | x = -x; | ||
| 157 | 157 | |||||||
| 158 | // pow10 returns infinity for large exponents, | 158 | // pow10 returns infinity for large exponents, | |||||
| 159 | // and zero times infinity is NaN | 159 | // and zero times infinity is NaN | |||||
| HITCBC | 160 | 1043157 | if(m == 0) | 160 | 1033899 | if(m == 0) | ||
| HITCBC | 161 | 7550 | return x; | 161 | 6254 | return x; | ||
| 162 | 162 | |||||||
| HITCBC | 163 | 1035607 | if(e < -305) | 163 | 1027645 | if(e < -305) | ||
| 164 | { | 164 | { | |||||
| HITCBC | 165 | 5269 | x *= 1e-305 ; | 165 | 5187 | x *= 1e-305 ; | ||
| HITCBC | 166 | 5269 | e += 305; | 166 | 5187 | e += 305; | ||
| 167 | } | 167 | } | |||||
| 168 | 168 | |||||||
| HITCBC | 169 | 1035607 | if(e >= -22 && e < 0) | 169 | 1027645 | if(e >= -22 && e < 0) | ||
| HITCBC | 170 | 57637 | return x / pow10(-e); | 170 | 53321 | return x / pow10(-e); | ||
| 171 | 171 | |||||||
| HITCBC | 172 | 977970 | return x * pow10(e); | 172 | 974324 | return x * pow10(e); | ||
| 173 | } | 173 | } | |||||
| 174 | 174 | |||||||
| 175 | inline | 175 | inline | |||||
| 176 | bool | 176 | bool | |||||
| 177 | is_control(char c) noexcept | 177 | is_control(char c) noexcept | |||||
| 178 | { | 178 | { | |||||
| 179 | return static_cast<unsigned char>(c) < 32; | 179 | return static_cast<unsigned char>(c) < 32; | |||||
| 180 | } | 180 | } | |||||
| 181 | 181 | |||||||
| 182 | inline | 182 | inline | |||||
| 183 | int | 183 | int | |||||
| HITCBC | 184 | 66931 | hex_digit(unsigned char c) noexcept | 184 | 66931 | hex_digit(unsigned char c) noexcept | ||
| 185 | { | 185 | { | |||||
| 186 | // by Peter Dimov | 186 | // by Peter Dimov | |||||
| HITCBC | 187 | 66931 | if( c >= '0' && c <= '9' ) | 187 | 66931 | if( c >= '0' && c <= '9' ) | ||
| HITCBC | 188 | 35759 | return c - '0'; | 188 | 35759 | return c - '0'; | ||
| HITCBC | 189 | 31172 | c &= ~0x20; | 189 | 31172 | c &= ~0x20; | ||
| HITCBC | 190 | 31172 | if( c >= 'A' && c <= 'F' ) | 190 | 31172 | if( c >= 'A' && c <= 'F' ) | ||
| HITCBC | 191 | 30562 | return 10 + c - 'A'; | 191 | 30562 | return 10 + c - 'A'; | ||
| HITCBC | 192 | 610 | return -1; | 192 | 610 | return -1; | ||
| 193 | } | 193 | } | |||||
| 194 | 194 | |||||||
| 195 | } // detail | 195 | } // detail | |||||
| 196 | 196 | |||||||
| 197 | //---------------------------------------------------------- | 197 | //---------------------------------------------------------- | |||||
| 198 | 198 | |||||||
| 199 | template< class Handler > | 199 | template< class Handler > | |||||
| 200 | template< bool StackEmpty_, char First_ > | 200 | template< bool StackEmpty_, char First_ > | |||||
| 201 | struct basic_parser<Handler>:: | 201 | struct basic_parser<Handler>:: | |||||
| 202 | parse_number_helper | 202 | parse_number_helper | |||||
| 203 | { | 203 | { | |||||
| 204 | + | template<number_precision N> | ||||||
| 205 | + | using index_t = mp11::mp_size_t<static_cast<std::size_t>(N)>; | ||||||
| 206 | + | |||||||
| 204 | basic_parser* parser; | 207 | basic_parser* parser; | |||||
| 205 | char const* p; | 208 | char const* p; | |||||
| 206 | - | template< std::size_t N > | ||||||
| 207 | 209 | |||||||
| 208 | char const* | 210 | char const* | |||||
| HITCBC | 209 | - | 10516087 | operator()( mp11::mp_size_t<N> ) const | 211 | + | 9483477 | operator()( index_t<number_precision::imprecise> ) const |
| 210 | { | 212 | { | |||||
| HITCBC | 211 | 21026669 | return parser->parse_number( | 213 | 18961450 | return parser->parse_number( | ||
| HITCBC | 212 | 10516087 | p, | 214 | 9483477 | p, | ||
| 213 | std::integral_constant<bool, StackEmpty_>(), | 215 | std::integral_constant<bool, StackEmpty_>(), | |||||
| HITGIC | 214 | - | std::integral_constant<char, First_>(), | 216 | + | 9477974 | std::integral_constant<char, First_>() ); | |
| 215 | - | std::integral_constant< | 217 | + | } | |||
| ECB | 216 | - | 10510583 | number_precision, static_cast<number_precision>(N)>() ); | 218 | + | ||
| 219 | + | char const* | ||||||
| HITGNC | 220 | + | 1040553 | operator()( index_t<number_precision::precise> ) const | ||||
| 221 | + | { | ||||||
| HITGNC | 222 | + | 2077655 | return parser->parse_number_precise( | ||||
| HITGNC | 223 | + | 1040553 | p, | ||||
| 224 | + | std::integral_constant<bool, StackEmpty_>(), | ||||||
| HITGNC | 225 | + | 1037102 | std::integral_constant<char, First_>() ); | ||||
| 226 | + | } | ||||||
| 227 | + | |||||||
| 228 | + | char const* | ||||||
| HITGNC | 229 | + | 40497 | operator()( index_t<number_precision::none> ) const | ||||
| 230 | + | { | ||||||
| HITGNC | 231 | + | 77544 | return parser->skip_number( | ||||
| HITGNC | 232 | + | 40497 | p, | ||||
| 233 | + | std::integral_constant<bool, StackEmpty_>(), | ||||||
| HITGNC | 234 | + | 37047 | std::integral_constant<char, First_>() ); | ||||
| 217 | } | 235 | } | |||||
| 218 | }; | 236 | }; | |||||
| 219 | 237 | |||||||
| 220 | //---------------------------------------------------------- | 238 | //---------------------------------------------------------- | |||||
| 221 | 239 | |||||||
| 222 | template<class Handler> | 240 | template<class Handler> | |||||
| 223 | void | 241 | void | |||||
| HITCBC | 224 | 8602650 | basic_parser<Handler>:: | 242 | 8627574 | basic_parser<Handler>:: | ||
| 225 | reserve() | 243 | reserve() | |||||
| 226 | { | 244 | { | |||||
| HITCBC | 227 | 8602650 | if(BOOST_JSON_LIKELY( | 245 | 8627574 | if(BOOST_JSON_LIKELY( | ||
| 228 | ! st_.empty())) | 246 | ! st_.empty())) | |||||
| HITCBC | 229 | 37573 | return; | 247 | 37573 | return; | ||
| 230 | // Reserve the largest stack we need, | 248 | // Reserve the largest stack we need, | |||||
| 231 | // to avoid reallocation during suspend. | 249 | // to avoid reallocation during suspend. | |||||
| HITCBC | 232 | 17130154 | st_.reserve( | 250 | 17180002 | st_.reserve( | ||
| 233 | sizeof(state) + // document parsing state | 251 | sizeof(state) + // document parsing state | |||||
| 234 | (sizeof(state) + | 252 | (sizeof(state) + | |||||
| HITCBC | 235 | 8565077 | sizeof(std::size_t)) * depth() + // array and object state + size | 253 | 8590001 | sizeof(std::size_t)) * depth() + // array and object state + size | ||
| 236 | sizeof(state) + // value parsing state | 254 | sizeof(state) + // value parsing state | |||||
| 237 | sizeof(std::size_t) + // string size | 255 | sizeof(std::size_t) + // string size | |||||
| 238 | sizeof(state)); // comment state | 256 | sizeof(state)); // comment state | |||||
| 239 | } | 257 | } | |||||
| 240 | 258 | |||||||
| 241 | //---------------------------------------------------------- | 259 | //---------------------------------------------------------- | |||||
| 242 | // | 260 | // | |||||
| 243 | // The sentinel value is returned by parse functions | 261 | // The sentinel value is returned by parse functions | |||||
| 244 | // to indicate that the parser failed, or suspended. | 262 | // to indicate that the parser failed, or suspended. | |||||
| 245 | // this is used as it is distinct from all valid values | 263 | // this is used as it is distinct from all valid values | |||||
| 246 | // for data in write | 264 | // for data in write | |||||
| 247 | 265 | |||||||
| 248 | template<class Handler> | 266 | template<class Handler> | |||||
| 249 | const char* | 267 | const char* | |||||
| HITCBC | 250 | 47302299 | basic_parser<Handler>:: | 268 | 47489407 | basic_parser<Handler>:: | ||
| 251 | sentinel() | 269 | sentinel() | |||||
| 252 | { | 270 | { | |||||
| 253 | // the "+1" ensures that the returned pointer is unique even if | 271 | // the "+1" ensures that the returned pointer is unique even if | |||||
| 254 | // the given input buffer borders on this object | 272 | // the given input buffer borders on this object | |||||
| 255 | return reinterpret_cast< | 273 | return reinterpret_cast< | |||||
| HITCBC | 256 | 47302299 | const char*>(this) + 1; | 274 | 47489407 | const char*>(this) + 1; | ||
| 257 | } | 275 | } | |||||
| 258 | 276 | |||||||
| 259 | template<class Handler> | 277 | template<class Handler> | |||||
| 260 | bool | 278 | bool | |||||
| HITCBC | 261 | 10852361 | basic_parser<Handler>:: | 279 | 10897335 | basic_parser<Handler>:: | ||
| 262 | incomplete( | 280 | incomplete( | |||||
| 263 | const detail::const_stream_wrapper& cs) | 281 | const detail::const_stream_wrapper& cs) | |||||
| 264 | { | 282 | { | |||||
| HITCBC | 265 | 10852361 | return cs.begin() == sentinel(); | 283 | 10897335 | return cs.begin() == sentinel(); | ||
| 266 | } | 284 | } | |||||
| 267 | 285 | |||||||
| 268 | //---------------------------------------------------------- | 286 | //---------------------------------------------------------- | |||||
| 269 | // | 287 | // | |||||
| 270 | // These functions are declared with the BOOST_NOINLINE | 288 | // These functions are declared with the BOOST_NOINLINE | |||||
| 271 | // attribute to avoid polluting the parsers hot-path. | 289 | // attribute to avoid polluting the parsers hot-path. | |||||
| 272 | // They return the canary value to indicate suspension | 290 | // They return the canary value to indicate suspension | |||||
| 273 | // or failure. | 291 | // or failure. | |||||
| 274 | 292 | |||||||
| 275 | template<class Handler> | 293 | template<class Handler> | |||||
| 276 | const char* | 294 | const char* | |||||
| 277 | basic_parser<Handler>:: | 295 | basic_parser<Handler>:: | |||||
| 278 | suspend_or_fail(state st) | 296 | suspend_or_fail(state st) | |||||
| 279 | { | 297 | { | |||||
| 280 | if(BOOST_JSON_LIKELY( | 298 | if(BOOST_JSON_LIKELY( | |||||
| 281 | ! ec_ && more_)) | 299 | ! ec_ && more_)) | |||||
| 282 | { | 300 | { | |||||
| 283 | // suspend | 301 | // suspend | |||||
| 284 | reserve(); | 302 | reserve(); | |||||
| 285 | st_.push_unchecked(st); | 303 | st_.push_unchecked(st); | |||||
| 286 | } | 304 | } | |||||
| 287 | return sentinel(); | 305 | return sentinel(); | |||||
| 288 | } | 306 | } | |||||
| 289 | 307 | |||||||
| 290 | template<class Handler> | 308 | template<class Handler> | |||||
| 291 | const char* | 309 | const char* | |||||
| HITCBC | 292 | 56215 | basic_parser<Handler>:: | 310 | 56215 | basic_parser<Handler>:: | ||
| 293 | suspend_or_fail( | 311 | suspend_or_fail( | |||||
| 294 | state st, | 312 | state st, | |||||
| 295 | std::size_t n) | 313 | std::size_t n) | |||||
| 296 | { | 314 | { | |||||
| HITCBC | 297 | 56215 | if(BOOST_JSON_LIKELY( | 315 | 56215 | if(BOOST_JSON_LIKELY( | ||
| 298 | ! ec_ && more_)) | 316 | ! ec_ && more_)) | |||||
| 299 | { | 317 | { | |||||
| 300 | // suspend | 318 | // suspend | |||||
| HITCBC | 301 | 35897 | reserve(); | 319 | 35897 | reserve(); | ||
| HITCBC | 302 | 35897 | st_.push_unchecked(n); | 320 | 35897 | st_.push_unchecked(n); | ||
| HITCBC | 303 | 35897 | st_.push_unchecked(st); | 321 | 35897 | st_.push_unchecked(st); | ||
| 304 | } | 322 | } | |||||
| HITCBC | 305 | 56215 | return sentinel(); | 323 | 56215 | return sentinel(); | ||
| 306 | } | 324 | } | |||||
| 307 | 325 | |||||||
| 308 | 326 | |||||||
| 309 | template<class Handler> | 327 | template<class Handler> | |||||
| 310 | const char* | 328 | const char* | |||||
| HITCBC | 311 | 19076 | basic_parser<Handler>:: | 329 | 26260 | basic_parser<Handler>:: | ||
| 312 | fail(const char* p) noexcept | 330 | fail(const char* p) noexcept | |||||
| 313 | { | 331 | { | |||||
| HITCBC | 314 | 19076 | BOOST_ASSERT( p != sentinel() ); | 332 | 26260 | BOOST_ASSERT( p != sentinel() ); | ||
| HITCBC | 315 | 19076 | end_ = p; | 333 | 26260 | end_ = p; | ||
| HITCBC | 316 | 19076 | return sentinel(); | 334 | 26260 | return sentinel(); | ||
| 317 | } | 335 | } | |||||
| 318 | 336 | |||||||
| 319 | template<class Handler> | 337 | template<class Handler> | |||||
| 320 | const char* | 338 | const char* | |||||
| HITCBC | 321 | 7781 | basic_parser<Handler>:: | 339 | 10159 | basic_parser<Handler>:: | ||
| 322 | fail( | 340 | fail( | |||||
| 323 | const char* p, | 341 | const char* p, | |||||
| 324 | error ev, | 342 | error ev, | |||||
| 325 | source_location const* loc) noexcept | 343 | source_location const* loc) noexcept | |||||
| 326 | { | 344 | { | |||||
| HITCBC | 327 | 7781 | BOOST_ASSERT( p != sentinel() ); | 345 | 10159 | BOOST_ASSERT( p != sentinel() ); | ||
| HITCBC | 328 | 7781 | end_ = p; | 346 | 10159 | end_ = p; | ||
| HITCBC | 329 | 7781 | ec_.assign(ev, loc); | 347 | 10159 | ec_.assign(ev, loc); | ||
| HITCBC | 330 | 7781 | return sentinel(); | 348 | 10159 | return sentinel(); | ||
| 331 | } | 349 | } | |||||
| 332 | 350 | |||||||
| 333 | template<class Handler> | 351 | template<class Handler> | |||||
| 334 | const char* | 352 | const char* | |||||
| HITCBC | 335 | 11446 | basic_parser<Handler>:: | 353 | 13588 | basic_parser<Handler>:: | ||
| 336 | maybe_suspend( | 354 | maybe_suspend( | |||||
| 337 | const char* p, | 355 | const char* p, | |||||
| 338 | state st) | 356 | state st) | |||||
| 339 | { | 357 | { | |||||
| HITCBC | 340 | 11446 | if( p != sentinel() ) | 358 | 13588 | if( p != sentinel() ) | ||
| HITCBC | 341 | 9508 | end_ = p; | 359 | 11650 | end_ = p; | ||
| HITCBC | 342 | 11446 | if(BOOST_JSON_LIKELY(more_)) | 360 | 13588 | if(BOOST_JSON_LIKELY(more_)) | ||
| 343 | { | 361 | { | |||||
| 344 | // suspend | 362 | // suspend | |||||
| HITCBC | 345 | 11173 | reserve(); | 363 | 13313 | reserve(); | ||
| HITCBC | 346 | 11173 | st_.push_unchecked(st); | 364 | 13313 | st_.push_unchecked(st); | ||
| 347 | } | 365 | } | |||||
| HITCBC | 348 | 11446 | return sentinel(); | 366 | 13588 | return sentinel(); | ||
| 349 | } | 367 | } | |||||
| 350 | 368 | |||||||
| 351 | template<class Handler> | 369 | template<class Handler> | |||||
| 352 | const char* | 370 | const char* | |||||
| HITCBC | 353 | 41284 | basic_parser<Handler>:: | 371 | 41284 | basic_parser<Handler>:: | ||
| 354 | maybe_suspend( | 372 | maybe_suspend( | |||||
| 355 | const char* p, | 373 | const char* p, | |||||
| 356 | state st, | 374 | state st, | |||||
| 357 | std::size_t n) | 375 | std::size_t n) | |||||
| 358 | { | 376 | { | |||||
| HITCBC | 359 | 41284 | BOOST_ASSERT( p != sentinel() ); | 377 | 41284 | BOOST_ASSERT( p != sentinel() ); | ||
| HITCBC | 360 | 41284 | end_ = p; | 378 | 41284 | end_ = p; | ||
| HITCBC | 361 | 41284 | if(BOOST_JSON_LIKELY(more_)) | 379 | 41284 | if(BOOST_JSON_LIKELY(more_)) | ||
| 362 | { | 380 | { | |||||
| 363 | // suspend | 381 | // suspend | |||||
| HITCBC | 364 | 40876 | reserve(); | 382 | 40876 | reserve(); | ||
| HITCBC | 365 | 40876 | st_.push_unchecked(n); | 383 | 40876 | st_.push_unchecked(n); | ||
| HITCBC | 366 | 40876 | st_.push_unchecked(st); | 384 | 40876 | st_.push_unchecked(st); | ||
| 367 | } | 385 | } | |||||
| HITCBC | 368 | 41284 | return sentinel(); | 386 | 41284 | return sentinel(); | ||
| 369 | } | 387 | } | |||||
| 370 | 388 | |||||||
| 371 | template<class Handler> | 389 | template<class Handler> | |||||
| 372 | const char* | 390 | const char* | |||||
| HITCBC | 373 | 1132 | basic_parser<Handler>:: | 391 | 2278 | basic_parser<Handler>:: | ||
| 374 | maybe_suspend( | 392 | maybe_suspend( | |||||
| 375 | const char* p, | 393 | const char* p, | |||||
| 376 | state st, | 394 | state st, | |||||
| 377 | const number& num) | 395 | const number& num) | |||||
| 378 | { | 396 | { | |||||
| HITCBC | 379 | 1132 | BOOST_ASSERT( p != sentinel() ); | 397 | 2278 | BOOST_ASSERT( p != sentinel() ); | ||
| HITCBC | 380 | 1132 | end_ = p; | 398 | 2278 | end_ = p; | ||
| HITCBC | 381 | 1132 | if(BOOST_JSON_LIKELY(more_)) | 399 | 2278 | if(BOOST_JSON_LIKELY(more_)) | ||
| 382 | { | 400 | { | |||||
| 383 | // suspend | 401 | // suspend | |||||
| HITCBC | 384 | 1132 | num_ = num; | 402 | 2278 | num_ = num; | ||
| HITCBC | 385 | 1132 | reserve(); | 403 | 2278 | reserve(); | ||
| HITCBC | 386 | 1132 | st_.push_unchecked(st);; | 404 | 2278 | st_.push_unchecked(st);; | ||
| 387 | } | 405 | } | |||||
| HITCBC | 388 | 1132 | return sentinel(); | 406 | 2278 | return sentinel(); | ||
| 389 | } | 407 | } | |||||
| 390 | 408 | |||||||
| 391 | template<class Handler> | 409 | template<class Handler> | |||||
| 392 | const char* | 410 | const char* | |||||
| HITCBC | 393 | 88669 | basic_parser<Handler>:: | 411 | 101323 | basic_parser<Handler>:: | ||
| 394 | suspend( | 412 | suspend( | |||||
| 395 | const char* p, | 413 | const char* p, | |||||
| 396 | state st) | 414 | state st) | |||||
| 397 | { | 415 | { | |||||
| HITCBC | 398 | 88669 | BOOST_ASSERT( p != sentinel() ); | 416 | 101323 | BOOST_ASSERT( p != sentinel() ); | ||
| HITCBC | 399 | 88669 | end_ = p; | 417 | 101323 | end_ = p; | ||
| 400 | // suspend | 418 | // suspend | |||||
| HITCBC | 401 | 88669 | reserve(); | 419 | 101323 | reserve(); | ||
| HITCBC | 402 | 88669 | st_.push_unchecked(st); | 420 | 101323 | st_.push_unchecked(st); | ||
| HITCBC | 403 | 88669 | return sentinel(); | 421 | 101323 | return sentinel(); | ||
| 404 | } | 422 | } | |||||
| 405 | 423 | |||||||
| 406 | template<class Handler> | 424 | template<class Handler> | |||||
| 407 | const char* | 425 | const char* | |||||
| HITCBC | 408 | 8424903 | basic_parser<Handler>:: | 426 | 8433887 | basic_parser<Handler>:: | ||
| 409 | suspend( | 427 | suspend( | |||||
| 410 | const char* p, | 428 | const char* p, | |||||
| 411 | state st, | 429 | state st, | |||||
| 412 | const number& num) | 430 | const number& num) | |||||
| 413 | { | 431 | { | |||||
| HITCBC | 414 | 8424903 | BOOST_ASSERT( p != sentinel() ); | 432 | 8433887 | BOOST_ASSERT( p != sentinel() ); | ||
| HITCBC | 415 | 8424903 | end_ = p; | 433 | 8433887 | end_ = p; | ||
| 416 | // suspend | 434 | // suspend | |||||
| HITCBC | 417 | 8424903 | num_ = num; | 435 | 8433887 | num_ = num; | ||
| HITCBC | 418 | 8424903 | reserve(); | 436 | 8433887 | reserve(); | ||
| HITCBC | 419 | 8424903 | st_.push_unchecked(st); | 437 | 8433887 | st_.push_unchecked(st); | ||
| HITCBC | 420 | 8424903 | return sentinel(); | 438 | 8433887 | return sentinel(); | ||
| 421 | } | 439 | } | |||||
| 422 | 440 | |||||||
| 423 | template<class Handler> | 441 | template<class Handler> | |||||
| 424 | template< | 442 | template< | |||||
| 425 | bool StackEmpty_/*, | 443 | bool StackEmpty_/*, | |||||
| 426 | bool Terminal_*/> | 444 | bool Terminal_*/> | |||||
| 427 | const char* | 445 | const char* | |||||
| HITCBC | 428 | 21827 | basic_parser<Handler>:: | 446 | 21827 | basic_parser<Handler>:: | ||
| 429 | parse_comment(const char* p, | 447 | parse_comment(const char* p, | |||||
| 430 | std::integral_constant<bool, StackEmpty_> stack_empty, | 448 | std::integral_constant<bool, StackEmpty_> stack_empty, | |||||
| 431 | /*std::integral_constant<bool, Terminal_>*/ bool terminal) | 449 | /*std::integral_constant<bool, Terminal_>*/ bool terminal) | |||||
| 432 | { | 450 | { | |||||
| HITCBC | 433 | 21827 | detail::const_stream_wrapper cs(p, end_); | 451 | 21827 | detail::const_stream_wrapper cs(p, end_); | ||
| HITCBC | 434 | 21827 | const char* start = cs.begin(); | 452 | 21827 | const char* start = cs.begin(); | ||
| 435 | std::size_t remain; | 453 | std::size_t remain; | |||||
| HITCBC | 436 | 21827 | if(! stack_empty && ! st_.empty()) | 454 | 21827 | if(! stack_empty && ! st_.empty()) | ||
| 437 | { | 455 | { | |||||
| 438 | state st; | 456 | state st; | |||||
| HITCBC | 439 | 3575 | st_.pop(st); | 457 | 3575 | st_.pop(st); | ||
| HITCBC | 440 | 3575 | switch(st) | 458 | 3575 | switch(st) | ||
| 441 | { | 459 | { | |||||
| 442 | default: BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE | 460 | default: BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE | |||||
| HITCBC | 443 | 541 | case state::com1: goto do_com1; | 461 | 541 | case state::com1: goto do_com1; | ||
| HITCBC | 444 | 2380 | case state::com2: goto do_com2; | 462 | 2380 | case state::com2: goto do_com2; | ||
| HITCBC | 445 | 438 | case state::com3: goto do_com3; | 463 | 438 | case state::com3: goto do_com3; | ||
| HITCBC | 446 | 216 | case state::com4: goto do_com4; | 464 | 216 | case state::com4: goto do_com4; | ||
| 447 | } | 465 | } | |||||
| 448 | } | 466 | } | |||||
| HITCBC | 449 | 18252 | BOOST_ASSERT(*cs == '/'); | 467 | 18252 | BOOST_ASSERT(*cs == '/'); | ||
| HITCBC | 450 | 18252 | ++cs; | 468 | 18252 | ++cs; | ||
| HITCBC | 451 | 18793 | do_com1: | 469 | 18793 | do_com1: | ||
| HITCBC | 452 | 18793 | if(BOOST_JSON_UNLIKELY(! cs)) | 470 | 18793 | if(BOOST_JSON_UNLIKELY(! cs)) | ||
| HITCBC | 453 | 558 | return maybe_suspend(cs.begin(), state::com1); | 471 | 558 | return maybe_suspend(cs.begin(), state::com1); | ||
| HITCBC | 454 | 18235 | switch(*cs) | 472 | 18235 | switch(*cs) | ||
| 455 | { | 473 | { | |||||
| HITCBC | 456 | 5 | default: | 474 | 5 | default: | ||
| 457 | { | 475 | { | |||||
| 458 | BOOST_STATIC_CONSTEXPR source_location loc | 476 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 459 | = BOOST_CURRENT_LOCATION; | 477 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 460 | 5 | return fail(cs.begin(), error::syntax, &loc); | 478 | 5 | return fail(cs.begin(), error::syntax, &loc); | ||
| 461 | } | 479 | } | |||||
| HITCBC | 462 | 10546 | case '/': | 480 | 10546 | case '/': | ||
| HITCBC | 463 | 10546 | ++cs; | 481 | 10546 | ++cs; | ||
| HITCBC | 464 | 12926 | do_com2: | 482 | 12926 | do_com2: | ||
| 465 | // KRYSTIAN TODO: this is a mess, we have to fix this | 483 | // KRYSTIAN TODO: this is a mess, we have to fix this | |||||
| HITCBC | 466 | 12926 | remain = cs.remain(); | 484 | 12926 | remain = cs.remain(); | ||
| HITCBC | 467 | 25852 | cs = remain ? static_cast<const char*>( | 485 | 25852 | cs = remain ? static_cast<const char*>( | ||
| HITCBC | 468 | 12926 | std::memchr(cs.begin(), '\n', remain)) : sentinel(); | 486 | 12926 | std::memchr(cs.begin(), '\n', remain)) : sentinel(); | ||
| HITCBC | 469 | 12926 | if(! cs.begin()) | 487 | 12926 | if(! cs.begin()) | ||
| HITCBC | 470 | 2197 | cs = sentinel(); | 488 | 2197 | cs = sentinel(); | ||
| HITCBC | 471 | 12926 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 489 | 12926 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | ||
| 472 | { | 490 | { | |||||
| 473 | // if the doc does not terminate | 491 | // if the doc does not terminate | |||||
| 474 | // with a newline, treat it as the | 492 | // with a newline, treat it as the | |||||
| 475 | // end of the comment | 493 | // end of the comment | |||||
| HITCBC | 476 | 2631 | if(terminal && ! more_) | 494 | 2631 | if(terminal && ! more_) | ||
| 477 | { | 495 | { | |||||
| HITCBC | 478 | 39 | if(BOOST_JSON_UNLIKELY(! h_.on_comment( | 496 | 39 | if(BOOST_JSON_UNLIKELY(! h_.on_comment( | ||
| 479 | {start, cs.remain(start)}, ec_))) | 497 | {start, cs.remain(start)}, ec_))) | |||||
| HITCBC | 480 | 2 | return fail(cs.end()); | 498 | 2 | return fail(cs.end()); | ||
| HITCBC | 481 | 35 | return cs.end(); | 499 | 35 | return cs.end(); | ||
| 482 | } | 500 | } | |||||
| HITCBC | 483 | 2592 | if(BOOST_JSON_UNLIKELY(! h_.on_comment_part( | 501 | 2592 | if(BOOST_JSON_UNLIKELY(! h_.on_comment_part( | ||
| 484 | {start, cs.remain(start)}, ec_))) | 502 | {start, cs.remain(start)}, ec_))) | |||||
| HITCBC | 485 | 96 | return fail(cs.end()); | 503 | 96 | return fail(cs.end()); | ||
| HITCBC | 486 | 2400 | if(terminal) | 504 | 2400 | if(terminal) | ||
| HITCBC | 487 | 106 | return suspend(cs.end(), state::com2); | 505 | 106 | return suspend(cs.end(), state::com2); | ||
| HITCBC | 488 | 2294 | return maybe_suspend(cs.end(), state::com2); | 506 | 2294 | return maybe_suspend(cs.end(), state::com2); | ||
| 489 | } | 507 | } | |||||
| HITCBC | 490 | 10295 | break; | 508 | 10295 | break; | ||
| HITCBC | 491 | 1684 | case '*': | 509 | 1684 | case '*': | ||
| 492 | do | 510 | do | |||||
| 493 | { | 511 | { | |||||
| HITCBC | 494 | 9368 | ++cs; | 512 | 9368 | ++cs; | ||
| HITCBC | 495 | 9806 | do_com3: | 513 | 9806 | do_com3: | ||
| 496 | // KRYSTIAN TODO: this is a mess, we have to fix this | 514 | // KRYSTIAN TODO: this is a mess, we have to fix this | |||||
| HITCBC | 497 | 9806 | remain = cs.remain(); | 515 | 9806 | remain = cs.remain(); | ||
| HITCBC | 498 | 19612 | cs = remain ? static_cast<const char*>( | 516 | 19612 | cs = remain ? static_cast<const char*>( | ||
| HITCBC | 499 | 9806 | std::memchr(cs.begin(), '*', remain)) : sentinel(); | 517 | 9806 | std::memchr(cs.begin(), '*', remain)) : sentinel(); | ||
| HITCBC | 500 | 9806 | if(! cs.begin()) | 518 | 9806 | if(! cs.begin()) | ||
| HITCBC | 501 | 242 | cs = sentinel(); | 519 | 242 | cs = sentinel(); | ||
| 502 | // stopped inside a c comment | 520 | // stopped inside a c comment | |||||
| HITCBC | 503 | 9806 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 521 | 9806 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | ||
| 504 | { | 522 | { | |||||
| HITCBC | 505 | 503 | if(BOOST_JSON_UNLIKELY(! h_.on_comment_part( | 523 | 503 | if(BOOST_JSON_UNLIKELY(! h_.on_comment_part( | ||
| 506 | {start, cs.remain(start)}, ec_))) | 524 | {start, cs.remain(start)}, ec_))) | |||||
| HITCBC | 507 | 30 | return fail(cs.end()); | 525 | 30 | return fail(cs.end()); | ||
| HITCBC | 508 | 443 | return maybe_suspend(cs.end(), state::com3); | 526 | 443 | return maybe_suspend(cs.end(), state::com3); | ||
| 509 | } | 527 | } | |||||
| 510 | // found a asterisk, check if the next char is a slash | 528 | // found a asterisk, check if the next char is a slash | |||||
| HITCBC | 511 | 9303 | ++cs; | 529 | 9303 | ++cs; | ||
| HITCBC | 512 | 9519 | do_com4: | 530 | 9519 | do_com4: | ||
| HITCBC | 513 | 9519 | if(BOOST_JSON_UNLIKELY(! cs)) | 531 | 9519 | if(BOOST_JSON_UNLIKELY(! cs)) | ||
| 514 | { | 532 | { | |||||
| HITCBC | 515 | 259 | if(BOOST_JSON_UNLIKELY(! h_.on_comment_part( | 533 | 259 | if(BOOST_JSON_UNLIKELY(! h_.on_comment_part( | ||
| 516 | {start, cs.used(start)}, ec_))) | 534 | {start, cs.used(start)}, ec_))) | |||||
| HITCBC | 517 | 18 | return fail(cs.begin()); | 535 | 18 | return fail(cs.begin()); | ||
| HITCBC | 518 | 223 | return maybe_suspend(cs.begin(), state::com4); | 536 | 223 | return maybe_suspend(cs.begin(), state::com4); | ||
| 519 | } | 537 | } | |||||
| 520 | } | 538 | } | |||||
| HITCBC | 521 | 9260 | while(*cs != '/'); | 539 | 9260 | while(*cs != '/'); | ||
| 522 | } | 540 | } | |||||
| HITCBC | 523 | 17871 | ++cs; | 541 | 17871 | ++cs; | ||
| HITCBC | 524 | 17871 | if(BOOST_JSON_UNLIKELY(! h_.on_comment( | 542 | 17871 | if(BOOST_JSON_UNLIKELY(! h_.on_comment( | ||
| 525 | {start, cs.used(start)}, ec_))) | 543 | {start, cs.used(start)}, ec_))) | |||||
| HITCBC | 526 | 968 | return fail(cs.begin()); | 544 | 968 | return fail(cs.begin()); | ||
| HITCBC | 527 | 15935 | return cs.begin(); | 545 | 15935 | return cs.begin(); | ||
| 528 | } | 546 | } | |||||
| 529 | 547 | |||||||
| 530 | template<class Handler> | 548 | template<class Handler> | |||||
| 531 | template<bool StackEmpty_> | 549 | template<bool StackEmpty_> | |||||
| 532 | const char* | 550 | const char* | |||||
| HITCBC | 533 | 10710738 | basic_parser<Handler>:: | 551 | 10769464 | basic_parser<Handler>:: | ||
| 534 | parse_document(const char* p, | 552 | parse_document(const char* p, | |||||
| 535 | std::integral_constant<bool, StackEmpty_> stack_empty) | 553 | std::integral_constant<bool, StackEmpty_> stack_empty) | |||||
| 536 | { | 554 | { | |||||
| HITCBC | 537 | 10710738 | detail::const_stream_wrapper cs(p, end_); | 555 | 10769464 | detail::const_stream_wrapper cs(p, end_); | ||
| HITCBC | 538 | 10710738 | if(! stack_empty && ! st_.empty()) | 556 | 10769464 | if(! stack_empty && ! st_.empty()) | ||
| 539 | { | 557 | { | |||||
| 540 | state st; | 558 | state st; | |||||
| HITCBC | 541 | 8561595 | st_.peek(st); | 559 | 8580215 | st_.peek(st); | ||
| HITCBC | 542 | 8561595 | switch(st) | 560 | 8580215 | switch(st) | ||
| 543 | { | 561 | { | |||||
| HITCBC | 544 | 8475518 | default: goto do_doc2; | 562 | 8487572 | default: goto do_doc2; | ||
| HITCBC | 545 | 601 | case state::doc1: | 563 | 817 | case state::doc1: | ||
| HITCBC | 546 | 601 | st_.pop(st); | 564 | 817 | st_.pop(st); | ||
| HITCBC | 547 | 601 | goto do_doc1; | 565 | 817 | goto do_doc1; | ||
| HITCBC | 548 | 85256 | case state::doc3: | 566 | 91606 | case state::doc3: | ||
| HITCBC | 549 | 85256 | st_.pop(st); | 567 | 91606 | st_.pop(st); | ||
| HITCBC | 550 | 85256 | goto do_doc3; | 568 | 91606 | goto do_doc3; | ||
| HITCBC | 551 | 220 | case state::com1: case state::com2: | 569 | 220 | case state::com1: case state::com2: | ||
| 552 | case state::com3: case state::com4: | 570 | case state::com3: case state::com4: | |||||
| HITCBC | 553 | 220 | goto do_doc4; | 571 | 220 | goto do_doc4; | ||
| 554 | } | 572 | } | |||||
| 555 | } | 573 | } | |||||
| HITCBC | 556 | 2149143 | do_doc1: | 574 | 2189249 | do_doc1: | ||
| HITCBC | 557 | 2149744 | cs = detail::count_whitespace(cs.begin(), cs.end()); | 575 | 2190066 | cs = detail::count_whitespace(cs.begin(), cs.end()); | ||
| HITCBC | 558 | 2149744 | if(BOOST_JSON_UNLIKELY(! cs)) | 576 | 2190066 | if(BOOST_JSON_UNLIKELY(! cs)) | ||
| HITCBC | 559 | 633 | return maybe_suspend(cs.begin(), state::doc1); | 577 | 851 | return maybe_suspend(cs.begin(), state::doc1); | ||
| HITCBC | 560 | 2149111 | do_doc2: | 578 | 2189215 | do_doc2: | ||
| HITCBC | 561 | 10624629 | switch(+opt_.allow_comments | | 579 | 10676787 | switch(+opt_.allow_comments | | ||
| HITCBC | 562 | 10624629 | (opt_.allow_trailing_commas << 1) | | 580 | 10676787 | (opt_.allow_trailing_commas << 1) | | ||
| HITCBC | 563 | 10624629 | (opt_.allow_invalid_utf8 << 2)) | 581 | 10676787 | (opt_.allow_invalid_utf8 << 2)) | ||
| 564 | { | 582 | { | |||||
| 565 | // no extensions | 583 | // no extensions | |||||
| HITCBC | 566 | 10600807 | default: | 584 | 10652965 | default: | ||
| HITCBC | 567 | 10600807 | cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::false_type(), std::false_type(), opt_.allow_invalid_utf16); | 585 | 10652965 | cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::false_type(), std::false_type(), opt_.allow_invalid_utf16); | ||
| HITCBC | 568 | 10585585 | break; | 586 | 10630559 | break; | ||
| 569 | // comments | 587 | // comments | |||||
| HITCBC | 570 | 13691 | case 1: | 588 | 13691 | case 1: | ||
| HITCBC | 571 | 13691 | cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::false_type(), std::false_type(), opt_.allow_invalid_utf16); | 589 | 13691 | cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::false_type(), std::false_type(), opt_.allow_invalid_utf16); | ||
| HITCBC | 572 | 11423 | break; | 590 | 11423 | break; | ||
| 573 | // trailing | 591 | // trailing | |||||
| HITCBC | 574 | 6710 | case 2: | 592 | 6710 | case 2: | ||
| HITCBC | 575 | 6710 | cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::true_type(), std::false_type(), opt_.allow_invalid_utf16); | 593 | 6710 | cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::true_type(), std::false_type(), opt_.allow_invalid_utf16); | ||
| HITCBC | 576 | 5117 | break; | 594 | 5117 | break; | ||
| 577 | // comments & trailing | 595 | // comments & trailing | |||||
| HITCBC | 578 | 761 | case 3: | 596 | 761 | case 3: | ||
| HITCBC | 579 | 761 | cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::true_type(), std::false_type(), opt_.allow_invalid_utf16); | 597 | 761 | cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::true_type(), std::false_type(), opt_.allow_invalid_utf16); | ||
| HITCBC | 580 | 761 | break; | 598 | 761 | break; | ||
| 581 | // skip validation | 599 | // skip validation | |||||
| HITCBC | 582 | 760 | case 4: | 600 | 760 | case 4: | ||
| HITCBC | 583 | 760 | cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::false_type(), std::true_type(), opt_.allow_invalid_utf16); | 601 | 760 | cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::false_type(), std::true_type(), opt_.allow_invalid_utf16); | ||
| HITCBC | 584 | 760 | break; | 602 | 760 | break; | ||
| 585 | // comments & skip validation | 603 | // comments & skip validation | |||||
| HITCBC | 586 | 760 | case 5: | 604 | 760 | case 5: | ||
| HITCBC | 587 | 760 | cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::false_type(), std::true_type(), opt_.allow_invalid_utf16); | 605 | 760 | cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::false_type(), std::true_type(), opt_.allow_invalid_utf16); | ||
| HITCBC | 588 | 760 | break; | 606 | 760 | break; | ||
| 589 | // trailing & skip validation | 607 | // trailing & skip validation | |||||
| HITCBC | 590 | 760 | case 6: | 608 | 760 | case 6: | ||
| HITCBC | 591 | 760 | cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::true_type(), std::true_type(), opt_.allow_invalid_utf16); | 609 | 760 | cs = parse_value(cs.begin(), stack_empty, std::false_type(), std::true_type(), std::true_type(), opt_.allow_invalid_utf16); | ||
| HITCBC | 592 | 760 | break; | 610 | 760 | break; | ||
| 593 | // comments & trailing & skip validation | 611 | // comments & trailing & skip validation | |||||
| HITCBC | 594 | 380 | case 7: | 612 | 380 | case 7: | ||
| HITCBC | 595 | 380 | cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::true_type(), std::true_type(), opt_.allow_invalid_utf16); | 613 | 380 | cs = parse_value(cs.begin(), stack_empty, std::true_type(), std::true_type(), std::true_type(), opt_.allow_invalid_utf16); | ||
| HITCBC | 596 | 380 | break; | 614 | 380 | break; | ||
| 597 | } | 615 | } | |||||
| HITCBC | 598 | 10605546 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 616 | 10650520 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | ||
| 599 | // the appropriate state has already been pushed into stack | 617 | // the appropriate state has already been pushed into stack | |||||
| HITCBC | 600 | 8502818 | return sentinel(); | 618 | 8524434 | return sentinel(); | ||
| HITCBC | 601 | 2102728 | do_doc3: | 619 | 2126086 | do_doc3: | ||
| HITCBC | 602 | 2188316 | cs = detail::count_whitespace(cs.begin(), cs.end()); | 620 | 2218024 | cs = detail::count_whitespace(cs.begin(), cs.end()); | ||
| HITCBC | 603 | 2188316 | if(BOOST_JSON_UNLIKELY(! cs)) | 621 | 2218024 | if(BOOST_JSON_UNLIKELY(! cs)) | ||
| 604 | { | 622 | { | |||||
| HITCBC | 605 | 2185718 | if(more_) | 623 | 2212102 | if(more_) | ||
| HITCBC | 606 | 88563 | return suspend(cs.begin(), state::doc3); | 624 | 101217 | return suspend(cs.begin(), state::doc3); | ||
| 607 | } | 625 | } | |||||
| HITCBC | 608 | 2598 | else if(opt_.allow_comments && *cs == '/') | 626 | 5922 | else if(opt_.allow_comments && *cs == '/') | ||
| 609 | { | 627 | { | |||||
| HITCBC | 610 | 536 | do_doc4: | 628 | 536 | do_doc4: | ||
| HITCBC | 611 | 756 | cs = parse_comment(cs.begin(), stack_empty, std::true_type()); | 629 | 756 | cs = parse_comment(cs.begin(), stack_empty, std::true_type()); | ||
| HITCBC | 612 | 671 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 630 | 671 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | ||
| HITCBC | 613 | 339 | return sentinel(); | 631 | 339 | return sentinel(); | ||
| HITCBC | 614 | 332 | goto do_doc3; | 632 | 332 | goto do_doc3; | ||
| 615 | } | 633 | } | |||||
| HITCBC | 616 | 2099217 | return cs.begin(); | 634 | 2116271 | return cs.begin(); | ||
| 617 | } | 635 | } | |||||
| 618 | 636 | |||||||
| 619 | template<class Handler> | 637 | template<class Handler> | |||||
| 620 | template< | 638 | template< | |||||
| 621 | bool StackEmpty_, | 639 | bool StackEmpty_, | |||||
| 622 | bool AllowComments_/*, | 640 | bool AllowComments_/*, | |||||
| 623 | bool AllowTrailing_, | 641 | bool AllowTrailing_, | |||||
| 624 | bool AllowBadUTF8_*/> | 642 | bool AllowBadUTF8_*/> | |||||
| 625 | const char* | 643 | const char* | |||||
| HITCBC | 626 | 10742424 | basic_parser<Handler>:: | 644 | 10794582 | basic_parser<Handler>:: | ||
| 627 | parse_value(const char* p, | 645 | parse_value(const char* p, | |||||
| 628 | std::integral_constant<bool, StackEmpty_> stack_empty, | 646 | std::integral_constant<bool, StackEmpty_> stack_empty, | |||||
| 629 | std::integral_constant<bool, AllowComments_> allow_comments, | 647 | std::integral_constant<bool, AllowComments_> allow_comments, | |||||
| 630 | /*std::integral_constant<bool, AllowTrailing_>*/ bool allow_trailing, | 648 | /*std::integral_constant<bool, AllowTrailing_>*/ bool allow_trailing, | |||||
| 631 | /*std::integral_constant<bool, AllowBadUTF8_>*/ bool allow_bad_utf8, | 649 | /*std::integral_constant<bool, AllowBadUTF8_>*/ bool allow_bad_utf8, | |||||
| 632 | bool allow_bad_utf16) | 650 | bool allow_bad_utf16) | |||||
| 633 | { | 651 | { | |||||
| HITCBC | 634 | 10742424 | if(stack_empty || st_.empty()) | 652 | 10794582 | if(stack_empty || st_.empty()) | ||
| 635 | { | 653 | { | |||||
| HITCBC | 636 | 2248488 | loop: | 654 | 2288592 | loop: | ||
| HITCBC | 637 | 2253404 | switch(*p) | 655 | 2293508 | switch(*p) | ||
| 638 | { | 656 | { | |||||
| HITCBC | 639 | 22761 | case '0': | 657 | 31459 | case '0': | ||
| HITCBC | 640 | 22761 | return mp11::mp_with_index<3>( | 658 | 31459 | return mp11::mp_with_index<3>( | ||
| HITCBC | 641 | 22761 | static_cast<unsigned char>(opt_.numbers), | 659 | 31459 | static_cast<unsigned char>(opt_.numbers), | ||
| HITCBC | 642 | 22100 | parse_number_helper<true, '0'>{ this, p }); | 660 | 29476 | parse_number_helper<true, '0'>{ this, p }); | ||
| HITCBC | 643 | 25185 | case '-': | 661 | 40985 | case '-': | ||
| HITCBC | 644 | 25185 | return mp11::mp_with_index<3>( | 662 | 40985 | return mp11::mp_with_index<3>( | ||
| HITCBC | 645 | 25185 | static_cast<unsigned char>(opt_.numbers), | 663 | 40985 | static_cast<unsigned char>(opt_.numbers), | ||
| HITCBC | 646 | 24073 | parse_number_helper<true, '-'>{ this, p }); | 664 | 37649 | parse_number_helper<true, '-'>{ this, p }); | ||
| HITCBC | 647 | 2042109 | case '1': case '2': case '3': | 665 | 2055921 | case '1': case '2': case '3': | ||
| 648 | case '4': case '5': case '6': | 666 | case '4': case '5': case '6': | |||||
| 649 | case '7': case '8': case '9': | 667 | case '7': case '8': case '9': | |||||
| HITCBC | 650 | 2042109 | return mp11::mp_with_index<3>( | 668 | 2055921 | return mp11::mp_with_index<3>( | ||
| HITCBC | 651 | 2042109 | static_cast<unsigned char>(opt_.numbers), | 669 | 2055921 | static_cast<unsigned char>(opt_.numbers), | ||
| HITCBC | 652 | 2039233 | parse_number_helper<true, '+'>{ this, p }); | 670 | 2051131 | parse_number_helper<true, '+'>{ this, p }); | ||
| HITCBC | 653 | 11381 | case 'n': | 671 | 11391 | case 'n': | ||
| HITCBC | 654 | 11381 | return parse_literal( p, detail::literals_c<detail::literals::null>() ); | 672 | 11391 | return parse_literal( p, detail::literals_c<detail::literals::null>() ); | ||
| HITCBC | 655 | 664 | case 't': | 673 | 664 | case 't': | ||
| HITCBC | 656 | 664 | return parse_literal( p, detail::literals_c<detail::literals::true_>() ); | 674 | 664 | return parse_literal( p, detail::literals_c<detail::literals::true_>() ); | ||
| HITCBC | 657 | 722 | case 'f': | 675 | 722 | case 'f': | ||
| HITCBC | 658 | 722 | return parse_literal( p, detail::literals_c<detail::literals::false_>() ); | 676 | 722 | return parse_literal( p, detail::literals_c<detail::literals::false_>() ); | ||
| HITCBC | 659 | 681 | case 'I': | 677 | 1935 | case 'I': | ||
| HITCBC | 660 | 681 | if( !opt_.allow_infinity_and_nan ) | 678 | 1935 | if( !opt_.allow_infinity_and_nan ) | ||
| 661 | { | 679 | { | |||||
| 662 | BOOST_STATIC_CONSTEXPR source_location loc | 680 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 663 | = BOOST_CURRENT_LOCATION; | 681 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 664 | 24 | return fail(p, error::syntax, &loc); | 682 | 24 | return fail(p, error::syntax, &loc); | ||
| 665 | } | 683 | } | |||||
| HITCBC | 666 | 657 | return parse_literal( p, detail::literals_c<detail::literals::infinity>() ); | 684 | 1911 | return parse_literal( p, detail::literals_c<detail::literals::infinity>() ); | ||
| HITCBC | 667 | 231 | case 'N': | 685 | 597 | case 'N': | ||
| HITCBC | 668 | 231 | if( !opt_.allow_infinity_and_nan ) | 686 | 597 | if( !opt_.allow_infinity_and_nan ) | ||
| 669 | { | 687 | { | |||||
| 670 | BOOST_STATIC_CONSTEXPR source_location loc | 688 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 671 | = BOOST_CURRENT_LOCATION; | 689 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 672 | 30 | return fail(p, error::syntax, &loc); | 690 | 30 | return fail(p, error::syntax, &loc); | ||
| 673 | } | 691 | } | |||||
| HITCBC | 674 | 201 | return parse_literal(p, detail::literals_c<detail::literals::nan>() ); | 692 | 567 | return parse_literal(p, detail::literals_c<detail::literals::nan>() ); | ||
| HITCBC | 675 | 47587 | case '"': | 693 | 47587 | case '"': | ||
| HITCBC | 676 | 47587 | return parse_string(p, std::true_type(), std::false_type(), allow_bad_utf8, allow_bad_utf16); | 694 | 47587 | return parse_string(p, std::true_type(), std::false_type(), allow_bad_utf8, allow_bad_utf16); | ||
| HITCBC | 677 | 20677 | case '[': | 695 | 20677 | case '[': | ||
| HITCBC | 678 | 20677 | return parse_array(p, std::true_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | 696 | 20677 | return parse_array(p, std::true_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | ||
| HITCBC | 679 | 74138 | case '{': | 697 | 74138 | case '{': | ||
| HITCBC | 680 | 74138 | return parse_object(p, std::true_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | 698 | 74138 | return parse_object(p, std::true_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | ||
| HITCBC | 681 | 6147 | case '/': | 699 | 6147 | case '/': | ||
| HITCBC | 682 | 6147 | if(! allow_comments) | 700 | 6147 | if(! allow_comments) | ||
| 683 | { | 701 | { | |||||
| 684 | BOOST_STATIC_CONSTEXPR source_location loc | 702 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 685 | = BOOST_CURRENT_LOCATION; | 703 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 686 | 284 | return fail(p, error::syntax, &loc); | 704 | 284 | return fail(p, error::syntax, &loc); | ||
| 687 | } | 705 | } | |||||
| HITCBC | 688 | 5863 | p = parse_comment(p, stack_empty, std::false_type()); | 706 | 5863 | p = parse_comment(p, stack_empty, std::false_type()); | ||
| 689 | // KRYSTIAN NOTE: incomplete takes const_stream, we either | 707 | // KRYSTIAN NOTE: incomplete takes const_stream, we either | |||||
| 690 | // can add an overload, change the existing one to take a pointer, | 708 | // can add an overload, change the existing one to take a pointer, | |||||
| 691 | // or just leave it as is | 709 | // or just leave it as is | |||||
| HITCBC | 692 | 5624 | if(BOOST_JSON_UNLIKELY(p == sentinel())) | 710 | 5624 | if(BOOST_JSON_UNLIKELY(p == sentinel())) | ||
| HITCBC | 693 | 605 | return maybe_suspend(p, state::val2); | 711 | 605 | return maybe_suspend(p, state::val2); | ||
| 694 | BOOST_FALLTHROUGH; | 712 | BOOST_FALLTHROUGH; | |||||
| 695 | case ' ': | 713 | case ' ': | |||||
| 696 | case '\t': | 714 | case '\t': | |||||
| 697 | case '\n': | 715 | case '\n': | |||||
| 698 | case '\r': | 716 | case '\r': | |||||
| HITCBC | 699 | 5035 | p = detail::count_whitespace(p, end_); | 717 | 5035 | p = detail::count_whitespace(p, end_); | ||
| HITCBC | 700 | 5035 | if(BOOST_JSON_UNLIKELY(p == end_)) | 718 | 5035 | if(BOOST_JSON_UNLIKELY(p == end_)) | ||
| HITCBC | 701 | 119 | return maybe_suspend(p, state::val1); | 719 | 119 | return maybe_suspend(p, state::val1); | ||
| HITCBC | 702 | 4916 | goto loop; | 720 | 4916 | goto loop; | ||
| HITCBC | 703 | 1105 | default: | 721 | 1269 | default: | ||
| 704 | { | 722 | { | |||||
| 705 | BOOST_STATIC_CONSTEXPR source_location loc | 723 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 706 | = BOOST_CURRENT_LOCATION; | 724 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 707 | 1105 | return fail(p, error::syntax, &loc); | 725 | 1269 | return fail(p, error::syntax, &loc); | ||
| 708 | } | 726 | } | |||||
| 709 | } | 727 | } | |||||
| 710 | } | 728 | } | |||||
| HITCBC | 711 | 8493936 | return resume_value(p, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | 729 | 8505990 | return resume_value(p, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | ||
| 712 | } | 730 | } | |||||
| 713 | 731 | |||||||
| 714 | template<class Handler> | 732 | template<class Handler> | |||||
| 715 | template< | 733 | template< | |||||
| 716 | bool AllowComments_/*, | 734 | bool AllowComments_/*, | |||||
| 717 | bool AllowTrailing_, | 735 | bool AllowTrailing_, | |||||
| 718 | bool AllowBadUTF8_*/> | 736 | bool AllowBadUTF8_*/> | |||||
| 719 | const char* | 737 | const char* | |||||
| HITCBC | 720 | 8493936 | basic_parser<Handler>:: | 738 | 8505990 | basic_parser<Handler>:: | ||
| 721 | resume_value(const char* p, | 739 | resume_value(const char* p, | |||||
| 722 | std::integral_constant<bool, AllowComments_> allow_comments, | 740 | std::integral_constant<bool, AllowComments_> allow_comments, | |||||
| 723 | /*std::integral_constant<bool, AllowTrailing_>*/ bool allow_trailing, | 741 | /*std::integral_constant<bool, AllowTrailing_>*/ bool allow_trailing, | |||||
| 724 | /*std::integral_constant<bool, AllowBadUTF8_>*/ bool allow_bad_utf8, | 742 | /*std::integral_constant<bool, AllowBadUTF8_>*/ bool allow_bad_utf8, | |||||
| 725 | bool allow_bad_utf16) | 743 | bool allow_bad_utf16) | |||||
| 726 | { | 744 | { | |||||
| 727 | state st; | 745 | state st; | |||||
| HITCBC | 728 | 8493936 | st_.peek(st); | 746 | 8505990 | st_.peek(st); | ||
| HITCBC | 729 | 8493936 | switch(st) | 747 | 8505990 | switch(st) | ||
| 730 | { | 748 | { | |||||
| 731 | default: BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE | 749 | default: BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE | |||||
| HITCBC | 732 | 1924 | case state::lit1: | 750 | 3848 | case state::lit1: | ||
| HITCBC | 733 | 1924 | return parse_literal(p, detail::literals_c<detail::literals::resume>() ); | 751 | 3848 | return parse_literal(p, detail::literals_c<detail::literals::resume>() ); | ||
| 734 | 752 | |||||||
| HITCBC | 735 | 23268 | case state::str1: case state::str2: | 753 | 23268 | case state::str1: case state::str2: | ||
| 736 | case state::str8: | 754 | case state::str8: | |||||
| HITCBC | 737 | 23268 | return parse_string(p, std::false_type(), std::false_type(), allow_bad_utf8, allow_bad_utf16); | 755 | 23268 | return parse_string(p, std::false_type(), std::false_type(), allow_bad_utf8, allow_bad_utf16); | ||
| 738 | 756 | |||||||
| HITCBC | 739 | 5780 | case state::arr1: case state::arr2: | 757 | 5780 | case state::arr1: case state::arr2: | ||
| 740 | case state::arr3: case state::arr4: | 758 | case state::arr3: case state::arr4: | |||||
| 741 | case state::arr5: case state::arr6: | 759 | case state::arr5: case state::arr6: | |||||
| HITCBC | 742 | 5780 | return parse_array(p, std::false_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | 760 | 5780 | return parse_array(p, std::false_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | ||
| 743 | 761 | |||||||
| HITCBC | 744 | 35074 | case state::obj1: case state::obj2: | 762 | 35074 | case state::obj1: case state::obj2: | ||
| 745 | case state::obj3: case state::obj4: | 763 | case state::obj3: case state::obj4: | |||||
| 746 | case state::obj5: case state::obj6: | 764 | case state::obj5: case state::obj6: | |||||
| 747 | case state::obj7: case state::obj8: | 765 | case state::obj7: case state::obj8: | |||||
| 748 | case state::obj9: case state::obj10: | 766 | case state::obj9: case state::obj10: | |||||
| 749 | case state::obj11: | 767 | case state::obj11: | |||||
| HITCBC | 750 | 35074 | return parse_object(p, std::false_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | 768 | 35074 | return parse_object(p, std::false_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | ||
| 751 | 769 | |||||||
| HITCBC | 752 | 8426032 | case state::num1: case state::num2: | 770 | 8436162 | case state::num1: case state::num2: | ||
| 753 | case state::num3: case state::num4: | 771 | case state::num3: case state::num4: | |||||
| 754 | case state::num5: case state::num6: | 772 | case state::num5: case state::num6: | |||||
| 755 | case state::num7: case state::num8: | 773 | case state::num7: case state::num8: | |||||
| 756 | case state::exp1: case state::exp2: | 774 | case state::exp1: case state::exp2: | |||||
| 757 | case state::exp3: | 775 | case state::exp3: | |||||
| HITCBC | 758 | 8426032 | return mp11::mp_with_index<3>( | 776 | 8436162 | return mp11::mp_with_index<3>( | ||
| HITCBC | 759 | 8426032 | static_cast<unsigned char>(opt_.numbers), | 777 | 8436162 | static_cast<unsigned char>(opt_.numbers), | ||
| HITCBC | 760 | 8425177 | parse_number_helper<false, 0>{ this, p }); | 778 | 8433867 | parse_number_helper<false, 0>{ this, p }); | ||
| 761 | 779 | |||||||
| 762 | // KRYSTIAN NOTE: these are special cases | 780 | // KRYSTIAN NOTE: these are special cases | |||||
| HITCBC | 763 | 112 | case state::val1: | 781 | 112 | case state::val1: | ||
| 764 | { | 782 | { | |||||
| HITCBC | 765 | 112 | st_.pop(st); | 783 | 112 | st_.pop(st); | ||
| HITCBC | 766 | 112 | BOOST_ASSERT(st_.empty()); | 784 | 112 | BOOST_ASSERT(st_.empty()); | ||
| HITCBC | 767 | 112 | p = detail::count_whitespace(p, end_); | 785 | 112 | p = detail::count_whitespace(p, end_); | ||
| HITCBC | 768 | 112 | if(BOOST_JSON_UNLIKELY(p == end_)) | 786 | 112 | if(BOOST_JSON_UNLIKELY(p == end_)) | ||
| HITCBC | 769 | 4 | return maybe_suspend(p, state::val1); | 787 | 4 | return maybe_suspend(p, state::val1); | ||
| HITCBC | 770 | 108 | return parse_value(p, std::true_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | 788 | 108 | return parse_value(p, std::true_type(), allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | ||
| 771 | } | 789 | } | |||||
| 772 | 790 | |||||||
| HITCBC | 773 | 1676 | case state::val2: | 791 | 1676 | case state::val2: | ||
| 774 | { | 792 | { | |||||
| HITCBC | 775 | 1676 | st_.pop(st); | 793 | 1676 | st_.pop(st); | ||
| HITCBC | 776 | 1676 | p = parse_comment(p, std::false_type(), std::false_type()); | 794 | 1676 | p = parse_comment(p, std::false_type(), std::false_type()); | ||
| HITCBC | 777 | 1656 | if(BOOST_JSON_UNLIKELY(p == sentinel())) | 795 | 1656 | if(BOOST_JSON_UNLIKELY(p == sentinel())) | ||
| HITCBC | 778 | 1333 | return maybe_suspend(p, state::val2); | 796 | 1333 | return maybe_suspend(p, state::val2); | ||
| HITCBC | 779 | 323 | if(BOOST_JSON_UNLIKELY( p == end_ )) | 797 | 323 | if(BOOST_JSON_UNLIKELY( p == end_ )) | ||
| HITCBC | 780 | 80 | return maybe_suspend(p, state::val3); | 798 | 80 | return maybe_suspend(p, state::val3); | ||
| HITCBC | 781 | 243 | BOOST_ASSERT(st_.empty()); | 799 | 243 | BOOST_ASSERT(st_.empty()); | ||
| HITCBC | 782 | 243 | return parse_value(p, std::true_type(), std::true_type(), allow_trailing, allow_bad_utf8, allow_bad_utf16); | 800 | 243 | return parse_value(p, std::true_type(), std::true_type(), allow_trailing, allow_bad_utf8, allow_bad_utf16); | ||
| 783 | } | 801 | } | |||||
| 784 | 802 | |||||||
| HITCBC | 785 | 70 | case state::val3: | 803 | 70 | case state::val3: | ||
| 786 | { | 804 | { | |||||
| HITCBC | 787 | 70 | st_.pop(st); | 805 | 70 | st_.pop(st); | ||
| HITCBC | 788 | 70 | return parse_value(p, std::true_type(), std::true_type(), allow_trailing, allow_bad_utf8, allow_bad_utf16); | 806 | 70 | return parse_value(p, std::true_type(), std::true_type(), allow_trailing, allow_bad_utf8, allow_bad_utf16); | ||
| 789 | } | 807 | } | |||||
| 790 | } | 808 | } | |||||
| 791 | } | 809 | } | |||||
| 792 | 810 | |||||||
| 793 | template<class Handler> | 811 | template<class Handler> | |||||
| 794 | template<class Literal> | 812 | template<class Literal> | |||||
| 795 | const char* | 813 | const char* | |||||
| HITCBC | 796 | 16565 | basic_parser<Handler>:: | 814 | 21963 | basic_parser<Handler>:: | ||
| 797 | parse_literal(const char* p, Literal) | 815 | parse_literal(const char* p, Literal) | |||||
| 798 | { | 816 | { | |||||
| 799 | using L = detail::literals; | 817 | using L = detail::literals; | |||||
| 800 | 818 | |||||||
| 801 | std::size_t cur_lit; | 819 | std::size_t cur_lit; | |||||
| 802 | std::size_t offset; | 820 | std::size_t offset; | |||||
| 803 | 821 | |||||||
| HITCBC | 804 | 16565 | detail::const_stream_wrapper cs(p, end_); | 822 | 21963 | detail::const_stream_wrapper cs(p, end_); | ||
| 805 | BOOST_IF_CONSTEXPR( Literal::value != L::resume ) | 823 | BOOST_IF_CONSTEXPR( Literal::value != L::resume ) | |||||
| 806 | { | 824 | { | |||||
| HITCBC | 807 | 13634 | constexpr std::size_t index = literal_index(Literal::value); | 825 | 15278 | constexpr std::size_t index = literal_index(Literal::value); | ||
| HITCBC | 808 | 13634 | constexpr char const* literal = detail::literal_strings[index]; | 826 | 15278 | constexpr char const* literal = detail::literal_strings[index]; | ||
| HITCBC | 809 | 13634 | constexpr std::size_t sz = detail::literal_sizes[index]; | 827 | 15278 | constexpr std::size_t sz = detail::literal_sizes[index]; | ||
| 810 | 828 | |||||||
| HITCBC | 811 | 13634 | if(BOOST_JSON_LIKELY( cs.remain() >= sz )) | 829 | 15278 | if(BOOST_JSON_LIKELY( cs.remain() >= sz )) | ||
| 812 | { | 830 | { | |||||
| HITCBC | 813 | 11984 | int const cmp = std::memcmp(cs.begin(), literal, sz); | 831 | 12408 | int const cmp = std::memcmp(cs.begin(), literal, sz); | ||
| HITCBC | 814 | 11984 | if( cmp != 0 ) | 832 | 12408 | if( cmp != 0 ) | ||
| 815 | { | 833 | { | |||||
| 816 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 834 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 817 | 197 | return fail(cs.begin(), error::syntax, &loc); | 835 | 273 | return fail(cs.begin(), error::syntax, &loc); | ||
| 818 | } | 836 | } | |||||
| 819 | 837 | |||||||
| 820 | BOOST_IF_CONSTEXPR( Literal::value == L::null ) | 838 | BOOST_IF_CONSTEXPR( Literal::value == L::null ) | |||||
| 821 | { | 839 | { | |||||
| HITCBC | 822 | 10789 | if(BOOST_JSON_UNLIKELY( | 840 | 10789 | if(BOOST_JSON_UNLIKELY( | ||
| 823 | ! h_.on_null(ec_))) | 841 | ! h_.on_null(ec_))) | |||||
| HITCBC | 824 | 161 | return fail(cs.begin()); | 842 | 161 | return fail(cs.begin()); | ||
| 825 | } | 843 | } | |||||
| 826 | else BOOST_IF_CONSTEXPR( Literal::value == L::true_ ) | 844 | else BOOST_IF_CONSTEXPR( Literal::value == L::true_ ) | |||||
| 827 | { | 845 | { | |||||
| HITCBC | 828 | 384 | if(BOOST_JSON_UNLIKELY( | 846 | 384 | if(BOOST_JSON_UNLIKELY( | ||
| 829 | ! h_.on_bool(true, ec_))) | 847 | ! h_.on_bool(true, ec_))) | |||||
| HITCBC | 830 | 14 | return fail(cs.begin()); | 848 | 14 | return fail(cs.begin()); | ||
| 831 | } | 849 | } | |||||
| 832 | else BOOST_IF_CONSTEXPR( Literal::value == L::false_ ) | 850 | else BOOST_IF_CONSTEXPR( Literal::value == L::false_ ) | |||||
| 833 | { | 851 | { | |||||
| HITCBC | 834 | 406 | if(BOOST_JSON_UNLIKELY( | 852 | 406 | if(BOOST_JSON_UNLIKELY( | ||
| 835 | ! h_.on_bool(false, ec_))) | 853 | ! h_.on_bool(false, ec_))) | |||||
| HITCBC | 836 | 13 | return fail(cs.begin()); | 854 | 13 | return fail(cs.begin()); | ||
| 837 | } | 855 | } | |||||
| 838 | else BOOST_IF_CONSTEXPR( Literal::value == L::infinity ) | 856 | else BOOST_IF_CONSTEXPR( Literal::value == L::infinity ) | |||||
| 839 | { | 857 | { | |||||
| HITCBC | 840 | 103 | if(BOOST_JSON_UNLIKELY( | 858 | 277 | if(BOOST_JSON_UNLIKELY( | ||
| 841 | ! h_.on_double( | 859 | ! h_.on_double( | |||||
| 842 | std::numeric_limits<double>::infinity(), | 860 | std::numeric_limits<double>::infinity(), | |||||
| 843 | string_view(literal, sz), | 861 | string_view(literal, sz), | |||||
| 844 | ec_))) | 862 | ec_))) | |||||
| HITCBC | 845 | 13 | return fail(cs.begin()); | 863 | 39 | return fail(cs.begin()); | ||
| 846 | } | 864 | } | |||||
| 847 | else BOOST_IF_CONSTEXPR( Literal::value == L::neg_infinity ) | 865 | else BOOST_IF_CONSTEXPR( Literal::value == L::neg_infinity ) | |||||
| 848 | { | 866 | { | |||||
| HITCBC | 849 | 9 | if(BOOST_JSON_UNLIKELY( | 867 | 23 | if(BOOST_JSON_UNLIKELY( | ||
| 850 | ! h_.on_double( | 868 | ! h_.on_double( | |||||
| 851 | -std::numeric_limits<double>::infinity(), | 869 | -std::numeric_limits<double>::infinity(), | |||||
| 852 | string_view(literal, sz), | 870 | string_view(literal, sz), | |||||
| 853 | ec_))) | 871 | ec_))) | |||||
| HITCBC | 854 | 1 | return fail(cs.begin()); | 872 | 3 | return fail(cs.begin()); | ||
| 855 | } | 873 | } | |||||
| 856 | else BOOST_IF_CONSTEXPR( Literal::value == L::nan ) | 874 | else BOOST_IF_CONSTEXPR( Literal::value == L::nan ) | |||||
| 857 | { | 875 | { | |||||
| HITCBC | 858 | 96 | if(BOOST_JSON_UNLIKELY( | 876 | 256 | if(BOOST_JSON_UNLIKELY( | ||
| 859 | ! h_.on_double( | 877 | ! h_.on_double( | |||||
| 860 | std::numeric_limits<double>::quiet_NaN(), | 878 | std::numeric_limits<double>::quiet_NaN(), | |||||
| 861 | string_view(literal, sz), | 879 | string_view(literal, sz), | |||||
| 862 | ec_))) | 880 | ec_))) | |||||
| HITCBC | 863 | 12 | return fail(cs.begin()); | 881 | 36 | return fail(cs.begin()); | ||
| 864 | } | 882 | } | |||||
| 865 | else | 883 | else | |||||
| 866 | { | 884 | { | |||||
| 867 | BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE | 885 | BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE | |||||
| 868 | } | 886 | } | |||||
| 869 | 887 | |||||||
| HITCBC | 870 | 11363 | cs += sz; | 888 | 11607 | cs += sz; | ||
| HITCBC | 871 | 11363 | return cs.begin(); | 889 | 11607 | return cs.begin(); | ||
| 872 | } | 890 | } | |||||
| 873 | 891 | |||||||
| HITCBC | 874 | 1650 | offset = 0; | 892 | 2870 | offset = 0; | ||
| HITCBC | 875 | 1650 | cur_lit = index; | 893 | 2870 | cur_lit = index; | ||
| 876 | } | 894 | } | |||||
| 877 | else | 895 | else | |||||
| 878 | { | 896 | { | |||||
| 879 | state st; | 897 | state st; | |||||
| HITCBC | 880 | 2931 | st_.pop(st); | 898 | 6685 | st_.pop(st); | ||
| HITCBC | 881 | 2931 | BOOST_ASSERT( st == state::lit1 ); | 899 | 6685 | BOOST_ASSERT( st == state::lit1 ); | ||
| 882 | 900 | |||||||
| HITCBC | 883 | 2931 | cur_lit = cur_lit_; | 901 | 6685 | cur_lit = cur_lit_; | ||
| HITCBC | 884 | 2931 | offset = lit_offset_; | 902 | 6685 | offset = lit_offset_; | ||
| 885 | } | 903 | } | |||||
| 886 | 904 | |||||||
| HITCBC | 887 | 4581 | std::size_t const lit_size = detail::literal_sizes[cur_lit]; | 905 | 9555 | std::size_t const lit_size = detail::literal_sizes[cur_lit]; | ||
| HITCBC | 888 | 4581 | std::size_t const size = (std::min)( lit_size - offset, cs.remain() ); | 906 | 9555 | std::size_t const size = (std::min)( lit_size - offset, cs.remain() ); | ||
| HITCBC | 889 | 4581 | int cmp = 0; | 907 | 9555 | int cmp = 0; | ||
| HITCBC | 890 | 4581 | if(BOOST_JSON_LIKELY( cs.begin() )) | 908 | 9555 | if(BOOST_JSON_LIKELY( cs.begin() )) | ||
| HITCBC | 891 | 4580 | cmp = std::memcmp( | 909 | 9554 | cmp = std::memcmp( | ||
| HITCBC | 892 | 4580 | cs.begin(), detail::literal_strings[cur_lit] + offset, size ); | 910 | 9554 | cs.begin(), detail::literal_strings[cur_lit] + offset, size ); | ||
| HITCBC | 893 | 4581 | if( cmp != 0 ) | 911 | 9555 | if( cmp != 0 ) | ||
| 894 | { | 912 | { | |||||
| 895 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 913 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 896 | 699 | return fail(cs.begin(), error::syntax, &loc); | 914 | 1741 | return fail(cs.begin(), error::syntax, &loc); | ||
| 897 | } | 915 | } | |||||
| 898 | 916 | |||||||
| HITCBC | 899 | 3882 | if(BOOST_JSON_UNLIKELY( offset + size < lit_size )) | 917 | 7814 | if(BOOST_JSON_UNLIKELY( offset + size < lit_size )) | ||
| 900 | { | 918 | { | |||||
| HITCBC | 901 | 1990 | BOOST_ASSERT( cur_lit < 256 ); | 919 | 3914 | BOOST_ASSERT( cur_lit < 256 ); | ||
| HITCBC | 902 | 1990 | cur_lit_ = static_cast<unsigned char>( cur_lit ); | 920 | 3914 | cur_lit_ = static_cast<unsigned char>( cur_lit ); | ||
| HITCBC | 903 | 1990 | BOOST_ASSERT( offset + size < 256 ); | 921 | 3914 | BOOST_ASSERT( offset + size < 256 ); | ||
| HITCBC | 904 | 1990 | lit_offset_ = static_cast<unsigned char>( offset + size ); | 922 | 3914 | lit_offset_ = static_cast<unsigned char>( offset + size ); | ||
| HITCBC | 905 | 1990 | return maybe_suspend(cs.begin() + size, state::lit1); | 923 | 3914 | return maybe_suspend(cs.begin() + size, state::lit1); | ||
| 906 | } | 924 | } | |||||
| 907 | 925 | |||||||
| HITCBC | 908 | 1892 | switch( static_cast<L>(cur_lit) ) | 926 | 3900 | switch( static_cast<L>(cur_lit) ) | ||
| 909 | { | 927 | { | |||||
| HITCBC | 910 | 472 | case L::null: | 928 | 472 | case L::null: | ||
| HITCBC | 911 | 472 | if(BOOST_JSON_UNLIKELY( | 929 | 472 | if(BOOST_JSON_UNLIKELY( | ||
| 912 | ! h_.on_null(ec_))) | 930 | ! h_.on_null(ec_))) | |||||
| HITCBC | 913 | 61 | return fail(cs.begin()); | 931 | 61 | return fail(cs.begin()); | ||
| HITCBC | 914 | 351 | break; | 932 | 351 | break; | ||
| HITCBC | 915 | 152 | case L::true_: | 933 | 152 | case L::true_: | ||
| HITCBC | 916 | 152 | if(BOOST_JSON_UNLIKELY( | 934 | 152 | if(BOOST_JSON_UNLIKELY( | ||
| 917 | ! h_.on_bool(true, ec_))) | 935 | ! h_.on_bool(true, ec_))) | |||||
| HITCBC | 918 | 22 | return fail(cs.begin()); | 936 | 22 | return fail(cs.begin()); | ||
| HITCBC | 919 | 109 | break; | 937 | 109 | break; | ||
| HITCBC | 920 | 198 | case L::false_: | 938 | 198 | case L::false_: | ||
| HITCBC | 921 | 198 | if(BOOST_JSON_UNLIKELY( | 939 | 198 | if(BOOST_JSON_UNLIKELY( | ||
| 922 | ! h_.on_bool(false, ec_))) | 940 | ! h_.on_bool(false, ec_))) | |||||
| HITCBC | 923 | 28 | return fail(cs.begin()); | 941 | 28 | return fail(cs.begin()); | ||
| HITCBC | 924 | 142 | break; | 942 | 142 | break; | ||
| HITCBC | 925 | 308 | case L::infinity: | 943 | 910 | case L::infinity: | ||
| HITCBC | 926 | 308 | if(BOOST_JSON_UNLIKELY( | 944 | 910 | if(BOOST_JSON_UNLIKELY( | ||
| 927 | ! h_.on_double( | 945 | ! h_.on_double( | |||||
| 928 | std::numeric_limits<double>::infinity(), | 946 | std::numeric_limits<double>::infinity(), | |||||
| 929 | string_view( | 947 | string_view( | |||||
| 930 | detail::literal_strings[ literal_index(L::infinity) ], | 948 | detail::literal_strings[ literal_index(L::infinity) ], | |||||
| 931 | detail::literal_sizes[ literal_index(L::infinity) ]), | 949 | detail::literal_sizes[ literal_index(L::infinity) ]), | |||||
| 932 | ec_))) | 950 | ec_))) | |||||
| HITCBC | 933 | 49 | return fail(cs.begin()); | 951 | 147 | return fail(cs.begin()); | ||
| HITCBC | 934 | 210 | break; | 952 | 616 | break; | ||
| HITCBC | 935 | 686 | case L::neg_infinity: | 953 | 1944 | case L::neg_infinity: | ||
| HITCBC | 936 | 686 | if(BOOST_JSON_UNLIKELY( | 954 | 1944 | if(BOOST_JSON_UNLIKELY( | ||
| 937 | ! h_.on_double( | 955 | ! h_.on_double( | |||||
| 938 | -std::numeric_limits<double>::infinity(), | 956 | -std::numeric_limits<double>::infinity(), | |||||
| 939 | string_view( | 957 | string_view( | |||||
| 940 | detail::literal_strings[ literal_index(L::neg_infinity) ], | 958 | detail::literal_strings[ literal_index(L::neg_infinity) ], | |||||
| 941 | detail::literal_sizes[ literal_index(L::neg_infinity) ]), | 959 | detail::literal_sizes[ literal_index(L::neg_infinity) ]), | |||||
| 942 | ec_))) | 960 | ec_))) | |||||
| HITCBC | 943 | 102 | return fail(cs.begin()); | 961 | 306 | return fail(cs.begin()); | ||
| HITCBC | 944 | 482 | break; | 962 | 1332 | break; | ||
| HITCBC | 945 | 76 | case L::nan: | 963 | 224 | case L::nan: | ||
| HITCBC | 946 | 76 | if(BOOST_JSON_UNLIKELY( | 964 | 224 | if(BOOST_JSON_UNLIKELY( | ||
| 947 | ! h_.on_double( | 965 | ! h_.on_double( | |||||
| 948 | std::numeric_limits<double>::quiet_NaN(), | 966 | std::numeric_limits<double>::quiet_NaN(), | |||||
| 949 | string_view( | 967 | string_view( | |||||
| 950 | detail::literal_strings[ literal_index(L::nan) ], | 968 | detail::literal_strings[ literal_index(L::nan) ], | |||||
| 951 | detail::literal_sizes[ literal_index(L::nan) ]), | 969 | detail::literal_sizes[ literal_index(L::nan) ]), | |||||
| 952 | ec_))) | 970 | ec_))) | |||||
| HITCBC | 953 | 12 | return fail(cs.begin()); | 971 | 36 | return fail(cs.begin()); | ||
| HITCBC | 954 | 52 | break; | 972 | 152 | break; | ||
| 955 | default: BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE | 973 | default: BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE | |||||
| 956 | } | 974 | } | |||||
| 957 | 975 | |||||||
| HITCBC | 958 | 1346 | cs += size; | 976 | 2702 | cs += size; | ||
| HITCBC | 959 | 1346 | return cs.begin(); | 977 | 2702 | return cs.begin(); | ||
| 960 | } | 978 | } | |||||
| 961 | 979 | |||||||
| 962 | //---------------------------------------------------------- | 980 | //---------------------------------------------------------- | |||||
| 963 | 981 | |||||||
| 964 | template<class Handler> | 982 | template<class Handler> | |||||
| 965 | template<bool StackEmpty_, bool IsKey_> | 983 | template<bool StackEmpty_, bool IsKey_> | |||||
| 966 | const char* | 984 | const char* | |||||
| HITCBC | 967 | 164348 | basic_parser<Handler>:: | 985 | 164348 | basic_parser<Handler>:: | ||
| 968 | parse_string(const char* p, | 986 | parse_string(const char* p, | |||||
| 969 | std::integral_constant<bool, StackEmpty_> stack_empty, | 987 | std::integral_constant<bool, StackEmpty_> stack_empty, | |||||
| 970 | std::integral_constant<bool, IsKey_> is_key, | 988 | std::integral_constant<bool, IsKey_> is_key, | |||||
| 971 | bool allow_bad_utf8, | 989 | bool allow_bad_utf8, | |||||
| 972 | bool allow_bad_utf16) | 990 | bool allow_bad_utf16) | |||||
| 973 | { | 991 | { | |||||
| HITCBC | 974 | 164348 | detail::const_stream_wrapper cs(p, end_); | 992 | 164348 | detail::const_stream_wrapper cs(p, end_); | ||
| 975 | std::size_t total; | 993 | std::size_t total; | |||||
| 976 | char const* start; | 994 | char const* start; | |||||
| 977 | std::size_t size; | 995 | std::size_t size; | |||||
| HITCBC | 978 | 164348 | if(! stack_empty && ! st_.empty()) | 996 | 164348 | if(! stack_empty && ! st_.empty()) | ||
| 979 | { | 997 | { | |||||
| 980 | state st; | 998 | state st; | |||||
| HITCBC | 981 | 35919 | st_.pop(st); | 999 | 35919 | st_.pop(st); | ||
| HITCBC | 982 | 35919 | st_.pop(total); | 1000 | 35919 | st_.pop(total); | ||
| HITCBC | 983 | 35919 | switch(st) | 1001 | 35919 | switch(st) | ||
| 984 | { | 1002 | { | |||||
| 985 | default: BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE | 1003 | default: BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE | |||||
| HITCBC | 986 | 3149 | case state::str2: goto do_str2; | 1004 | 3149 | case state::str2: goto do_str2; | ||
| HITCBC | 987 | 1868 | case state::str8: goto do_str8; | 1005 | 1868 | case state::str8: goto do_str8; | ||
| HITCBC | 988 | 30902 | case state::str1: break; | 1006 | 30902 | case state::str1: break; | ||
| 989 | } | 1007 | } | |||||
| 990 | } | 1008 | } | |||||
| 991 | else | 1009 | else | |||||
| 992 | { | 1010 | { | |||||
| HITCBC | 993 | 128429 | BOOST_ASSERT(*cs == '\x22'); // '"' | 1011 | 128429 | BOOST_ASSERT(*cs == '\x22'); // '"' | ||
| HITCBC | 994 | 128429 | ++cs; | 1012 | 128429 | ++cs; | ||
| HITCBC | 995 | 128429 | total = 0; | 1013 | 128429 | total = 0; | ||
| 996 | } | 1014 | } | |||||
| 997 | 1015 | |||||||
| HITCBC | 998 | 167824 | do_str1: | 1016 | 167824 | do_str1: | ||
| HITCBC | 999 | 167824 | start = cs.begin(); | 1017 | 167824 | start = cs.begin(); | ||
| HITCBC | 1000 | 335648 | cs = allow_bad_utf8? | 1018 | 335648 | cs = allow_bad_utf8? | ||
| HITCBC | 1001 | 2177 | detail::count_valid<true>(cs.begin(), cs.end()): | 1019 | 2177 | detail::count_valid<true>(cs.begin(), cs.end()): | ||
| HITCBC | 1002 | 165647 | detail::count_valid<false>(cs.begin(), cs.end()); | 1020 | 165647 | detail::count_valid<false>(cs.begin(), cs.end()); | ||
| HITCBC | 1003 | 167824 | size = cs.used(start); | 1021 | 167824 | size = cs.used(start); | ||
| HITCBC | 1004 | 167824 | if(is_key) | 1022 | 167824 | if(is_key) | ||
| 1005 | { | 1023 | { | |||||
| HITCBC | 1006 | 46712 | BOOST_ASSERT(total <= Handler::max_key_size); | 1024 | 46712 | BOOST_ASSERT(total <= Handler::max_key_size); | ||
| HITCBC | 1007 | 94023 | if(BOOST_JSON_UNLIKELY(size > | 1025 | 94023 | if(BOOST_JSON_UNLIKELY(size > | ||
| 1008 | Handler::max_key_size - total)) | 1026 | Handler::max_key_size - total)) | |||||
| 1009 | { | 1027 | { | |||||
| 1010 | BOOST_STATIC_CONSTEXPR source_location loc | 1028 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 1011 | = BOOST_CURRENT_LOCATION; | 1029 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1012 | 3 | return fail(cs.begin(), error::key_too_large, &loc); | 1030 | 3 | return fail(cs.begin(), error::key_too_large, &loc); | ||
| 1013 | } | 1031 | } | |||||
| 1014 | } | 1032 | } | |||||
| 1015 | else | 1033 | else | |||||
| 1016 | { | 1034 | { | |||||
| HITCBC | 1017 | 38330 | BOOST_ASSERT(total <= Handler::max_string_size); | 1035 | 38330 | BOOST_ASSERT(total <= Handler::max_string_size); | ||
| HITCBC | 1018 | 73801 | if(BOOST_JSON_UNLIKELY(size > | 1036 | 73801 | if(BOOST_JSON_UNLIKELY(size > | ||
| 1019 | Handler::max_string_size - total)) | 1037 | Handler::max_string_size - total)) | |||||
| 1020 | { | 1038 | { | |||||
| 1021 | BOOST_STATIC_CONSTEXPR source_location loc | 1039 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 1022 | = BOOST_CURRENT_LOCATION; | 1040 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1023 | 3 | return fail(cs.begin(), error::string_too_large, &loc); | 1041 | 3 | return fail(cs.begin(), error::string_too_large, &loc); | ||
| 1024 | } | 1042 | } | |||||
| 1025 | } | 1043 | } | |||||
| HITCBC | 1026 | 167818 | total += size; | 1044 | 167818 | total += size; | ||
| HITCBC | 1027 | 167818 | if(BOOST_JSON_UNLIKELY(! cs)) | 1045 | 167818 | if(BOOST_JSON_UNLIKELY(! cs)) | ||
| 1028 | { | 1046 | { | |||||
| 1029 | // call handler if the string isn't empty | 1047 | // call handler if the string isn't empty | |||||
| HITCBC | 1030 | 33236 | if(BOOST_JSON_LIKELY(size)) | 1048 | 33236 | if(BOOST_JSON_LIKELY(size)) | ||
| 1031 | { | 1049 | { | |||||
| 1032 | { | 1050 | { | |||||
| HITCBC | 1033 | 30068 | bool r = is_key? | 1051 | 30068 | bool r = is_key? | ||
| HITCBC | 1034 | 12406 | h_.on_key_part( {start, size}, total, ec_ ): | 1052 | 12406 | h_.on_key_part( {start, size}, total, ec_ ): | ||
| HITCBC | 1035 | 18996 | h_.on_string_part( {start, size}, total, ec_ ); | 1053 | 18996 | h_.on_string_part( {start, size}, total, ec_ ); | ||
| 1036 | 1054 | |||||||
| HITCBC | 1037 | 28960 | if(BOOST_JSON_UNLIKELY(!r)) | 1055 | 28960 | if(BOOST_JSON_UNLIKELY(!r)) | ||
| 1038 | { | 1056 | { | |||||
| HITCBC | 1039 | 1110 | return fail(cs.begin()); | 1057 | 1110 | return fail(cs.begin()); | ||
| 1040 | } | 1058 | } | |||||
| 1041 | } | 1059 | } | |||||
| 1042 | } | 1060 | } | |||||
| HITCBC | 1043 | 31018 | return maybe_suspend(cs.begin(), state::str1, total); | 1061 | 31018 | return maybe_suspend(cs.begin(), state::str1, total); | ||
| 1044 | } | 1062 | } | |||||
| 1045 | // at this point all valid characters have been skipped, so any remaining | 1063 | // at this point all valid characters have been skipped, so any remaining | |||||
| 1046 | // if there are any more characters, they are either escaped, or incomplete | 1064 | // if there are any more characters, they are either escaped, or incomplete | |||||
| 1047 | // utf8, or invalid utf8 | 1065 | // utf8, or invalid utf8 | |||||
| HITCBC | 1048 | 134582 | if(BOOST_JSON_UNLIKELY(*cs != '\x22')) // '"' | 1066 | 134582 | if(BOOST_JSON_UNLIKELY(*cs != '\x22')) // '"' | ||
| 1049 | { | 1067 | { | |||||
| 1050 | // sequence is invalid or incomplete | 1068 | // sequence is invalid or incomplete | |||||
| HITCBC | 1051 | 15081 | if((*cs & 0x80) && !allow_bad_utf8) | 1069 | 15081 | if((*cs & 0x80) && !allow_bad_utf8) | ||
| 1052 | { | 1070 | { | |||||
| HITCBC | 1053 | 3472 | seq_.save(cs.begin(), cs.remain()); | 1071 | 3472 | seq_.save(cs.begin(), cs.remain()); | ||
| HITCBC | 1054 | 3472 | if(BOOST_JSON_UNLIKELY(seq_.complete())) | 1072 | 3472 | if(BOOST_JSON_UNLIKELY(seq_.complete())) | ||
| 1055 | { | 1073 | { | |||||
| 1056 | BOOST_STATIC_CONSTEXPR source_location loc | 1074 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 1057 | = BOOST_CURRENT_LOCATION; | 1075 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1058 | 1557 | return fail(cs.begin(), error::syntax, &loc); | 1076 | 1557 | return fail(cs.begin(), error::syntax, &loc); | ||
| 1059 | } | 1077 | } | |||||
| HITCBC | 1060 | 1915 | if(BOOST_JSON_LIKELY(size)) | 1078 | 1915 | if(BOOST_JSON_LIKELY(size)) | ||
| 1061 | { | 1079 | { | |||||
| HITCBC | 1062 | 245 | bool const r = is_key? | 1080 | 245 | bool const r = is_key? | ||
| HITCBC | 1063 | 22 | h_.on_key_part( {start, size}, total, ec_ ): | 1081 | 22 | h_.on_key_part( {start, size}, total, ec_ ): | ||
| HITCBC | 1064 | 245 | h_.on_string_part( {start, size}, total, ec_ ); | 1082 | 245 | h_.on_string_part( {start, size}, total, ec_ ); | ||
| HITCBC | 1065 | 223 | if(BOOST_JSON_UNLIKELY( !r )) | 1083 | 223 | if(BOOST_JSON_UNLIKELY( !r )) | ||
| HITCBC | 1066 | 22 | return fail( cs.begin() ); | 1084 | 22 | return fail( cs.begin() ); | ||
| 1067 | } | 1085 | } | |||||
| HITCBC | 1068 | 1871 | return maybe_suspend(cs.end(), state::str8, total); | 1086 | 1871 | return maybe_suspend(cs.end(), state::str8, total); | ||
| 1069 | } | 1087 | } | |||||
| HITCBC | 1070 | 11609 | else if(BOOST_JSON_LIKELY(*cs == '\\')) | 1088 | 11609 | else if(BOOST_JSON_LIKELY(*cs == '\\')) | ||
| 1071 | { | 1089 | { | |||||
| 1072 | // flush unescaped run from input | 1090 | // flush unescaped run from input | |||||
| HITCBC | 1073 | 11500 | if(BOOST_JSON_LIKELY(size)) | 1091 | 11500 | if(BOOST_JSON_LIKELY(size)) | ||
| 1074 | { | 1092 | { | |||||
| HITCBC | 1075 | 4250 | bool const r = is_key? | 1093 | 4250 | bool const r = is_key? | ||
| HITCBC | 1076 | 1226 | h_.on_key_part( {start, size}, total, ec_ ): | 1094 | 1226 | h_.on_key_part( {start, size}, total, ec_ ): | ||
| HITCBC | 1077 | 3554 | h_.on_string_part( {start, size}, total, ec_ ); | 1095 | 3554 | h_.on_string_part( {start, size}, total, ec_ ); | ||
| HITCBC | 1078 | 3766 | if(BOOST_JSON_UNLIKELY( !r )) | 1096 | 3766 | if(BOOST_JSON_UNLIKELY( !r )) | ||
| HITCBC | 1079 | 484 | return fail( cs.begin() ); | 1097 | 484 | return fail( cs.begin() ); | ||
| 1080 | } | 1098 | } | |||||
| HITCBC | 1081 | 7250 | do_str2: | 1099 | 7250 | do_str2: | ||
| HITCBC | 1082 | 13681 | cs = parse_escaped(cs.begin(), total, stack_empty, is_key, allow_bad_utf16); | 1100 | 13681 | cs = parse_escaped(cs.begin(), total, stack_empty, is_key, allow_bad_utf16); | ||
| HITCBC | 1083 | 12719 | if(BOOST_JSON_UNLIKELY( incomplete(cs) )) | 1101 | 12719 | if(BOOST_JSON_UNLIKELY( incomplete(cs) )) | ||
| HITCBC | 1084 | 5476 | return suspend_or_fail(state::str2, total); | 1102 | 5476 | return suspend_or_fail(state::str2, total); | ||
| 1085 | 1103 | |||||||
| HITCBC | 1086 | 7243 | goto do_str1; | 1104 | 7243 | goto do_str1; | ||
| 1087 | } | 1105 | } | |||||
| 1088 | // illegal control | 1106 | // illegal control | |||||
| 1089 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 1107 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1090 | 109 | return fail(cs.begin(), error::syntax, &loc); | 1108 | 109 | return fail(cs.begin(), error::syntax, &loc); | ||
| 1091 | } | 1109 | } | |||||
| 1092 | 1110 | |||||||
| 1093 | { | 1111 | { | |||||
| HITCBC | 1094 | 119501 | bool r = is_key? | 1112 | 119501 | bool r = is_key? | ||
| HITCBC | 1095 | 84525 | h_.on_key( {start, size}, total, ec_ ): | 1113 | 84525 | h_.on_key( {start, size}, total, ec_ ): | ||
| HITCBC | 1096 | 41985 | h_.on_string( {start, size}, total, ec_ ); | 1114 | 41985 | h_.on_string( {start, size}, total, ec_ ); | ||
| 1097 | 1115 | |||||||
| HITCBC | 1098 | 115127 | if(BOOST_JSON_UNLIKELY(!r)) | 1116 | 115127 | if(BOOST_JSON_UNLIKELY(!r)) | ||
| 1099 | { | 1117 | { | |||||
| HITCBC | 1100 | 4318 | return fail(cs.begin()); | 1118 | 4318 | return fail(cs.begin()); | ||
| 1101 | } | 1119 | } | |||||
| 1102 | } | 1120 | } | |||||
| 1103 | 1121 | |||||||
| HITCBC | 1104 | 110809 | ++cs; | 1122 | 110809 | ++cs; | ||
| HITCBC | 1105 | 110809 | return cs.begin(); | 1123 | 110809 | return cs.begin(); | ||
| 1106 | 1124 | |||||||
| HITCBC | 1107 | 1868 | do_str8: | 1125 | 1868 | do_str8: | ||
| HITCBC | 1108 | 1868 | uint8_t needed = seq_.needed(); | 1126 | 1868 | uint8_t needed = seq_.needed(); | ||
| HITCBC | 1109 | 1868 | if(BOOST_JSON_UNLIKELY( !seq_.append(cs.begin(), cs.remain()) )) | 1127 | 1868 | if(BOOST_JSON_UNLIKELY( !seq_.append(cs.begin(), cs.remain()) )) | ||
| HITCBC | 1110 | 4 | return maybe_suspend(cs.end(), state::str8, total); | 1128 | 4 | return maybe_suspend(cs.end(), state::str8, total); | ||
| HITCBC | 1111 | 1864 | if(BOOST_JSON_UNLIKELY( !seq_.valid() )) | 1129 | 1864 | if(BOOST_JSON_UNLIKELY( !seq_.valid() )) | ||
| 1112 | { | 1130 | { | |||||
| 1113 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 1131 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1114 | 210 | return fail(cs.begin(), error::syntax, &loc); | 1132 | 210 | return fail(cs.begin(), error::syntax, &loc); | ||
| 1115 | } | 1133 | } | |||||
| 1116 | { | 1134 | { | |||||
| HITCBC | 1117 | 1654 | std::size_t const n = seq_.length(); | 1135 | 1654 | std::size_t const n = seq_.length(); | ||
| 1118 | bool r; | 1136 | bool r; | |||||
| HITCBC | 1119 | 1654 | if(is_key) | 1137 | 1654 | if(is_key) | ||
| 1120 | { | 1138 | { | |||||
| HITCBC | 1121 | 2 | BOOST_ASSERT(total <= Handler::max_key_size); | 1139 | 2 | BOOST_ASSERT(total <= Handler::max_key_size); | ||
| HITCBC | 1122 | 2 | if(BOOST_JSON_UNLIKELY(n > | 1140 | 2 | if(BOOST_JSON_UNLIKELY(n > | ||
| 1123 | Handler::max_key_size - total)) | 1141 | Handler::max_key_size - total)) | |||||
| 1124 | { | 1142 | { | |||||
| 1125 | BOOST_STATIC_CONSTEXPR source_location loc | 1143 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 1126 | = BOOST_CURRENT_LOCATION; | 1144 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1127 | 1 | return fail(cs.begin(), error::key_too_large, &loc); | 1145 | 1 | return fail(cs.begin(), error::key_too_large, &loc); | ||
| 1128 | } | 1146 | } | |||||
| HITCBC | 1129 | 1 | total += n; | 1147 | 1 | total += n; | ||
| HITCBC | 1130 | 1 | r = h_.on_key_part( {seq_.data(), n}, total, ec_ ); | 1148 | 1 | r = h_.on_key_part( {seq_.data(), n}, total, ec_ ); | ||
| 1131 | } | 1149 | } | |||||
| 1132 | else | 1150 | else | |||||
| 1133 | { | 1151 | { | |||||
| HITCBC | 1134 | 1 | BOOST_ASSERT(total <= Handler::max_string_size); | 1152 | 1 | BOOST_ASSERT(total <= Handler::max_string_size); | ||
| HITCBC | 1135 | 1652 | if(BOOST_JSON_UNLIKELY(n > | 1153 | 1652 | if(BOOST_JSON_UNLIKELY(n > | ||
| 1136 | Handler::max_string_size - total)) | 1154 | Handler::max_string_size - total)) | |||||
| 1137 | { | 1155 | { | |||||
| 1138 | BOOST_STATIC_CONSTEXPR source_location loc | 1156 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 1139 | = BOOST_CURRENT_LOCATION; | 1157 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1140 | 1 | return fail(cs.begin(), error::string_too_large, &loc); | 1158 | 1 | return fail(cs.begin(), error::string_too_large, &loc); | ||
| 1141 | } | 1159 | } | |||||
| HITCBC | 1142 | 1651 | total += n; | 1160 | 1651 | total += n; | ||
| HITCBC | 1143 | 1651 | r = h_.on_string_part( {seq_.data(), n}, total, ec_ ); | 1161 | 1651 | r = h_.on_string_part( {seq_.data(), n}, total, ec_ ); | ||
| 1144 | } | 1162 | } | |||||
| HITCBC | 1145 | 1451 | if(BOOST_JSON_UNLIKELY( !r )) | 1163 | 1451 | if(BOOST_JSON_UNLIKELY( !r )) | ||
| HITCBC | 1146 | 201 | return fail( cs.begin() ); | 1164 | 201 | return fail( cs.begin() ); | ||
| 1147 | } | 1165 | } | |||||
| HITCBC | 1148 | 1250 | cs += needed; | 1166 | 1250 | cs += needed; | ||
| HITCBC | 1149 | 1250 | goto do_str1; | 1167 | 1250 | goto do_str1; | ||
| 1150 | } | 1168 | } | |||||
| 1151 | 1169 | |||||||
| 1152 | template<class Handler> | 1170 | template<class Handler> | |||||
| 1153 | template<bool StackEmpty_> | 1171 | template<bool StackEmpty_> | |||||
| 1154 | const char* | 1172 | const char* | |||||
| HITCBC | 1155 | 13681 | basic_parser<Handler>:: | 1173 | 13681 | basic_parser<Handler>:: | ||
| 1156 | parse_escaped( | 1174 | parse_escaped( | |||||
| 1157 | const char* p, | 1175 | const char* p, | |||||
| 1158 | std::size_t& total, | 1176 | std::size_t& total, | |||||
| 1159 | std::integral_constant<bool, StackEmpty_> stack_empty, | 1177 | std::integral_constant<bool, StackEmpty_> stack_empty, | |||||
| 1160 | bool is_key, | 1178 | bool is_key, | |||||
| 1161 | bool allow_bad_utf16) | 1179 | bool allow_bad_utf16) | |||||
| 1162 | { | 1180 | { | |||||
| HITCBC | 1163 | 13681 | constexpr unsigned urc = 0xFFFD; // Unicode replacement character | 1181 | 13681 | constexpr unsigned urc = 0xFFFD; // Unicode replacement character | ||
| HITCBC | 1164 | 13681 | auto const ev_too_large = is_key? | 1182 | 13681 | auto const ev_too_large = is_key? | ||
| 1165 | error::key_too_large : error::string_too_large; | 1183 | error::key_too_large : error::string_too_large; | |||||
| HITCBC | 1166 | 13681 | auto const max_size = is_key? | 1184 | 13681 | auto const max_size = is_key? | ||
| 1167 | Handler::max_key_size : Handler::max_string_size; | 1185 | Handler::max_key_size : Handler::max_string_size; | |||||
| 1168 | int digit; | 1186 | int digit; | |||||
| 1169 | 1187 | |||||||
| 1170 | //--------------------------------------------------------------- | 1188 | //--------------------------------------------------------------- | |||||
| 1171 | // | 1189 | // | |||||
| 1172 | // To handle escapes, a local temporary buffer accumulates | 1190 | // To handle escapes, a local temporary buffer accumulates | |||||
| 1173 | // the unescaped result. The algorithm attempts to fill the | 1191 | // the unescaped result. The algorithm attempts to fill the | |||||
| 1174 | // buffer to capacity before invoking the handler. | 1192 | // buffer to capacity before invoking the handler. | |||||
| 1175 | // In some cases the temporary buffer needs to be flushed | 1193 | // In some cases the temporary buffer needs to be flushed | |||||
| 1176 | // before it is full: | 1194 | // before it is full: | |||||
| 1177 | // * When the closing double quote is seen | 1195 | // * When the closing double quote is seen | |||||
| 1178 | // * When there in no more input (and more is expected later) | 1196 | // * When there in no more input (and more is expected later) | |||||
| 1179 | // A goal of the algorithm is to call the handler as few times | 1197 | // A goal of the algorithm is to call the handler as few times | |||||
| 1180 | // as possible. Thus, when the first escape is encountered, | 1198 | // as possible. Thus, when the first escape is encountered, | |||||
| 1181 | // the algorithm attempts to fill the temporary buffer first. | 1199 | // the algorithm attempts to fill the temporary buffer first. | |||||
| 1182 | // | 1200 | // | |||||
| HITCBC | 1183 | 13681 | detail::buffer<BOOST_JSON_STACK_BUFFER_SIZE> temp; | 1201 | 13681 | detail::buffer<BOOST_JSON_STACK_BUFFER_SIZE> temp; | ||
| 1184 | 1202 | |||||||
| 1185 | // Unescaped JSON is never larger than its escaped version. | 1203 | // Unescaped JSON is never larger than its escaped version. | |||||
| 1186 | // To efficiently process only what will fit in the temporary buffer, | 1204 | // To efficiently process only what will fit in the temporary buffer, | |||||
| 1187 | // the size of the input stream is temporarily "clipped" to the size | 1205 | // the size of the input stream is temporarily "clipped" to the size | |||||
| 1188 | // of the temporary buffer. | 1206 | // of the temporary buffer. | |||||
| 1189 | // handle escaped character | 1207 | // handle escaped character | |||||
| HITCBC | 1190 | 13681 | detail::clipped_const_stream cs(p, end_); | 1208 | 13681 | detail::clipped_const_stream cs(p, end_); | ||
| HITCBC | 1191 | 13681 | cs.clip(temp.max_size()); | 1209 | 13681 | cs.clip(temp.max_size()); | ||
| 1192 | 1210 | |||||||
| HITCBC | 1193 | 13681 | if(! stack_empty && ! st_.empty()) | 1211 | 13681 | if(! stack_empty && ! st_.empty()) | ||
| 1194 | { | 1212 | { | |||||
| 1195 | state st; | 1213 | state st; | |||||
| HITCBC | 1196 | 3149 | st_.pop(st); | 1214 | 3149 | st_.pop(st); | ||
| HITCBC | 1197 | 3149 | switch(st) | 1215 | 3149 | switch(st) | ||
| 1198 | { | 1216 | { | |||||
| 1199 | default: BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE | 1217 | default: BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE | |||||
| HITCBC | 1200 | 528 | case state::str3: goto do_str3; | 1218 | 528 | case state::str3: goto do_str3; | ||
| HITCBC | 1201 | 392 | case state::str4: goto do_str4; | 1219 | 392 | case state::str4: goto do_str4; | ||
| HITCBC | 1202 | 390 | case state::str5: goto do_str5; | 1220 | 390 | case state::str5: goto do_str5; | ||
| HITCBC | 1203 | 389 | case state::str6: goto do_str6; | 1221 | 389 | case state::str6: goto do_str6; | ||
| HITCBC | 1204 | 386 | case state::str7: goto do_str7; | 1222 | 386 | case state::str7: goto do_str7; | ||
| HITCBC | 1205 | 232 | case state::sur1: goto do_sur1; | 1223 | 232 | case state::sur1: goto do_sur1; | ||
| HITCBC | 1206 | 188 | case state::sur2: goto do_sur2; | 1224 | 188 | case state::sur2: goto do_sur2; | ||
| HITCBC | 1207 | 164 | case state::sur3: goto do_sur3; | 1225 | 164 | case state::sur3: goto do_sur3; | ||
| HITCBC | 1208 | 162 | case state::sur4: goto do_sur4; | 1226 | 162 | case state::sur4: goto do_sur4; | ||
| HITCBC | 1209 | 160 | case state::sur5: goto do_sur5; | 1227 | 160 | case state::sur5: goto do_sur5; | ||
| HITCBC | 1210 | 158 | case state::sur6: goto do_sur6; | 1228 | 158 | case state::sur6: goto do_sur6; | ||
| 1211 | } | 1229 | } | |||||
| 1212 | } | 1230 | } | |||||
| 1213 | 1231 | |||||||
| HITCBC | 1214 | 3783 | while(true) | 1232 | 3783 | while(true) | ||
| 1215 | { | 1233 | { | |||||
| HITCBC | 1216 | 14315 | BOOST_ASSERT( temp.capacity() ); | 1234 | 14315 | BOOST_ASSERT( temp.capacity() ); | ||
| HITCBC | 1217 | 14315 | BOOST_ASSERT(*cs == '\\'); | 1235 | 14315 | BOOST_ASSERT(*cs == '\\'); | ||
| HITCBC | 1218 | 14315 | ++cs; | 1236 | 14315 | ++cs; | ||
| HITCBC | 1219 | 15174 | do_str3: | 1237 | 15174 | do_str3: | ||
| HITCBC | 1220 | 15379 | if(BOOST_JSON_UNLIKELY(! cs)) | 1238 | 15379 | if(BOOST_JSON_UNLIKELY(! cs)) | ||
| 1221 | { | 1239 | { | |||||
| HITCBC | 1222 | 562 | if(BOOST_JSON_LIKELY(! temp.empty())) | 1240 | 562 | if(BOOST_JSON_LIKELY(! temp.empty())) | ||
| 1223 | { | 1241 | { | |||||
| HITCBC | 1224 | 1 | BOOST_ASSERT(total <= max_size); | 1242 | 1 | BOOST_ASSERT(total <= max_size); | ||
| HITCBC | 1225 | 101 | if(BOOST_JSON_UNLIKELY( | 1243 | 101 | if(BOOST_JSON_UNLIKELY( | ||
| 1226 | temp.size() > max_size - total)) | 1244 | temp.size() > max_size - total)) | |||||
| 1227 | { | 1245 | { | |||||
| 1228 | BOOST_STATIC_CONSTEXPR source_location loc | 1246 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 1229 | = BOOST_CURRENT_LOCATION; | 1247 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1230 | 1 | return fail(cs.begin(), ev_too_large, &loc); | 1248 | 1 | return fail(cs.begin(), ev_too_large, &loc); | ||
| 1231 | } | 1249 | } | |||||
| HITCBC | 1232 | 100 | total += temp.size(); | 1250 | 100 | total += temp.size(); | ||
| 1233 | { | 1251 | { | |||||
| HITCBC | 1234 | 91 | bool r = is_key | 1252 | 91 | bool r = is_key | ||
| HITCBC | 1235 | 100 | ? h_.on_key_part(temp.get(), total, ec_) | 1253 | 100 | ? h_.on_key_part(temp.get(), total, ec_) | ||
| HITCBC | 1236 | 100 | : h_.on_string_part(temp.get(), total, ec_); | 1254 | 100 | : h_.on_string_part(temp.get(), total, ec_); | ||
| 1237 | 1255 | |||||||
| HITCBC | 1238 | 91 | if(BOOST_JSON_UNLIKELY(!r)) | 1256 | 91 | if(BOOST_JSON_UNLIKELY(!r)) | ||
| 1239 | { | 1257 | { | |||||
| HITCBC | 1240 | 9 | return fail(cs.begin()); | 1258 | 9 | return fail(cs.begin()); | ||
| 1241 | } | 1259 | } | |||||
| 1242 | } | 1260 | } | |||||
| HITCBC | 1243 | 82 | temp.clear(); | 1261 | 82 | temp.clear(); | ||
| 1244 | } | 1262 | } | |||||
| HITCBC | 1245 | 543 | cs.clip(temp.max_size()); | 1263 | 543 | cs.clip(temp.max_size()); | ||
| HITCBC | 1246 | 543 | if(BOOST_JSON_UNLIKELY(! cs)) | 1264 | 543 | if(BOOST_JSON_UNLIKELY(! cs)) | ||
| HITCBC | 1247 | 543 | return maybe_suspend(cs.begin(), state::str3); | 1265 | 543 | return maybe_suspend(cs.begin(), state::str3); | ||
| 1248 | } | 1266 | } | |||||
| HITCBC | 1249 | 14817 | switch(*cs) | 1267 | 14817 | switch(*cs) | ||
| 1250 | { | 1268 | { | |||||
| HITCBC | 1251 | 191 | default: | 1269 | 191 | default: | ||
| 1252 | { | 1270 | { | |||||
| 1253 | BOOST_STATIC_CONSTEXPR source_location loc | 1271 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 1254 | = BOOST_CURRENT_LOCATION; | 1272 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1255 | 191 | return fail(cs.begin(), error::syntax, &loc); | 1273 | 191 | return fail(cs.begin(), error::syntax, &loc); | ||
| 1256 | } | 1274 | } | |||||
| HITCBC | 1257 | 265 | case '\x22': // '"' | 1275 | 265 | case '\x22': // '"' | ||
| HITCBC | 1258 | 265 | temp.push_back('\x22'); | 1276 | 265 | temp.push_back('\x22'); | ||
| HITCBC | 1259 | 265 | ++cs; | 1277 | 265 | ++cs; | ||
| HITCBC | 1260 | 265 | break; | 1278 | 265 | break; | ||
| HITCBC | 1261 | 178 | case '\\': | 1279 | 178 | case '\\': | ||
| HITCBC | 1262 | 178 | temp.push_back('\\'); | 1280 | 178 | temp.push_back('\\'); | ||
| HITCBC | 1263 | 178 | ++cs; | 1281 | 178 | ++cs; | ||
| HITCBC | 1264 | 178 | break; | 1282 | 178 | break; | ||
| HITCBC | 1265 | 96 | case '/': | 1283 | 96 | case '/': | ||
| HITCBC | 1266 | 96 | temp.push_back('/'); | 1284 | 96 | temp.push_back('/'); | ||
| HITCBC | 1267 | 96 | ++cs; | 1285 | 96 | ++cs; | ||
| HITCBC | 1268 | 96 | break; | 1286 | 96 | break; | ||
| HITCBC | 1269 | 112 | case 'b': | 1287 | 112 | case 'b': | ||
| HITCBC | 1270 | 112 | temp.push_back('\x08'); | 1288 | 112 | temp.push_back('\x08'); | ||
| HITCBC | 1271 | 112 | ++cs; | 1289 | 112 | ++cs; | ||
| HITCBC | 1272 | 112 | break; | 1290 | 112 | break; | ||
| HITCBC | 1273 | 108 | case 'f': | 1291 | 108 | case 'f': | ||
| HITCBC | 1274 | 108 | temp.push_back('\x0c'); | 1292 | 108 | temp.push_back('\x0c'); | ||
| HITCBC | 1275 | 108 | ++cs; | 1293 | 108 | ++cs; | ||
| HITCBC | 1276 | 108 | break; | 1294 | 108 | break; | ||
| HITCBC | 1277 | 1766 | case 'n': | 1295 | 1766 | case 'n': | ||
| HITCBC | 1278 | 1766 | temp.push_back('\x0a'); | 1296 | 1766 | temp.push_back('\x0a'); | ||
| HITCBC | 1279 | 1766 | ++cs; | 1297 | 1766 | ++cs; | ||
| HITCBC | 1280 | 1766 | break; | 1298 | 1766 | break; | ||
| HITCBC | 1281 | 146 | case 'r': | 1299 | 146 | case 'r': | ||
| HITCBC | 1282 | 146 | temp.push_back('\x0d'); | 1300 | 146 | temp.push_back('\x0d'); | ||
| HITCBC | 1283 | 146 | ++cs; | 1301 | 146 | ++cs; | ||
| HITCBC | 1284 | 146 | break; | 1302 | 146 | break; | ||
| HITCBC | 1285 | 266 | case 't': | 1303 | 266 | case 't': | ||
| HITCBC | 1286 | 266 | temp.push_back('\x09'); | 1304 | 266 | temp.push_back('\x09'); | ||
| HITCBC | 1287 | 266 | ++cs; | 1305 | 266 | ++cs; | ||
| HITCBC | 1288 | 266 | break; | 1306 | 266 | break; | ||
| HITCBC | 1289 | 11689 | case 'u': | 1307 | 11689 | case 'u': | ||
| 1290 | // utf16 escape | 1308 | // utf16 escape | |||||
| 1291 | // | 1309 | // | |||||
| 1292 | // fast path only when the buffer | 1310 | // fast path only when the buffer | |||||
| 1293 | // is large enough for 2 surrogates | 1311 | // is large enough for 2 surrogates | |||||
| HITCBC | 1294 | 11689 | if(BOOST_JSON_LIKELY(cs.remain() > 10)) | 1312 | 11689 | if(BOOST_JSON_LIKELY(cs.remain() > 10)) | ||
| 1295 | { | 1313 | { | |||||
| 1296 | // KRYSTIAN TODO: this could be done | 1314 | // KRYSTIAN TODO: this could be done | |||||
| 1297 | // with fewer instructions | 1315 | // with fewer instructions | |||||
| HITCBC | 1298 | 11394 | digit = detail::load_little_endian<4>( | 1316 | 11394 | digit = detail::load_little_endian<4>( | ||
| HITCBC | 1299 | 5697 | cs.begin() + 1); | 1317 | 5697 | cs.begin() + 1); | ||
| HITCBC | 1300 | 5697 | int d4 = detail::hex_digit(static_cast< | 1318 | 5697 | int d4 = detail::hex_digit(static_cast< | ||
| HITCBC | 1301 | 5697 | unsigned char>(digit >> 24)); | 1319 | 5697 | unsigned char>(digit >> 24)); | ||
| HITCBC | 1302 | 5697 | int d3 = detail::hex_digit(static_cast< | 1320 | 5697 | int d3 = detail::hex_digit(static_cast< | ||
| HITCBC | 1303 | 5697 | unsigned char>(digit >> 16)); | 1321 | 5697 | unsigned char>(digit >> 16)); | ||
| HITCBC | 1304 | 5697 | int d2 = detail::hex_digit(static_cast< | 1322 | 5697 | int d2 = detail::hex_digit(static_cast< | ||
| HITCBC | 1305 | 5697 | unsigned char>(digit >> 8)); | 1323 | 5697 | unsigned char>(digit >> 8)); | ||
| HITCBC | 1306 | 5697 | int d1 = detail::hex_digit(static_cast< | 1324 | 5697 | int d1 = detail::hex_digit(static_cast< | ||
| 1307 | unsigned char>(digit)); | 1325 | unsigned char>(digit)); | |||||
| HITCBC | 1308 | 5697 | if(BOOST_JSON_UNLIKELY( | 1326 | 5697 | if(BOOST_JSON_UNLIKELY( | ||
| 1309 | (d1 | d2 | d3 | d4) == -1)) | 1327 | (d1 | d2 | d3 | d4) == -1)) | |||||
| 1310 | { | 1328 | { | |||||
| HITCBC | 1311 | 60 | if(d1 != -1) | 1329 | 60 | if(d1 != -1) | ||
| HITCBC | 1312 | 45 | ++cs; | 1330 | 45 | ++cs; | ||
| HITCBC | 1313 | 60 | if(d2 != -1) | 1331 | 60 | if(d2 != -1) | ||
| HITCBC | 1314 | 30 | ++cs; | 1332 | 30 | ++cs; | ||
| HITCBC | 1315 | 60 | if(d3 != -1) | 1333 | 60 | if(d3 != -1) | ||
| HITCBC | 1316 | 15 | ++cs; | 1334 | 15 | ++cs; | ||
| 1317 | BOOST_STATIC_CONSTEXPR source_location loc | 1335 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 1318 | = BOOST_CURRENT_LOCATION; | 1336 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1319 | 60 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1337 | 60 | return fail(cs.begin(), error::expected_hex_digit, &loc); | ||
| 1320 | } | 1338 | } | |||||
| 1321 | // 32 bit unicode scalar value | 1339 | // 32 bit unicode scalar value | |||||
| HITCBC | 1322 | 5637 | unsigned u1 = | 1340 | 5637 | unsigned u1 = | ||
| HITCBC | 1323 | 5637 | (d1 << 12) + (d2 << 8) + | 1341 | 5637 | (d1 << 12) + (d2 << 8) + | ||
| HITCBC | 1324 | 5637 | (d3 << 4) + d4; | 1342 | 5637 | (d3 << 4) + d4; | ||
| 1325 | // valid unicode scalar values are | 1343 | // valid unicode scalar values are | |||||
| 1326 | // [0, D7FF] and [E000, 10FFFF] | 1344 | // [0, D7FF] and [E000, 10FFFF] | |||||
| 1327 | // values within this range are valid utf-8 | 1345 | // values within this range are valid utf-8 | |||||
| 1328 | // code points and invalid leading surrogates. | 1346 | // code points and invalid leading surrogates. | |||||
| HITCBC | 1329 | 5637 | if(BOOST_JSON_LIKELY( | 1347 | 5637 | if(BOOST_JSON_LIKELY( | ||
| 1330 | u1 < 0xd800 || u1 > 0xdfff)) | 1348 | u1 < 0xd800 || u1 > 0xdfff)) | |||||
| 1331 | { | 1349 | { | |||||
| HITCBC | 1332 | 1340 | cs += 5; | 1350 | 1340 | cs += 5; | ||
| HITCBC | 1333 | 1340 | temp.append_utf8(u1); | 1351 | 1340 | temp.append_utf8(u1); | ||
| HITCBC | 1334 | 1340 | break; | 1352 | 1340 | break; | ||
| 1335 | } | 1353 | } | |||||
| HITCBC | 1336 | 4297 | if(BOOST_JSON_UNLIKELY(u1 > 0xdbff)) | 1354 | 4297 | if(BOOST_JSON_UNLIKELY(u1 > 0xdbff)) | ||
| 1337 | { | 1355 | { | |||||
| 1338 | // If it's an illegal leading surrogate and | 1356 | // If it's an illegal leading surrogate and | |||||
| 1339 | // the parser does not allow it, return an error. | 1357 | // the parser does not allow it, return an error. | |||||
| HITCBC | 1340 | 707 | if(!allow_bad_utf16) | 1358 | 707 | if(!allow_bad_utf16) | ||
| 1341 | { | 1359 | { | |||||
| 1342 | BOOST_STATIC_CONSTEXPR source_location loc | 1360 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 1343 | = BOOST_CURRENT_LOCATION; | 1361 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1344 | 122 | return fail(cs.begin(), error::illegal_leading_surrogate, | 1362 | 122 | return fail(cs.begin(), error::illegal_leading_surrogate, | ||
| HITCBC | 1345 | 122 | &loc); | 1363 | 122 | &loc); | ||
| 1346 | } | 1364 | } | |||||
| 1347 | // Otherwise, append the Unicode replacement character | 1365 | // Otherwise, append the Unicode replacement character | |||||
| 1348 | else | 1366 | else | |||||
| 1349 | { | 1367 | { | |||||
| HITCBC | 1350 | 585 | cs += 5; | 1368 | 585 | cs += 5; | ||
| HITCBC | 1351 | 585 | temp.append_utf8(urc); | 1369 | 585 | temp.append_utf8(urc); | ||
| HITCBC | 1352 | 585 | break; | 1370 | 585 | break; | ||
| 1353 | } | 1371 | } | |||||
| 1354 | } | 1372 | } | |||||
| HITCBC | 1355 | 3590 | cs += 5; | 1373 | 3590 | cs += 5; | ||
| 1356 | // KRYSTIAN TODO: this can be a two byte load | 1374 | // KRYSTIAN TODO: this can be a two byte load | |||||
| 1357 | // and a single comparison. We lose error information, | 1375 | // and a single comparison. We lose error information, | |||||
| 1358 | // but it's faster. | 1376 | // but it's faster. | |||||
| HITCBC | 1359 | 3590 | if(BOOST_JSON_UNLIKELY(*cs != '\\')) | 1377 | 3590 | if(BOOST_JSON_UNLIKELY(*cs != '\\')) | ||
| 1360 | { | 1378 | { | |||||
| 1361 | // If the next character is not a backslash and | 1379 | // If the next character is not a backslash and | |||||
| 1362 | // the parser does not allow it, return a syntax error. | 1380 | // the parser does not allow it, return a syntax error. | |||||
| HITCBC | 1363 | 156 | if(!allow_bad_utf16) | 1381 | 156 | if(!allow_bad_utf16) | ||
| 1364 | { | 1382 | { | |||||
| 1365 | BOOST_STATIC_CONSTEXPR source_location loc | 1383 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 1366 | = BOOST_CURRENT_LOCATION; | 1384 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1367 | 15 | return fail(cs.begin(), error::syntax, &loc); | 1385 | 15 | return fail(cs.begin(), error::syntax, &loc); | ||
| 1368 | } | 1386 | } | |||||
| 1369 | // Otherwise, append the Unicode replacement character since | 1387 | // Otherwise, append the Unicode replacement character since | |||||
| 1370 | // the first code point is a valid leading surrogate | 1388 | // the first code point is a valid leading surrogate | |||||
| 1371 | else | 1389 | else | |||||
| 1372 | { | 1390 | { | |||||
| HITCBC | 1373 | 141 | temp.append_utf8(urc); | 1391 | 141 | temp.append_utf8(urc); | ||
| HITCBC | 1374 | 141 | break; | 1392 | 141 | break; | ||
| 1375 | } | 1393 | } | |||||
| 1376 | } | 1394 | } | |||||
| HITCBC | 1377 | 3434 | ++cs; | 1395 | 3434 | ++cs; | ||
| HITCBC | 1378 | 3434 | if(BOOST_JSON_UNLIKELY(*cs != 'u')) | 1396 | 3434 | if(BOOST_JSON_UNLIKELY(*cs != 'u')) | ||
| 1379 | { | 1397 | { | |||||
| HITCBC | 1380 | 220 | if (!allow_bad_utf16) | 1398 | 220 | if (!allow_bad_utf16) | ||
| 1381 | { | 1399 | { | |||||
| 1382 | BOOST_STATIC_CONSTEXPR source_location loc | 1400 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 1383 | = BOOST_CURRENT_LOCATION; | 1401 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1384 | 15 | return fail(cs.begin(), error::syntax, &loc); | 1402 | 15 | return fail(cs.begin(), error::syntax, &loc); | ||
| 1385 | } | 1403 | } | |||||
| 1386 | // Otherwise, append the Unicode replacement character since | 1404 | // Otherwise, append the Unicode replacement character since | |||||
| 1387 | // the first code point is a valid leading surrogate | 1405 | // the first code point is a valid leading surrogate | |||||
| 1388 | else | 1406 | else | |||||
| 1389 | { | 1407 | { | |||||
| HITCBC | 1390 | 205 | temp.append_utf8(urc); | 1408 | 205 | temp.append_utf8(urc); | ||
| HITCBC | 1391 | 205 | goto do_str3; | 1409 | 205 | goto do_str3; | ||
| 1392 | } | 1410 | } | |||||
| 1393 | } | 1411 | } | |||||
| HITCBC | 1394 | 3214 | ++cs; | 1412 | 3214 | ++cs; | ||
| HITCBC | 1395 | 3214 | digit = detail::load_little_endian<4>(cs.begin()); | 1413 | 3214 | digit = detail::load_little_endian<4>(cs.begin()); | ||
| HITCBC | 1396 | 3214 | d4 = detail::hex_digit(static_cast< | 1414 | 3214 | d4 = detail::hex_digit(static_cast< | ||
| HITCBC | 1397 | 3214 | unsigned char>(digit >> 24)); | 1415 | 3214 | unsigned char>(digit >> 24)); | ||
| HITCBC | 1398 | 3214 | d3 = detail::hex_digit(static_cast< | 1416 | 3214 | d3 = detail::hex_digit(static_cast< | ||
| HITCBC | 1399 | 3214 | unsigned char>(digit >> 16)); | 1417 | 3214 | unsigned char>(digit >> 16)); | ||
| HITCBC | 1400 | 3214 | d2 = detail::hex_digit(static_cast< | 1418 | 3214 | d2 = detail::hex_digit(static_cast< | ||
| HITCBC | 1401 | 3214 | unsigned char>(digit >> 8)); | 1419 | 3214 | unsigned char>(digit >> 8)); | ||
| HITCBC | 1402 | 3214 | d1 = detail::hex_digit(static_cast< | 1420 | 3214 | d1 = detail::hex_digit(static_cast< | ||
| 1403 | unsigned char>(digit)); | 1421 | unsigned char>(digit)); | |||||
| HITCBC | 1404 | 3214 | if(BOOST_JSON_UNLIKELY( | 1422 | 3214 | if(BOOST_JSON_UNLIKELY( | ||
| 1405 | (d1 | d2 | d3 | d4) == -1)) | 1423 | (d1 | d2 | d3 | d4) == -1)) | |||||
| 1406 | { | 1424 | { | |||||
| HITCBC | 1407 | 90 | if(d1 != -1) | 1425 | 90 | if(d1 != -1) | ||
| HITCBC | 1408 | 75 | ++cs; | 1426 | 75 | ++cs; | ||
| HITCBC | 1409 | 90 | if(d2 != -1) | 1427 | 90 | if(d2 != -1) | ||
| HITCBC | 1410 | 45 | ++cs; | 1428 | 45 | ++cs; | ||
| HITCBC | 1411 | 90 | if(d3 != -1) | 1429 | 90 | if(d3 != -1) | ||
| HITCBC | 1412 | 15 | ++cs; | 1430 | 15 | ++cs; | ||
| 1413 | BOOST_STATIC_CONSTEXPR source_location loc | 1431 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 1414 | = BOOST_CURRENT_LOCATION; | 1432 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1415 | 90 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1433 | 90 | return fail(cs.begin(), error::expected_hex_digit, &loc); | ||
| 1416 | } | 1434 | } | |||||
| HITCBC | 1417 | 3124 | unsigned u2 = | 1435 | 3124 | unsigned u2 = | ||
| HITCBC | 1418 | 3124 | (d1 << 12) + (d2 << 8) + | 1436 | 3124 | (d1 << 12) + (d2 << 8) + | ||
| HITCBC | 1419 | 3124 | (d3 << 4) + d4; | 1437 | 3124 | (d3 << 4) + d4; | ||
| 1420 | // Check if the second code point is a valid trailing surrogate. | 1438 | // Check if the second code point is a valid trailing surrogate. | |||||
| 1421 | // Valid trailing surrogates are [DC00, DFFF] | 1439 | // Valid trailing surrogates are [DC00, DFFF] | |||||
| HITCBC | 1422 | 3124 | if(BOOST_JSON_UNLIKELY( | 1440 | 3124 | if(BOOST_JSON_UNLIKELY( | ||
| 1423 | u2 < 0xdc00 || u2 > 0xdfff)) | 1441 | u2 < 0xdc00 || u2 > 0xdfff)) | |||||
| 1424 | { | 1442 | { | |||||
| 1425 | // If not valid and the parser does not allow it, return an error. | 1443 | // If not valid and the parser does not allow it, return an error. | |||||
| HITCBC | 1426 | 1353 | if(!allow_bad_utf16) | 1444 | 1353 | if(!allow_bad_utf16) | ||
| 1427 | { | 1445 | { | |||||
| 1428 | BOOST_STATIC_CONSTEXPR source_location loc | 1446 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 1429 | = BOOST_CURRENT_LOCATION; | 1447 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1430 | 136 | return fail(cs.begin(), error::illegal_trailing_surrogate, | 1448 | 136 | return fail(cs.begin(), error::illegal_trailing_surrogate, | ||
| HITCBC | 1431 | 136 | &loc); | 1449 | 136 | &loc); | ||
| 1432 | } | 1450 | } | |||||
| 1433 | // Append the replacement character for the | 1451 | // Append the replacement character for the | |||||
| 1434 | // first leading surrogate. | 1452 | // first leading surrogate. | |||||
| HITCBC | 1435 | 1217 | cs += 4; | 1453 | 1217 | cs += 4; | ||
| HITCBC | 1436 | 1217 | temp.append_utf8(urc); | 1454 | 1217 | temp.append_utf8(urc); | ||
| 1437 | // Check if the second code point is a | 1455 | // Check if the second code point is a | |||||
| 1438 | // valid unicode scalar value (invalid leading | 1456 | // valid unicode scalar value (invalid leading | |||||
| 1439 | // or trailing surrogate) | 1457 | // or trailing surrogate) | |||||
| HITCBC | 1440 | 1217 | if (u2 < 0xd800 || u2 > 0xdbff) | 1458 | 1217 | if (u2 < 0xd800 || u2 > 0xdbff) | ||
| 1441 | { | 1459 | { | |||||
| HITCBC | 1442 | 524 | temp.append_utf8(u2); | 1460 | 524 | temp.append_utf8(u2); | ||
| HITCBC | 1443 | 524 | break; | 1461 | 524 | break; | ||
| 1444 | } | 1462 | } | |||||
| 1445 | // If it is a valid leading surrogate | 1463 | // If it is a valid leading surrogate | |||||
| 1446 | else | 1464 | else | |||||
| 1447 | { | 1465 | { | |||||
| HITCBC | 1448 | 693 | u1_ = u2; | 1466 | 693 | u1_ = u2; | ||
| HITCBC | 1449 | 693 | goto do_sur1; | 1467 | 693 | goto do_sur1; | ||
| 1450 | } | 1468 | } | |||||
| 1451 | } | 1469 | } | |||||
| HITCBC | 1452 | 1771 | cs += 4; | 1470 | 1771 | cs += 4; | ||
| 1453 | // Calculate the Unicode code point from the surrogate pair and | 1471 | // Calculate the Unicode code point from the surrogate pair and | |||||
| 1454 | // append the UTF-8 representation. | 1472 | // append the UTF-8 representation. | |||||
| HITCBC | 1455 | 1771 | unsigned cp = | 1473 | 1771 | unsigned cp = | ||
| HITCBC | 1456 | 1771 | ((u1 - 0xd800) << 10) + | 1474 | 1771 | ((u1 - 0xd800) << 10) + | ||
| 1457 | ((u2 - 0xdc00)) + | 1475 | ((u2 - 0xdc00)) + | |||||
| 1458 | 0x10000; | 1476 | 0x10000; | |||||
| 1459 | // utf-16 surrogate pair | 1477 | // utf-16 surrogate pair | |||||
| HITCBC | 1460 | 1771 | temp.append_utf8(cp); | 1478 | 1771 | temp.append_utf8(cp); | ||
| HITCBC | 1461 | 1771 | break; | 1479 | 1771 | break; | ||
| 1462 | } | 1480 | } | |||||
| 1463 | // flush | 1481 | // flush | |||||
| HITCBC | 1464 | 5992 | if(BOOST_JSON_LIKELY(! temp.empty())) | 1482 | 5992 | if(BOOST_JSON_LIKELY(! temp.empty())) | ||
| 1465 | { | 1483 | { | |||||
| HITCBC | 1466 | 4 | BOOST_ASSERT(total <= max_size); | 1484 | 4 | BOOST_ASSERT(total <= max_size); | ||
| HITCBC | 1467 | 1723 | if(BOOST_JSON_UNLIKELY( | 1485 | 1723 | if(BOOST_JSON_UNLIKELY( | ||
| 1468 | temp.size() > max_size - total)) | 1486 | temp.size() > max_size - total)) | |||||
| 1469 | { | 1487 | { | |||||
| 1470 | BOOST_STATIC_CONSTEXPR source_location loc | 1488 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 1471 | = BOOST_CURRENT_LOCATION; | 1489 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1472 | 1 | return fail(cs.begin(), ev_too_large, &loc); | 1490 | 1 | return fail(cs.begin(), ev_too_large, &loc); | ||
| 1473 | } | 1491 | } | |||||
| HITCBC | 1474 | 1722 | total += temp.size(); | 1492 | 1722 | total += temp.size(); | ||
| 1475 | { | 1493 | { | |||||
| HITCBC | 1476 | 1582 | bool r = is_key | 1494 | 1582 | bool r = is_key | ||
| HITCBC | 1477 | 1722 | ? h_.on_key_part(temp.get(), total, ec_) | 1495 | 1722 | ? h_.on_key_part(temp.get(), total, ec_) | ||
| HITCBC | 1478 | 1722 | : h_.on_string_part(temp.get(), total, ec_); | 1496 | 1722 | : h_.on_string_part(temp.get(), total, ec_); | ||
| 1479 | 1497 | |||||||
| HITCBC | 1480 | 1582 | if(BOOST_JSON_UNLIKELY(!r)) | 1498 | 1582 | if(BOOST_JSON_UNLIKELY(!r)) | ||
| 1481 | { | 1499 | { | |||||
| HITCBC | 1482 | 140 | return fail(cs.begin()); | 1500 | 140 | return fail(cs.begin()); | ||
| 1483 | } | 1501 | } | |||||
| 1484 | } | 1502 | } | |||||
| HITCBC | 1485 | 1442 | temp.clear(); | 1503 | 1442 | temp.clear(); | ||
| HITCBC | 1486 | 1442 | cs.clip(temp.max_size()); | 1504 | 1442 | cs.clip(temp.max_size()); | ||
| 1487 | } | 1505 | } | |||||
| HITCBC | 1488 | 5711 | ++cs; | 1506 | 5711 | ++cs; | ||
| 1489 | // utf-16 escape | 1507 | // utf-16 escape | |||||
| HITCBC | 1490 | 6103 | do_str4: | 1508 | 6103 | do_str4: | ||
| HITCBC | 1491 | 6103 | if(BOOST_JSON_UNLIKELY(! cs)) | 1509 | 6103 | if(BOOST_JSON_UNLIKELY(! cs)) | ||
| HITCBC | 1492 | 392 | return maybe_suspend(cs.begin(), state::str4); | 1510 | 392 | return maybe_suspend(cs.begin(), state::str4); | ||
| HITCBC | 1493 | 5711 | digit = detail::hex_digit(*cs); | 1511 | 5711 | digit = detail::hex_digit(*cs); | ||
| HITCBC | 1494 | 5711 | if(BOOST_JSON_UNLIKELY(digit == -1)) | 1512 | 5711 | if(BOOST_JSON_UNLIKELY(digit == -1)) | ||
| 1495 | { | 1513 | { | |||||
| 1496 | BOOST_STATIC_CONSTEXPR source_location loc | 1514 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 1497 | = BOOST_CURRENT_LOCATION; | 1515 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1498 | 50 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1516 | 50 | return fail(cs.begin(), error::expected_hex_digit, &loc); | ||
| 1499 | } | 1517 | } | |||||
| HITCBC | 1500 | 5661 | ++cs; | 1518 | 5661 | ++cs; | ||
| HITCBC | 1501 | 5661 | u1_ = digit << 12; | 1519 | 5661 | u1_ = digit << 12; | ||
| HITCBC | 1502 | 6051 | do_str5: | 1520 | 6051 | do_str5: | ||
| HITCBC | 1503 | 6051 | if(BOOST_JSON_UNLIKELY(! cs)) | 1521 | 6051 | if(BOOST_JSON_UNLIKELY(! cs)) | ||
| HITCBC | 1504 | 390 | return maybe_suspend(cs.begin(), state::str5); | 1522 | 390 | return maybe_suspend(cs.begin(), state::str5); | ||
| HITCBC | 1505 | 5661 | digit = detail::hex_digit(*cs); | 1523 | 5661 | digit = detail::hex_digit(*cs); | ||
| HITCBC | 1506 | 5661 | if(BOOST_JSON_UNLIKELY(digit == -1)) | 1524 | 5661 | if(BOOST_JSON_UNLIKELY(digit == -1)) | ||
| 1507 | { | 1525 | { | |||||
| 1508 | BOOST_STATIC_CONSTEXPR source_location loc | 1526 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 1509 | = BOOST_CURRENT_LOCATION; | 1527 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1510 | 20 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1528 | 20 | return fail(cs.begin(), error::expected_hex_digit, &loc); | ||
| 1511 | } | 1529 | } | |||||
| HITCBC | 1512 | 5641 | ++cs; | 1530 | 5641 | ++cs; | ||
| HITCBC | 1513 | 5641 | u1_ += digit << 8; | 1531 | 5641 | u1_ += digit << 8; | ||
| HITCBC | 1514 | 6030 | do_str6: | 1532 | 6030 | do_str6: | ||
| HITCBC | 1515 | 6030 | if(BOOST_JSON_UNLIKELY(! cs)) | 1533 | 6030 | if(BOOST_JSON_UNLIKELY(! cs)) | ||
| HITCBC | 1516 | 389 | return maybe_suspend(cs.begin(), state::str6); | 1534 | 389 | return maybe_suspend(cs.begin(), state::str6); | ||
| HITCBC | 1517 | 5641 | digit = detail::hex_digit(*cs); | 1535 | 5641 | digit = detail::hex_digit(*cs); | ||
| HITCBC | 1518 | 5641 | if(BOOST_JSON_UNLIKELY(digit == -1)) | 1536 | 5641 | if(BOOST_JSON_UNLIKELY(digit == -1)) | ||
| 1519 | { | 1537 | { | |||||
| 1520 | BOOST_STATIC_CONSTEXPR source_location loc | 1538 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 1521 | = BOOST_CURRENT_LOCATION; | 1539 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1522 | 20 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1540 | 20 | return fail(cs.begin(), error::expected_hex_digit, &loc); | ||
| 1523 | } | 1541 | } | |||||
| HITCBC | 1524 | 5621 | ++cs; | 1542 | 5621 | ++cs; | ||
| HITCBC | 1525 | 5621 | u1_ += digit << 4; | 1543 | 5621 | u1_ += digit << 4; | ||
| HITCBC | 1526 | 6007 | do_str7: | 1544 | 6007 | do_str7: | ||
| HITCBC | 1527 | 6007 | if(BOOST_JSON_UNLIKELY(! cs)) | 1545 | 6007 | if(BOOST_JSON_UNLIKELY(! cs)) | ||
| HITCBC | 1528 | 386 | return maybe_suspend(cs.begin(), state::str7); | 1546 | 386 | return maybe_suspend(cs.begin(), state::str7); | ||
| HITCBC | 1529 | 5621 | digit = detail::hex_digit(*cs); | 1547 | 5621 | digit = detail::hex_digit(*cs); | ||
| HITCBC | 1530 | 5621 | if(BOOST_JSON_UNLIKELY(digit == -1)) | 1548 | 5621 | if(BOOST_JSON_UNLIKELY(digit == -1)) | ||
| 1531 | { | 1549 | { | |||||
| 1532 | BOOST_STATIC_CONSTEXPR source_location loc | 1550 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 1533 | = BOOST_CURRENT_LOCATION; | 1551 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1534 | 35 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1552 | 35 | return fail(cs.begin(), error::expected_hex_digit, &loc); | ||
| 1535 | } | 1553 | } | |||||
| HITCBC | 1536 | 5586 | ++cs; | 1554 | 5586 | ++cs; | ||
| HITCBC | 1537 | 5586 | u1_ += digit; | 1555 | 5586 | u1_ += digit; | ||
| HITCBC | 1538 | 5586 | if(BOOST_JSON_LIKELY( | 1556 | 5586 | if(BOOST_JSON_LIKELY( | ||
| 1539 | u1_ < 0xd800 || u1_ > 0xdfff)) | 1557 | u1_ < 0xd800 || u1_ > 0xdfff)) | |||||
| 1540 | { | 1558 | { | |||||
| HITCBC | 1541 | 1434 | BOOST_ASSERT(temp.empty()); | 1559 | 1434 | BOOST_ASSERT(temp.empty()); | ||
| 1542 | // utf-8 codepoint | 1560 | // utf-8 codepoint | |||||
| HITCBC | 1543 | 1434 | temp.append_utf8(u1_); | 1561 | 1434 | temp.append_utf8(u1_); | ||
| HITCBC | 1544 | 1434 | break; | 1562 | 1434 | break; | ||
| 1545 | } | 1563 | } | |||||
| HITCBC | 1546 | 4152 | if(BOOST_JSON_UNLIKELY(u1_ > 0xdbff)) | 1564 | 4152 | if(BOOST_JSON_UNLIKELY(u1_ > 0xdbff)) | ||
| 1547 | { | 1565 | { | |||||
| 1548 | // If it's an illegal leading surrogate and | 1566 | // If it's an illegal leading surrogate and | |||||
| 1549 | // the parser does not allow it, return an error. | 1567 | // the parser does not allow it, return an error. | |||||
| HITCBC | 1550 | 1585 | if(!allow_bad_utf16) | 1568 | 1585 | if(!allow_bad_utf16) | ||
| 1551 | { | 1569 | { | |||||
| 1552 | BOOST_STATIC_CONSTEXPR source_location loc | 1570 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 1553 | = BOOST_CURRENT_LOCATION; | 1571 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1554 | 209 | return fail(cs.begin(), error::illegal_leading_surrogate, &loc); | 1572 | 209 | return fail(cs.begin(), error::illegal_leading_surrogate, &loc); | ||
| 1555 | } | 1573 | } | |||||
| 1556 | // Otherwise, append the Unicode replacement character | 1574 | // Otherwise, append the Unicode replacement character | |||||
| 1557 | else | 1575 | else | |||||
| 1558 | { | 1576 | { | |||||
| HITCBC | 1559 | 1376 | BOOST_ASSERT(temp.empty()); | 1577 | 1376 | BOOST_ASSERT(temp.empty()); | ||
| HITCBC | 1560 | 1376 | temp.append_utf8(urc); | 1578 | 1376 | temp.append_utf8(urc); | ||
| HITCBC | 1561 | 1376 | break; | 1579 | 1376 | break; | ||
| 1562 | } | 1580 | } | |||||
| 1563 | } | 1581 | } | |||||
| HITCBC | 1564 | 2567 | do_sur1: | 1582 | 2567 | do_sur1: | ||
| HITCBC | 1565 | 3792 | if(BOOST_JSON_UNLIKELY(! cs)) | 1583 | 3792 | if(BOOST_JSON_UNLIKELY(! cs)) | ||
| HITCBC | 1566 | 232 | return maybe_suspend(cs.begin(), state::sur1); | 1584 | 232 | return maybe_suspend(cs.begin(), state::sur1); | ||
| HITCBC | 1567 | 3560 | if(BOOST_JSON_UNLIKELY(*cs != '\\')) | 1585 | 3560 | if(BOOST_JSON_UNLIKELY(*cs != '\\')) | ||
| 1568 | { | 1586 | { | |||||
| 1569 | // If the next character is not a backslash and | 1587 | // If the next character is not a backslash and | |||||
| 1570 | // the parser does not allow it, return a syntax error. | 1588 | // the parser does not allow it, return a syntax error. | |||||
| HITCBC | 1571 | 952 | if(!allow_bad_utf16) | 1589 | 952 | if(!allow_bad_utf16) | ||
| 1572 | { | 1590 | { | |||||
| 1573 | BOOST_STATIC_CONSTEXPR source_location loc | 1591 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 1574 | = BOOST_CURRENT_LOCATION; | 1592 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1575 | 149 | return fail(cs.begin(), error::syntax, &loc); | 1593 | 149 | return fail(cs.begin(), error::syntax, &loc); | ||
| 1576 | } | 1594 | } | |||||
| 1577 | // Otherwise, append the Unicode replacement character since | 1595 | // Otherwise, append the Unicode replacement character since | |||||
| 1578 | // the first code point is a valid leading surrogate | 1596 | // the first code point is a valid leading surrogate | |||||
| 1579 | else | 1597 | else | |||||
| 1580 | { | 1598 | { | |||||
| HITCBC | 1581 | 803 | temp.append_utf8(urc); | 1599 | 803 | temp.append_utf8(urc); | ||
| HITCBC | 1582 | 803 | break; | 1600 | 803 | break; | ||
| 1583 | } | 1601 | } | |||||
| 1584 | } | 1602 | } | |||||
| HITCBC | 1585 | 2608 | ++cs; | 1603 | 2608 | ++cs; | ||
| HITCBC | 1586 | 2796 | do_sur2: | 1604 | 2796 | do_sur2: | ||
| HITCBC | 1587 | 2796 | if(BOOST_JSON_UNLIKELY(! cs)) | 1605 | 2796 | if(BOOST_JSON_UNLIKELY(! cs)) | ||
| HITCBC | 1588 | 188 | return maybe_suspend(cs.begin(), state::sur2); | 1606 | 188 | return maybe_suspend(cs.begin(), state::sur2); | ||
| HITCBC | 1589 | 2608 | if(BOOST_JSON_UNLIKELY(*cs != 'u')) | 1607 | 2608 | if(BOOST_JSON_UNLIKELY(*cs != 'u')) | ||
| 1590 | { | 1608 | { | |||||
| HITCBC | 1591 | 396 | if (!allow_bad_utf16) | 1609 | 396 | if (!allow_bad_utf16) | ||
| 1592 | { | 1610 | { | |||||
| 1593 | BOOST_STATIC_CONSTEXPR source_location loc | 1611 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 1594 | = BOOST_CURRENT_LOCATION; | 1612 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1595 | 65 | return fail(cs.begin(), error::syntax, &loc); | 1613 | 65 | return fail(cs.begin(), error::syntax, &loc); | ||
| 1596 | } | 1614 | } | |||||
| 1597 | // Otherwise, append the Unicode replacement character since | 1615 | // Otherwise, append the Unicode replacement character since | |||||
| 1598 | // the first code point is a valid leading surrogate | 1616 | // the first code point is a valid leading surrogate | |||||
| 1599 | else | 1617 | else | |||||
| 1600 | { | 1618 | { | |||||
| HITCBC | 1601 | 331 | temp.append_utf8(urc); | 1619 | 331 | temp.append_utf8(urc); | ||
| HITCBC | 1602 | 331 | goto do_str3; | 1620 | 331 | goto do_str3; | ||
| 1603 | } | 1621 | } | |||||
| 1604 | } | 1622 | } | |||||
| HITCBC | 1605 | 2212 | ++cs; | 1623 | 2212 | ++cs; | ||
| HITCBC | 1606 | 2376 | do_sur3: | 1624 | 2376 | do_sur3: | ||
| HITCBC | 1607 | 2376 | if(BOOST_JSON_UNLIKELY(! cs)) | 1625 | 2376 | if(BOOST_JSON_UNLIKELY(! cs)) | ||
| HITCBC | 1608 | 164 | return maybe_suspend(cs.begin(), state::sur3); | 1626 | 164 | return maybe_suspend(cs.begin(), state::sur3); | ||
| HITCBC | 1609 | 2212 | digit = detail::hex_digit(*cs); | 1627 | 2212 | digit = detail::hex_digit(*cs); | ||
| HITCBC | 1610 | 2212 | if(BOOST_JSON_UNLIKELY(digit == -1)) | 1628 | 2212 | if(BOOST_JSON_UNLIKELY(digit == -1)) | ||
| 1611 | { | 1629 | { | |||||
| 1612 | BOOST_STATIC_CONSTEXPR source_location loc | 1630 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 1613 | = BOOST_CURRENT_LOCATION; | 1631 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1614 | 35 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1632 | 35 | return fail(cs.begin(), error::expected_hex_digit, &loc); | ||
| 1615 | } | 1633 | } | |||||
| HITCBC | 1616 | 2177 | ++cs; | 1634 | 2177 | ++cs; | ||
| HITCBC | 1617 | 2177 | u2_ = digit << 12; | 1635 | 2177 | u2_ = digit << 12; | ||
| HITCBC | 1618 | 2339 | do_sur4: | 1636 | 2339 | do_sur4: | ||
| HITCBC | 1619 | 2339 | if(BOOST_JSON_UNLIKELY(! cs)) | 1637 | 2339 | if(BOOST_JSON_UNLIKELY(! cs)) | ||
| HITCBC | 1620 | 162 | return maybe_suspend(cs.begin(), state::sur4); | 1638 | 162 | return maybe_suspend(cs.begin(), state::sur4); | ||
| HITCBC | 1621 | 2177 | digit = detail::hex_digit(*cs); | 1639 | 2177 | digit = detail::hex_digit(*cs); | ||
| HITCBC | 1622 | 2177 | if(BOOST_JSON_UNLIKELY(digit == -1)) | 1640 | 2177 | if(BOOST_JSON_UNLIKELY(digit == -1)) | ||
| 1623 | { | 1641 | { | |||||
| 1624 | BOOST_STATIC_CONSTEXPR source_location loc | 1642 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 1625 | = BOOST_CURRENT_LOCATION; | 1643 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1626 | 35 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1644 | 35 | return fail(cs.begin(), error::expected_hex_digit, &loc); | ||
| 1627 | } | 1645 | } | |||||
| HITCBC | 1628 | 2142 | ++cs; | 1646 | 2142 | ++cs; | ||
| HITCBC | 1629 | 2142 | u2_ += digit << 8; | 1647 | 2142 | u2_ += digit << 8; | ||
| HITCBC | 1630 | 2302 | do_sur5: | 1648 | 2302 | do_sur5: | ||
| HITCBC | 1631 | 2302 | if(BOOST_JSON_UNLIKELY(! cs)) | 1649 | 2302 | if(BOOST_JSON_UNLIKELY(! cs)) | ||
| HITCBC | 1632 | 160 | return maybe_suspend(cs.begin(), state::sur5); | 1650 | 160 | return maybe_suspend(cs.begin(), state::sur5); | ||
| HITCBC | 1633 | 2142 | digit = detail::hex_digit(*cs); | 1651 | 2142 | digit = detail::hex_digit(*cs); | ||
| HITCBC | 1634 | 2142 | if(BOOST_JSON_UNLIKELY(digit == -1)) | 1652 | 2142 | if(BOOST_JSON_UNLIKELY(digit == -1)) | ||
| 1635 | { | 1653 | { | |||||
| 1636 | BOOST_STATIC_CONSTEXPR source_location loc | 1654 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 1637 | = BOOST_CURRENT_LOCATION; | 1655 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1638 | 20 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1656 | 20 | return fail(cs.begin(), error::expected_hex_digit, &loc); | ||
| 1639 | } | 1657 | } | |||||
| HITCBC | 1640 | 2122 | ++cs; | 1658 | 2122 | ++cs; | ||
| HITCBC | 1641 | 2122 | u2_ += digit << 4; | 1659 | 2122 | u2_ += digit << 4; | ||
| HITCBC | 1642 | 2280 | do_sur6: | 1660 | 2280 | do_sur6: | ||
| HITCBC | 1643 | 2280 | if(BOOST_JSON_UNLIKELY(! cs)) | 1661 | 2280 | if(BOOST_JSON_UNLIKELY(! cs)) | ||
| HITCBC | 1644 | 158 | return maybe_suspend(cs.begin(), state::sur6); | 1662 | 158 | return maybe_suspend(cs.begin(), state::sur6); | ||
| HITCBC | 1645 | 2122 | digit = detail::hex_digit(*cs); | 1663 | 2122 | digit = detail::hex_digit(*cs); | ||
| HITCBC | 1646 | 2122 | if(BOOST_JSON_UNLIKELY(digit == -1)) | 1664 | 2122 | if(BOOST_JSON_UNLIKELY(digit == -1)) | ||
| 1647 | { | 1665 | { | |||||
| 1648 | BOOST_STATIC_CONSTEXPR source_location loc | 1666 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 1649 | = BOOST_CURRENT_LOCATION; | 1667 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1650 | 20 | return fail(cs.begin(), error::expected_hex_digit, &loc); | 1668 | 20 | return fail(cs.begin(), error::expected_hex_digit, &loc); | ||
| 1651 | } | 1669 | } | |||||
| HITCBC | 1652 | 2102 | ++cs; | 1670 | 2102 | ++cs; | ||
| HITCBC | 1653 | 2102 | u2_ += digit; | 1671 | 2102 | u2_ += digit; | ||
| 1654 | // Check if the second code point is a valid trailing surrogate. | 1672 | // Check if the second code point is a valid trailing surrogate. | |||||
| 1655 | // Valid trailing surrogates are [DC00, DFFF] | 1673 | // Valid trailing surrogates are [DC00, DFFF] | |||||
| HITCBC | 1656 | 2102 | if(BOOST_JSON_UNLIKELY( | 1674 | 2102 | if(BOOST_JSON_UNLIKELY( | ||
| 1657 | u2_ < 0xdc00 || u2_ > 0xdfff)) | 1675 | u2_ < 0xdc00 || u2_ > 0xdfff)) | |||||
| 1658 | { | 1676 | { | |||||
| 1659 | // If not valid and the parser does not allow it, return an error. | 1677 | // If not valid and the parser does not allow it, return an error. | |||||
| HITCBC | 1660 | 580 | if(!allow_bad_utf16) | 1678 | 580 | if(!allow_bad_utf16) | ||
| 1661 | { | 1679 | { | |||||
| 1662 | BOOST_STATIC_CONSTEXPR source_location loc | 1680 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 1663 | = BOOST_CURRENT_LOCATION; | 1681 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1664 | 60 | return fail(cs.begin(), error::illegal_trailing_surrogate, &loc); | 1682 | 60 | return fail(cs.begin(), error::illegal_trailing_surrogate, &loc); | ||
| 1665 | } | 1683 | } | |||||
| 1666 | // Append the replacement character for the | 1684 | // Append the replacement character for the | |||||
| 1667 | // first leading surrogate. | 1685 | // first leading surrogate. | |||||
| HITCBC | 1668 | 520 | temp.append_utf8(urc); | 1686 | 520 | temp.append_utf8(urc); | ||
| 1669 | // Check if the second code point is a | 1687 | // Check if the second code point is a | |||||
| 1670 | // valid unicode scalar value (invalid leading | 1688 | // valid unicode scalar value (invalid leading | |||||
| 1671 | // or trailing surrogate) | 1689 | // or trailing surrogate) | |||||
| HITCBC | 1672 | 520 | if (u2_ < 0xd800 || u2_ > 0xdbff) | 1690 | 520 | if (u2_ < 0xd800 || u2_ > 0xdbff) | ||
| 1673 | { | 1691 | { | |||||
| HITCBC | 1674 | 220 | temp.append_utf8(u2_); | 1692 | 220 | temp.append_utf8(u2_); | ||
| HITCBC | 1675 | 220 | break; | 1693 | 220 | break; | ||
| 1676 | } | 1694 | } | |||||
| 1677 | // If it is a valid leading surrogate | 1695 | // If it is a valid leading surrogate | |||||
| 1678 | else | 1696 | else | |||||
| 1679 | { | 1697 | { | |||||
| HITCBC | 1680 | 300 | u1_ = u2_; | 1698 | 300 | u1_ = u2_; | ||
| HITCBC | 1681 | 300 | goto do_sur1; | 1699 | 300 | goto do_sur1; | ||
| 1682 | } | 1700 | } | |||||
| 1683 | } | 1701 | } | |||||
| 1684 | // Calculate the Unicode code point from the surrogate pair and | 1702 | // Calculate the Unicode code point from the surrogate pair and | |||||
| 1685 | // append the UTF-8 representation. | 1703 | // append the UTF-8 representation. | |||||
| HITCBC | 1686 | 1522 | unsigned cp = | 1704 | 1522 | unsigned cp = | ||
| HITCBC | 1687 | 1522 | ((u1_ - 0xd800) << 10) + | 1705 | 1522 | ((u1_ - 0xd800) << 10) + | ||
| HITCBC | 1688 | 1522 | ((u2_ - 0xdc00)) + | 1706 | 1522 | ((u2_ - 0xdc00)) + | ||
| 1689 | 0x10000; | 1707 | 0x10000; | |||||
| 1690 | // utf-16 surrogate pair | 1708 | // utf-16 surrogate pair | |||||
| HITCBC | 1691 | 1522 | temp.append_utf8(cp); | 1709 | 1522 | temp.append_utf8(cp); | ||
| 1692 | } | 1710 | } | |||||
| 1693 | 1711 | |||||||
| 1694 | // flush | 1712 | // flush | |||||
| HITCBC | 1695 | 12653 | if(BOOST_JSON_UNLIKELY( !cs ) || *cs != '\\') | 1713 | 12653 | if(BOOST_JSON_UNLIKELY( !cs ) || *cs != '\\') | ||
| HITCBC | 1696 | 8870 | break; | 1714 | 8870 | break; | ||
| 1697 | } | 1715 | } | |||||
| 1698 | 1716 | |||||||
| HITCBC | 1699 | 8870 | if(BOOST_JSON_LIKELY( temp.size() )) | 1717 | 8870 | if(BOOST_JSON_LIKELY( temp.size() )) | ||
| 1700 | { | 1718 | { | |||||
| HITCBC | 1701 | 434 | BOOST_ASSERT(total <= max_size); | 1719 | 434 | BOOST_ASSERT(total <= max_size); | ||
| HITCBC | 1702 | 8870 | if(BOOST_JSON_UNLIKELY( temp.size() > max_size - total )) | 1720 | 8870 | if(BOOST_JSON_UNLIKELY( temp.size() > max_size - total )) | ||
| 1703 | { | 1721 | { | |||||
| 1704 | BOOST_STATIC_CONSTEXPR source_location loc | 1722 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 1705 | = BOOST_CURRENT_LOCATION; | 1723 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1706 | 1 | return fail(cs.begin(), ev_too_large, &loc); | 1724 | 1 | return fail(cs.begin(), ev_too_large, &loc); | ||
| 1707 | } | 1725 | } | |||||
| 1708 | 1726 | |||||||
| HITCBC | 1709 | 8869 | total += temp.size(); | 1727 | 8869 | total += temp.size(); | ||
| HITCBC | 1710 | 8056 | bool const r = is_key | 1728 | 8056 | bool const r = is_key | ||
| HITCBC | 1711 | 8869 | ? h_.on_key_part(temp.get(), total, ec_) | 1729 | 8869 | ? h_.on_key_part(temp.get(), total, ec_) | ||
| HITCBC | 1712 | 8152 | : h_.on_string_part(temp.get(), total, ec_); | 1730 | 8152 | : h_.on_string_part(temp.get(), total, ec_); | ||
| HITCBC | 1713 | 8056 | if(BOOST_JSON_UNLIKELY( !r )) | 1731 | 8056 | if(BOOST_JSON_UNLIKELY( !r )) | ||
| HITCBC | 1714 | 813 | return fail( cs.begin() ); | 1732 | 813 | return fail( cs.begin() ); | ||
| 1715 | } | 1733 | } | |||||
| 1716 | 1734 | |||||||
| HITCBC | 1717 | 7243 | return cs.begin(); | 1735 | 7243 | return cs.begin(); | ||
| 1718 | } | 1736 | } | |||||
| 1719 | 1737 | |||||||
| 1720 | //---------------------------------------------------------- | 1738 | //---------------------------------------------------------- | |||||
| 1721 | 1739 | |||||||
| 1722 | template<class Handler> | 1740 | template<class Handler> | |||||
| 1723 | template< | 1741 | template< | |||||
| 1724 | bool StackEmpty_, | 1742 | bool StackEmpty_, | |||||
| 1725 | bool AllowComments_/*, | 1743 | bool AllowComments_/*, | |||||
| 1726 | bool AllowTrailing_, | 1744 | bool AllowTrailing_, | |||||
| 1727 | bool AllowBadUTF8_*/> | 1745 | bool AllowBadUTF8_*/> | |||||
| 1728 | const char* | 1746 | const char* | |||||
| HITCBC | 1729 | 109212 | basic_parser<Handler>:: | 1747 | 109212 | basic_parser<Handler>:: | ||
| 1730 | parse_object(const char* p, | 1748 | parse_object(const char* p, | |||||
| 1731 | std::integral_constant<bool, StackEmpty_> stack_empty, | 1749 | std::integral_constant<bool, StackEmpty_> stack_empty, | |||||
| 1732 | std::integral_constant<bool, AllowComments_> allow_comments, | 1750 | std::integral_constant<bool, AllowComments_> allow_comments, | |||||
| 1733 | /*std::integral_constant<bool, AllowTrailing_>*/ bool allow_trailing, | 1751 | /*std::integral_constant<bool, AllowTrailing_>*/ bool allow_trailing, | |||||
| 1734 | /*std::integral_constant<bool, AllowBadUTF8_>*/ bool allow_bad_utf8, | 1752 | /*std::integral_constant<bool, AllowBadUTF8_>*/ bool allow_bad_utf8, | |||||
| 1735 | bool allow_bad_utf16) | 1753 | bool allow_bad_utf16) | |||||
| 1736 | { | 1754 | { | |||||
| HITCBC | 1737 | 109212 | detail::const_stream_wrapper cs(p, end_); | 1755 | 109212 | detail::const_stream_wrapper cs(p, end_); | ||
| 1738 | std::size_t size; | 1756 | std::size_t size; | |||||
| HITCBC | 1739 | 109212 | if(! stack_empty && ! st_.empty()) | 1757 | 109212 | if(! stack_empty && ! st_.empty()) | ||
| 1740 | { | 1758 | { | |||||
| 1741 | // resume | 1759 | // resume | |||||
| 1742 | state st; | 1760 | state st; | |||||
| HITCBC | 1743 | 35074 | st_.pop(st); | 1761 | 35074 | st_.pop(st); | ||
| HITCBC | 1744 | 35074 | st_.pop(size); | 1762 | 35074 | st_.pop(size); | ||
| HITCBC | 1745 | 35074 | switch(st) | 1763 | 35074 | switch(st) | ||
| 1746 | { | 1764 | { | |||||
| 1747 | default: BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE | 1765 | default: BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE | |||||
| HITCBC | 1748 | 1596 | case state::obj1: goto do_obj1; | 1766 | 1596 | case state::obj1: goto do_obj1; | ||
| HITCBC | 1749 | 235 | case state::obj2: goto do_obj2; | 1767 | 235 | case state::obj2: goto do_obj2; | ||
| HITCBC | 1750 | 12651 | case state::obj3: goto do_obj3; | 1768 | 12651 | case state::obj3: goto do_obj3; | ||
| HITCBC | 1751 | 1692 | case state::obj4: goto do_obj4; | 1769 | 1692 | case state::obj4: goto do_obj4; | ||
| HITCBC | 1752 | 251 | case state::obj5: goto do_obj5; | 1770 | 251 | case state::obj5: goto do_obj5; | ||
| HITCBC | 1753 | 1593 | case state::obj6: goto do_obj6; | 1771 | 1593 | case state::obj6: goto do_obj6; | ||
| HITCBC | 1754 | 15453 | case state::obj7: goto do_obj7; | 1772 | 15453 | case state::obj7: goto do_obj7; | ||
| HITCBC | 1755 | 427 | case state::obj8: goto do_obj8; | 1773 | 427 | case state::obj8: goto do_obj8; | ||
| HITCBC | 1756 | 661 | case state::obj9: goto do_obj9; | 1774 | 661 | case state::obj9: goto do_obj9; | ||
| HITCBC | 1757 | 181 | case state::obj10: goto do_obj10; | 1775 | 181 | case state::obj10: goto do_obj10; | ||
| HITCBC | 1758 | 334 | case state::obj11: goto do_obj11; | 1776 | 334 | case state::obj11: goto do_obj11; | ||
| 1759 | } | 1777 | } | |||||
| 1760 | } | 1778 | } | |||||
| HITCBC | 1761 | 74138 | BOOST_ASSERT(*cs == '{'); | 1779 | 74138 | BOOST_ASSERT(*cs == '{'); | ||
| HITCBC | 1762 | 74138 | size = 0; | 1780 | 74138 | size = 0; | ||
| HITCBC | 1763 | 74138 | if(BOOST_JSON_UNLIKELY(! depth_)) | 1781 | 74138 | if(BOOST_JSON_UNLIKELY(! depth_)) | ||
| 1764 | { | 1782 | { | |||||
| 1765 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 1783 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1766 | 3 | return fail(cs.begin(), error::too_deep, &loc); | 1784 | 3 | return fail(cs.begin(), error::too_deep, &loc); | ||
| 1767 | } | 1785 | } | |||||
| HITCBC | 1768 | 74135 | --depth_; | 1786 | 74135 | --depth_; | ||
| HITCBC | 1769 | 74135 | if(BOOST_JSON_UNLIKELY( | 1787 | 74135 | if(BOOST_JSON_UNLIKELY( | ||
| 1770 | ! h_.on_object_begin(ec_))) | 1788 | ! h_.on_object_begin(ec_))) | |||||
| HITCBC | 1771 | 2040 | return fail(cs.begin()); | 1789 | 2040 | return fail(cs.begin()); | ||
| HITCBC | 1772 | 70057 | ++cs; | 1790 | 70057 | ++cs; | ||
| 1773 | // object: | 1791 | // object: | |||||
| 1774 | // '{' *ws '}' | 1792 | // '{' *ws '}' | |||||
| 1775 | // '{' *ws string *ws ':' *ws value *ws *[ ',' *ws string *ws ':' *ws value *ws ] '}' | 1793 | // '{' *ws string *ws ':' *ws value *ws *[ ',' *ws string *ws ':' *ws value *ws ] '}' | |||||
| HITCBC | 1776 | 73624 | do_obj1: | 1794 | 73624 | do_obj1: | ||
| HITCBC | 1777 | 73624 | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1795 | 73624 | cs = detail::count_whitespace(cs.begin(), cs.end()); | ||
| HITCBC | 1778 | 73624 | if(BOOST_JSON_UNLIKELY(! cs)) | 1796 | 73624 | if(BOOST_JSON_UNLIKELY(! cs)) | ||
| HITCBC | 1779 | 1630 | return maybe_suspend(cs.begin(), state::obj1, size); | 1797 | 1630 | return maybe_suspend(cs.begin(), state::obj1, size); | ||
| HITCBC | 1780 | 71994 | if(BOOST_JSON_LIKELY(*cs != '}')) | 1798 | 71994 | if(BOOST_JSON_LIKELY(*cs != '}')) | ||
| 1781 | { | 1799 | { | |||||
| HITCBC | 1782 | 69095 | if(BOOST_JSON_UNLIKELY(*cs != '\x22')) | 1800 | 69095 | if(BOOST_JSON_UNLIKELY(*cs != '\x22')) | ||
| 1783 | { | 1801 | { | |||||
| HITCBC | 1784 | 2411 | if(allow_comments && *cs == '/') | 1802 | 2411 | if(allow_comments && *cs == '/') | ||
| 1785 | { | 1803 | { | |||||
| HITCBC | 1786 | 2139 | do_obj2: | 1804 | 2139 | do_obj2: | ||
| HITCBC | 1787 | 2374 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); | 1805 | 2374 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); | ||
| HITCBC | 1788 | 2290 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1806 | 2290 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | ||
| HITCBC | 1789 | 319 | return suspend_or_fail(state::obj2, size); | 1807 | 319 | return suspend_or_fail(state::obj2, size); | ||
| HITCBC | 1790 | 1971 | goto do_obj1; | 1808 | 1971 | goto do_obj1; | ||
| 1791 | } | 1809 | } | |||||
| 1792 | BOOST_STATIC_CONSTEXPR source_location loc | 1810 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 1793 | = BOOST_CURRENT_LOCATION; | 1811 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1794 | 272 | return fail(cs.begin(), error::syntax, &loc); | 1812 | 272 | return fail(cs.begin(), error::syntax, &loc); | ||
| 1795 | } | 1813 | } | |||||
| HITCBC | 1796 | 66684 | loop: | 1814 | 66684 | loop: | ||
| HITCBC | 1797 | 80843 | if(BOOST_JSON_UNLIKELY(++size > | 1815 | 80843 | if(BOOST_JSON_UNLIKELY(++size > | ||
| 1798 | Handler::max_object_size)) | 1816 | Handler::max_object_size)) | |||||
| 1799 | { | 1817 | { | |||||
| 1800 | BOOST_STATIC_CONSTEXPR source_location loc | 1818 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 1801 | = BOOST_CURRENT_LOCATION; | 1819 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1802 | 1 | return fail(cs.begin(), error::object_too_large, &loc); | 1820 | 1 | return fail(cs.begin(), error::object_too_large, &loc); | ||
| 1803 | } | 1821 | } | |||||
| HITCBC | 1804 | 80842 | do_obj3: | 1822 | 80842 | do_obj3: | ||
| HITCBC | 1805 | 93493 | cs = parse_string(cs.begin(), stack_empty, std::true_type(), allow_bad_utf8, allow_bad_utf16); | 1823 | 93493 | cs = parse_string(cs.begin(), stack_empty, std::true_type(), allow_bad_utf8, allow_bad_utf16); | ||
| HITCBC | 1806 | 90537 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1824 | 90537 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | ||
| HITCBC | 1807 | 15596 | return suspend_or_fail(state::obj3, size); | 1825 | 15596 | return suspend_or_fail(state::obj3, size); | ||
| HITCBC | 1808 | 74941 | do_obj4: | 1826 | 74941 | do_obj4: | ||
| HITCBC | 1809 | 79104 | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1827 | 79104 | cs = detail::count_whitespace(cs.begin(), cs.end()); | ||
| HITCBC | 1810 | 79104 | if(BOOST_JSON_UNLIKELY(! cs)) | 1828 | 79104 | if(BOOST_JSON_UNLIKELY(! cs)) | ||
| HITCBC | 1811 | 1707 | return maybe_suspend(cs.begin(), state::obj4, size); | 1829 | 1707 | return maybe_suspend(cs.begin(), state::obj4, size); | ||
| HITCBC | 1812 | 77397 | if(BOOST_JSON_UNLIKELY(*cs != ':')) | 1830 | 77397 | if(BOOST_JSON_UNLIKELY(*cs != ':')) | ||
| 1813 | { | 1831 | { | |||||
| HITCBC | 1814 | 2925 | if(allow_comments && *cs == '/') | 1832 | 2925 | if(allow_comments && *cs == '/') | ||
| 1815 | { | 1833 | { | |||||
| HITCBC | 1816 | 2779 | do_obj5: | 1834 | 2779 | do_obj5: | ||
| HITCBC | 1817 | 3030 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); | 1835 | 3030 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); | ||
| HITCBC | 1818 | 2876 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1836 | 2876 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | ||
| HITCBC | 1819 | 405 | return suspend_or_fail(state::obj5, size); | 1837 | 405 | return suspend_or_fail(state::obj5, size); | ||
| HITCBC | 1820 | 2471 | goto do_obj4; | 1838 | 2471 | goto do_obj4; | ||
| 1821 | } | 1839 | } | |||||
| 1822 | BOOST_STATIC_CONSTEXPR source_location loc | 1840 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 1823 | = BOOST_CURRENT_LOCATION; | 1841 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1824 | 146 | return fail(cs.begin(), error::syntax, &loc); | 1842 | 146 | return fail(cs.begin(), error::syntax, &loc); | ||
| 1825 | } | 1843 | } | |||||
| HITCBC | 1826 | 74472 | ++cs; | 1844 | 74472 | ++cs; | ||
| HITCBC | 1827 | 76065 | do_obj6: | 1845 | 76065 | do_obj6: | ||
| HITCBC | 1828 | 76065 | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1846 | 76065 | cs = detail::count_whitespace(cs.begin(), cs.end()); | ||
| HITCBC | 1829 | 76065 | if(BOOST_JSON_UNLIKELY(! cs)) | 1847 | 76065 | if(BOOST_JSON_UNLIKELY(! cs)) | ||
| HITCBC | 1830 | 1624 | return maybe_suspend(cs.begin(), state::obj6, size); | 1848 | 1624 | return maybe_suspend(cs.begin(), state::obj6, size); | ||
| HITCBC | 1831 | 74441 | do_obj7: | 1849 | 74441 | do_obj7: | ||
| HITCBC | 1832 | 89894 | cs = parse_value(cs.begin(), stack_empty, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | 1850 | 89894 | cs = parse_value(cs.begin(), stack_empty, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | ||
| HITCBC | 1833 | 82545 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1851 | 82545 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | ||
| HITCBC | 1834 | 23598 | return suspend_or_fail(state::obj7, size); | 1852 | 23598 | return suspend_or_fail(state::obj7, size); | ||
| HITCBC | 1835 | 58947 | do_obj8: | 1853 | 58947 | do_obj8: | ||
| HITCBC | 1836 | 61210 | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1854 | 61210 | cs = detail::count_whitespace(cs.begin(), cs.end()); | ||
| HITCBC | 1837 | 61210 | if(BOOST_JSON_UNLIKELY(! cs)) | 1855 | 61210 | if(BOOST_JSON_UNLIKELY(! cs)) | ||
| HITCBC | 1838 | 442 | return maybe_suspend(cs.begin(), state::obj8, size); | 1856 | 442 | return maybe_suspend(cs.begin(), state::obj8, size); | ||
| HITCBC | 1839 | 60768 | if(BOOST_JSON_LIKELY(*cs == ',')) | 1857 | 60768 | if(BOOST_JSON_LIKELY(*cs == ',')) | ||
| 1840 | { | 1858 | { | |||||
| HITCBC | 1841 | 17799 | ++cs; | 1859 | 17799 | ++cs; | ||
| HITCBC | 1842 | 19715 | do_obj9: | 1860 | 19715 | do_obj9: | ||
| HITCBC | 1843 | 19715 | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1861 | 19715 | cs = detail::count_whitespace(cs.begin(), cs.end()); | ||
| HITCBC | 1844 | 19715 | if(BOOST_JSON_UNLIKELY(! cs)) | 1862 | 19715 | if(BOOST_JSON_UNLIKELY(! cs)) | ||
| HITCBC | 1845 | 691 | return maybe_suspend(cs.begin(), state::obj9, size); | 1863 | 691 | return maybe_suspend(cs.begin(), state::obj9, size); | ||
| 1846 | 1864 | |||||||
| 1847 | // loop for next element | 1865 | // loop for next element | |||||
| HITCBC | 1848 | 19024 | if(BOOST_JSON_LIKELY(*cs == '\x22')) | 1866 | 19024 | if(BOOST_JSON_LIKELY(*cs == '\x22')) | ||
| HITCBC | 1849 | 14159 | goto loop; | 1867 | 14159 | goto loop; | ||
| HITCBC | 1850 | 4865 | if(! allow_trailing || *cs != '}') | 1868 | 4865 | if(! allow_trailing || *cs != '}') | ||
| 1851 | { | 1869 | { | |||||
| HITCBC | 1852 | 1644 | if(allow_comments && *cs == '/') | 1870 | 1644 | if(allow_comments && *cs == '/') | ||
| 1853 | { | 1871 | { | |||||
| HITCBC | 1854 | 1433 | do_obj10: | 1872 | 1433 | do_obj10: | ||
| HITCBC | 1855 | 1614 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); | 1873 | 1614 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); | ||
| HITCBC | 1856 | 1525 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1874 | 1525 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | ||
| HITCBC | 1857 | 270 | return suspend_or_fail(state::obj10, size); | 1875 | 270 | return suspend_or_fail(state::obj10, size); | ||
| HITCBC | 1858 | 1255 | goto do_obj9; | 1876 | 1255 | goto do_obj9; | ||
| 1859 | } | 1877 | } | |||||
| 1860 | BOOST_STATIC_CONSTEXPR source_location loc | 1878 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 1861 | = BOOST_CURRENT_LOCATION; | 1879 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1862 | 211 | return fail(cs.begin(), error::syntax, &loc); | 1880 | 211 | return fail(cs.begin(), error::syntax, &loc); | ||
| 1863 | } | 1881 | } | |||||
| 1864 | } | 1882 | } | |||||
| HITCBC | 1865 | 42969 | else if(BOOST_JSON_UNLIKELY(*cs != '}')) | 1883 | 42969 | else if(BOOST_JSON_UNLIKELY(*cs != '}')) | ||
| 1866 | { | 1884 | { | |||||
| HITCBC | 1867 | 2325 | if(allow_comments && *cs == '/') | 1885 | 2325 | if(allow_comments && *cs == '/') | ||
| 1868 | { | 1886 | { | |||||
| HITCBC | 1869 | 2172 | do_obj11: | 1887 | 2172 | do_obj11: | ||
| HITCBC | 1870 | 2506 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); | 1888 | 2506 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); | ||
| HITCBC | 1871 | 2338 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1889 | 2338 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | ||
| HITCBC | 1872 | 502 | return suspend_or_fail(state::obj11, size); | 1890 | 502 | return suspend_or_fail(state::obj11, size); | ||
| HITCBC | 1873 | 1836 | goto do_obj8; | 1891 | 1836 | goto do_obj8; | ||
| 1874 | } | 1892 | } | |||||
| 1875 | BOOST_STATIC_CONSTEXPR source_location loc | 1893 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 1876 | = BOOST_CURRENT_LOCATION; | 1894 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1877 | 153 | return fail(cs.begin(), error::syntax, &loc); | 1895 | 153 | return fail(cs.begin(), error::syntax, &loc); | ||
| 1878 | } | 1896 | } | |||||
| 1879 | // got closing brace, fall through | 1897 | // got closing brace, fall through | |||||
| 1880 | } | 1898 | } | |||||
| HITCBC | 1881 | 46764 | if(BOOST_JSON_UNLIKELY( | 1899 | 46764 | if(BOOST_JSON_UNLIKELY( | ||
| 1882 | ! h_.on_object_end(size, ec_))) | 1900 | ! h_.on_object_end(size, ec_))) | |||||
| HITCBC | 1883 | 1502 | return fail(cs.begin()); | 1901 | 1502 | return fail(cs.begin()); | ||
| HITCBC | 1884 | 43721 | ++depth_; | 1902 | 43721 | ++depth_; | ||
| HITCBC | 1885 | 43721 | ++cs; | 1903 | 43721 | ++cs; | ||
| HITCBC | 1886 | 43721 | return cs.begin(); | 1904 | 43721 | return cs.begin(); | ||
| 1887 | } | 1905 | } | |||||
| 1888 | 1906 | |||||||
| 1889 | //---------------------------------------------------------- | 1907 | //---------------------------------------------------------- | |||||
| 1890 | 1908 | |||||||
| 1891 | template<class Handler> | 1909 | template<class Handler> | |||||
| 1892 | template< | 1910 | template< | |||||
| 1893 | bool StackEmpty_, | 1911 | bool StackEmpty_, | |||||
| 1894 | bool AllowComments_/*, | 1912 | bool AllowComments_/*, | |||||
| 1895 | bool AllowTrailing_, | 1913 | bool AllowTrailing_, | |||||
| 1896 | bool AllowBadUTF8_*/> | 1914 | bool AllowBadUTF8_*/> | |||||
| 1897 | const char* | 1915 | const char* | |||||
| HITCBC | 1898 | 26457 | basic_parser<Handler>:: | 1916 | 26457 | basic_parser<Handler>:: | ||
| 1899 | parse_array(const char* p, | 1917 | parse_array(const char* p, | |||||
| 1900 | std::integral_constant<bool, StackEmpty_> stack_empty, | 1918 | std::integral_constant<bool, StackEmpty_> stack_empty, | |||||
| 1901 | std::integral_constant<bool, AllowComments_> allow_comments, | 1919 | std::integral_constant<bool, AllowComments_> allow_comments, | |||||
| 1902 | /*std::integral_constant<bool, AllowTrailing_>*/ bool allow_trailing, | 1920 | /*std::integral_constant<bool, AllowTrailing_>*/ bool allow_trailing, | |||||
| 1903 | /*std::integral_constant<bool, AllowBadUTF8_>*/ bool allow_bad_utf8, | 1921 | /*std::integral_constant<bool, AllowBadUTF8_>*/ bool allow_bad_utf8, | |||||
| 1904 | bool allow_bad_utf16) | 1922 | bool allow_bad_utf16) | |||||
| 1905 | { | 1923 | { | |||||
| HITCBC | 1906 | 26457 | detail::const_stream_wrapper cs(p, end_); | 1924 | 26457 | detail::const_stream_wrapper cs(p, end_); | ||
| 1907 | std::size_t size; | 1925 | std::size_t size; | |||||
| HITCBC | 1908 | 26457 | if(! stack_empty && ! st_.empty()) | 1926 | 26457 | if(! stack_empty && ! st_.empty()) | ||
| 1909 | { | 1927 | { | |||||
| 1910 | // resume | 1928 | // resume | |||||
| 1911 | state st; | 1929 | state st; | |||||
| HITCBC | 1912 | 5780 | st_.pop(st); | 1930 | 5780 | st_.pop(st); | ||
| HITCBC | 1913 | 5780 | st_.pop(size); | 1931 | 5780 | st_.pop(size); | ||
| HITCBC | 1914 | 5780 | switch(st) | 1932 | 5780 | switch(st) | ||
| 1915 | { | 1933 | { | |||||
| 1916 | default: BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE | 1934 | default: BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE | |||||
| HITCBC | 1917 | 1061 | case state::arr1: goto do_arr1; | 1935 | 1061 | case state::arr1: goto do_arr1; | ||
| HITCBC | 1918 | 384 | case state::arr2: goto do_arr2; | 1936 | 384 | case state::arr2: goto do_arr2; | ||
| HITCBC | 1919 | 2965 | case state::arr3: goto do_arr3; | 1937 | 2965 | case state::arr3: goto do_arr3; | ||
| HITCBC | 1920 | 396 | case state::arr4: goto do_arr4; | 1938 | 396 | case state::arr4: goto do_arr4; | ||
| HITCBC | 1921 | 680 | case state::arr5: goto do_arr5; | 1939 | 680 | case state::arr5: goto do_arr5; | ||
| HITCBC | 1922 | 294 | case state::arr6: goto do_arr6; | 1940 | 294 | case state::arr6: goto do_arr6; | ||
| 1923 | } | 1941 | } | |||||
| 1924 | } | 1942 | } | |||||
| HITCBC | 1925 | 20677 | BOOST_ASSERT(*cs == '['); | 1943 | 20677 | BOOST_ASSERT(*cs == '['); | ||
| HITCBC | 1926 | 20677 | size = 0; | 1944 | 20677 | size = 0; | ||
| HITCBC | 1927 | 20677 | if(BOOST_JSON_UNLIKELY(! depth_)) | 1945 | 20677 | if(BOOST_JSON_UNLIKELY(! depth_)) | ||
| 1928 | { | 1946 | { | |||||
| 1929 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 1947 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1930 | 34 | return fail(cs.begin(), error::too_deep, &loc); | 1948 | 34 | return fail(cs.begin(), error::too_deep, &loc); | ||
| 1931 | } | 1949 | } | |||||
| HITCBC | 1932 | 20643 | --depth_; | 1950 | 20643 | --depth_; | ||
| HITCBC | 1933 | 20643 | if(BOOST_JSON_UNLIKELY( | 1951 | 20643 | if(BOOST_JSON_UNLIKELY( | ||
| 1934 | ! h_.on_array_begin(ec_))) | 1952 | ! h_.on_array_begin(ec_))) | |||||
| HITCBC | 1935 | 812 | return fail(cs.begin()); | 1953 | 812 | return fail(cs.begin()); | ||
| HITCBC | 1936 | 19025 | ++cs; | 1954 | 19025 | ++cs; | ||
| 1937 | // array: | 1955 | // array: | |||||
| 1938 | // '[' *ws ']' | 1956 | // '[' *ws ']' | |||||
| 1939 | // '[' *ws value *ws *[ ',' *ws value *ws ] ']' | 1957 | // '[' *ws value *ws *[ ',' *ws value *ws ] ']' | |||||
| HITCBC | 1940 | 21619 | do_arr1: | 1958 | 21619 | do_arr1: | ||
| HITCBC | 1941 | 21619 | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1959 | 21619 | cs = detail::count_whitespace(cs.begin(), cs.end()); | ||
| HITCBC | 1942 | 21619 | if(BOOST_JSON_UNLIKELY(! cs)) | 1960 | 21619 | if(BOOST_JSON_UNLIKELY(! cs)) | ||
| HITCBC | 1943 | 1082 | return maybe_suspend(cs.begin(), state::arr1, size); | 1961 | 1082 | return maybe_suspend(cs.begin(), state::arr1, size); | ||
| HITCBC | 1944 | 20537 | if(BOOST_JSON_LIKELY(*cs != ']')) | 1962 | 20537 | if(BOOST_JSON_LIKELY(*cs != ']')) | ||
| 1945 | { | 1963 | { | |||||
| HITCBC | 1946 | 18782 | loop: | 1964 | 18782 | loop: | ||
| HITCBC | 1947 | 26305 | if(allow_comments && *cs == '/') | 1965 | 26305 | if(allow_comments && *cs == '/') | ||
| 1948 | { | 1966 | { | |||||
| HITCBC | 1949 | 1789 | do_arr2: | 1967 | 1789 | do_arr2: | ||
| HITCBC | 1950 | 2173 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); | 1968 | 2173 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); | ||
| HITCBC | 1951 | 2045 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1969 | 2045 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | ||
| HITCBC | 1952 | 512 | return suspend_or_fail(state::arr2, size); | 1970 | 512 | return suspend_or_fail(state::arr2, size); | ||
| HITCBC | 1953 | 1533 | goto do_arr1; | 1971 | 1533 | goto do_arr1; | ||
| 1954 | } | 1972 | } | |||||
| HITCBC | 1955 | 24516 | if(BOOST_JSON_UNLIKELY(++size > | 1973 | 24516 | if(BOOST_JSON_UNLIKELY(++size > | ||
| 1956 | Handler::max_array_size)) | 1974 | Handler::max_array_size)) | |||||
| 1957 | { | 1975 | { | |||||
| 1958 | BOOST_STATIC_CONSTEXPR source_location loc | 1976 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 1959 | = BOOST_CURRENT_LOCATION; | 1977 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1960 | 1 | return fail(cs.begin(), error::array_too_large, &loc); | 1978 | 1 | return fail(cs.begin(), error::array_too_large, &loc); | ||
| 1961 | } | 1979 | } | |||||
| HITCBC | 1962 | 24515 | do_arr3: | 1980 | 24515 | do_arr3: | ||
| 1963 | // array is not empty, value required | 1981 | // array is not empty, value required | |||||
| HITCBC | 1964 | 27480 | cs = parse_value(cs.begin(), stack_empty, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | 1982 | 27480 | cs = parse_value(cs.begin(), stack_empty, allow_comments, allow_trailing, allow_bad_utf8, allow_bad_utf16); | ||
| HITCBC | 1965 | 24849 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 1983 | 24849 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | ||
| HITCBC | 1966 | 9079 | return suspend_or_fail(state::arr3, size); | 1984 | 9079 | return suspend_or_fail(state::arr3, size); | ||
| HITCBC | 1967 | 15770 | do_arr4: | 1985 | 15770 | do_arr4: | ||
| HITCBC | 1968 | 17396 | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1986 | 17396 | cs = detail::count_whitespace(cs.begin(), cs.end()); | ||
| HITCBC | 1969 | 17396 | if(BOOST_JSON_UNLIKELY(! cs)) | 1987 | 17396 | if(BOOST_JSON_UNLIKELY(! cs)) | ||
| HITCBC | 1970 | 505 | return maybe_suspend(cs.begin(), state::arr4, size); | 1988 | 505 | return maybe_suspend(cs.begin(), state::arr4, size); | ||
| HITCBC | 1971 | 16891 | if(BOOST_JSON_LIKELY(*cs == ',')) | 1989 | 16891 | if(BOOST_JSON_LIKELY(*cs == ',')) | ||
| 1972 | { | 1990 | { | |||||
| HITCBC | 1973 | 9236 | ++cs; | 1991 | 9236 | ++cs; | ||
| HITCBC | 1974 | 9916 | do_arr5: | 1992 | 9916 | do_arr5: | ||
| HITCBC | 1975 | 9916 | cs = detail::count_whitespace(cs.begin(), cs.end()); | 1993 | 9916 | cs = detail::count_whitespace(cs.begin(), cs.end()); | ||
| HITCBC | 1976 | 9916 | if(BOOST_JSON_UNLIKELY(! cs)) | 1994 | 9916 | if(BOOST_JSON_UNLIKELY(! cs)) | ||
| HITCBC | 1977 | 710 | return maybe_suspend(cs.begin(), state::arr5, size); | 1995 | 710 | return maybe_suspend(cs.begin(), state::arr5, size); | ||
| 1978 | // loop for next element | 1996 | // loop for next element | |||||
| HITCBC | 1979 | 9206 | if(! allow_trailing || *cs != ']') | 1997 | 9206 | if(! allow_trailing || *cs != ']') | ||
| HITCBC | 1980 | 7523 | goto loop; | 1998 | 7523 | goto loop; | ||
| 1981 | } | 1999 | } | |||||
| HITCBC | 1982 | 7655 | else if(BOOST_JSON_UNLIKELY(*cs != ']')) | 2000 | 7655 | else if(BOOST_JSON_UNLIKELY(*cs != ']')) | ||
| 1983 | { | 2001 | { | |||||
| HITCBC | 1984 | 1969 | if(allow_comments && *cs == '/') | 2002 | 1969 | if(allow_comments && *cs == '/') | ||
| 1985 | { | 2003 | { | |||||
| HITCBC | 1986 | 1541 | do_arr6: | 2004 | 1541 | do_arr6: | ||
| HITCBC | 1987 | 1835 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); | 2005 | 1835 | cs = parse_comment(cs.begin(), stack_empty, std::false_type()); | ||
| HITCBC | 1988 | 1688 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | 2006 | 1688 | if(BOOST_JSON_UNLIKELY(incomplete(cs))) | ||
| HITCBC | 1989 | 458 | return suspend_or_fail(state::arr6, size); | 2007 | 458 | return suspend_or_fail(state::arr6, size); | ||
| HITCBC | 1990 | 1230 | goto do_arr4; | 2008 | 1230 | goto do_arr4; | ||
| 1991 | } | 2009 | } | |||||
| 1992 | BOOST_STATIC_CONSTEXPR source_location loc | 2010 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 1993 | = BOOST_CURRENT_LOCATION; | 2011 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 1994 | 428 | return fail(cs.begin(), error::syntax, &loc); | 2012 | 428 | return fail(cs.begin(), error::syntax, &loc); | ||
| 1995 | } | 2013 | } | |||||
| 1996 | // got closing bracket; fall through | 2014 | // got closing bracket; fall through | |||||
| 1997 | } | 2015 | } | |||||
| HITCBC | 1998 | 9124 | if(BOOST_JSON_UNLIKELY( | 2016 | 9124 | if(BOOST_JSON_UNLIKELY( | ||
| 1999 | ! h_.on_array_end(size, ec_))) | 2017 | ! h_.on_array_end(size, ec_))) | |||||
| HITCBC | 2000 | 549 | return fail(cs.begin()); | 2018 | 549 | return fail(cs.begin()); | ||
| HITCBC | 2001 | 7996 | ++depth_; | 2019 | 7996 | ++depth_; | ||
| HITCBC | 2002 | 7996 | ++cs; | 2020 | 7996 | ++cs; | ||
| HITCBC | 2003 | 7996 | return cs.begin(); | 2021 | 7996 | return cs.begin(); | ||
| 2004 | } | 2022 | } | |||||
| 2005 | 2023 | |||||||
| 2006 | //---------------------------------------------------------- | 2024 | //---------------------------------------------------------- | |||||
| 2007 | 2025 | |||||||
| 2008 | template<class Handler> | 2026 | template<class Handler> | |||||
| 2009 | - | template<bool StackEmpty_, char First_, number_precision Numbers_> | 2027 | + | template<bool StackEmpty_, char First_> | |||
| 2010 | - | const char* | 2028 | + | char const* | |||
| HITCBC | 2011 | 10516087 | basic_parser<Handler>:: | 2029 | 9483477 | basic_parser<Handler>:: | ||
| 2012 | - | parse_number(const char* p, | 2030 | + | parse_number( | |||
| 2031 | + | char const* p, | ||||||
| 2013 | std::integral_constant<bool, StackEmpty_> stack_empty, | 2032 | std::integral_constant<bool, StackEmpty_> stack_empty, | |||||
| 2014 | - | std::integral_constant<char, First_> first, | 2033 | + | std::integral_constant<char, First_> first) | |||
| 2015 | - | std::integral_constant<number_precision, Numbers_> mode) | ||||||
| 2016 | - | constexpr bool precise_parsing = mode == number_precision::precise; | ||||||
| DCB | 2017 | - | 10516087 | constexpr bool no_parsing = mode == number_precision::none; | ||||
| DCB | 2018 | - | 10516087 | |||||
| 2019 | { | 2034 | { | |||||
| 2020 | // only one of these will be true if we are not resuming | 2035 | // only one of these will be true if we are not resuming | |||||
| 2021 | // if negative then !zero_first && !nonzero_first | 2036 | // if negative then !zero_first && !nonzero_first | |||||
| 2022 | // if zero_first then !nonzero_first && !negative | 2037 | // if zero_first then !nonzero_first && !negative | |||||
| 2023 | // if nonzero_first then !zero_first && !negative | 2038 | // if nonzero_first then !zero_first && !negative | |||||
| HITCBC | 2024 | 10516087 | bool const negative = first == '-'; | 2039 | 9483477 | bool const negative = first == '-'; | ||
| HITCBC | 2025 | 10516087 | bool const zero_first = first == '0'; | 2040 | 9483477 | bool const zero_first = first == '0'; | ||
| HITCBC | 2026 | 10516087 | bool const nonzero_first = first == '+'; | 2041 | 9483477 | bool const nonzero_first = first == '+'; | ||
| HITCBC | 2027 | 10516087 | detail::const_stream_wrapper cs(p, end_); | 2042 | 9483477 | detail::const_stream_wrapper cs(p, end_); | ||
| 2028 | number num; | 2043 | number num; | |||||
| HITCBC | 2029 | 10516087 | const char* begin = cs.begin(); | 2044 | 9483477 | const char* begin = cs.begin(); | ||
| HITCBC | 2030 | 10516087 | if(stack_empty || st_.empty()) | 2045 | 9483477 | if(stack_empty || st_.empty()) | ||
| 2031 | { | 2046 | { | |||||
| HITCBC | 2032 | 2090055 | num.bias = 0; | 2047 | 1071486 | num.bias = 0; | ||
| HITCBC | 2033 | 2090055 | num.exp = 0; | 2048 | 1071486 | num.exp = 0; | ||
| HITCBC | 2034 | 2090055 | num.frac = false; | 2049 | 1071486 | num.frac = false; | ||
| HITCBC | 2035 | - | 2090055 | num_buf_.clear(); | 2050 | + | 1071486 | num.neg = negative; |
| 2036 | 2051 | |||||||
| 2037 | //---------------------------------- | 2052 | //---------------------------------- | |||||
| 2038 | // | 2053 | // | |||||
| 2039 | // '-' | 2054 | // '-' | |||||
| 2040 | // leading minus sign | 2055 | // leading minus sign | |||||
| 2041 | // | 2056 | // | |||||
| HITCBC | 2042 | 2090055 | BOOST_ASSERT(cs); | 2057 | 1071486 | BOOST_ASSERT(cs); | ||
| 2043 | if(negative) | 2058 | if(negative) | |||||
| HITCBC | 2044 | 25185 | ++cs; | 2059 | 17385 | ++cs; | ||
| 2045 | - | num.neg = negative; | ||||||
| DCB | 2046 | - | 2090055 | num.frac = false; | ||||
| DCB | 2047 | - | 2090055 | num.exp = 0; | ||||
| DCB | 2048 | - | 2090055 | num.bias = 0; | ||||
| DCB | 2049 | - | 2090055 | |||||
| 2050 | 2060 | |||||||
| 2051 | // fast path | 2061 | // fast path | |||||
| HITCBC | 2052 | 2090055 | if( cs.remain() >= 16 + 1 + 16 ) // digits . digits | 2062 | 1071486 | if( cs.remain() >= 16 + 1 + 16 ) // digits . digits | ||
| 2053 | { | 2063 | { | |||||
| 2054 | int n1; | 2064 | int n1; | |||||
| 2055 | 2065 | |||||||
| HITCBC | 2056 | 9989 | if( nonzero_first || | 2066 | 5149 | if( nonzero_first || | ||
| HITCBC | 2057 | 9989 | (negative && *cs != '0') ) | 2067 | 5149 | (negative && *cs != '0') ) | ||
| 2058 | { | 2068 | { | |||||
| HITCBC | 2059 | 2007319 | n1 = detail::count_digits( cs.begin() ); | 2069 | 1005623 | n1 = detail::count_digits( cs.begin() ); | ||
| HITCBC | 2060 | 2007319 | BOOST_ASSERT(n1 >= 0 && n1 <= 16); | 2070 | 1005623 | BOOST_ASSERT(n1 >= 0 && n1 <= 16); | ||
| 2061 | 2071 | |||||||
| HITCBC | 2062 | 1837 | if( negative && n1 == 0 && opt_.allow_infinity_and_nan ) | 2072 | 1063 | if( negative && n1 == 0 && opt_.allow_infinity_and_nan ) | ||
| 2063 | { | 2073 | { | |||||
| HITCBC | 2064 | 9 | return parse_literal( | 2074 | 9 | return parse_literal( | ||
| 2065 | p - 1, | 2075 | p - 1, | |||||
| HITCBC | 2066 | 8 | detail::literals_c<detail::literals::neg_infinity>()); | 2076 | 8 | detail::literals_c<detail::literals::neg_infinity>()); | ||
| 2067 | } | 2077 | } | |||||
| 2068 | 2078 | |||||||
| HITCBC | 2069 | 1828 | if( ! nonzero_first && n1 == 0 ) | 2079 | 1054 | if( ! nonzero_first && n1 == 0 ) | ||
| 2070 | { | 2080 | { | |||||
| 2071 | // digit required | 2081 | // digit required | |||||
| 2072 | BOOST_STATIC_CONSTEXPR source_location loc | 2082 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 2073 | = BOOST_CURRENT_LOCATION; | 2083 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 2074 | 2 | return fail(cs.begin(), error::syntax, &loc); | 2084 | 2 | return fail(cs.begin(), error::syntax, &loc); | ||
| 2075 | } | 2085 | } | |||||
| 2076 | 2086 | |||||||
| HITGIC | 2077 | - | BOOST_IF_CONSTEXPR( !no_parsing ) | 2087 | + | 1005612 | num.mant = detail::parse_unsigned( 0, cs.begin(), n1 ); | |
| DCB | 2078 | - | 2006460 | num.mant = detail::parse_unsigned( 0, cs.begin(), n1 ); | ||||
| 2079 | - | else | ||||||
| DCB | 2080 | - | 848 | num.mant = 0; | ||||
| 2081 | - | |||||||
| HITCBC | 2082 | 2007308 | cs += n1; | 2088 | 1005612 | cs += n1; | ||
| 2083 | 2089 | |||||||
| 2084 | // integer or floating-point with | 2090 | // integer or floating-point with | |||||
| 2085 | // >= 16 leading digits | 2091 | // >= 16 leading digits | |||||
| HITCBC | 2086 | 2007308 | if( n1 == 16 ) | 2092 | 1005612 | if( n1 == 16 ) | ||
| 2087 | { | 2093 | { | |||||
| HITCBC | 2088 | 2001425 | goto do_num2; | 2094 | 1001029 | goto do_num2; | ||
| 2089 | } | 2095 | } | |||||
| 2090 | } | 2096 | } | |||||
| 2091 | else | 2097 | else | |||||
| 2092 | { | 2098 | { | |||||
| 2093 | // 0. floating-point or 0e integer | 2099 | // 0. floating-point or 0e integer | |||||
| HITCBC | 2094 | 21187 | num.mant = 0; | 2100 | 10733 | num.mant = 0; | ||
| HITCBC | 2095 | 21187 | n1 = 0; | 2101 | 10733 | n1 = 0; | ||
| HITCBC | 2096 | 21187 | ++cs; | 2102 | 10733 | ++cs; | ||
| 2097 | } | 2103 | } | |||||
| 2098 | 2104 | |||||||
| 2099 | { | 2105 | { | |||||
| HITCBC | 2100 | 27070 | const char c = *cs; | 2106 | 15316 | const char c = *cs; | ||
| HITCBC | 2101 | 27070 | if(c != '.') | 2107 | 15316 | if(c != '.') | ||
| 2102 | { | 2108 | { | |||||
| HITCBC | 2103 | 9871 | if((c | 32) == 'e') | 2109 | 6613 | if((c | 32) == 'e') | ||
| 2104 | { | 2110 | { | |||||
| HITCBC | 2105 | 6576 | ++cs; | 2111 | 3318 | ++cs; | ||
| HITCBC | 2106 | 6576 | goto do_exp1; | 2112 | 3318 | goto do_exp1; | ||
| 2107 | } | 2113 | } | |||||
| 2108 | - | BOOST_IF_CONSTEXPR( negative && !no_parsing ) | 2114 | + | BOOST_IF_CONSTEXPR( negative ) | |||
| HITCBC | 2109 | 20 | num.mant = ~num.mant + 1; | 2115 | 20 | num.mant = ~num.mant + 1; | ||
| HITCBC | 2110 | 3295 | goto finish_signed; | 2116 | 3295 | goto finish_signed; | ||
| 2111 | } | 2117 | } | |||||
| 2112 | } | 2118 | } | |||||
| 2113 | 2119 | |||||||
| 2114 | // floating-point number | 2120 | // floating-point number | |||||
| 2115 | 2121 | |||||||
| HITCBC | 2116 | 17199 | ++cs; | 2122 | 8703 | ++cs; | ||
| 2117 | 2123 | |||||||
| HITCBC | 2118 | 17199 | int n2 = detail::count_digits( cs.begin() ); | 2124 | 8703 | int n2 = detail::count_digits( cs.begin() ); | ||
| HITCBC | 2119 | 17199 | BOOST_ASSERT(n2 >= 0 && n2 <= 16); | 2125 | 8703 | BOOST_ASSERT(n2 >= 0 && n2 <= 16); | ||
| 2120 | 2126 | |||||||
| HITCBC | 2121 | 17199 | if( n2 == 0 ) | 2127 | 8703 | if( n2 == 0 ) | ||
| 2122 | { | 2128 | { | |||||
| 2123 | // digit required | 2129 | // digit required | |||||
| 2124 | BOOST_STATIC_CONSTEXPR source_location loc | 2130 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 2125 | = BOOST_CURRENT_LOCATION; | 2131 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 2126 | 3 | return fail(cs.begin(), error::syntax, &loc); | 2132 | 3 | return fail(cs.begin(), error::syntax, &loc); | ||
| 2127 | } | 2133 | } | |||||
| 2128 | 2134 | |||||||
| 2129 | // floating-point mantissa overflow | 2135 | // floating-point mantissa overflow | |||||
| HITCBC | 2130 | 17196 | if( n1 + n2 >= 19 ) | 2136 | 8700 | if( n1 + n2 >= 19 ) | ||
| 2131 | { | 2137 | { | |||||
| HITCBC | 2132 | 122 | goto do_num7; | 2138 | 64 | goto do_num7; | ||
| 2133 | } | 2139 | } | |||||
| 2134 | 2140 | |||||||
| HITGIC | 2135 | - | BOOST_IF_CONSTEXPR( !no_parsing ) | 2141 | + | 8636 | num.mant = detail::parse_unsigned( num.mant, cs.begin(), n2 ); | |
| DCB | 2136 | - | 12855 | num.mant = detail::parse_unsigned( num.mant, cs.begin(), n2 ); | ||||
| 2137 | 2142 | |||||||
| HITCBC | 2138 | 17074 | BOOST_ASSERT(num.bias == 0); | 2143 | 8636 | BOOST_ASSERT(num.bias == 0); | ||
| 2139 | 2144 | |||||||
| HITCBC | 2140 | 17074 | num.bias -= n2; | 2145 | 8636 | num.bias -= n2; | ||
| 2141 | 2146 | |||||||
| HITCBC | 2142 | 17074 | cs += n2; | 2147 | 8636 | cs += n2; | ||
| 2143 | 2148 | |||||||
| HITCBC | 2144 | 17074 | char ch = *cs; | 2149 | 8636 | char ch = *cs; | ||
| 2145 | 2150 | |||||||
| HITCBC | 2146 | 17074 | if( (ch | 32) == 'e' ) | 2151 | 8636 | if( (ch | 32) == 'e' ) | ||
| 2147 | { | 2152 | { | |||||
| HITCBC | 2148 | 110 | ++cs; | 2153 | 110 | ++cs; | ||
| HITCBC | 2149 | 110 | goto do_exp1; | 2154 | 110 | goto do_exp1; | ||
| 2150 | } | 2155 | } | |||||
| HITCBC | 2151 | 16964 | else if( ch >= '0' && ch <= '9' ) | 2156 | 8526 | else if( ch >= '0' && ch <= '9' ) | ||
| 2152 | { | 2157 | { | |||||
| HITCBC | 2153 | 10017 | goto do_num8; | 2158 | 5017 | goto do_num8; | ||
| 2154 | } | 2159 | } | |||||
| 2155 | 2160 | |||||||
| HITCBC | 2156 | 6947 | goto finish_dub; | 2161 | 3509 | goto finish_dub; | ||
| 2157 | } | 2162 | } | |||||
| 2158 | } | 2163 | } | |||||
| 2159 | else | 2164 | else | |||||
| 2160 | { | 2165 | { | |||||
| HITCBC | 2161 | 8426032 | num = num_; | 2166 | 8411991 | num = num_; | ||
| 2162 | state st; | 2167 | state st; | |||||
| HITCBC | 2163 | 8426032 | st_.pop(st); | 2168 | 8411991 | st_.pop(st); | ||
| HITCBC | 2164 | 8426032 | switch(st) | 2169 | 8411991 | switch(st) | ||
| 2165 | { | 2170 | { | |||||
| 2166 | default: BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE | 2171 | default: BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE | |||||
| HITCBC | 2167 | 603 | case state::num1: goto do_num1; | 2172 | 475 | case state::num1: goto do_num1; | ||
| HITCBC | 2168 | 6473 | case state::num2: goto do_num2; | 2173 | 6049 | case state::num2: goto do_num2; | ||
| HITCBC | 2169 | 4195112 | case state::num3: goto do_num3; | 2174 | 4195100 | case state::num3: goto do_num3; | ||
| HITCBC | 2170 | 52 | case state::num4: goto do_num4; | 2175 | 48 | case state::num4: goto do_num4; | ||
| HITCBC | 2171 | 4537 | case state::num5: goto do_num5; | 2176 | 741 | case state::num5: goto do_num5; | ||
| HITCBC | 2172 | 668 | case state::num6: goto do_num6; | 2177 | 474 | case state::num6: goto do_num6; | ||
| HITCBC | 2173 | 618 | case state::num7: goto do_num7; | 2178 | 422 | case state::num7: goto do_num7; | ||
| HITCBC | 2174 | 4205248 | case state::num8: goto do_num8; | 2179 | 4201807 | case state::num8: goto do_num8; | ||
| HITCBC | 2175 | 477 | case state::exp1: goto do_exp1; | 2180 | 385 | case state::exp1: goto do_exp1; | ||
| HITCBC | 2176 | 139 | case state::exp2: goto do_exp2; | 2181 | 131 | case state::exp2: goto do_exp2; | ||
| HITCBC | 2177 | 12105 | case state::exp3: goto do_exp3; | 2182 | 6359 | case state::exp3: goto do_exp3; | ||
| 2178 | } | 2183 | } | |||||
| 2179 | } | 2184 | } | |||||
| 2180 | 2185 | |||||||
| 2181 | //---------------------------------- | 2186 | //---------------------------------- | |||||
| 2182 | // | 2187 | // | |||||
| 2183 | // DIGIT | 2188 | // DIGIT | |||||
| 2184 | // first digit | 2189 | // first digit | |||||
| 2185 | // | 2190 | // | |||||
| HITCBC | 2186 | 62152 | do_num1: | 2191 | 55605 | do_num1: | ||
| HITCBC | 2187 | 15799 | if(zero_first || nonzero_first || | 2192 | 12711 | if(zero_first || nonzero_first || | ||
| HITCBC | 2188 | 15799 | BOOST_JSON_LIKELY(cs)) | 2193 | 12711 | BOOST_JSON_LIKELY(cs)) | ||
| 2189 | { | 2194 | { | |||||
| HITCBC | 2190 | 61429 | char const c = *cs; | 2195 | 55010 | char const c = *cs; | ||
| 2191 | if(zero_first) | 2196 | if(zero_first) | |||||
| 2192 | { | 2197 | { | |||||
| HITCBC | 2193 | 9726 | ++cs; | 2198 | 7236 | ++cs; | ||
| HITCBC | 2194 | 9726 | num.mant = 0; | 2199 | 7236 | num.mant = 0; | ||
| HITCBC | 2195 | 9726 | goto do_num6; | 2200 | 7236 | goto do_num6; | ||
| 2196 | } | 2201 | } | |||||
| HITCBC | 2197 | 15076 | else if(nonzero_first || BOOST_JSON_LIKELY( | 2202 | 12116 | else if(nonzero_first || BOOST_JSON_LIKELY( | ||
| 2198 | c >= '1' && c <= '9')) | 2203 | c >= '1' && c <= '9')) | |||||
| 2199 | { | 2204 | { | |||||
| HITCBC | 2200 | 42874 | ++cs; | 2205 | 41088 | ++cs; | ||
| HITCBC | 2201 | 42874 | num.mant = c - '0'; | 2206 | 41088 | num.mant = c - '0'; | ||
| 2202 | } | 2207 | } | |||||
| HITCBC | 2203 | 8829 | else if(BOOST_JSON_UNLIKELY( | 2208 | 6686 | else if(BOOST_JSON_UNLIKELY( | ||
| 2204 | c == '0')) | 2209 | c == '0')) | |||||
| 2205 | { | 2210 | { | |||||
| HITCBC | 2206 | 7634 | ++cs; | 2211 | 5491 | ++cs; | ||
| HITCBC | 2207 | 7634 | num.mant = 0; | 2212 | 5491 | num.mant = 0; | ||
| HITCBC | 2208 | 7634 | goto do_num6; | 2213 | 5491 | goto do_num6; | ||
| 2209 | } | 2214 | } | |||||
| HITCBC | 2210 | 1195 | else if( (negative || num.neg) && opt_.allow_infinity_and_nan ) | 2215 | 1195 | else if( (negative || num.neg) && opt_.allow_infinity_and_nan ) | ||
| 2211 | { | 2216 | { | |||||
| HITCBC | 2212 | 1007 | st_.push(state::lit1); | 2217 | 1007 | st_.push(state::lit1); | ||
| HITCBC | 2213 | 1007 | cur_lit_ = literal_index(detail::literals::neg_infinity); | 2218 | 1007 | cur_lit_ = literal_index(detail::literals::neg_infinity); | ||
| HITCBC | 2214 | 1007 | lit_offset_ = 1; | 2219 | 1007 | lit_offset_ = 1; | ||
| HITCBC | 2215 | 1007 | return parse_literal( | 2220 | 1007 | return parse_literal( | ||
| HITCBC | 2216 | 961 | cs.begin(), detail::literals_c<detail::literals::resume>() ); | 2221 | 961 | cs.begin(), detail::literals_c<detail::literals::resume>() ); | ||
| 2217 | } | 2222 | } | |||||
| 2218 | else | 2223 | else | |||||
| 2219 | { | 2224 | { | |||||
| 2220 | BOOST_STATIC_CONSTEXPR source_location loc | 2225 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 2221 | = BOOST_CURRENT_LOCATION; | 2226 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 2222 | 188 | return fail(cs.begin(), error::syntax, &loc); | 2227 | 188 | return fail(cs.begin(), error::syntax, &loc); | ||
| 2223 | } | 2228 | } | |||||
| 2224 | } | 2229 | } | |||||
| 2225 | else | 2230 | else | |||||
| 2226 | { | 2231 | { | |||||
| HITCBC | 2227 | 723 | if(BOOST_JSON_UNLIKELY( | 2232 | 595 | if(BOOST_JSON_UNLIKELY( | ||
| 2228 | ! h_.on_number_part( | 2233 | ! h_.on_number_part( | |||||
| 2229 | {begin, cs.used(begin)}, ec_))) | 2234 | {begin, cs.used(begin)}, ec_))) | |||||
| HITCBC | 2230 | 60 | return fail(cs.begin()); | 2235 | 60 | return fail(cs.begin()); | ||
| 2231 | - | BOOST_IF_CONSTEXPR( precise_parsing ) | ||||||
| 2232 | - | num_buf_.append( begin, cs.used(begin) ); | ||||||
| EUB | 2233 | ✗ | 2236 | |||||
| HITCBC | 2234 | 603 | return maybe_suspend( | 2237 | 475 | return maybe_suspend( | ||
| HITCBC | 2235 | 603 | cs.begin(), state::num1, num); | 2238 | 475 | cs.begin(), state::num1, num); | ||
| 2236 | } | 2239 | } | |||||
| 2237 | 2240 | |||||||
| 2238 | //---------------------------------- | 2241 | //---------------------------------- | |||||
| 2239 | // | 2242 | // | |||||
| 2240 | // 1*DIGIT | 2243 | // 1*DIGIT | |||||
| 2241 | // significant digits left of decimal | 2244 | // significant digits left of decimal | |||||
| 2242 | // | 2245 | // | |||||
| HITCBC | 2243 | 2050772 | do_num2: | 2246 | 1048166 | do_num2: | ||
| HITCBC | 2244 | 2044514 | if(negative || (!stack_empty && num.neg)) | 2247 | 1042685 | if(negative || (!stack_empty && num.neg)) | ||
| 2245 | { | 2248 | { | |||||
| HITCBC | 2246 | 22400 | for(;;) | 2249 | 21876 | for(;;) | ||
| 2247 | { | 2250 | { | |||||
| HITCBC | 2248 | 30225 | if(BOOST_JSON_UNLIKELY(! cs)) | 2251 | 28820 | if(BOOST_JSON_UNLIKELY(! cs)) | ||
| 2249 | { | 2252 | { | |||||
| HITCBC | 2250 | 1921 | if(BOOST_JSON_UNLIKELY(more_)) | 2253 | 1857 | if(BOOST_JSON_UNLIKELY(more_)) | ||
| 2251 | { | 2254 | { | |||||
| HITCBC | 2252 | 1469 | if(BOOST_JSON_UNLIKELY( | 2255 | 1405 | if(BOOST_JSON_UNLIKELY( | ||
| 2253 | ! h_.on_number_part( | 2256 | ! h_.on_number_part( | |||||
| 2254 | {begin, cs.used(begin)}, ec_))) | 2257 | {begin, cs.used(begin)}, ec_))) | |||||
| HITCBC | 2255 | 69 | return fail(cs.begin()); | 2258 | 69 | return fail(cs.begin()); | ||
| 2256 | - | BOOST_IF_CONSTEXPR( precise_parsing ) | ||||||
| 2257 | - | num_buf_.append( begin, cs.used(begin) ); | ||||||
| EUB | 2258 | ✗ | 2259 | |||||
| HITCBC | 2259 | 1331 | return suspend(cs.begin(), state::num2, num); | 2260 | 1267 | return suspend(cs.begin(), state::num2, num); | ||
| 2260 | } | 2261 | } | |||||
| HITCBC | 2261 | 452 | goto finish_int; | 2262 | 452 | goto finish_int; | ||
| 2262 | } | 2263 | } | |||||
| HITCBC | 2263 | 28304 | char const c = *cs; | 2264 | 26963 | char const c = *cs; | ||
| HITCBC | 2264 | 28304 | if(BOOST_JSON_LIKELY( | 2265 | 26963 | if(BOOST_JSON_LIKELY( | ||
| 2265 | c >= '0' && c <= '9')) | 2266 | c >= '0' && c <= '9')) | |||||
| 2266 | { | 2267 | { | |||||
| HITCBC | 2267 | 23223 | ++cs; | 2268 | 22699 | ++cs; | ||
| 2268 | // 9223372036854775808 INT64_MIN | 2269 | // 9223372036854775808 INT64_MIN | |||||
| HITCBC | 2269 | 23223 | if( num.mant > 922337203685477580 || ( | 2270 | 22699 | if( num.mant > 922337203685477580 || ( | ||
| HITCBC | 2270 | 22508 | num.mant == 922337203685477580 && c > '8')) | 2271 | 21984 | num.mant == 922337203685477580 && c > '8')) | ||
| 2271 | break; | 2272 | break; | |||||
| HITGIC | 2272 | - | BOOST_IF_CONSTEXPR( !no_parsing ) | 2273 | + | 21876 | num.mant = 10 * num.mant + ( c - '0' ); | |
| DCB | 2273 | - | 22141 | num.mant = 10 * num.mant + ( c - '0' ); | ||||
| HITCBC | 2274 | 22400 | continue; | 2274 | 21876 | continue; | ||
| 2275 | } | 2275 | } | |||||
| HITCBC | 2276 | 5081 | goto do_num6; // [.eE] | 2276 | 4264 | goto do_num6; // [.eE] | ||
| 2277 | } | 2277 | } | |||||
| 2278 | } | 2278 | } | |||||
| 2279 | else | 2279 | else | |||||
| 2280 | { | 2280 | { | |||||
| HITCBC | 2281 | 6889563 | for(;;) | 2281 | 3480940 | for(;;) | ||
| 2282 | { | 2282 | { | |||||
| HITCBC | 2283 | 8932510 | if(BOOST_JSON_UNLIKELY(! cs)) | 2283 | 4522162 | if(BOOST_JSON_UNLIKELY(! cs)) | ||
| 2284 | { | 2284 | { | |||||
| HITCBC | 2285 | 6601 | if(BOOST_JSON_UNLIKELY(more_)) | 2285 | 6241 | if(BOOST_JSON_UNLIKELY(more_)) | ||
| 2286 | { | 2286 | { | |||||
| HITCBC | 2287 | 5988 | if(BOOST_JSON_UNLIKELY( | 2287 | 5628 | if(BOOST_JSON_UNLIKELY( | ||
| 2288 | ! h_.on_number_part( | 2288 | ! h_.on_number_part( | |||||
| 2289 | {begin, cs.used(begin)}, ec_))) | 2289 | {begin, cs.used(begin)}, ec_))) | |||||
| HITCBC | 2290 | 426 | return fail(cs.begin()); | 2290 | 426 | return fail(cs.begin()); | ||
| 2291 | - | BOOST_IF_CONSTEXPR( precise_parsing ) | ||||||
| 2292 | - | num_buf_.append( begin, cs.used(begin) ); | ||||||
| EUB | 2293 | ✗ | 2291 | |||||
| HITCBC | 2294 | 5142 | return suspend(cs.begin(), state::num2, num); | 2292 | 4782 | return suspend(cs.begin(), state::num2, num); | ||
| 2295 | } | 2293 | } | |||||
| HITCBC | 2296 | 613 | goto finish_int; | 2294 | 613 | goto finish_int; | ||
| 2297 | } | 2295 | } | |||||
| HITCBC | 2298 | 8925909 | char const c = *cs; | 2296 | 4515921 | char const c = *cs; | ||
| HITCBC | 2299 | 8925909 | if(BOOST_JSON_LIKELY( | 2297 | 4515921 | if(BOOST_JSON_LIKELY( | ||
| 2300 | c >= '0' && c <= '9')) | 2298 | c >= '0' && c <= '9')) | |||||
| 2301 | { | 2299 | { | |||||
| HITCBC | 2302 | 6893607 | ++cs; | 2300 | 3484632 | ++cs; | ||
| 2303 | // 18446744073709551615 UINT64_MAX | 2301 | // 18446744073709551615 UINT64_MAX | |||||
| HITCBC | 2304 | 6893607 | if( num.mant > 1844674407370955161 || ( | 2302 | 3484632 | if( num.mant > 1844674407370955161 || ( | ||
| HITCBC | 2305 | 6889985 | num.mant == 1844674407370955161 && c > '5')) | 2303 | 3481362 | num.mant == 1844674407370955161 && c > '5')) | ||
| 2306 | break; | 2304 | break; | |||||
| HITGIC | 2307 | - | BOOST_IF_CONSTEXPR( !no_parsing ) | 2305 | + | 3480940 | num.mant = 10 * num.mant + ( c - '0' ); | |
| DCB | 2308 | - | 6883965 | num.mant = 10 * num.mant + ( c - '0' ); | ||||
| 2309 | } | 2306 | } | |||||
| 2310 | else | 2307 | else | |||||
| 2311 | { | 2308 | { | |||||
| HITCBC | 2312 | 2032302 | goto do_num6; // [.eE] | 2309 | 1031289 | goto do_num6; // [.eE] | ||
| 2313 | } | 2310 | } | |||||
| 2314 | } | 2311 | } | |||||
| 2315 | } | 2312 | } | |||||
| HITCBC | 2316 | 4867 | ++num.bias; | 2313 | 4515 | ++num.bias; | ||
| 2317 | 2314 | |||||||
| 2318 | //---------------------------------- | 2315 | //---------------------------------- | |||||
| 2319 | // | 2316 | // | |||||
| 2320 | // 1*DIGIT | 2317 | // 1*DIGIT | |||||
| 2321 | // non-significant digits left of decimal | 2318 | // non-significant digits left of decimal | |||||
| 2322 | // | 2319 | // | |||||
| HITCBC | 2323 | 4199979 | do_num3: | 2320 | 4199615 | do_num3: | ||
| HITCBC | 2324 | 4294978560 | for(;;) | 2321 | 4294978208 | for(;;) | ||
| 2325 | { | 2322 | { | |||||
| HITCBC | 2326 | 4299178539 | if(BOOST_JSON_UNLIKELY(! cs)) | 2323 | 4299177823 | if(BOOST_JSON_UNLIKELY(! cs)) | ||
| 2327 | { | 2324 | { | |||||
| HITCBC | 2328 | 4195839 | if(BOOST_JSON_UNLIKELY(more_)) | 2325 | 4195827 | if(BOOST_JSON_UNLIKELY(more_)) | ||
| 2329 | { | 2326 | { | |||||
| HITCBC | 2330 | 4195206 | if(BOOST_JSON_UNLIKELY( | 2327 | 4195194 | if(BOOST_JSON_UNLIKELY( | ||
| 2331 | ! h_.on_number_part( | 2328 | ! h_.on_number_part( | |||||
| 2332 | {begin, cs.used(begin)}, ec_))) | 2329 | {begin, cs.used(begin)}, ec_))) | |||||
| HITCBC | 2333 | 47 | return fail(cs.begin()); | 2330 | 47 | return fail(cs.begin()); | ||
| 2334 | - | BOOST_IF_CONSTEXPR( precise_parsing ) | ||||||
| 2335 | - | num_buf_.append( begin, cs.used(begin) ); | ||||||
| EUB | 2336 | ✗ | 2331 | |||||
| HITCBC | 2337 | 4195112 | return suspend(cs.begin(), state::num3, num); | 2332 | 4195100 | return suspend(cs.begin(), state::num3, num); | ||
| 2338 | } | 2333 | } | |||||
| HITCBC | 2339 | 633 | goto finish_dub; | 2334 | 633 | goto finish_dub; | ||
| 2340 | } | 2335 | } | |||||
| HITCBC | 2341 | 4294982700 | char const c = *cs; | 2336 | 4294981996 | char const c = *cs; | ||
| HITCBC | 2342 | 4294982700 | if(BOOST_JSON_UNLIKELY( | 2337 | 4294981996 | if(BOOST_JSON_UNLIKELY( | ||
| 2343 | c >= '0' && c <= '9')) | 2338 | c >= '0' && c <= '9')) | |||||
| 2344 | { | 2339 | { | |||||
| HITCBC | 2345 | 4294978561 | if(BOOST_JSON_UNLIKELY( num.bias + 1 == INT_MAX )) | 2340 | 4294978209 | if(BOOST_JSON_UNLIKELY( num.bias + 1 == INT_MAX )) | ||
| 2346 | { | 2341 | { | |||||
| 2347 | BOOST_STATIC_CONSTEXPR source_location loc | 2342 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 2348 | = BOOST_CURRENT_LOCATION; | 2343 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 2349 | 1 | return fail(cs.begin(), error::exponent_overflow, &loc); | 2344 | 1 | return fail(cs.begin(), error::exponent_overflow, &loc); | ||
| 2350 | } | 2345 | } | |||||
| HITCBC | 2351 | 4294978560 | ++cs; | 2346 | 4294978208 | ++cs; | ||
| HITCBC | 2352 | 4294978560 | ++num.bias; | 2347 | 4294978208 | ++num.bias; | ||
| 2353 | } | 2348 | } | |||||
| HITCBC | 2354 | 4139 | else if(BOOST_JSON_LIKELY( | 2349 | 3787 | else if(BOOST_JSON_LIKELY( | ||
| 2355 | c == '.')) | 2350 | c == '.')) | |||||
| 2356 | { | 2351 | { | |||||
| HITCBC | 2357 | 2028 | ++cs; | 2352 | 1796 | ++cs; | ||
| HITCBC | 2358 | 2028 | break; | 2353 | 1796 | break; | ||
| 2359 | } | 2354 | } | |||||
| HITCBC | 2360 | 2111 | else if((c | 32) == 'e') | 2355 | 1991 | else if((c | 32) == 'e') | ||
| 2361 | { | 2356 | { | |||||
| HITCBC | 2362 | 762 | ++cs; | 2357 | 642 | ++cs; | ||
| HITCBC | 2363 | 762 | goto do_exp1; | 2358 | 642 | goto do_exp1; | ||
| 2364 | } | 2359 | } | |||||
| 2365 | else | 2360 | else | |||||
| 2366 | { | 2361 | { | |||||
| HITCBC | 2367 | 1349 | goto finish_dub; | 2362 | 1349 | goto finish_dub; | ||
| 2368 | } | 2363 | } | |||||
| 2369 | } | 2364 | } | |||||
| 2370 | 2365 | |||||||
| 2371 | //---------------------------------- | 2366 | //---------------------------------- | |||||
| 2372 | // | 2367 | // | |||||
| 2373 | // DIGIT | 2368 | // DIGIT | |||||
| 2374 | // first non-significant digit | 2369 | // first non-significant digit | |||||
| 2375 | // to the right of decimal | 2370 | // to the right of decimal | |||||
| 2376 | // | 2371 | // | |||||
| HITCBC | 2377 | 2080 | do_num4: | 2372 | 1844 | do_num4: | ||
| 2378 | { | 2373 | { | |||||
| HITCBC | 2379 | 2080 | if(BOOST_JSON_UNLIKELY(! cs)) | 2374 | 1844 | if(BOOST_JSON_UNLIKELY(! cs)) | ||
| 2380 | { | 2375 | { | |||||
| HITCBC | 2381 | 64 | if(BOOST_JSON_UNLIKELY( | 2376 | 60 | if(BOOST_JSON_UNLIKELY( | ||
| 2382 | ! h_.on_number_part( | 2377 | ! h_.on_number_part( | |||||
| 2383 | {begin, cs.used(begin)}, ec_))) | 2378 | {begin, cs.used(begin)}, ec_))) | |||||
| HITCBC | 2384 | 6 | return fail(cs.begin()); | 2379 | 6 | return fail(cs.begin()); | ||
| 2385 | - | BOOST_IF_CONSTEXPR( precise_parsing ) | ||||||
| 2386 | - | num_buf_.append( begin, cs.used(begin) ); | ||||||
| EUB | 2387 | ✗ | 2380 | |||||
| HITCBC | 2388 | 52 | return maybe_suspend( | 2381 | 48 | return maybe_suspend( | ||
| HITCBC | 2389 | 52 | cs.begin(), state::num4, num); | 2382 | 48 | cs.begin(), state::num4, num); | ||
| 2390 | } | 2383 | } | |||||
| HITCBC | 2391 | 2016 | char const c = *cs; | 2384 | 1784 | char const c = *cs; | ||
| HITCBC | 2392 | 2016 | if(BOOST_JSON_LIKELY( | 2385 | 1784 | if(BOOST_JSON_LIKELY( | ||
| 2393 | //static_cast<unsigned char>(c - '0') < 10)) | 2386 | //static_cast<unsigned char>(c - '0') < 10)) | |||||
| 2394 | c >= '0' && c <= '9')) | 2387 | c >= '0' && c <= '9')) | |||||
| 2395 | { | 2388 | { | |||||
| HITCBC | 2396 | 1949 | ++cs; | 2389 | 1717 | ++cs; | ||
| 2397 | } | 2390 | } | |||||
| 2398 | else | 2391 | else | |||||
| 2399 | { | 2392 | { | |||||
| 2400 | // digit required | 2393 | // digit required | |||||
| 2401 | BOOST_STATIC_CONSTEXPR source_location loc | 2394 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 2402 | = BOOST_CURRENT_LOCATION; | 2395 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 2403 | 67 | return fail(cs.begin(), error::syntax, &loc); | 2396 | 67 | return fail(cs.begin(), error::syntax, &loc); | ||
| 2404 | } | 2397 | } | |||||
| 2405 | } | 2398 | } | |||||
| 2406 | 2399 | |||||||
| 2407 | //---------------------------------- | 2400 | //---------------------------------- | |||||
| 2408 | // | 2401 | // | |||||
| 2409 | // 1*DIGIT | 2402 | // 1*DIGIT | |||||
| 2410 | // non-significant digits | 2403 | // non-significant digits | |||||
| 2411 | // to the right of decimal | 2404 | // to the right of decimal | |||||
| 2412 | // | 2405 | // | |||||
| HITCBC | 2413 | 2013470 | do_num5: | 2406 | 1003880 | do_num5: | ||
| HITCBC | 2414 | 37889832 | for(;;) | 2407 | 18406185 | for(;;) | ||
| 2415 | { | 2408 | { | |||||
| HITCBC | 2416 | 39903302 | if(BOOST_JSON_UNLIKELY(! cs)) | 2409 | 19410065 | if(BOOST_JSON_UNLIKELY(! cs)) | ||
| 2417 | { | 2410 | { | |||||
| HITCBC | 2418 | 6112 | if(BOOST_JSON_UNLIKELY(more_)) | 2411 | 1541 | if(BOOST_JSON_UNLIKELY(more_)) | ||
| 2419 | { | 2412 | { | |||||
| HITCBC | 2420 | 4577 | if(BOOST_JSON_UNLIKELY( | 2413 | 781 | if(BOOST_JSON_UNLIKELY( | ||
| 2421 | ! h_.on_number_part( | 2414 | ! h_.on_number_part( | |||||
| 2422 | {begin, cs.used(begin)}, ec_))) | 2415 | {begin, cs.used(begin)}, ec_))) | |||||
| HITCBC | 2423 | 20 | return fail(cs.begin()); | 2416 | 20 | return fail(cs.begin()); | ||
| 2424 | - | BOOST_IF_CONSTEXPR( precise_parsing ) | ||||||
| 2425 | - | num_buf_.append( begin, cs.used(begin) ); | ||||||
| EUB | 2426 | ✗ | 2417 | |||||
| HITCBC | 2427 | 4537 | return suspend(cs.begin(), state::num5, num); | 2418 | 741 | return suspend(cs.begin(), state::num5, num); | ||
| 2428 | } | 2419 | } | |||||
| HITCBC | 2429 | 1535 | goto finish_dub; | 2420 | 760 | goto finish_dub; | ||
| 2430 | } | 2421 | } | |||||
| HITCBC | 2431 | 39897190 | char const c = *cs; | 2422 | 19408524 | char const c = *cs; | ||
| HITCBC | 2432 | 39897190 | if(BOOST_JSON_LIKELY( | 2423 | 19408524 | if(BOOST_JSON_LIKELY( | ||
| 2433 | c >= '0' && c <= '9')) | 2424 | c >= '0' && c <= '9')) | |||||
| 2434 | { | 2425 | { | |||||
| HITCBC | 2435 | 37889832 | ++cs; | 2426 | 18406185 | ++cs; | ||
| 2436 | } | 2427 | } | |||||
| HITCBC | 2437 | 2007358 | else if((c | 32) == 'e') | 2428 | 1002339 | else if((c | 32) == 'e') | ||
| 2438 | { | 2429 | { | |||||
| HITCBC | 2439 | 2003236 | ++cs; | 2430 | 1000472 | ++cs; | ||
| HITCBC | 2440 | 2003236 | goto do_exp1; | 2431 | 1000472 | goto do_exp1; | ||
| 2441 | } | 2432 | } | |||||
| 2442 | else | 2433 | else | |||||
| 2443 | { | 2434 | { | |||||
| HITCBC | 2444 | 4122 | goto finish_dub; | 2435 | 1867 | goto finish_dub; | ||
| 2445 | } | 2436 | } | |||||
| 2446 | } | 2437 | } | |||||
| 2447 | 2438 | |||||||
| 2448 | //---------------------------------- | 2439 | //---------------------------------- | |||||
| 2449 | // | 2440 | // | |||||
| 2450 | // [.eE] | 2441 | // [.eE] | |||||
| 2451 | // | 2442 | // | |||||
| HITCBC | 2452 | 2055411 | do_num6: | 2443 | 1048754 | do_num6: | ||
| 2453 | { | 2444 | { | |||||
| HITCBC | 2454 | 2055411 | if(BOOST_JSON_UNLIKELY(! cs)) | 2445 | 1048754 | if(BOOST_JSON_UNLIKELY(! cs)) | ||
| 2455 | { | 2446 | { | |||||
| HITCBC | 2456 | 800 | if(BOOST_JSON_UNLIKELY(more_)) | 2447 | 606 | if(BOOST_JSON_UNLIKELY(more_)) | ||
| 2457 | { | 2448 | { | |||||
| HITCBC | 2458 | 753 | if(BOOST_JSON_UNLIKELY( | 2449 | 559 | if(BOOST_JSON_UNLIKELY( | ||
| 2459 | ! h_.on_number_part( | 2450 | ! h_.on_number_part( | |||||
| 2460 | {begin, cs.used(begin)}, ec_))) | 2451 | {begin, cs.used(begin)}, ec_))) | |||||
| HITCBC | 2461 | 42 | return fail(cs.begin()); | 2452 | 42 | return fail(cs.begin()); | ||
| 2462 | - | BOOST_IF_CONSTEXPR( precise_parsing ) | ||||||
| 2463 | - | num_buf_.append( begin, cs.used(begin) ); | ||||||
| ECB | 2464 | 2 | 2453 | |||||
| HITCBC | 2465 | 669 | return suspend(cs.begin(), state::num6, num); | 2454 | 475 | return suspend(cs.begin(), state::num6, num); | ||
| 2466 | } | 2455 | } | |||||
| HITCBC | 2467 | 47 | goto finish_int; | 2456 | 47 | goto finish_int; | ||
| 2468 | } | 2457 | } | |||||
| HITCBC | 2469 | 2054611 | char const c = *cs; | 2458 | 1048148 | char const c = *cs; | ||
| HITCBC | 2470 | 2054611 | if(BOOST_JSON_LIKELY( | 2459 | 1048148 | if(BOOST_JSON_LIKELY( | ||
| 2471 | c == '.')) | 2460 | c == '.')) | |||||
| 2472 | { | 2461 | { | |||||
| HITCBC | 2473 | 2016099 | ++cs; | 2462 | 1011194 | ++cs; | ||
| 2474 | } | 2463 | } | |||||
| HITCBC | 2475 | 38512 | else if((c | 32) == 'e') | 2464 | 36954 | else if((c | 32) == 'e') | ||
| 2476 | { | 2465 | { | |||||
| HITCBC | 2477 | 9153 | ++cs; | 2466 | 7595 | ++cs; | ||
| HITCBC | 2478 | 9153 | goto do_exp1; | 2467 | 7595 | goto do_exp1; | ||
| 2479 | } | 2468 | } | |||||
| 2480 | else | 2469 | else | |||||
| 2481 | { | 2470 | { | |||||
| HITCBC | 2482 | 29359 | goto finish_int; | 2471 | 29359 | goto finish_int; | ||
| 2483 | } | 2472 | } | |||||
| 2484 | } | 2473 | } | |||||
| 2485 | 2474 | |||||||
| 2486 | //---------------------------------- | 2475 | //---------------------------------- | |||||
| 2487 | // | 2476 | // | |||||
| 2488 | // DIGIT | 2477 | // DIGIT | |||||
| 2489 | // first significant digit | 2478 | // first significant digit | |||||
| 2490 | // to the right of decimal | 2479 | // to the right of decimal | |||||
| 2491 | // | 2480 | // | |||||
| HITCBC | 2492 | 2016839 | do_num7: | 2481 | 1011680 | do_num7: | ||
| 2493 | { | 2482 | { | |||||
| HITCBC | 2494 | 2016839 | if(BOOST_JSON_UNLIKELY(! cs)) | 2483 | 1011680 | if(BOOST_JSON_UNLIKELY(! cs)) | ||
| 2495 | { | 2484 | { | |||||
| HITCBC | 2496 | 693 | if(BOOST_JSON_UNLIKELY(more_)) | 2485 | 497 | if(BOOST_JSON_UNLIKELY(more_)) | ||
| 2497 | { | 2486 | { | |||||
| HITCBC | 2498 | 689 | if(BOOST_JSON_UNLIKELY( | 2487 | 493 | if(BOOST_JSON_UNLIKELY( | ||
| 2499 | ! h_.on_number_part( | 2488 | ! h_.on_number_part( | |||||
| 2500 | {begin, cs.used(begin)}, ec_))) | 2489 | {begin, cs.used(begin)}, ec_))) | |||||
| HITCBC | 2501 | 35 | return fail(cs.begin()); | 2490 | 35 | return fail(cs.begin()); | ||
| 2502 | - | BOOST_IF_CONSTEXPR( precise_parsing ) | ||||||
| 2503 | - | num_buf_.append( begin, cs.used(begin) ); | ||||||
| EUB | 2504 | ✗ | 2491 | |||||
| HITCBC | 2505 | 619 | return suspend(cs.begin(), state::num7, num); | 2492 | 423 | return suspend(cs.begin(), state::num7, num); | ||
| 2506 | } | 2493 | } | |||||
| 2507 | // digit required | 2494 | // digit required | |||||
| 2508 | BOOST_STATIC_CONSTEXPR source_location loc | 2495 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 2509 | = BOOST_CURRENT_LOCATION; | 2496 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 2510 | 4 | return fail(cs.begin(), error::syntax, &loc); | 2497 | 4 | return fail(cs.begin(), error::syntax, &loc); | ||
| 2511 | } | 2498 | } | |||||
| HITCBC | 2512 | 2016146 | char const c = *cs; | 2499 | 1011183 | char const c = *cs; | ||
| HITCBC | 2513 | 2016146 | if(BOOST_JSON_UNLIKELY( | 2500 | 1011183 | if(BOOST_JSON_UNLIKELY( | ||
| 2514 | c < '0' || c > '9')) | 2501 | c < '0' || c > '9')) | |||||
| 2515 | { | 2502 | { | |||||
| 2516 | // digit required | 2503 | // digit required | |||||
| 2517 | BOOST_STATIC_CONSTEXPR source_location loc | 2504 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 2518 | = BOOST_CURRENT_LOCATION; | 2505 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 2519 | 169 | return fail(cs.begin(), error::syntax, &loc); | 2506 | 169 | return fail(cs.begin(), error::syntax, &loc); | ||
| 2520 | } | 2507 | } | |||||
| 2521 | } | 2508 | } | |||||
| 2522 | 2509 | |||||||
| 2523 | //---------------------------------- | 2510 | //---------------------------------- | |||||
| 2524 | // | 2511 | // | |||||
| 2525 | // 1*DIGIT | 2512 | // 1*DIGIT | |||||
| 2526 | // significant digits | 2513 | // significant digits | |||||
| 2527 | // to the right of decimal | 2514 | // to the right of decimal | |||||
| 2528 | // | 2515 | // | |||||
| HITCBC | 2529 | 6228742 | do_num8: | 2516 | 5217838 | do_num8: | ||
| HITCBC | 2530 | 4298245220 | for(;;) | 2517 | 4297156220 | for(;;) | ||
| 2531 | { | 2518 | { | |||||
| HITCBC | 2532 | 4304476462 | if(BOOST_JSON_UNLIKELY(! cs)) | 2519 | 4302374058 | if(BOOST_JSON_UNLIKELY(! cs)) | ||
| 2533 | { | 2520 | { | |||||
| HITCBC | 2534 | 4207120 | if(BOOST_JSON_UNLIKELY(more_)) | 2521 | 4203159 | if(BOOST_JSON_UNLIKELY(more_)) | ||
| 2535 | { | 2522 | { | |||||
| HITCBC | 2536 | 4205384 | if(BOOST_JSON_UNLIKELY( | 2523 | 4201942 | if(BOOST_JSON_UNLIKELY( | ||
| 2537 | ! h_.on_number_part( | 2524 | ! h_.on_number_part( | |||||
| 2538 | {begin, cs.used(begin)}, ec_))) | 2525 | {begin, cs.used(begin)}, ec_))) | |||||
| HITCBC | 2539 | 67 | return fail(cs.begin()); | 2526 | 67 | return fail(cs.begin()); | ||
| 2540 | - | BOOST_IF_CONSTEXPR( precise_parsing ) | ||||||
| 2541 | - | num_buf_.append( begin, cs.used(begin) ); | ||||||
| ECB | 2542 | 2 | 2527 | |||||
| HITCBC | 2543 | 4205249 | return suspend(cs.begin(), state::num8, num); | 2528 | 4201808 | return suspend(cs.begin(), state::num8, num); | ||
| 2544 | } | 2529 | } | |||||
| HITCBC | 2545 | 1736 | goto finish_dub; | 2530 | 1217 | goto finish_dub; | ||
| 2546 | } | 2531 | } | |||||
| HITCBC | 2547 | 4300269342 | char const c = *cs; | 2532 | 4298170899 | char const c = *cs; | ||
| HITCBC | 2548 | 4300269342 | if(BOOST_JSON_LIKELY( | 2533 | 4298170899 | if(BOOST_JSON_LIKELY( | ||
| 2549 | c >= '0' && c <= '9')) | 2534 | c >= '0' && c <= '9')) | |||||
| 2550 | { | 2535 | { | |||||
| HITCBC | 2551 | 4300252205 | ++cs; | 2536 | 4298157643 | ++cs; | ||
| HITCBC | 2552 | - | 4300247112 | if(!no_parsing && BOOST_JSON_LIKELY( | 2537 | + | 4298157643 | if(BOOST_JSON_LIKELY( num.mant <= 9007199254740991 )) // 2^53-1 |
| 2553 | - | num.mant <= 9007199254740991)) // 2^53-1 | ||||||
| 2554 | { | 2538 | { | |||||
| HITCBC | 2555 | 4298245221 | if(BOOST_JSON_UNLIKELY( num.bias - 1 == INT_MIN )) | 2539 | 4297156221 | if(BOOST_JSON_UNLIKELY( num.bias - 1 == INT_MIN )) | ||
| 2556 | { | 2540 | { | |||||
| 2557 | BOOST_STATIC_CONSTEXPR source_location loc | 2541 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 2558 | = BOOST_CURRENT_LOCATION; | 2542 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 2559 | 1 | return fail(cs.begin(), error::exponent_overflow, &loc); | 2543 | 1 | return fail(cs.begin(), error::exponent_overflow, &loc); | ||
| 2560 | } | 2544 | } | |||||
| HITCBC | 2561 | 4298245220 | --num.bias; | 2545 | 4297156220 | --num.bias; | ||
| HITCBC | 2562 | 4298245220 | num.mant = 10 * num.mant + ( c - '0' ); | 2546 | 4297156220 | num.mant = 10 * num.mant + ( c - '0' ); | ||
| 2563 | } | 2547 | } | |||||
| 2564 | else | 2548 | else | |||||
| 2565 | { | 2549 | { | |||||
| HITCBC | 2566 | 2006984 | goto do_num5; | 2550 | 1001422 | goto do_num5; | ||
| 2567 | } | 2551 | } | |||||
| 2568 | } | 2552 | } | |||||
| HITCBC | 2569 | 17137 | else if((c | 32) == 'e') | 2553 | 13256 | else if((c | 32) == 'e') | ||
| 2570 | { | 2554 | { | |||||
| HITCBC | 2571 | 11134 | ++cs; | 2555 | 8606 | ++cs; | ||
| HITCBC | 2572 | 11134 | goto do_exp1; | 2556 | 8606 | goto do_exp1; | ||
| 2573 | } | 2557 | } | |||||
| 2574 | else | 2558 | else | |||||
| 2575 | { | 2559 | { | |||||
| HITCBC | 2576 | 6003 | goto finish_dub; | 2560 | 4650 | goto finish_dub; | ||
| 2577 | } | 2561 | } | |||||
| 2578 | } | 2562 | } | |||||
| 2579 | 2563 | |||||||
| 2580 | //---------------------------------- | 2564 | //---------------------------------- | |||||
| 2581 | // | 2565 | // | |||||
| 2582 | // *[+-] | 2566 | // *[+-] | |||||
| 2583 | // | 2567 | // | |||||
| HITCBC | 2584 | 2031448 | do_exp1: | 2568 | 1021128 | do_exp1: | ||
| HITCBC | 2585 | 2031448 | if(BOOST_JSON_UNLIKELY(! cs)) | 2569 | 1021128 | if(BOOST_JSON_UNLIKELY(! cs)) | ||
| 2586 | { | 2570 | { | |||||
| HITCBC | 2587 | 575 | if(BOOST_JSON_UNLIKELY( | 2571 | 483 | if(BOOST_JSON_UNLIKELY( | ||
| 2588 | ! h_.on_number_part( | 2572 | ! h_.on_number_part( | |||||
| 2589 | {begin, cs.used(begin)}, ec_))) | 2573 | {begin, cs.used(begin)}, ec_))) | |||||
| HITCBC | 2590 | 49 | return fail(cs.begin()); | 2574 | 49 | return fail(cs.begin()); | ||
| 2591 | - | BOOST_IF_CONSTEXPR( precise_parsing ) | ||||||
| 2592 | - | num_buf_.append( begin, cs.used(begin) ); | ||||||
| EUB | 2593 | ✗ | 2575 | |||||
| HITCBC | 2594 | 477 | return maybe_suspend( | 2576 | 385 | return maybe_suspend( | ||
| HITCBC | 2595 | 477 | cs.begin(), state::exp1, num); | 2577 | 385 | cs.begin(), state::exp1, num); | ||
| 2596 | } | 2578 | } | |||||
| HITCBC | 2597 | 2030873 | if(*cs == '+') | 2579 | 1020645 | if(*cs == '+') | ||
| 2598 | { | 2580 | { | |||||
| HITCBC | 2599 | 2364 | ++cs; | 2581 | 2364 | ++cs; | ||
| 2600 | } | 2582 | } | |||||
| HITCBC | 2601 | 2028509 | else if(*cs == '-') | 2583 | 1018281 | else if(*cs == '-') | ||
| 2602 | { | 2584 | { | |||||
| HITCBC | 2603 | 1001936 | ++cs; | 2585 | 502089 | ++cs; | ||
| HITCBC | 2604 | 1001936 | num.frac = true; | 2586 | 502089 | num.frac = true; | ||
| 2605 | } | 2587 | } | |||||
| 2606 | 2588 | |||||||
| 2607 | //---------------------------------- | 2589 | //---------------------------------- | |||||
| 2608 | // | 2590 | // | |||||
| 2609 | // DIGIT | 2591 | // DIGIT | |||||
| 2610 | // first digit of the exponent | 2592 | // first digit of the exponent | |||||
| 2611 | // | 2593 | // | |||||
| HITCBC | 2612 | 1026573 | do_exp2: | 2594 | 516192 | do_exp2: | ||
| 2613 | { | 2595 | { | |||||
| HITCBC | 2614 | 2031012 | if(BOOST_JSON_UNLIKELY(! cs)) | 2596 | 1020776 | if(BOOST_JSON_UNLIKELY(! cs)) | ||
| 2615 | { | 2597 | { | |||||
| HITCBC | 2616 | 188 | if(BOOST_JSON_UNLIKELY(more_)) | 2598 | 180 | if(BOOST_JSON_UNLIKELY(more_)) | ||
| 2617 | { | 2599 | { | |||||
| HITCBC | 2618 | 179 | if(BOOST_JSON_UNLIKELY( | 2600 | 171 | if(BOOST_JSON_UNLIKELY( | ||
| 2619 | ! h_.on_number_part( | 2601 | ! h_.on_number_part( | |||||
| 2620 | {begin, cs.used(begin)}, ec_))) | 2602 | {begin, cs.used(begin)}, ec_))) | |||||
| HITCBC | 2621 | 20 | return fail(cs.begin()); | 2603 | 20 | return fail(cs.begin()); | ||
| 2622 | - | BOOST_IF_CONSTEXPR( precise_parsing ) | ||||||
| 2623 | - | num_buf_.append( begin, cs.used(begin) ); | ||||||
| EUB | 2624 | ✗ | 2604 | |||||
| HITCBC | 2625 | 139 | return suspend(cs.begin(), state::exp2, num); | 2605 | 131 | return suspend(cs.begin(), state::exp2, num); | ||
| 2626 | } | 2606 | } | |||||
| 2627 | // digit required | 2607 | // digit required | |||||
| 2628 | BOOST_STATIC_CONSTEXPR source_location loc | 2608 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 2629 | = BOOST_CURRENT_LOCATION; | 2609 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 2630 | 9 | return fail(cs.begin(), error::syntax, &loc); | 2610 | 9 | return fail(cs.begin(), error::syntax, &loc); | ||
| 2631 | } | 2611 | } | |||||
| HITCBC | 2632 | 2030824 | char const c = *cs; | 2612 | 1020596 | char const c = *cs; | ||
| HITCBC | 2633 | 2030824 | if(BOOST_JSON_UNLIKELY( | 2613 | 1020596 | if(BOOST_JSON_UNLIKELY( | ||
| 2634 | c < '0' || c > '9')) | 2614 | c < '0' || c > '9')) | |||||
| 2635 | { | 2615 | { | |||||
| 2636 | // digit required | 2616 | // digit required | |||||
| 2637 | BOOST_STATIC_CONSTEXPR source_location loc | 2617 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 2638 | = BOOST_CURRENT_LOCATION; | 2618 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 2639 | 508 | return fail(cs.begin(), error::syntax, &loc); | 2619 | 508 | return fail(cs.begin(), error::syntax, &loc); | ||
| 2640 | } | 2620 | } | |||||
| HITCBC | 2641 | 2030316 | ++cs; | 2621 | 1020088 | ++cs; | ||
| HITCBC | 2642 | 2030316 | num.exp = c - '0'; | 2622 | 1020088 | num.exp = c - '0'; | ||
| 2643 | } | 2623 | } | |||||
| 2644 | 2624 | |||||||
| 2645 | //---------------------------------- | 2625 | //---------------------------------- | |||||
| 2646 | // | 2626 | // | |||||
| 2647 | // 1*DIGIT | 2627 | // 1*DIGIT | |||||
| 2648 | // subsequent digits in the exponent | 2628 | // subsequent digits in the exponent | |||||
| 2649 | // | 2629 | // | |||||
| HITCBC | 2650 | 2042421 | do_exp3: | 2630 | 1026447 | do_exp3: | ||
| HITCBC | 2651 | 5468163 | for(;;) | 2631 | 2740361 | for(;;) | ||
| 2652 | { | 2632 | { | |||||
| HITCBC | 2653 | 7510584 | if(BOOST_JSON_UNLIKELY(! cs)) | 2633 | 3766808 | if(BOOST_JSON_UNLIKELY(! cs)) | ||
| 2654 | { | 2634 | { | |||||
| HITCBC | 2655 | 2020838 | if(BOOST_JSON_UNLIKELY(more_)) | 2635 | 1011428 | if(BOOST_JSON_UNLIKELY(more_)) | ||
| 2656 | { | 2636 | { | |||||
| HITCBC | 2657 | 12277 | if(BOOST_JSON_UNLIKELY( | 2637 | 6531 | if(BOOST_JSON_UNLIKELY( | ||
| 2658 | ! h_.on_number_part( | 2638 | ! h_.on_number_part( | |||||
| 2659 | {begin, cs.used(begin)}, ec_))) | 2639 | {begin, cs.used(begin)}, ec_))) | |||||
| HITCBC | 2660 | 86 | return fail(cs.begin()); | 2640 | 86 | return fail(cs.begin()); | ||
| 2661 | - | BOOST_IF_CONSTEXPR( precise_parsing ) | ||||||
| 2662 | - | num_buf_.append( begin, cs.used(begin) ); | ||||||
| EUB | 2663 | ✗ | 2641 | |||||
| HITCBC | 2664 | 12105 | return suspend(cs.begin(), state::exp3, num); | 2642 | 6359 | return suspend(cs.begin(), state::exp3, num); | ||
| 2665 | } | 2643 | } | |||||
| 2666 | } | 2644 | } | |||||
| 2667 | else | 2645 | else | |||||
| 2668 | { | 2646 | { | |||||
| HITCBC | 2669 | 5489746 | char const c = *cs; | 2647 | 2755380 | char const c = *cs; | ||
| HITCBC | 2670 | 5489746 | if(BOOST_JSON_LIKELY( c >= '0' && c <= '9' )) | 2648 | 2755380 | if(BOOST_JSON_LIKELY( c >= '0' && c <= '9' )) | ||
| 2671 | { | 2649 | { | |||||
| HITCBC | 2672 | 5468163 | if(BOOST_JSON_UNLIKELY( | 2650 | 2740361 | if(BOOST_JSON_UNLIKELY( | ||
| 2673 | // 2147483647 INT_MAX | 2651 | // 2147483647 INT_MAX | |||||
| 2674 | num.exp > 214748364 || | 2652 | num.exp > 214748364 || | |||||
| 2675 | (num.exp == 214748364 && c > '7') | 2653 | (num.exp == 214748364 && c > '7') | |||||
| 2676 | )) | 2654 | )) | |||||
| HITCBC | 2677 | 3855 | num.exp = INT_MAX; | 2655 | 3855 | num.exp = INT_MAX; | ||
| 2678 | - | else BOOST_IF_CONSTEXPR( !no_parsing ) | 2656 | + | else | |||
| HITCBC | 2679 | 4923456 | num.exp = 10 * num.exp + ( c - '0' ); | 2657 | 2736506 | num.exp = 10 * num.exp + ( c - '0' ); | ||
| 2680 | 2658 | |||||||
| HITCBC | 2681 | 5468163 | ++cs; | 2659 | 2740361 | ++cs; | ||
| HITCBC | 2682 | 5468163 | continue; | 2660 | 2740361 | continue; | ||
| 2683 | } | 2661 | } | |||||
| 2684 | } | 2662 | } | |||||
| HITCBC | 2685 | 2030144 | BOOST_ASSERT(num.exp >= 0); | 2663 | 1019916 | BOOST_ASSERT(num.exp >= 0); | ||
| HITCBC | 2686 | 2030144 | if ( num.frac ) | 2664 | 1019916 | if ( num.frac ) | ||
| 2687 | { | 2665 | { | |||||
| HITCBC | 2688 | 1001800 | if(BOOST_JSON_UNLIKELY( num.bias < (INT_MIN + num.exp) )) | 2666 | 501953 | if(BOOST_JSON_UNLIKELY( num.bias < (INT_MIN + num.exp) )) | ||
| 2689 | { | 2667 | { | |||||
| 2690 | // if exponent overflowed, bias is a very large negative | 2668 | // if exponent overflowed, bias is a very large negative | |||||
| 2691 | // number, and mantissa isn't zero, then we cannot parse the | 2669 | // number, and mantissa isn't zero, then we cannot parse the | |||||
| 2692 | // number correctly | 2670 | // number correctly | |||||
| HITCBC | 2693 | 92 | if(BOOST_JSON_UNLIKELY( | 2671 | 92 | if(BOOST_JSON_UNLIKELY( | ||
| 2694 | (num.exp == INT_MAX) && | 2672 | (num.exp == INT_MAX) && | |||||
| 2695 | (num.bias < 0) && | 2673 | (num.bias < 0) && | |||||
| 2696 | (num.exp + num.bias < 308) && | 2674 | (num.exp + num.bias < 308) && | |||||
| 2697 | num.mant )) | 2675 | num.mant )) | |||||
| 2698 | { | 2676 | { | |||||
| 2699 | BOOST_STATIC_CONSTEXPR source_location loc | 2677 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 2700 | = BOOST_CURRENT_LOCATION; | 2678 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 2701 | 1 | return fail(cs.begin(), error::exponent_overflow, &loc); | 2679 | 1 | return fail(cs.begin(), error::exponent_overflow, &loc); | ||
| 2702 | } | 2680 | } | |||||
| 2703 | 2681 | |||||||
| HITCBC | 2704 | 91 | num.bias = 0; | 2682 | 91 | num.bias = 0; | ||
| HITCBC | 2705 | 91 | num.exp = INT_MAX; | 2683 | 91 | num.exp = INT_MAX; | ||
| 2706 | } | 2684 | } | |||||
| 2707 | } | 2685 | } | |||||
| HITCBC | 2708 | 1028344 | else if (BOOST_JSON_UNLIKELY( num.bias > (INT_MAX - num.exp) )) | 2686 | 517963 | else if (BOOST_JSON_UNLIKELY( num.bias > (INT_MAX - num.exp) )) | ||
| 2709 | { | 2687 | { | |||||
| 2710 | // if exponent overflowed, bias is a very large positive number, | 2688 | // if exponent overflowed, bias is a very large positive number, | |||||
| 2711 | // and mantissa isn't zero, then we cannot parse the | 2689 | // and mantissa isn't zero, then we cannot parse the | |||||
| 2712 | // number correctly | 2690 | // number correctly | |||||
| HITCBC | 2713 | 194 | if(BOOST_JSON_UNLIKELY( | 2691 | 194 | if(BOOST_JSON_UNLIKELY( | ||
| 2714 | (num.exp == INT_MAX) && | 2692 | (num.exp == INT_MAX) && | |||||
| 2715 | (num.bias > 0) && | 2693 | (num.bias > 0) && | |||||
| 2716 | (num.exp - num.bias < 308) && | 2694 | (num.exp - num.bias < 308) && | |||||
| 2717 | num.mant )) | 2695 | num.mant )) | |||||
| 2718 | { | 2696 | { | |||||
| 2719 | BOOST_STATIC_CONSTEXPR source_location loc | 2697 | BOOST_STATIC_CONSTEXPR source_location loc | |||||
| 2720 | = BOOST_CURRENT_LOCATION; | 2698 | = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 2721 | 1 | return fail(cs.begin(), error::exponent_overflow, &loc); | 2699 | 1 | return fail(cs.begin(), error::exponent_overflow, &loc); | ||
| 2722 | } | 2700 | } | |||||
| 2723 | 2701 | |||||||
| HITCBC | 2724 | 193 | num.bias = 0; | 2702 | 193 | num.bias = 0; | ||
| HITCBC | 2725 | 193 | num.exp = INT_MAX; | 2703 | 193 | num.exp = INT_MAX; | ||
| 2726 | } | 2704 | } | |||||
| HITCBC | 2727 | 2030142 | goto finish_dub; | 2705 | 1019914 | goto finish_dub; | ||
| 2728 | } | 2706 | } | |||||
| 2729 | 2707 | |||||||
| HITCBC | 2730 | 30471 | finish_int: | 2708 | 30471 | finish_int: | ||
| HITCBC | 2731 | 28542 | if(negative || (!stack_empty && num.neg)) | 2709 | 28542 | if(negative || (!stack_empty && num.neg)) | ||
| 2732 | { | 2710 | { | |||||
| HITCBC | 2733 | 2531 | if(BOOST_JSON_UNLIKELY( | 2711 | 2531 | if(BOOST_JSON_UNLIKELY( | ||
| 2734 | ! h_.on_int64(static_cast< | 2712 | ! h_.on_int64(static_cast< | |||||
| 2735 | int64_t>(~num.mant + 1), {begin, cs.used(begin)}, ec_))) | 2713 | int64_t>(~num.mant + 1), {begin, cs.used(begin)}, ec_))) | |||||
| HITCBC | 2736 | 310 | return fail(cs.begin()); | 2714 | 310 | return fail(cs.begin()); | ||
| HITCBC | 2737 | 1913 | return cs.begin(); | 2715 | 1913 | return cs.begin(); | ||
| 2738 | } | 2716 | } | |||||
| HITCBC | 2739 | 27940 | if(num.mant <= INT64_MAX) | 2717 | 27940 | if(num.mant <= INT64_MAX) | ||
| 2740 | { | 2718 | { | |||||
| HITCBC | 2741 | 27639 | finish_signed: | 2719 | 27639 | finish_signed: | ||
| HITCBC | 2742 | 30914 | if(BOOST_JSON_UNLIKELY( | 2720 | 30914 | if(BOOST_JSON_UNLIKELY( | ||
| 2743 | ! h_.on_int64(static_cast< | 2721 | ! h_.on_int64(static_cast< | |||||
| 2744 | int64_t>(num.mant), {begin, cs.used(begin)}, ec_))) | 2722 | int64_t>(num.mant), {begin, cs.used(begin)}, ec_))) | |||||
| HITCBC | 2745 | 2267 | return fail(cs.begin()); | 2723 | 2267 | return fail(cs.begin()); | ||
| HITCBC | 2746 | 26387 | return cs.begin(); | 2724 | 26387 | return cs.begin(); | ||
| 2747 | } | 2725 | } | |||||
| HITCBC | 2748 | 321 | if(BOOST_JSON_UNLIKELY( | 2726 | 321 | if(BOOST_JSON_UNLIKELY( | ||
| 2749 | ! h_.on_uint64(num.mant, {begin, cs.used(begin)}, ec_))) | 2727 | ! h_.on_uint64(num.mant, {begin, cs.used(begin)}, ec_))) | |||||
| HITCBC | 2750 | 35 | return fail(cs.begin()); | 2728 | 35 | return fail(cs.begin()); | ||
| HITCBC | 2751 | 254 | return cs.begin(); | 2729 | 254 | return cs.begin(); | ||
| HITCBC | 2752 | 2052467 | finish_dub: | 2730 | 1033899 | finish_dub: | ||
| 2753 | double d; | 2731 | double d; | |||||
| HITCBC | 2754 | 2052467 | std::size_t const size = cs.used(begin); | 2732 | 1033899 | std::size_t const size = cs.used(begin); | ||
| HITCBC | 2755 | - | 2052467 | BOOST_ASSERT( !num_buf_.size() || precise_parsing ); | 2733 | + | 1033899 | d = detail::dec_to_float( |
| 2756 | - | BOOST_IF_CONSTEXPR( precise_parsing ) | 2734 | + | num.mant, | |||
| HITGNC | 2735 | + | 531947 | num.bias + (num.frac ? | ||||
| HITGNC | 2736 | + | 501952 | -num.exp : num.exp), | ||||
| HITGNC | 2737 | + | 1033899 | num.neg); | ||||
| HITGNC | 2738 | + | 1033899 | if(BOOST_JSON_UNLIKELY( | ||||
| 2739 | + | ! h_.on_double(d, {begin, size}, ec_))) | ||||||
| HITGNC | 2740 | + | 1935 | return fail(cs.begin()); | ||||
| HITGNC | 2741 | + | 1030029 | return cs.begin(); | ||||
| 2742 | + | } | ||||||
| 2743 | + | |||||||
| 2744 | + | template<class Handler> | ||||||
| 2745 | + | template<bool StackEmpty_, char First_> | ||||||
| 2746 | + | char const* | ||||||
| HITGNC | 2747 | + | 1040553 | basic_parser<Handler>:: | ||||
| 2748 | + | parse_number_precise( | ||||||
| 2749 | + | char const* p, | ||||||
| 2750 | + | std::integral_constant<bool, StackEmpty_> stack_empty, | ||||||
| 2751 | + | std::integral_constant<char, First_> first) | ||||||
| 2752 | + | { | ||||||
| 2753 | + | // only one of these will be true if we are not resuming | ||||||
| 2754 | + | // if negative then !zero_first && !nonzero_first | ||||||
| 2755 | + | // if zero_first then !nonzero_first && !negative | ||||||
| 2756 | + | // if nonzero_first then !zero_first && !negative | ||||||
| HITGNC | 2757 | + | 1040553 | bool const negative = first == '-'; | ||||
| HITGNC | 2758 | + | 1040553 | bool const zero_first = first == '0'; | ||||
| HITGNC | 2759 | + | 1040553 | bool const nonzero_first = first == '+'; | ||||
| HITGNC | 2760 | + | 1040553 | detail::const_stream_wrapper cs(p, end_); | ||||
| 2761 | + | number num; | ||||||
| HITGNC | 2762 | + | 1040553 | const char* begin = cs.begin(); | ||||
| HITGNC | 2763 | + | 1040553 | if(stack_empty || st_.empty()) | ||||
| 2757 | { | 2764 | { | |||||
| HITCBC | 2758 | - | 1000052 | char const* data = begin; | 2765 | + | 1028466 | num_buf_.clear(); |
| HITCBC | 2759 | - | 1000052 | std::size_t full_size = size; | 2766 | + | 1028466 | num.neg = negative; |
| 2760 | - | // if we previously suspended or if the current input ends with the | 2767 | + | ||||
| 2761 | - | // number, we need to copy the current part of the number to the | 2768 | + | // '-' | |||
| 2762 | - | // temporary buffer | 2769 | + | // leading minus sign | |||
| HITCBC | 2763 | - | 1000052 | if(BOOST_JSON_UNLIKELY( num_buf_.size() )) | 2770 | + | 1028466 | BOOST_ASSERT(cs); |
| 2771 | + | if(negative) | ||||||
| HITGNC | 2772 | + | 11802 | ++cs; | ||||
| 2773 | + | |||||||
| 2774 | + | // fast path | ||||||
| HITGNC | 2775 | + | 1028466 | if( cs.remain() >= 16 + 1 + 16 ) // digits . digits | ||||
| 2764 | { | 2776 | { | |||||
| ECB | 2765 | - | 1 | data = num_buf_.append( begin, size ); | 2777 | + | int n1; | |
| ECB | 2766 | - | 1 | full_size = num_buf_.size(); | 2778 | + | ||
| HITGNC | 2779 | + | 2433 | if( nonzero_first || (negative && *cs != '0') ) | ||||
| 2780 | + | { | ||||||
| HITGNC | 2781 | + | 1000950 | n1 = detail::count_digits( cs.begin() ); | ||||
| HITGNC | 2782 | + | 1000950 | BOOST_ASSERT(n1 >= 0 && n1 <= 16); | ||||
| 2783 | + | |||||||
| HITGNC | 2784 | + | 396 | if( negative && n1 == 0 && opt_.allow_infinity_and_nan ) | ||||
| 2785 | + | { | ||||||
| HITGNC | 2786 | + | 7 | return parse_literal( | ||||
| 2787 | + | p - 1, | ||||||
| HITGNC | 2788 | + | 6 | detail::literals_c<detail::literals::neg_infinity>()); | ||||
| 2789 | + | } | ||||||
| 2790 | + | |||||||
| HITGNC | 2791 | + | 389 | if( ! nonzero_first && n1 == 0 ) | ||||
| 2792 | + | { | ||||||
| 2793 | + | // digit required | ||||||
| 2794 | + | BOOST_STATIC_CONSTEXPR source_location loc | ||||||
| 2795 | + | = BOOST_CURRENT_LOCATION; | ||||||
| HITGNC | 2796 | + | 2 | return fail(cs.begin(), error::syntax, &loc); | ||||
| 2797 | + | } | ||||||
| 2798 | + | |||||||
| HITGNC | 2799 | + | 1000941 | num.mant = detail::parse_unsigned( 0, cs.begin(), n1 ); | ||||
| 2800 | + | |||||||
| HITGNC | 2801 | + | 1000941 | cs += n1; | ||||
| 2802 | + | |||||||
| 2803 | + | // integer or floating-point with | ||||||
| 2804 | + | // >= 16 leading digits | ||||||
| HITGNC | 2805 | + | 1000941 | if( n1 == 16 ) | ||||
| 2806 | + | { | ||||||
| HITGNC | 2807 | + | 1000222 | goto do_num2; | ||||
| 2808 | + | } | ||||||
| 2809 | + | } | ||||||
| 2810 | + | else | ||||||
| 2811 | + | { | ||||||
| 2812 | + | // 0. floating-point or 0e integer | ||||||
| HITGNC | 2813 | + | 5295 | num.mant = 0; | ||||
| HITGNC | 2814 | + | 5295 | n1 = 0; | ||||
| HITGNC | 2815 | + | 5295 | ++cs; | ||||
| 2816 | + | } | ||||||
| 2817 | + | |||||||
| 2818 | + | { | ||||||
| HITGNC | 2819 | + | 6014 | char const c = *cs; | ||||
| HITGNC | 2820 | + | 6014 | if(c != '.') | ||||
| 2821 | + | { | ||||||
| HITGNC | 2822 | + | 1693 | if( (c | 32) == 'e' ) | ||||
| 2823 | + | { | ||||||
| HITGNC | 2824 | + | 1644 | ++cs; | ||||
| HITGNC | 2825 | + | 1644 | goto do_exp1; | ||||
| 2826 | + | } | ||||||
| 2827 | + | BOOST_IF_CONSTEXPR( negative ) | ||||||
| HITGNC | 2828 | + | 4 | num.mant = ~num.mant + 1; | ||||
| HITGNC | 2829 | + | 49 | goto finish_signed; | ||||
| 2830 | + | } | ||||||
| 2831 | + | } | ||||||
| 2832 | + | |||||||
| 2833 | + | // floating-point number | ||||||
| 2834 | + | |||||||
| HITGNC | 2835 | + | 4321 | ++cs; | ||||
| 2836 | + | |||||||
| HITGNC | 2837 | + | 4321 | int n2 = detail::count_digits( cs.begin() ); | ||||
| HITGNC | 2838 | + | 4321 | BOOST_ASSERT(n2 >= 0 && n2 <= 16); | ||||
| 2839 | + | |||||||
| HITGNC | 2840 | + | 4321 | if( n2 == 0 ) | ||||
| 2841 | + | { | ||||||
| 2842 | + | // digit required | ||||||
| 2843 | + | BOOST_STATIC_CONSTEXPR source_location loc | ||||||
| 2844 | + | = BOOST_CURRENT_LOCATION; | ||||||
| HITGNC | 2845 | + | 3 | return fail(cs.begin(), error::syntax, &loc); | ||||
| 2846 | + | } | ||||||
| 2847 | + | |||||||
| 2848 | + | // floating-point mantissa overflow | ||||||
| HITGNC | 2849 | + | 4318 | if( n1 + n2 >= 19 ) | ||||
| 2850 | + | { | ||||||
| HITGNC | 2851 | + | 64 | goto do_num7; | ||||
| 2852 | + | } | ||||||
| 2853 | + | |||||||
| HITGNC | 2854 | + | 4254 | cs += n2; | ||||
| 2855 | + | |||||||
| HITGNC | 2856 | + | 4254 | char ch = *cs; | ||||
| 2857 | + | |||||||
| HITGNC | 2858 | + | 4254 | if( (ch | 32) == 'e' ) | ||||
| 2859 | + | { | ||||||
| HITGNC | 2860 | + | 23 | ++cs; | ||||
| HITGNC | 2861 | + | 23 | goto do_exp1; | ||||
| 2862 | + | } | ||||||
| HITGNC | 2863 | + | 4231 | else if( ch >= '0' && ch <= '9' ) | ||||
| 2864 | + | { | ||||||
| HITGNC | 2865 | + | 2501 | goto do_num8; | ||||
| 2866 | + | } | ||||||
| 2867 | + | |||||||
| HITGNC | 2868 | + | 1730 | goto finish_dub; | ||||
| 2767 | - | auto const err = detail::charconv::from_chars( | ||||||
| DCB | 2768 | - | 1000052 | data, data + full_size, d ); | ||||
| 2769 | - | BOOST_ASSERT( err.ec != std::errc::invalid_argument ); | ||||||
| DCB | 2770 | - | 1000052 | BOOST_ASSERT( err.ptr == data + full_size ); | ||||
| DCB | 2771 | - | 1000052 | (void)err; | ||||
| 2772 | } | 2869 | } | |||||
| 2773 | - | else BOOST_IF_CONSTEXPR( no_parsing ) | ||||||
| 2774 | - | d = 0; | ||||||
| ECB | 2775 | 9258 | } | 2870 | } | |||
| 2776 | else | 2871 | else | |||||
| ECB | 2777 | - | 1043157 | d = detail::dec_to_float( | 2872 | + | { | |
| HITGIC | 2778 | - | num.mant, | 2873 | + | 12087 | num = num_; | |
| ECB | 2779 | - | 541045 | num.bias + (num.frac ? | 2874 | + | state st; | |
| HITCBC | 2780 | - | 502112 | -num.exp : num.exp), | 2875 | + | 12087 | st_.pop(st); |
| HITCBC | 2781 | - | 1043157 | num.neg); | 2876 | + | 12087 | switch(st) |
| 2877 | + | { | ||||||
| 2878 | + | default: BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE | ||||||
| HITGNC | 2879 | + | 361 | case state::num1: goto do_num1; | ||||
| HITGNC | 2880 | + | 2428 | case state::num2: goto do_num2; | ||||
| HITGNC | 2881 | + | 394 | case state::num3: goto do_num3; | ||||
| HITGNC | 2882 | + | 335 | case state::num6: goto do_num6; | ||||
| HITGNC | 2883 | + | 338 | case state::num7: goto do_num7; | ||||
| HITGNC | 2884 | + | 4342 | case state::num8: goto do_num8; | ||||
| HITGNC | 2885 | + | 324 | case state::exp1: goto do_exp1; | ||||
| HITGNC | 2886 | + | 116 | case state::exp2: goto do_exp2; | ||||
| HITGNC | 2887 | + | 3449 | case state::exp3: goto do_exp3; | ||||
| 2888 | + | } | ||||||
| 2889 | + | } | ||||||
| 2890 | + | |||||||
| 2891 | + | // DIGIT | ||||||
| 2892 | + | // first digit | ||||||
| HITGNC | 2893 | + | 22582 | do_num1: | ||||
| HITGNC | 2894 | + | 9730 | if( zero_first || nonzero_first || BOOST_JSON_LIKELY(cs) ) | ||||
| 2895 | + | { | ||||||
| HITGNC | 2896 | + | 22101 | char const c = *cs; | ||||
| 2897 | + | if(zero_first) | ||||||
| 2898 | + | { | ||||||
| HITGNC | 2899 | + | 5531 | ++cs; | ||||
| HITGNC | 2900 | + | 5531 | num.mant = 0; | ||||
| HITGNC | 2901 | + | 5531 | goto do_num6; | ||||
| 2902 | + | } | ||||||
| HITGNC | 2903 | + | 9249 | else if( nonzero_first || BOOST_JSON_LIKELY(c >= '1' && c <= '9') ) | ||||
| 2904 | + | { | ||||||
| HITGNC | 2905 | + | 11213 | ++cs; | ||||
| HITGNC | 2906 | + | 11213 | num.mant = c - '0'; | ||||
| 2907 | + | } | ||||||
| HITGNC | 2908 | + | 5357 | else if(BOOST_JSON_UNLIKELY( c == '0' )) | ||||
| 2909 | + | { | ||||||
| HITGNC | 2910 | + | 4310 | ++cs; | ||||
| HITGNC | 2911 | + | 4310 | num.mant = 0; | ||||
| HITGNC | 2912 | + | 4310 | goto do_num6; | ||||
| 2913 | + | } | ||||||
| HITGNC | 2914 | + | 1047 | else if( (negative || num.neg) && opt_.allow_infinity_and_nan ) | ||||
| 2915 | + | { | ||||||
| HITGNC | 2916 | + | 915 | st_.push(state::lit1); | ||||
| HITGNC | 2917 | + | 915 | cur_lit_ = literal_index(detail::literals::neg_infinity); | ||||
| HITGNC | 2918 | + | 915 | lit_offset_ = 1; | ||||
| HITGNC | 2919 | + | 915 | return parse_literal( | ||||
| HITGNC | 2920 | + | 869 | cs.begin(), detail::literals_c<detail::literals::resume>() ); | ||||
| 2921 | + | } | ||||||
| 2922 | + | else | ||||||
| 2923 | + | { | ||||||
| 2924 | + | BOOST_STATIC_CONSTEXPR source_location loc | ||||||
| 2925 | + | = BOOST_CURRENT_LOCATION; | ||||||
| HITGNC | 2926 | + | 132 | return fail(cs.begin(), error::syntax, &loc); | ||||
| 2927 | + | } | ||||||
| 2928 | + | } | ||||||
| 2929 | + | else | ||||||
| 2930 | + | { | ||||||
| HITGNC | 2931 | + | 481 | if(BOOST_JSON_UNLIKELY( | ||||
| 2932 | + | !h_.on_number_part({begin, cs.used(begin)}, ec_) )) | ||||||
| HITGNC | 2933 | + | 60 | return fail(cs.begin()); | ||||
| 2934 | + | |||||||
| HITGNC | 2935 | + | 361 | num_buf_.append( begin, cs.used(begin) ); | ||||
| HITGNC | 2936 | + | 361 | return maybe_suspend(cs.begin(), state::num1, num); | ||||
| 2937 | + | } | ||||||
| 2938 | + | |||||||
| 2939 | + | // 1*DIGIT | ||||||
| 2940 | + | // significant digits left of decimal | ||||||
| HITGNC | 2941 | + | 1013863 | do_num2: | ||||
| HITGNC | 2942 | + | 1010103 | if( negative || (!stack_empty && num.neg) ) | ||||
| 2943 | + | { | ||||||
| HITGNC | 2944 | + | 10681 | for(;;) | ||||
| 2945 | + | { | ||||||
| HITGNC | 2946 | + | 15060 | if(BOOST_JSON_UNLIKELY( !cs )) | ||||
| 2947 | + | { | ||||||
| HITGNC | 2948 | + | 722 | if(BOOST_JSON_UNLIKELY( more_ )) | ||||
| 2949 | + | { | ||||||
| HITGNC | 2950 | + | 625 | if(BOOST_JSON_UNLIKELY( | ||||
| 2951 | + | !h_.on_number_part({begin, cs.used(begin)}, ec_) )) | ||||||
| HITGNC | 2952 | + | 69 | return fail(cs.begin()); | ||||
| 2953 | + | |||||||
| HITGNC | 2954 | + | 487 | num_buf_.append( begin, cs.used(begin) ); | ||||
| HITGNC | 2955 | + | 487 | return suspend(cs.begin(), state::num2, num); | ||||
| 2956 | + | } | ||||||
| HITGNC | 2957 | + | 97 | goto finish_int; | ||||
| 2958 | + | } | ||||||
| HITGNC | 2959 | + | 14338 | char const c = *cs; | ||||
| HITGNC | 2960 | + | 14338 | if(BOOST_JSON_LIKELY( c >= '0' && c <= '9' )) | ||||
| 2961 | + | { | ||||||
| HITGNC | 2962 | + | 10925 | ++cs; | ||||
| 2963 | + | // 9223372036854775808 INT64_MIN | ||||||
| HITGNC | 2964 | + | 10925 | if( num.mant > 922337203685477580 || ( | ||||
| HITGNC | 2965 | + | 10681 | num.mant == 922337203685477580 && c > '8')) | ||||
| 2966 | + | break; | ||||||
| HITGNC | 2967 | + | 10681 | num.mant = 10 * num.mant + ( c - '0' ); | ||||
| HITGNC | 2968 | + | 10681 | continue; | ||||
| 2969 | + | } | ||||||
| HITGNC | 2970 | + | 3413 | goto do_num6; // [.eE] | ||||
| 2971 | + | } | ||||||
| 2972 | + | } | ||||||
| 2973 | + | else | ||||||
| 2974 | + | { | ||||||
| HITGNC | 2975 | + | 3458262 | for(;;) | ||||
| 2976 | + | { | ||||||
| HITGNC | 2977 | + | 4467746 | if(BOOST_JSON_UNLIKELY( !cs )) | ||||
| 2978 | + | { | ||||||
| HITGNC | 2979 | + | 2604 | if(BOOST_JSON_UNLIKELY( more_ )) | ||||
| 2980 | + | { | ||||||
| HITGNC | 2981 | + | 2513 | if(BOOST_JSON_UNLIKELY( | ||||
| 2982 | + | !h_.on_number_part({begin, cs.used(begin)}, ec_) )) | ||||||
| HITGNC | 2983 | + | 286 | return fail(cs.begin()); | ||||
| 2984 | + | |||||||
| HITGNC | 2985 | + | 1941 | num_buf_.append( begin, cs.used(begin) ); | ||||
| HITGNC | 2986 | + | 1941 | return suspend(cs.begin(), state::num2, num); | ||||
| 2987 | + | } | ||||||
| HITGNC | 2988 | + | 91 | goto finish_int; | ||||
| 2989 | + | } | ||||||
| HITGNC | 2990 | + | 4465142 | char const c = *cs; | ||||
| HITGNC | 2991 | + | 4465142 | if(BOOST_JSON_LIKELY( c >= '0' && c <= '9' )) | ||||
| 2992 | + | { | ||||||
| HITGNC | 2993 | + | 3460729 | ++cs; | ||||
| 2994 | + | // 18446744073709551615 UINT64_MAX | ||||||
| HITGNC | 2995 | + | 3460729 | if( num.mant > 1844674407370955161 || ( | ||||
| HITGNC | 2996 | + | 3458419 | num.mant == 1844674407370955161 && c > '5')) | ||||
| 2997 | + | break; | ||||||
| HITGNC | 2998 | + | 3458262 | num.mant = 10 * num.mant + ( c - '0' ); | ||||
| 2999 | + | } | ||||||
| 3000 | + | else | ||||||
| 3001 | + | { | ||||||
| HITGNC | 3002 | + | 1004413 | goto do_num6; // [.eE] | ||||
| 3003 | + | } | ||||||
| 3004 | + | } | ||||||
| 3005 | + | } | ||||||
| 3006 | + | |||||||
| 3007 | + | // 1*DIGIT | ||||||
| 3008 | + | // non-significant digits left of decimal | ||||||
| HITGNC | 3009 | + | 3105 | do_num3: | ||||
| HITGNC | 3010 | + | 7852 | for(;;) | ||||
| 3011 | + | { | ||||||
| HITGNC | 3012 | + | 10957 | if(BOOST_JSON_UNLIKELY( !cs )) | ||||
| 3013 | + | { | ||||||
| HITGNC | 3014 | + | 735 | if(BOOST_JSON_UNLIKELY( more_ )) | ||||
| 3015 | + | { | ||||||
| HITGNC | 3016 | + | 488 | if(BOOST_JSON_UNLIKELY( | ||||
| 3017 | + | !h_.on_number_part({begin, cs.used(begin)}, ec_) )) | ||||||
| HITGNC | 3018 | + | 47 | return fail(cs.begin()); | ||||
| 3019 | + | |||||||
| HITGNC | 3020 | + | 394 | num_buf_.append( begin, cs.used(begin) ); | ||||
| HITGNC | 3021 | + | 394 | return suspend(cs.begin(), state::num3, num); | ||||
| 3022 | + | } | ||||||
| HITGNC | 3023 | + | 247 | goto finish_dub; | ||||
| 3024 | + | } | ||||||
| HITGNC | 3025 | + | 10222 | char const c = *cs; | ||||
| HITGNC | 3026 | + | 10222 | if(BOOST_JSON_UNLIKELY( c >= '0' && c <= '9' )) | ||||
| 3027 | + | { | ||||||
| HITGNC | 3028 | + | 7852 | ++cs; | ||||
| 3029 | + | } | ||||||
| 3030 | + | else | ||||||
| 3031 | + | { | ||||||
| HITGNC | 3032 | + | 2370 | goto do_num6; // [.eE] | ||||
| 3033 | + | } | ||||||
| 3034 | + | } | ||||||
| 3035 | + | |||||||
| 3036 | + | // [.eE] | ||||||
| HITGNC | 3037 | + | 1020372 | do_num6: | ||||
| 3038 | + | { | ||||||
| HITGNC | 3039 | + | 1020372 | if(BOOST_JSON_UNLIKELY( !cs )) | ||||
| 3040 | + | { | ||||||
| HITGNC | 3041 | + | 420 | if(BOOST_JSON_UNLIKELY( more_ )) | ||||
| 3042 | + | { | ||||||
| HITGNC | 3043 | + | 419 | if(BOOST_JSON_UNLIKELY( | ||||
| 3044 | + | !h_.on_number_part({begin, cs.used(begin)}, ec_) )) | ||||||
| HITGNC | 3045 | + | 42 | return fail(cs.begin()); | ||||
| 3046 | + | |||||||
| HITGNC | 3047 | + | 335 | num_buf_.append( begin, cs.used(begin) ); | ||||
| HITGNC | 3048 | + | 335 | return suspend(cs.begin(), state::num6, num); | ||||
| 3049 | + | } | ||||||
| HITGNC | 3050 | + | 1 | goto finish_int; | ||||
| 3051 | + | } | ||||||
| HITGNC | 3052 | + | 1019952 | char const c = *cs; | ||||
| HITGNC | 3053 | + | 1019952 | if(BOOST_JSON_LIKELY( c == '.' )) | ||||
| 3054 | + | { | ||||||
| HITGNC | 3055 | + | 1009590 | ++cs; | ||||
| 3056 | + | } | ||||||
| HITGNC | 3057 | + | 10362 | else if( (c | 32) == 'e' ) | ||||
| 3058 | + | { | ||||||
| HITGNC | 3059 | + | 6105 | ++cs; | ||||
| HITGNC | 3060 | + | 6105 | goto do_exp1; | ||||
| 3061 | + | } | ||||||
| 3062 | + | else | ||||||
| 3063 | + | { | ||||||
| HITGNC | 3064 | + | 4257 | goto finish_int; | ||||
| 3065 | + | } | ||||||
| 3066 | + | } | ||||||
| 3067 | + | |||||||
| 3068 | + | // DIGIT | ||||||
| 3069 | + | // first significant digit to the right of decimal | ||||||
| HITGNC | 3070 | + | 1009992 | do_num7: | ||||
| 3071 | + | { | ||||||
| HITGNC | 3072 | + | 1009992 | if(BOOST_JSON_UNLIKELY( !cs )) | ||||
| 3073 | + | { | ||||||
| HITGNC | 3074 | + | 423 | if(BOOST_JSON_UNLIKELY( more_ )) | ||||
| 3075 | + | { | ||||||
| HITGNC | 3076 | + | 420 | if(BOOST_JSON_UNLIKELY( | ||||
| 3077 | + | !h_.on_number_part({begin, cs.used(begin)}, ec_) )) | ||||||
| HITGNC | 3078 | + | 41 | return fail(cs.begin()); | ||||
| 3079 | + | |||||||
| HITGNC | 3080 | + | 338 | num_buf_.append( begin, cs.used(begin) ); | ||||
| HITGNC | 3081 | + | 338 | return suspend(cs.begin(), state::num7, num); | ||||
| 3082 | + | } | ||||||
| 3083 | + | // digit required | ||||||
| 3084 | + | BOOST_STATIC_CONSTEXPR source_location loc | ||||||
| 3085 | + | = BOOST_CURRENT_LOCATION; | ||||||
| HITGNC | 3086 | + | 3 | return fail(cs.begin(), error::syntax, &loc); | ||||
| 3087 | + | } | ||||||
| HITGNC | 3088 | + | 1009569 | char const c = *cs; | ||||
| HITGNC | 3089 | + | 1009569 | if(BOOST_JSON_UNLIKELY( c < '0' || c > '9' )) | ||||
| 3090 | + | { | ||||||
| 3091 | + | // digit required | ||||||
| 3092 | + | BOOST_STATIC_CONSTEXPR source_location loc | ||||||
| 3093 | + | = BOOST_CURRENT_LOCATION; | ||||||
| HITGNC | 3094 | + | 131 | return fail(cs.begin(), error::syntax, &loc); | ||||
| 3095 | + | } | ||||||
| 3096 | + | } | ||||||
| 3097 | + | |||||||
| 3098 | + | // 1*DIGIT | ||||||
| 3099 | + | // significant digits to the right of decimal | ||||||
| HITGNC | 3100 | + | 1016281 | do_num8: | ||||
| HITGNC | 3101 | + | 20507386 | for(;;) | ||||
| 3102 | + | { | ||||||
| HITGNC | 3103 | + | 21523667 | if(BOOST_JSON_UNLIKELY( !cs )) | ||||
| 3104 | + | { | ||||||
| HITGNC | 3105 | + | 5600 | if(BOOST_JSON_UNLIKELY( more_ )) | ||||
| 3106 | + | { | ||||||
| HITGNC | 3107 | + | 4517 | if(BOOST_JSON_UNLIKELY( | ||||
| 3108 | + | !h_.on_number_part({begin, cs.used(begin)}, ec_) )) | ||||||
| HITGNC | 3109 | + | 87 | return fail(cs.begin()); | ||||
| 3110 | + | |||||||
| HITGNC | 3111 | + | 4343 | num_buf_.append( begin, cs.used(begin) ); | ||||
| HITGNC | 3112 | + | 4342 | return suspend(cs.begin(), state::num8, num); | ||||
| 3113 | + | } | ||||||
| HITGNC | 3114 | + | 1083 | goto finish_dub; | ||||
| 3115 | + | } | ||||||
| HITGNC | 3116 | + | 21518067 | char const c = *cs; | ||||
| HITGNC | 3117 | + | 21518067 | if(BOOST_JSON_LIKELY( c >= '0' && c <= '9' )) | ||||
| 3118 | + | { | ||||||
| HITGNC | 3119 | + | 20507386 | ++cs; | ||||
| 3120 | + | } | ||||||
| HITGNC | 3121 | + | 1010681 | else if( (c | 32) == 'e' ) | ||||
| 3122 | + | { | ||||||
| HITGNC | 3123 | + | 1006180 | ++cs; | ||||
| HITGNC | 3124 | + | 1006180 | goto do_exp1; | ||||
| 3125 | + | } | ||||||
| 3126 | + | else | ||||||
| 3127 | + | { | ||||||
| HITGNC | 3128 | + | 4501 | goto finish_dub; | ||||
| 3129 | + | } | ||||||
| 3130 | + | } | ||||||
| 3131 | + | |||||||
| 3132 | + | // *[+-] | ||||||
| HITGNC | 3133 | + | 1014276 | do_exp1: | ||||
| HITGNC | 3134 | + | 1014276 | if(BOOST_JSON_UNLIKELY( !cs )) | ||||
| 3135 | + | { | ||||||
| HITGNC | 3136 | + | 422 | if(BOOST_JSON_UNLIKELY( | ||||
| 3137 | + | !h_.on_number_part({begin, cs.used(begin)}, ec_) )) | ||||||
| HITGNC | 3138 | + | 49 | return fail(cs.begin()); | ||||
| 3139 | + | |||||||
| HITGNC | 3140 | + | 324 | num_buf_.append( begin, cs.used(begin) ); | ||||
| HITGNC | 3141 | + | 324 | return maybe_suspend(cs.begin(), state::exp1, num); | ||||
| 3142 | + | } | ||||||
| HITGNC | 3143 | + | 1013854 | if( (*cs == '+') || (*cs == '-') ) | ||||
| 3144 | + | { | ||||||
| HITGNC | 3145 | + | 503310 | ++cs; | ||||
| 3146 | + | } | ||||||
| 3147 | + | |||||||
| 3148 | + | // DIGIT | ||||||
| 3149 | + | // first digit of the exponent | ||||||
| HITGNC | 3150 | + | 510544 | do_exp2: | ||||
| 3151 | + | { | ||||||
| HITGNC | 3152 | + | 1013970 | if(BOOST_JSON_UNLIKELY( !cs )) | ||||
| 3153 | + | { | ||||||
| HITGNC | 3154 | + | 165 | if(BOOST_JSON_UNLIKELY( more_ )) | ||||
| 3155 | + | { | ||||||
| HITGNC | 3156 | + | 156 | if(BOOST_JSON_UNLIKELY( | ||||
| 3157 | + | !h_.on_number_part({begin, cs.used(begin)}, ec_) )) | ||||||
| HITGNC | 3158 | + | 20 | return fail(cs.begin()); | ||||
| 3159 | + | |||||||
| HITGNC | 3160 | + | 116 | num_buf_.append( begin, cs.used(begin) ); | ||||
| HITGNC | 3161 | + | 116 | return suspend(cs.begin(), state::exp2, num); | ||||
| 3162 | + | } | ||||||
| 3163 | + | // digit required | ||||||
| 3164 | + | BOOST_STATIC_CONSTEXPR source_location loc | ||||||
| 3165 | + | = BOOST_CURRENT_LOCATION; | ||||||
| HITGNC | 3166 | + | 9 | return fail(cs.begin(), error::syntax, &loc); | ||||
| 3167 | + | } | ||||||
| HITGNC | 3168 | + | 1013805 | char const c = *cs; | ||||
| HITGNC | 3169 | + | 1013805 | if(BOOST_JSON_UNLIKELY( c < '0' || c > '9' )) | ||||
| 3170 | + | { | ||||||
| 3171 | + | // digit required | ||||||
| 3172 | + | BOOST_STATIC_CONSTEXPR source_location loc | ||||||
| 3173 | + | = BOOST_CURRENT_LOCATION; | ||||||
| HITGNC | 3174 | + | 268 | return fail(cs.begin(), error::syntax, &loc); | ||||
| 3175 | + | } | ||||||
| HITGNC | 3176 | + | 1013537 | ++cs; | ||||
| 3177 | + | } | ||||||
| 3178 | + | |||||||
| 3179 | + | // 1*DIGIT | ||||||
| 3180 | + | // subsequent digits in the exponent | ||||||
| HITGNC | 3181 | + | 1016986 | do_exp3: | ||||
| HITGNC | 3182 | + | 2193285 | for(;;) | ||||
| 3183 | + | { | ||||||
| HITGNC | 3184 | + | 3210271 | if(BOOST_JSON_UNLIKELY( !cs )) | ||||
| 3185 | + | { | ||||||
| HITGNC | 3186 | + | 1005978 | if(BOOST_JSON_UNLIKELY( more_ )) | ||||
| 3187 | + | { | ||||||
| HITGNC | 3188 | + | 3621 | if(BOOST_JSON_UNLIKELY( | ||||
| 3189 | + | !h_.on_number_part({begin, cs.used(begin)}, ec_) )) | ||||||
| HITGNC | 3190 | + | 86 | return fail(cs.begin()); | ||||
| 3191 | + | |||||||
| HITGNC | 3192 | + | 3449 | num_buf_.append( begin, cs.used(begin) ); | ||||
| HITGNC | 3193 | + | 3449 | return suspend(cs.begin(), state::exp3, num); | ||||
| 3194 | + | } | ||||||
| 3195 | + | } | ||||||
| 3196 | + | else | ||||||
| 3197 | + | { | ||||||
| HITGNC | 3198 | + | 2204293 | char const c = *cs; | ||||
| HITGNC | 3199 | + | 2204293 | if(BOOST_JSON_LIKELY( c >= '0' && c <= '9' )) | ||||
| 3200 | + | { | ||||||
| HITGNC | 3201 | + | 2193285 | ++cs; | ||||
| HITGNC | 3202 | + | 2193285 | continue; | ||||
| 3203 | + | } | ||||||
| 3204 | + | } | ||||||
| HITGNC | 3205 | + | 1013365 | goto finish_dub; | ||||
| 3206 | + | } | ||||||
| 3207 | + | |||||||
| HITGNC | 3208 | + | 4446 | finish_int: | ||||
| HITGNC | 3209 | + | 2843 | if( negative || (!stack_empty && num.neg) ) | ||||
| 3210 | + | { | ||||||
| HITGNC | 3211 | + | 2047 | if(BOOST_JSON_UNLIKELY( | ||||
| 3212 | + | !h_.on_int64( | ||||||
| 3213 | + | static_cast<int64_t>(~num.mant + 1), | ||||||
| 3214 | + | {begin, cs.used(begin)}, | ||||||
| 3215 | + | ec_) )) | ||||||
| HITGNC | 3216 | + | 340 | return fail( cs.begin() ); | ||||
| HITGNC | 3217 | + | 1367 | return cs.begin(); | ||||
| 3218 | + | } | ||||||
| HITGNC | 3219 | + | 2399 | if(num.mant <= INT64_MAX) | ||||
| 3220 | + | { | ||||||
| HITGNC | 3221 | + | 2017 | finish_signed: | ||||
| HITGNC | 3222 | + | 2062 | if(BOOST_JSON_UNLIKELY( | ||||
| 3223 | + | !h_.on_int64( | ||||||
| 3224 | + | static_cast<int64_t>(num.mant), | ||||||
| 3225 | + | {begin, cs.used(begin)}, | ||||||
| 3226 | + | ec_) )) | ||||||
| HITGNC | 3227 | + | 341 | return fail( cs.begin() ); | ||||
| HITGNC | 3228 | + | 1380 | return cs.begin(); | ||||
| 3229 | + | } | ||||||
| HITCBC | 2782 | 2052467 | if(BOOST_JSON_UNLIKELY( | 3230 | 386 | if(BOOST_JSON_UNLIKELY( | ||
| 2783 | - | ! h_.on_double(d, {begin, size}, ec_))) | 3231 | + | !h_.on_uint64(num.mant, {begin, cs.used(begin)}, ec_) )) | |||
| HITCBC | 2784 | - | 1935 | return fail(cs.begin()); | 3232 | + | 64 | return fail( cs.begin() ); |
| HITGNC | 3233 | + | 258 | return cs.begin(); | ||||
| HITGNC | 3234 | + | 1020926 | finish_dub: | ||||
| 3235 | + | double d; | ||||||
| HITGNC | 3236 | + | 1020926 | std::size_t const size = cs.used(begin); | ||||
| HITGNC | 3237 | + | 1020926 | char const* data = begin; | ||||
| HITGNC | 3238 | + | 1020926 | std::size_t full_size = size; | ||||
| 3239 | + | // if we previously suspended or if the current input ends with the | ||||||
| 3240 | + | // number, we need to copy the current part of the number to the | ||||||
| 3241 | + | // temporary buffer | ||||||
| HITGNC | 3242 | + | 1020926 | if(BOOST_JSON_UNLIKELY( num_buf_.size() )) | ||||
| 3243 | + | { | ||||||
| HITGNC | 3244 | + | 8393 | data = num_buf_.append(begin, size); | ||||
| HITGNC | 3245 | + | 8393 | full_size = num_buf_.size(); | ||||
| 3246 | + | } | ||||||
| HITGNC | 3247 | + | 1020926 | auto const err = detail::charconv::from_chars(data, data + full_size, d); | ||||
| HITGNC | 3248 | + | 1020926 | BOOST_ASSERT( err.ec != std::errc::invalid_argument ); | ||||
| HITGNC | 3249 | + | 1020926 | BOOST_ASSERT( err.ptr == data + full_size ); | ||||
| 3250 | + | (void)err; | ||||||
| HITGNC | 3251 | + | 1020926 | if(BOOST_JSON_UNLIKELY( !h_.on_double(d, {begin, size}, ec_) )) | ||||
| HITGNC | 3252 | + | 1871 | return fail( cs.begin() ); | ||||
| HITGNC | 3253 | + | 1017184 | return cs.begin(); | ||||
| 3254 | + | } | ||||||
| 3255 | + | |||||||
| 3256 | + | template<class Handler> | ||||||
| 3257 | + | template<bool StackEmpty_, char First_> | ||||||
| 3258 | + | char const* | ||||||
| HITGNC | 3259 | + | 40497 | basic_parser<Handler>:: | ||||
| 3260 | + | skip_number( | ||||||
| 3261 | + | char const* p, | ||||||
| 3262 | + | std::integral_constant<bool, StackEmpty_> stack_empty, | ||||||
| 3263 | + | std::integral_constant<char, First_> first) | ||||||
| 3264 | + | { | ||||||
| 3265 | + | // only one of these will be true if we are not resuming | ||||||
| 3266 | + | // if negative then !zero_first && !nonzero_first | ||||||
| 3267 | + | // if zero_first then !nonzero_first && !negative | ||||||
| 3268 | + | // if nonzero_first then !zero_first && !negative | ||||||
| HITGNC | 3269 | + | 40497 | bool const negative = first == '-'; | ||||
| HITGNC | 3270 | + | 40497 | bool const zero_first = first == '0'; | ||||
| HITGNC | 3271 | + | 40497 | bool const nonzero_first = first == '+'; | ||||
| HITGNC | 3272 | + | 40497 | detail::const_stream_wrapper cs(p, end_); | ||||
| 3273 | + | number num; | ||||||
| HITGNC | 3274 | + | 40497 | const char* begin = cs.begin(); | ||||
| HITGNC | 3275 | + | 40497 | if(stack_empty || st_.empty()) | ||||
| 3276 | + | { | ||||||
| HITGNC | 3277 | + | 28413 | num.neg = negative; | ||||
| 3278 | + | |||||||
| 3279 | + | //---------------------------------- | ||||||
| 3280 | + | // | ||||||
| 3281 | + | // '-' | ||||||
| 3282 | + | // leading minus sign | ||||||
| 3283 | + | // | ||||||
| HITGNC | 3284 | + | 28413 | BOOST_ASSERT(cs); | ||||
| 3285 | + | if(negative) | ||||||
| HITGNC | 3286 | + | 11798 | ++cs; | ||||
| 3287 | + | |||||||
| 3288 | + | // fast path | ||||||
| HITGNC | 3289 | + | 28413 | if( cs.remain() >= 16 + 1 + 16 ) // digits . digits | ||||
| 3290 | + | { | ||||||
| 3291 | + | int n1; | ||||||
| 3292 | + | |||||||
| HITGNC | 3293 | + | 2433 | if( nonzero_first || (negative && *cs != '0') ) | ||||
| 3294 | + | { | ||||||
| HITGNC | 3295 | + | 950 | n1 = detail::count_digits( cs.begin() ); | ||||
| HITGNC | 3296 | + | 950 | BOOST_ASSERT(n1 >= 0 && n1 <= 16); | ||||
| 3297 | + | |||||||
| HITGNC | 3298 | + | 396 | if( negative && n1 == 0 && opt_.allow_infinity_and_nan ) | ||||
| 3299 | + | { | ||||||
| HITGNC | 3300 | + | 7 | return parse_literal( | ||||
| 3301 | + | p - 1, | ||||||
| HITGNC | 3302 | + | 6 | detail::literals_c<detail::literals::neg_infinity>()); | ||||
| 3303 | + | } | ||||||
| 3304 | + | |||||||
| HITGNC | 3305 | + | 389 | if( ! nonzero_first && n1 == 0 ) | ||||
| 3306 | + | { | ||||||
| 3307 | + | // digit required | ||||||
| 3308 | + | BOOST_STATIC_CONSTEXPR source_location loc | ||||||
| 3309 | + | = BOOST_CURRENT_LOCATION; | ||||||
| HITGNC | 3310 | + | 2 | return fail(cs.begin(), error::syntax, &loc); | ||||
| 3311 | + | } | ||||||
| 3312 | + | |||||||
| HITGNC | 3313 | + | 941 | cs += n1; | ||||
| 3314 | + | |||||||
| 3315 | + | // integer or floating-point with | ||||||
| 3316 | + | // >= 16 leading digits | ||||||
| HITGNC | 3317 | + | 941 | if( n1 == 16 ) | ||||
| 3318 | + | { | ||||||
| HITGNC | 3319 | + | 280 | goto do_num2; | ||||
| 3320 | + | } | ||||||
| 3321 | + | } | ||||||
| 3322 | + | else | ||||||
| 3323 | + | { | ||||||
| 3324 | + | // 0. floating-point or 0e integer | ||||||
| HITGNC | 3325 | + | 5295 | n1 = 0; | ||||
| HITGNC | 3326 | + | 5295 | ++cs; | ||||
| 3327 | + | } | ||||||
| 3328 | + | |||||||
| 3329 | + | { | ||||||
| HITGNC | 3330 | + | 5956 | char const c = *cs; | ||||
| HITGNC | 3331 | + | 5956 | if(c != '.') | ||||
| 3332 | + | { | ||||||
| HITGNC | 3333 | + | 1693 | if((c | 32) == 'e') | ||||
| 3334 | + | { | ||||||
| HITGNC | 3335 | + | 1644 | ++cs; | ||||
| HITGNC | 3336 | + | 1644 | goto do_exp1; | ||||
| 3337 | + | } | ||||||
| HITGNC | 3338 | + | 49 | goto finish_int; | ||||
| 3339 | + | } | ||||||
| 3340 | + | } | ||||||
| 3341 | + | |||||||
| 3342 | + | // floating-point number | ||||||
| 3343 | + | |||||||
| HITGNC | 3344 | + | 4263 | ++cs; | ||||
| 3345 | + | |||||||
| HITGNC | 3346 | + | 4263 | int n2 = detail::count_digits( cs.begin() ); | ||||
| HITGNC | 3347 | + | 4263 | BOOST_ASSERT(n2 >= 0 && n2 <= 16); | ||||
| 3348 | + | |||||||
| HITGNC | 3349 | + | 4263 | if( n2 == 0 ) | ||||
| 3350 | + | { | ||||||
| 3351 | + | // digit required | ||||||
| 3352 | + | BOOST_STATIC_CONSTEXPR source_location loc | ||||||
| 3353 | + | = BOOST_CURRENT_LOCATION; | ||||||
| HITGNC | 3354 | + | 3 | return fail(cs.begin(), error::syntax, &loc); | ||||
| 3355 | + | } | ||||||
| 3356 | + | |||||||
| 3357 | + | // floating-point mantissa overflow | ||||||
| HITGNC | 3358 | + | 4260 | if( n1 + n2 >= 19 ) | ||||
| 3359 | + | { | ||||||
| HITGNC | 3360 | + | 6 | goto do_num7; | ||||
| 3361 | + | } | ||||||
| 3362 | + | |||||||
| HITGNC | 3363 | + | 4254 | cs += n2; | ||||
| 3364 | + | |||||||
| HITGNC | 3365 | + | 4254 | char ch = *cs; | ||||
| 3366 | + | |||||||
| HITGNC | 3367 | + | 4254 | if( (ch | 32) == 'e' ) | ||||
| 3368 | + | { | ||||||
| HITGNC | 3369 | + | 23 | ++cs; | ||||
| HITGNC | 3370 | + | 23 | goto do_exp1; | ||||
| 3371 | + | } | ||||||
| HITGNC | 3372 | + | 4231 | else if( ch >= '0' && ch <= '9' ) | ||||
| 3373 | + | { | ||||||
| HITGNC | 3374 | + | 2501 | goto do_num8; | ||||
| 3375 | + | } | ||||||
| 3376 | + | |||||||
| HITGNC | 3377 | + | 1730 | goto finish_dub; | ||||
| 3378 | + | } | ||||||
| 3379 | + | } | ||||||
| 3380 | + | else | ||||||
| 3381 | + | { | ||||||
| HITGNC | 3382 | + | 12084 | num = num_; | ||||
| 3383 | + | state st; | ||||||
| HITGNC | 3384 | + | 12084 | st_.pop(st); | ||||
| HITGNC | 3385 | + | 12084 | switch(st) | ||||
| 3386 | + | { | ||||||
| 3387 | + | default: BOOST_JSON_UNREACHABLE(); // LCOV_EXCL_LINE | ||||||
| HITGNC | 3388 | + | 361 | case state::num1: goto do_num1; | ||||
| HITGNC | 3389 | + | 2822 | case state::num2: goto do_num2; | ||||
| HITGNC | 3390 | + | 333 | case state::num6: goto do_num6; | ||||
| HITGNC | 3391 | + | 338 | case state::num7: goto do_num7; | ||||
| HITGNC | 3392 | + | 4341 | case state::num8: goto do_num8; | ||||
| HITGNC | 3393 | + | 324 | case state::exp1: goto do_exp1; | ||||
| HITGNC | 3394 | + | 116 | case state::exp2: goto do_exp2; | ||||
| HITGNC | 3395 | + | 3449 | case state::exp3: goto do_exp3; | ||||
| 3396 | + | } | ||||||
| 3397 | + | } | ||||||
| 3398 | + | |||||||
| 3399 | + | // DIGIT first digit | ||||||
| HITGNC | 3400 | + | 22529 | do_num1: | ||||
| HITGNC | 3401 | + | 9726 | if( zero_first || nonzero_first || BOOST_JSON_LIKELY(cs) ) | ||||
| 3402 | + | { | ||||||
| HITGNC | 3403 | + | 22048 | char const c = *cs; | ||||
| 3404 | + | if(zero_first) | ||||||
| 3405 | + | { | ||||||
| HITGNC | 3406 | + | 5529 | ++cs; | ||||
| HITGNC | 3407 | + | 5529 | goto do_num6; | ||||
| 3408 | + | } | ||||||
| HITGNC | 3409 | + | 9245 | else if( nonzero_first || BOOST_JSON_LIKELY(c >= '1' && c <= '9') ) | ||||
| 3410 | + | { | ||||||
| HITGNC | 3411 | + | 11163 | ++cs; | ||||
| 3412 | + | } | ||||||
| HITGNC | 3413 | + | 5356 | else if(BOOST_JSON_UNLIKELY( c == '0' )) | ||||
| 3414 | + | { | ||||||
| HITGNC | 3415 | + | 4309 | ++cs; | ||||
| HITGNC | 3416 | + | 4309 | goto do_num6; | ||||
| 3417 | + | } | ||||||
| HITGNC | 3418 | + | 1047 | else if( (negative || num.neg) && opt_.allow_infinity_and_nan ) | ||||
| 3419 | + | { | ||||||
| HITGNC | 3420 | + | 915 | st_.push(state::lit1); | ||||
| HITGNC | 3421 | + | 915 | cur_lit_ = literal_index(detail::literals::neg_infinity); | ||||
| HITGNC | 3422 | + | 915 | lit_offset_ = 1; | ||||
| HITGNC | 3423 | + | 915 | return parse_literal( | ||||
| HITGNC | 3424 | + | 869 | cs.begin(), detail::literals_c<detail::literals::resume>() ); | ||||
| 3425 | + | } | ||||||
| 3426 | + | else | ||||||
| 3427 | + | { | ||||||
| 3428 | + | BOOST_STATIC_CONSTEXPR source_location loc | ||||||
| 3429 | + | = BOOST_CURRENT_LOCATION; | ||||||
| HITGNC | 3430 | + | 132 | return fail(cs.begin(), error::syntax, &loc); | ||||
| 3431 | + | } | ||||||
| 3432 | + | } | ||||||
| 3433 | + | else | ||||||
| 3434 | + | { | ||||||
| HITGNC | 3435 | + | 481 | if(BOOST_JSON_UNLIKELY( | ||||
| 3436 | + | !h_.on_number_part({begin, cs.used(begin)}, ec_) )) | ||||||
| HITGNC | 3437 | + | 60 | return fail(cs.begin()); | ||||
| HITGNC | 3438 | + | 361 | return maybe_suspend(cs.begin(), state::num1, num); | ||||
| 3439 | + | } | ||||||
| 3440 | + | |||||||
| 3441 | + | // 1*DIGIT | ||||||
| 3442 | + | // significant digits left of decimal | ||||||
| HITGNC | 3443 | + | 14265 | do_num2: | ||||
| HITGNC | 3444 | + | 81369 | for(;;) | ||||
| 3445 | + | { | ||||||
| HITGNC | 3446 | + | 95634 | if(BOOST_JSON_UNLIKELY( !cs )) | ||||
| 3447 | + | { | ||||||
| HITGNC | 3448 | + | 4061 | if(BOOST_JSON_UNLIKELY( more_ )) | ||||
| 3449 | + | { | ||||||
| HITGNC | 3450 | + | 3626 | if(BOOST_JSON_UNLIKELY( | ||||
| 3451 | + | !h_.on_number_part({begin, cs.used(begin)}, ec_) )) | ||||||
| HITGNC | 3452 | + | 402 | return fail(cs.begin()); | ||||
| HITGNC | 3453 | + | 2822 | return suspend(cs.begin(), state::num2, num); | ||||
| 3454 | + | } | ||||||
| HITGNC | 3455 | + | 435 | goto finish_int; | ||||
| 3456 | + | } | ||||||
| HITGNC | 3457 | + | 91573 | char const c = *cs; | ||||
| HITGNC | 3458 | + | 91573 | if(BOOST_JSON_LIKELY( c >= '0' && c <= '9' )) | ||||
| HITGNC | 3459 | + | 81369 | ++cs; | ||||
| 3460 | + | else | ||||||
| HITGNC | 3461 | + | 10204 | break; | ||||
| 3462 | + | } | ||||||
| 3463 | + | |||||||
| 3464 | + | // [.eE] | ||||||
| HITGNC | 3465 | + | 20375 | do_num6: | ||||
| 3466 | + | { | ||||||
| HITGNC | 3467 | + | 20375 | if(BOOST_JSON_UNLIKELY( !cs )) | ||||
| 3468 | + | { | ||||||
| HITGNC | 3469 | + | 418 | if(BOOST_JSON_UNLIKELY( more_ )) | ||||
| 3470 | + | { | ||||||
| HITGNC | 3471 | + | 417 | if(BOOST_JSON_UNLIKELY( | ||||
| 3472 | + | !h_.on_number_part({begin, cs.used(begin)}, ec_) )) | ||||||
| HITGNC | 3473 | + | 42 | return fail(cs.begin()); | ||||
| HITGNC | 3474 | + | 333 | return suspend(cs.begin(), state::num6, num); | ||||
| 3475 | + | } | ||||||
| HITGNC | 3476 | + | 1 | goto finish_int; | ||||
| 3477 | + | } | ||||||
| HITGNC | 3478 | + | 19957 | char const c = *cs; | ||||
| HITGNC | 3479 | + | 19957 | if(BOOST_JSON_LIKELY( c == '.' )) | ||||
| 3480 | + | { | ||||||
| HITGNC | 3481 | + | 9639 | ++cs; | ||||
| 3482 | + | } | ||||||
| HITGNC | 3483 | + | 10318 | else if((c | 32) == 'e') | ||||
| 3484 | + | { | ||||||
| HITGNC | 3485 | + | 6061 | ++cs; | ||||
| HITGNC | 3486 | + | 6061 | goto do_exp1; | ||||
| 3487 | + | } | ||||||
| 3488 | + | else | ||||||
| 3489 | + | { | ||||||
| HITGNC | 3490 | + | 4257 | goto finish_int; | ||||
| 3491 | + | } | ||||||
| 3492 | + | } | ||||||
| 3493 | + | |||||||
| 3494 | + | // DIGIT | ||||||
| 3495 | + | // first significant digit to the right of decimal | ||||||
| HITGNC | 3496 | + | 9983 | do_num7: | ||||
| 3497 | + | { | ||||||
| HITGNC | 3498 | + | 9983 | if(BOOST_JSON_UNLIKELY( !cs )) | ||||
| 3499 | + | { | ||||||
| HITGNC | 3500 | + | 423 | if(BOOST_JSON_UNLIKELY( more_ )) | ||||
| 3501 | + | { | ||||||
| HITGNC | 3502 | + | 420 | if(BOOST_JSON_UNLIKELY( | ||||
| 3503 | + | !h_.on_number_part({begin, cs.used(begin)}, ec_) )) | ||||||
| HITGNC | 3504 | + | 41 | return fail(cs.begin()); | ||||
| HITGNC | 3505 | + | 338 | return suspend(cs.begin(), state::num7, num); | ||||
| 3506 | + | } | ||||||
| 3507 | + | // digit required | ||||||
| 3508 | + | BOOST_STATIC_CONSTEXPR source_location loc | ||||||
| 3509 | + | = BOOST_CURRENT_LOCATION; | ||||||
| HITGNC | 3510 | + | 3 | return fail(cs.begin(), error::syntax, &loc); | ||||
| 3511 | + | } | ||||||
| HITGNC | 3512 | + | 9560 | char const c = *cs; | ||||
| HITGNC | 3513 | + | 9560 | if(BOOST_JSON_UNLIKELY( c < '0' || c > '9' )) | ||||
| 3514 | + | { | ||||||
| 3515 | + | // digit required | ||||||
| 3516 | + | BOOST_STATIC_CONSTEXPR source_location loc | ||||||
| 3517 | + | = BOOST_CURRENT_LOCATION; | ||||||
| HITGNC | 3518 | + | 131 | return fail(cs.begin(), error::syntax, &loc); | ||||
| 3519 | + | } | ||||||
| 3520 | + | } | ||||||
| 3521 | + | |||||||
| 3522 | + | // 1*DIGIT | ||||||
| 3523 | + | // significant digits to the right of decimal | ||||||
| HITGNC | 3524 | + | 16271 | do_num8: | ||||
| HITGNC | 3525 | + | 1107975 | for(;;) | ||||
| 3526 | + | { | ||||||
| HITGNC | 3527 | + | 1124246 | if(BOOST_JSON_UNLIKELY( !cs )) | ||||
| 3528 | + | { | ||||||
| HITGNC | 3529 | + | 5590 | if(BOOST_JSON_UNLIKELY( more_ )) | ||||
| 3530 | + | { | ||||||
| HITGNC | 3531 | + | 4515 | if(BOOST_JSON_UNLIKELY( | ||||
| 3532 | + | !h_.on_number_part({begin, cs.used(begin)}, ec_) )) | ||||||
| HITGNC | 3533 | + | 87 | return fail(cs.begin()); | ||||
| HITGNC | 3534 | + | 4341 | return suspend(cs.begin(), state::num8, num); | ||||
| 3535 | + | } | ||||||
| HITGNC | 3536 | + | 1075 | goto finish_dub; | ||||
| 3537 | + | } | ||||||
| HITGNC | 3538 | + | 1118656 | char const c = *cs; | ||||
| HITGNC | 3539 | + | 1118656 | if(BOOST_JSON_LIKELY( c >= '0' && c <= '9' )) | ||||
| 3540 | + | { | ||||||
| HITGNC | 3541 | + | 1107975 | ++cs; | ||||
| 3542 | + | } | ||||||
| HITGNC | 3543 | + | 10681 | else if((c | 32) == 'e') | ||||
| 3544 | + | { | ||||||
| HITGNC | 3545 | + | 6180 | ++cs; | ||||
| HITGNC | 3546 | + | 6180 | goto do_exp1; | ||||
| 3547 | + | } | ||||||
| 3548 | + | else | ||||||
| 3549 | + | { | ||||||
| HITGNC | 3550 | + | 4501 | goto finish_dub; | ||||
| 3551 | + | } | ||||||
| 3552 | + | } | ||||||
| 3553 | + | |||||||
| 3554 | + | // *[+-] | ||||||
| HITGNC | 3555 | + | 14232 | do_exp1: | ||||
| HITGNC | 3556 | + | 14232 | if(BOOST_JSON_UNLIKELY( !cs )) | ||||
| 3557 | + | { | ||||||
| HITGNC | 3558 | + | 422 | if(BOOST_JSON_UNLIKELY( | ||||
| 3559 | + | !h_.on_number_part({begin, cs.used(begin)}, ec_) )) | ||||||
| HITGNC | 3560 | + | 49 | return fail(cs.begin()); | ||||
| HITGNC | 3561 | + | 324 | return maybe_suspend(cs.begin(), state::exp1, num); | ||||
| 3562 | + | } | ||||||
| HITGNC | 3563 | + | 13810 | if( (*cs == '+') ||(*cs == '-') ) | ||||
| 3564 | + | { | ||||||
| HITGNC | 3565 | + | 3783 | ++cs; | ||||
| 3566 | + | } | ||||||
| 3567 | + | |||||||
| 3568 | + | // DIGIT | ||||||
| 3569 | + | // first digit of the exponent | ||||||
| HITGNC | 3570 | + | 10027 | do_exp2: | ||||
| 3571 | + | { | ||||||
| HITGNC | 3572 | + | 13926 | if(BOOST_JSON_UNLIKELY( !cs )) | ||||
| 3573 | + | { | ||||||
| HITGNC | 3574 | + | 165 | if(BOOST_JSON_UNLIKELY( more_ )) | ||||
| 3575 | + | { | ||||||
| HITGNC | 3576 | + | 156 | if(BOOST_JSON_UNLIKELY( | ||||
| 3577 | + | !h_.on_number_part({begin, cs.used(begin)}, ec_) )) | ||||||
| HITGNC | 3578 | + | 20 | return fail(cs.begin()); | ||||
| HITGNC | 3579 | + | 116 | return suspend(cs.begin(), state::exp2, num); | ||||
| 3580 | + | } | ||||||
| 3581 | + | // digit required | ||||||
| 3582 | + | BOOST_STATIC_CONSTEXPR source_location loc | ||||||
| 3583 | + | = BOOST_CURRENT_LOCATION; | ||||||
| HITGNC | 3584 | + | 9 | return fail(cs.begin(), error::syntax, &loc); | ||||
| 3585 | + | } | ||||||
| HITGNC | 3586 | + | 13761 | char const c = *cs; | ||||
| HITGNC | 3587 | + | 13761 | if(BOOST_JSON_UNLIKELY( c < '0' || c > '9' )) | ||||
| 3588 | + | { | ||||||
| 3589 | + | // digit required | ||||||
| 3590 | + | BOOST_STATIC_CONSTEXPR source_location loc | ||||||
| 3591 | + | = BOOST_CURRENT_LOCATION; | ||||||
| HITGNC | 3592 | + | 268 | return fail(cs.begin(), error::syntax, &loc); | ||||
| 3593 | + | } | ||||||
| HITGNC | 3594 | + | 13493 | ++cs; | ||||
| 3595 | + | } | ||||||
| 3596 | + | |||||||
| 3597 | + | // 1*DIGIT | ||||||
| 3598 | + | // subsequent digits in the exponent | ||||||
| HITGNC | 3599 | + | 16942 | do_exp3: | ||||
| HITGNC | 3600 | + | 547187 | for(;;) | ||||
| 3601 | + | { | ||||||
| HITGNC | 3602 | + | 564129 | if(BOOST_JSON_UNLIKELY( !cs )) | ||||
| 3603 | + | { | ||||||
| HITGNC | 3604 | + | 5934 | if(BOOST_JSON_UNLIKELY( more_ )) | ||||
| 3605 | + | { | ||||||
| HITGNC | 3606 | + | 3621 | if(BOOST_JSON_UNLIKELY( | ||||
| 3607 | + | !h_.on_number_part({begin, cs.used(begin)}, ec_) )) | ||||||
| HITGNC | 3608 | + | 86 | return fail(cs.begin()); | ||||
| HITGNC | 3609 | + | 3449 | return suspend(cs.begin(), state::exp3, num); | ||||
| 3610 | + | } | ||||||
| 3611 | + | } | ||||||
| 3612 | + | else | ||||||
| 3613 | + | { | ||||||
| HITGNC | 3614 | + | 558195 | char const c = *cs; | ||||
| HITGNC | 3615 | + | 558195 | if(BOOST_JSON_LIKELY( c >= '0' && c <= '9' )) | ||||
| 3616 | + | { | ||||||
| HITGNC | 3617 | + | 547187 | ++cs; | ||||
| HITGNC | 3618 | + | 547187 | continue; | ||||
| 3619 | + | } | ||||||
| 3620 | + | } | ||||||
| HITGNC | 3621 | + | 13321 | goto finish_dub; | ||||
| 3622 | + | } | ||||||
| 3623 | + | |||||||
| HITGNC | 3624 | + | 4742 | finish_int: | ||||
| HITGNC | 3625 | + | 4742 | if(BOOST_JSON_UNLIKELY( !h_.on_int64(0, {begin, cs.used(begin)}, ec_) )) | ||||
| HITGNC | 3626 | + | 770 | return fail( cs.begin() ); | ||||
| HITGNC | 3627 | + | 3202 | return cs.begin(); | ||||
| HITGNC | 3628 | + | 20627 | finish_dub: | ||||
| HITGNC | 3629 | + | 20627 | std::size_t const size = cs.used(begin); | ||||
| HITGNC | 3630 | + | 20627 | if(BOOST_JSON_UNLIKELY( !h_.on_double(0, {begin, size}, ec_) )) | ||||
| HITGNC | 3631 | + | 1846 | return fail( cs.begin() ); | ||||
| HITCBC | 2785 | 2048597 | return cs.begin(); | 3632 | 16935 | return cs.begin(); | ||
| 2786 | } | 3633 | } | |||||
| 2787 | 3634 | |||||||
| 2788 | //---------------------------------------------------------- | 3635 | //---------------------------------------------------------- | |||||
| 2789 | 3636 | |||||||
| 2790 | template<class Handler> | 3637 | template<class Handler> | |||||
| 2791 | template<class... Args> | 3638 | template<class... Args> | |||||
| HITCBC | 2792 | 2165011 | basic_parser<Handler>:: | 3639 | 2218617 | basic_parser<Handler>:: | ||
| 2793 | basic_parser( | 3640 | basic_parser( | |||||
| 2794 | parse_options const& opt, | 3641 | parse_options const& opt, | |||||
| 2795 | Args&&... args) | 3642 | Args&&... args) | |||||
| HITCBC | 2796 | 2165002 | : h_(std::forward<Args>(args)...) | 3643 | 2218608 | : h_(std::forward<Args>(args)...) | ||
| HITCBC | 2797 | 2165011 | , opt_(opt) | 3644 | 2218617 | , opt_(opt) | ||
| 2798 | { | 3645 | { | |||||
| HITCBC | 2799 | 2165011 | } | 3646 | 2218617 | } | ||
| 2800 | 3647 | |||||||
| 2801 | //---------------------------------------------------------- | 3648 | //---------------------------------------------------------- | |||||
| 2802 | 3649 | |||||||
| 2803 | template<class Handler> | 3650 | template<class Handler> | |||||
| 2804 | void | 3651 | void | |||||
| HITCBC | 2805 | 4153166 | basic_parser<Handler>:: | 3652 | 4154570 | basic_parser<Handler>:: | ||
| 2806 | reset() noexcept | 3653 | reset() noexcept | |||||
| 2807 | { | 3654 | { | |||||
| HITCBC | 2808 | 4153166 | ec_ = {}; | 3655 | 4154570 | ec_ = {}; | ||
| HITCBC | 2809 | 4153166 | st_.clear(); | 3656 | 4154570 | st_.clear(); | ||
| HITCBC | 2810 | 4153166 | more_ = true; | 3657 | 4154570 | more_ = true; | ||
| HITCBC | 2811 | 4153166 | done_ = false; | 3658 | 4154570 | done_ = false; | ||
| HITCBC | 2812 | 4153166 | clean_ = true; | 3659 | 4154570 | clean_ = true; | ||
| HITCBC | 2813 | 4153166 | num_buf_.clear(); | 3660 | 4154570 | num_buf_.clear(); | ||
| HITCBC | 2814 | 4153166 | } | 3661 | 4154570 | } | ||
| 2815 | 3662 | |||||||
| 2816 | template<class Handler> | 3663 | template<class Handler> | |||||
| 2817 | void | 3664 | void | |||||
| HITCBC | 2818 | 18 | basic_parser<Handler>:: | 3665 | 18 | basic_parser<Handler>:: | ||
| 2819 | fail(system::error_code ec) noexcept | 3666 | fail(system::error_code ec) noexcept | |||||
| 2820 | { | 3667 | { | |||||
| HITCBC | 2821 | 18 | if(! ec) | 3668 | 18 | if(! ec) | ||
| 2822 | { | 3669 | { | |||||
| 2823 | // assign an arbitrary | 3670 | // assign an arbitrary | |||||
| 2824 | // error code to prevent UB | 3671 | // error code to prevent UB | |||||
| HITCBC | 2825 | 1 | BOOST_JSON_FAIL(ec_, error::incomplete); | 3672 | 1 | BOOST_JSON_FAIL(ec_, error::incomplete); | ||
| 2826 | } | 3673 | } | |||||
| 2827 | else | 3674 | else | |||||
| 2828 | { | 3675 | { | |||||
| HITCBC | 2829 | 17 | ec_ = ec; | 3676 | 17 | ec_ = ec; | ||
| 2830 | } | 3677 | } | |||||
| HITCBC | 2831 | 18 | done_ = false; | 3678 | 18 | done_ = false; | ||
| HITCBC | 2832 | 18 | } | 3679 | 18 | } | ||
| 2833 | 3680 | |||||||
| 2834 | //---------------------------------------------------------- | 3681 | //---------------------------------------------------------- | |||||
| 2835 | 3682 | |||||||
| 2836 | template<class Handler> | 3683 | template<class Handler> | |||||
| 2837 | std::size_t | 3684 | std::size_t | |||||
| HITCBC | 2838 | 10726600 | basic_parser<Handler>:: | 3685 | 10798826 | basic_parser<Handler>:: | ||
| 2839 | write_some( | 3686 | write_some( | |||||
| 2840 | bool more, | 3687 | bool more, | |||||
| 2841 | char const* data, | 3688 | char const* data, | |||||
| 2842 | std::size_t size, | 3689 | std::size_t size, | |||||
| 2843 | system::error_code& ec) | 3690 | system::error_code& ec) | |||||
| 2844 | { | 3691 | { | |||||
| 2845 | // see if we exited via exception | 3692 | // see if we exited via exception | |||||
| 2846 | // on the last call to write_some | 3693 | // on the last call to write_some | |||||
| HITCBC | 2847 | 10726600 | if(! clean_) | 3694 | 10798826 | if(! clean_) | ||
| 2848 | { | 3695 | { | |||||
| 2849 | // prevent UB | 3696 | // prevent UB | |||||
| HITCBC | 2850 | 1 | if(! ec_) | 3697 | 1 | if(! ec_) | ||
| 2851 | { | 3698 | { | |||||
| HITCBC | 2852 | 1 | BOOST_JSON_FAIL(ec_, error::exception); | 3699 | 1 | BOOST_JSON_FAIL(ec_, error::exception); | ||
| 2853 | } | 3700 | } | |||||
| 2854 | } | 3701 | } | |||||
| HITCBC | 2855 | 10726600 | if(ec_) | 3702 | 10798826 | if(ec_) | ||
| 2856 | { | 3703 | { | |||||
| 2857 | // error is sticky | 3704 | // error is sticky | |||||
| HITCBC | 2858 | 5 | ec = ec_; | 3705 | 5 | ec = ec_; | ||
| HITCBC | 2859 | 5 | return 0; | 3706 | 5 | return 0; | ||
| 2860 | } | 3707 | } | |||||
| HITCBC | 2861 | 10726595 | clean_ = false; | 3708 | 10798821 | clean_ = false; | ||
| HITCBC | 2862 | 10726595 | more_ = more; | 3709 | 10798821 | more_ = more; | ||
| HITCBC | 2863 | 10726595 | end_ = data + size; | 3710 | 10798821 | end_ = data + size; | ||
| 2864 | const char* p; | 3711 | const char* p; | |||||
| HITCBC | 2865 | 10726595 | if(BOOST_JSON_LIKELY(st_.empty())) | 3712 | 10798821 | if(BOOST_JSON_LIKELY(st_.empty())) | ||
| 2866 | { | 3713 | { | |||||
| 2867 | // first time | 3714 | // first time | |||||
| HITCBC | 2868 | 2165000 | depth_ = opt_.max_depth; | 3715 | 2218606 | depth_ = opt_.max_depth; | ||
| HITCBC | 2869 | 2165000 | if(BOOST_JSON_UNLIKELY( | 3716 | 2218606 | if(BOOST_JSON_UNLIKELY( | ||
| 2870 | ! h_.on_document_begin(ec_))) | 3717 | ! h_.on_document_begin(ec_))) | |||||
| 2871 | { | 3718 | { | |||||
| HITCBC | 2872 | 7928 | ec = ec_; | 3719 | 14678 | ec = ec_; | ||
| HITCBC | 2873 | 7928 | return 0; | 3720 | 14678 | return 0; | ||
| 2874 | } | 3721 | } | |||||
| HITCBC | 2875 | 2149143 | p = parse_document(data, std::true_type()); | 3722 | 2189249 | p = parse_document(data, std::true_type()); | ||
| 2876 | } | 3723 | } | |||||
| 2877 | else | 3724 | else | |||||
| 2878 | { | 3725 | { | |||||
| HITCBC | 2879 | 8561595 | p = parse_document(data, std::false_type()); | 3726 | 8580215 | p = parse_document(data, std::false_type()); | ||
| 2880 | } | 3727 | } | |||||
| 2881 | 3728 | |||||||
| HITCBC | 2882 | 10691570 | if(BOOST_JSON_LIKELY(p != sentinel())) | 3729 | 10743112 | if(BOOST_JSON_LIKELY(p != sentinel())) | ||
| 2883 | { | 3730 | { | |||||
| HITCBC | 2884 | 2099217 | BOOST_ASSERT(! ec_); | 3731 | 2116271 | BOOST_ASSERT(! ec_); | ||
| HITCBC | 2885 | 2099217 | if(! done_) | 3732 | 2116271 | if(! done_) | ||
| 2886 | { | 3733 | { | |||||
| HITCBC | 2887 | 2031790 | done_ = true; | 3734 | 2042494 | done_ = true; | ||
| HITCBC | 2888 | 2031790 | h_.on_document_end(ec_); | 3735 | 2042494 | h_.on_document_end(ec_); | ||
| 2889 | } | 3736 | } | |||||
| 2890 | } | 3737 | } | |||||
| 2891 | else | 3738 | else | |||||
| 2892 | { | 3739 | { | |||||
| HITCBC | 2893 | 8592353 | if(! ec_) | 3740 | 8626841 | if(! ec_) | ||
| 2894 | { | 3741 | { | |||||
| HITCBC | 2895 | 8565496 | if(! more_) | 3742 | 8590422 | if(! more_) | ||
| 2896 | { | 3743 | { | |||||
| HITCBC | 2897 | 589 | BOOST_JSON_FAIL(ec_, error::incomplete); | 3744 | 591 | BOOST_JSON_FAIL(ec_, error::incomplete); | ||
| 2898 | } | 3745 | } | |||||
| HITCBC | 2899 | 8564907 | else if(! st_.empty()) | 3746 | 8589831 | else if(! st_.empty()) | ||
| 2900 | { | 3747 | { | |||||
| 2901 | // consume as much trailing whitespace in | 3748 | // consume as much trailing whitespace in | |||||
| 2902 | // the JSON document as possible, but still | 3749 | // the JSON document as possible, but still | |||||
| 2903 | // consider the parse complete | 3750 | // consider the parse complete | |||||
| 2904 | state st; | 3751 | state st; | |||||
| HITCBC | 2905 | 8564907 | st_.peek(st); | 3752 | 8589831 | st_.peek(st); | ||
| HITCBC | 2906 | 8564907 | if( st == state::doc3 && | 3753 | 8589831 | if( st == state::doc3 && | ||
| HITCBC | 2907 | 88563 | ! done_) | 3754 | 101217 | ! done_) | ||
| 2908 | { | 3755 | { | |||||
| HITCBC | 2909 | 70736 | done_ = true; | 3756 | 83390 | done_ = true; | ||
| HITCBC | 2910 | 70736 | h_.on_document_end(ec_); | 3757 | 83390 | h_.on_document_end(ec_); | ||
| 2911 | } | 3758 | } | |||||
| 2912 | } | 3759 | } | |||||
| 2913 | } | 3760 | } | |||||
| HITCBC | 2914 | 8590709 | p = end_; | 3761 | 8622045 | p = end_; | ||
| 2915 | } | 3762 | } | |||||
| HITCBC | 2916 | 10685934 | ec = ec_; | 3763 | 10731866 | ec = ec_; | ||
| HITCBC | 2917 | 10685934 | clean_ = true; | 3764 | 10731866 | clean_ = true; | ||
| HITCBC | 2918 | 10685934 | return p - data; | 3765 | 10731866 | return p - data; | ||
| 2919 | } | 3766 | } | |||||
| 2920 | 3767 | |||||||
| 2921 | template<class Handler> | 3768 | template<class Handler> | |||||
| 2922 | std::size_t | 3769 | std::size_t | |||||
| HITCBC | 2923 | 1 | basic_parser<Handler>:: | 3770 | 1 | basic_parser<Handler>:: | ||
| 2924 | write_some( | 3771 | write_some( | |||||
| 2925 | bool more, | 3772 | bool more, | |||||
| 2926 | char const* data, | 3773 | char const* data, | |||||
| 2927 | std::size_t size, | 3774 | std::size_t size, | |||||
| 2928 | std::error_code& ec) | 3775 | std::error_code& ec) | |||||
| 2929 | { | 3776 | { | |||||
| HITCBC | 2930 | 1 | system::error_code jec; | 3777 | 1 | system::error_code jec; | ||
| HITCBC | 2931 | 1 | std::size_t const result = write_some(more, data, size, jec); | 3778 | 1 | std::size_t const result = write_some(more, data, size, jec); | ||
| HITCBC | 2932 | 1 | ec = jec; | 3779 | 1 | ec = jec; | ||
| HITCBC | 2933 | 1 | return result; | 3780 | 1 | return result; | ||
| 2934 | } | 3781 | } | |||||
| 2935 | 3782 | |||||||
| 2936 | #endif | 3783 | #endif | |||||
| 2937 | 3784 | |||||||
| 2938 | } // namespace json | 3785 | } // namespace json | |||||
| 2939 | } // namespace boost | 3786 | } // namespace boost | |||||
| 2940 | 3787 | |||||||
| 2941 | #ifdef _MSC_VER | 3788 | #ifdef _MSC_VER | |||||
| 2942 | #pragma warning(pop) | 3789 | #pragma warning(pop) | |||||
| 2943 | #endif | 3790 | #endif | |||||
| 2944 | 3791 | |||||||
| 2945 | #endif | 3792 | #endif | |||||