From 1f9b1a6706edd0592022f2d58778e475a7268907 Mon Sep 17 00:00:00 2001 From: zejal Date: Mon, 13 May 2024 14:24:48 +0200 Subject: [PATCH 1/2] from_chars_advanced overload function taking parsed_number_string_t --- include/fast_float/parse_number.h | 57 +++++++++++++++++++------------ 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/include/fast_float/parse_number.h b/include/fast_float/parse_number.h index a97906e..8bcdb6c 100644 --- a/include/fast_float/parse_number.h +++ b/include/fast_float/parse_number.h @@ -189,33 +189,13 @@ from_chars_result_t from_chars(UC const * first, UC const * last, template FASTFLOAT_CONSTEXPR20 -from_chars_result_t from_chars_advanced(UC const * first, UC const * last, - T &value, parse_options_t options) noexcept { +from_chars_result_t from_chars_advanced(parsed_number_string_t& pns, + T &value) noexcept { static_assert (is_supported_float_type(), "only some floating-point types are supported"); static_assert (is_supported_char_type(), "only char, wchar_t, char16_t and char32_t are supported"); from_chars_result_t answer; -#ifdef FASTFLOAT_SKIP_WHITE_SPACE // disabled by default - while ((first != last) && fast_float::is_space(uint8_t(*first))) { - first++; - } -#endif - if (first == last) { - answer.ec = std::errc::invalid_argument; - answer.ptr = first; - return answer; - } - parsed_number_string_t pns = parse_number_string(first, last, options); - if (!pns.valid) { - if (options.format & chars_format::no_infnan) { - answer.ec = std::errc::invalid_argument; - answer.ptr = first; - return answer; - } else { - return detail::parse_infnan(first, last, value); - } - } answer.ec = std::errc(); // be optimistic answer.ptr = pns.lastmatch; @@ -276,6 +256,39 @@ from_chars_result_t from_chars_advanced(UC const * first, UC const * last, return answer; } +template +FASTFLOAT_CONSTEXPR20 +from_chars_result_t from_chars_advanced(UC const * first, UC const * last, + T &value, parse_options_t options) noexcept { + + static_assert (is_supported_float_type(), "only some floating-point types are supported"); + static_assert (is_supported_char_type(), "only char, wchar_t, char16_t and char32_t are supported"); + + from_chars_result_t answer; +#ifdef FASTFLOAT_SKIP_WHITE_SPACE // disabled by default + while ((first != last) && fast_float::is_space(uint8_t(*first))) { + first++; + } +#endif + if (first == last) { + answer.ec = std::errc::invalid_argument; + answer.ptr = first; + return answer; + } + parsed_number_string_t pns = parse_number_string(first, last, options); + if (!pns.valid) { + if (options.format & chars_format::no_infnan) { + answer.ec = std::errc::invalid_argument; + answer.ptr = first; + return answer; + } else { + return detail::parse_infnan(first, last, value); + } + } + + return from_chars_advanced(pns, value); +} + template FASTFLOAT_CONSTEXPR20 From 85911abb59a458afa8409992e0dae626487baff7 Mon Sep 17 00:00:00 2001 From: zejal Date: Mon, 13 May 2024 19:55:46 +0200 Subject: [PATCH 2/2] added couple of comments --- include/fast_float/parse_number.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/fast_float/parse_number.h b/include/fast_float/parse_number.h index 8bcdb6c..57bcf46 100644 --- a/include/fast_float/parse_number.h +++ b/include/fast_float/parse_number.h @@ -187,6 +187,11 @@ from_chars_result_t from_chars(UC const * first, UC const * last, return from_chars_caller::call(first, last, value, parse_options_t(fmt)); } +/** + * This function overload takes parsed_number_string_t structure that is created and populated + * either by from_chars_advanced function taking chars range and parsing options + * or other parsing custom function implemented by user. + */ template FASTFLOAT_CONSTEXPR20 from_chars_result_t from_chars_advanced(parsed_number_string_t& pns, @@ -286,6 +291,7 @@ from_chars_result_t from_chars_advanced(UC const * first, UC const * last, } } + // call overload that takes parsed_number_string_t directly. return from_chars_advanced(pns, value); }