diff --git a/include/fast_float/ascii_number.h b/include/fast_float/ascii_number.h index 9001016..fae0c15 100644 --- a/include/fast_float/ascii_number.h +++ b/include/fast_float/ascii_number.h @@ -279,7 +279,7 @@ report_parse_error(UC const *p, parse_error error) { // Assuming that you use no more than 19 digits, this will // parse an ASCII string. -template +template fastfloat_really_inline FASTFLOAT_CONSTEXPR20 parsed_number_string_t parse_number_string(UC const *p, UC const *pend, parse_options_t options) noexcept { @@ -293,14 +293,14 @@ parse_number_string(UC const *p, UC const *pend, answer.negative = (*p == UC('-')); // 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('+'))) { + (allow_leading_plus && + !basic_json_fmt && *p == UC('+'))) { ++p; if (p == pend) { return report_parse_error( p, parse_error::missing_integer_or_dot_after_sign); } - if (uint64_t(fmt & detail::basic_json_fmt)) { + if (basic_json_fmt) { if (!is_integer(*p)) { // a sign must be followed by an integer return report_parse_error(p, parse_error::missing_integer_after_sign); @@ -329,7 +329,7 @@ parse_number_string(UC const *p, UC const *pend, UC const *const end_of_integer_part = p; int64_t digit_count = int64_t(end_of_integer_part - start_digits); answer.integer = span(start_digits, size_t(digit_count)); - if (uint64_t(fmt & detail::basic_json_fmt)) { + if (basic_json_fmt) { // at least 1 digit in integer part, without leading zeros if (digit_count == 0) { return report_parse_error(p, parse_error::no_digits_in_integer_part); @@ -358,7 +358,7 @@ parse_number_string(UC const *p, UC const *pend, answer.fraction = span(before, size_t(p - before)); digit_count -= exponent; } - if (uint64_t(fmt & detail::basic_json_fmt)) { + if (basic_json_fmt) { // at least 1 digit in fractional part if (has_decimal_point && exponent == 0) { return report_parse_error(p, @@ -470,11 +470,11 @@ parse_number_string(UC const *p, UC const *pend, return answer; } -template +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 = detail::adjust_for_feature_macros(options.format); + //chars_format const fmt = detail::adjust_for_feature_macros(options.format); int const base = options.base; from_chars_result_t answer; @@ -495,7 +495,7 @@ parse_int_string(UC const *p, UC const *pend, T &value, return answer; } if ((*p == UC('-')) || - (uint64_t(fmt & chars_format::allow_leading_plus) && (*p == UC('+')))) { + (allow_leading_plus && (*p == UC('+')))) { ++p; } diff --git a/include/fast_float/parse_number.h b/include/fast_float/parse_number.h index 0dbb3a1..81d9e06 100644 --- a/include/fast_float/parse_number.h +++ b/include/fast_float/parse_number.h @@ -304,8 +304,11 @@ from_chars_float_advanced(UC const *first, UC const *last, T &value, answer.ptr = first; return answer; } - parsed_number_string_t pns = - parse_number_string(first, last, options); + bool allow_leading_plus = uint64_t(fmt & chars_format::allow_leading_plus); + bool basic_json_fmt = uint64_t(fmt & detail::basic_json_fmt); + parsed_number_string_t pns = allow_leading_plus ? + (basic_json_fmt ? parse_number_string(first, last, options): parse_number_string(first, last, options)) : + (basic_json_fmt ? parse_number_string(first, last, options): parse_number_string(first, last, options)); if (!pns.valid) { if (uint64_t(fmt & chars_format::no_infnan)) { answer.ec = std::errc::invalid_argument; diff --git a/tests/json_fmt.cpp b/tests/json_fmt.cpp index f04207a..43d1462 100644 --- a/tests/json_fmt.cpp +++ b/tests/json_fmt.cpp @@ -131,7 +131,7 @@ int main() { for (std::size_t i = 0; i < reject.size(); ++i) { auto const &f = reject[i].input; auto const &expected_reason = reject[i].reason; - auto answer = fast_float::parse_number_string( + auto answer = fast_float::parse_number_string( f.data(), f.data() + f.size(), fast_float::parse_options( fast_float::chars_format::json |