diff --git a/include/fast_float/ascii_number.h b/include/fast_float/ascii_number.h index f9680ec..21fbac4 100644 --- a/include/fast_float/ascii_number.h +++ b/include/fast_float/ascii_number.h @@ -280,7 +280,7 @@ parsed_number_string_t parse_number_string(UC const *p, UC const * pend, par answer.too_many_digits = false; answer.negative = (*p == UC('-')); #ifdef FASTFLOAT_ALLOWS_LEADING_PLUS // disabled by default - if ((*p == UC('-')) || (*p == UC('+'))) { + if ((*p == UC('-')) || (fmt != chars_format::json && *p == UC('+'))) { #else if (*p == UC('-')) { // C++17 20.19.3.(7.1) explicitly forbids '+' sign here #endif diff --git a/tests/json_fmt.cpp b/tests/json_fmt.cpp index 0c1c365..b1c3977 100644 --- a/tests/json_fmt.cpp +++ b/tests/json_fmt.cpp @@ -3,13 +3,16 @@ #include #include +// test that this option is ignored +#define FASTFLOAT_ALLOWS_LEADING_PLUS + #include "fast_float/fast_float.h" int main() { const std::vector expected{ -0.2, 0.02, 0.002, 1., 0. }; const std::vector accept{ "-0.2", "0.02", "0.002", "1e+0000", "0e-2" }; - const std::vector reject{ "-.2", "00.02", "0.e+1", "00.e+1", ".25"}; + const std::vector reject{ "-.2", "00.02", "0.e+1", "00.e+1", ".25", "+0.25"}; const auto fmt = fast_float::chars_format::json; for (std::size_t i = 0; i < accept.size(); ++i)