diff --git a/include/fast_float/ascii_number.h b/include/fast_float/ascii_number.h index e840d08..f2484e8 100644 --- a/include/fast_float/ascii_number.h +++ b/include/fast_float/ascii_number.h @@ -283,7 +283,7 @@ template fastfloat_really_inline FASTFLOAT_CONSTEXPR20 parsed_number_string_t parse_number_string(UC const *p, UC const *pend, parse_options_t options) noexcept { - chars_format const fmt = options.format; + chars_format const fmt = detail::adjust_for_feature_macros(options.format); UC const decimal_point = options.decimal_point; parsed_number_string_t answer; @@ -291,15 +291,10 @@ parse_number_string(UC const *p, UC const *pend, answer.too_many_digits = false; // assume p < pend, so dereference without checks; answer.negative = (*p == UC('-')); -#ifdef FASTFLOAT_ALLOWS_LEADING_PLUS // disabled by default - if ((*p == UC('-')) || - (!uint64_t(fmt & detail::basic_json_fmt) && *p == UC('+'))) { -#else // C++17 20.19.3.(7.1) explicitly forbids '+' sign here if ((*p == UC('-')) || (uint64_t(fmt & chars_format::allow_leading_plus) && !uint64_t(fmt & detail::basic_json_fmt) && *p == UC('+'))) { -#endif ++p; if (p == pend) { return report_parse_error( @@ -479,7 +474,7 @@ template fastfloat_really_inline FASTFLOAT_CONSTEXPR20 from_chars_result_t parse_int_string(UC const *p, UC const *pend, T &value, parse_options_t options) { - chars_format const fmt = options.format; + chars_format const fmt = detail::adjust_for_feature_macros(options.format); int const base = options.base; from_chars_result_t answer; @@ -492,12 +487,8 @@ parse_int_string(UC const *p, UC const *pend, T &value, answer.ptr = first; return answer; } -#ifdef FASTFLOAT_ALLOWS_LEADING_PLUS // disabled by default - if ((*p == UC('-')) || (*p == UC('+'))) { -#else if ((*p == UC('-')) || (uint64_t(fmt & chars_format::allow_leading_plus) && (*p == UC('+')))) { -#endif ++p; } diff --git a/include/fast_float/float_common.h b/include/fast_float/float_common.h index df77a3e..1085fde 100644 --- a/include/fast_float/float_common.h +++ b/include/fast_float/float_common.h @@ -841,6 +841,20 @@ operator^=(chars_format &lhs, chars_format rhs) noexcept { return lhs = (lhs ^ rhs); } +namespace detail { +// adjust for deprecated feature macros +constexpr chars_format adjust_for_feature_macros(chars_format fmt) { + return fmt +#ifdef FASTFLOAT_ALLOWS_LEADING_PLUS + | chars_format::allow_leading_plus +#endif +#ifdef FASTFLOAT_SKIP_WHITE_SPACE + | chars_format::skip_white_space +#endif + ; +} +} // namespace detail + } // namespace fast_float #endif diff --git a/include/fast_float/parse_number.h b/include/fast_float/parse_number.h index 872d23d..a44c77f 100644 --- a/include/fast_float/parse_number.h +++ b/include/fast_float/parse_number.h @@ -27,14 +27,10 @@ from_chars_result_t answer.ec = std::errc(); // be optimistic // assume first < last, so dereference without checks; bool const minusSign = (*first == UC('-')); -#ifdef FASTFLOAT_ALLOWS_LEADING_PLUS // disabled by default - if ((*first == UC('-')) || (*first == UC('+'))) { -#else // C++17 20.19.3.(7.1) explicitly forbids '+' sign here if ((*first == UC('-')) || (uint64_t(fmt & chars_format::allow_leading_plus) && (*first == UC('+')))) { -#endif ++first; } if (last - first >= 3) { @@ -294,18 +290,14 @@ from_chars_float_advanced(UC const *first, UC const *last, T &value, static_assert(is_supported_char_type(), "only char, wchar_t, char16_t and char32_t are supported"); - chars_format const fmt = options.format; + chars_format const fmt = detail::adjust_for_feature_macros(options.format); from_chars_result_t answer; -#ifndef FASTFLOAT_SKIP_WHITE_SPACE // disabled by default if (uint64_t(fmt & chars_format::skip_white_space)) { -#endif while ((first != last) && fast_float::is_space(uint8_t(*first))) { first++; } -#ifndef FASTFLOAT_SKIP_WHITE_SPACE // disabled by default } -#endif if (first == last) { answer.ec = std::errc::invalid_argument; answer.ptr = first; @@ -349,19 +341,15 @@ from_chars_int_advanced(UC const *first, UC const *last, T &value, static_assert(is_supported_char_type(), "only char, wchar_t, char16_t and char32_t are supported"); - chars_format const fmt = options.format; + chars_format const fmt = detail::adjust_for_feature_macros(options.format); int const base = options.base; from_chars_result_t answer; -#ifndef FASTFLOAT_SKIP_WHITE_SPACE // disabled by default if (uint64_t(fmt & chars_format::skip_white_space)) { -#endif while ((first != last) && fast_float::is_space(uint8_t(*first))) { first++; } -#ifndef FASTFLOAT_SKIP_WHITE_SPACE // disabled by default } -#endif if (first == last || base < 2 || base > 36) { answer.ec = std::errc::invalid_argument; answer.ptr = first;