type usage fix

This commit is contained in:
IRainman 2025-05-07 00:44:20 +03:00
parent 2f8ff9a6eb
commit 4b94a612cf
3 changed files with 21 additions and 27 deletions

View File

@ -303,8 +303,8 @@ parse_number_string(UC const *p, UC const *pend,
answer.negative = (*p == UC('-')); answer.negative = (*p == UC('-'));
// C++17 20.19.3.(7.1) explicitly forbids '+' sign here // C++17 20.19.3.(7.1) explicitly forbids '+' sign here
if ((*p == UC('-')) || if ((*p == UC('-')) ||
(chars_format_t(options.format & chars_format::allow_leading_plus) && ((chars_format_t(options.format & chars_format::allow_leading_plus)) &&
!basic_json_fmt && *p == UC('+'))) { (!basic_json_fmt && *p == UC('+')))) {
++p; ++p;
if (p == pend) { if (p == pend) {
return report_parse_error<UC>( return report_parse_error<UC>(
@ -393,14 +393,14 @@ parse_number_string(UC const *p, UC const *pend,
// Now we can parse the explicit exponential part. // Now we can parse the explicit exponential part.
am_pow_t exp_number = 0; // explicit exponential part am_pow_t exp_number = 0; // explicit exponential part
if (((p != pend) && if (((p != pend) &&
(((chars_format_t(options.format & chars_format::scientific) && (((chars_format_t(options.format & chars_format::scientific)) &&
((UC('e') == *p) || (UC('E') == *p)))) ((UC('e') == *p) || (UC('E') == *p))))
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN #ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|| (chars_format_t(options.format & detail::basic_fortran_fmt) && || (((chars_format_t(options.format & detail::basic_fortran_fmt))) &&
((UC('+') == *p) || (UC('-') == *p) || (UC('d') == *p) || ((UC('+') == *p) || (UC('-') == *p) || (UC('d') == *p) ||
(UC('D') == *p))) (UC('D') == *p)))
#endif #endif
))) { )) {
UC const *location_of_e = p; UC const *location_of_e = p;
#ifdef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN #ifdef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
++p; ++p;
@ -421,7 +421,7 @@ parse_number_string(UC const *p, UC const *pend,
} }
} }
if ((p == pend) || !is_integer(*p)) { if ((p == pend) || !is_integer(*p)) {
if (!chars_format_t(options.format & chars_format::fixed)) { if (!(chars_format_t(options.format & chars_format::fixed))) {
// The exponential part is invalid for scientific notation, so it // The exponential part is invalid for scientific notation, so it
// must be a trailing token for fixed notation. However, fixed // must be a trailing token for fixed notation. However, fixed
// notation is disabled, so report a scientific notation error. // notation is disabled, so report a scientific notation error.
@ -445,8 +445,8 @@ parse_number_string(UC const *p, UC const *pend,
} }
} else { } else {
// If it scientific and not fixed, we have to bail out. // If it scientific and not fixed, we have to bail out.
if (chars_format_t(options.format & chars_format::scientific) && if ((chars_format_t(options.format & chars_format::scientific)) &&
!chars_format_t(options.format & chars_format::fixed)) { !(chars_format_t(options.format & chars_format::fixed))) {
return report_parse_error<UC>(p, parse_error::missing_exponential_part); return report_parse_error<UC>(p, parse_error::missing_exponential_part);
} }
} }
@ -531,7 +531,7 @@ parse_int_string(UC const *p, UC const *pend, T &value,
return answer; return answer;
} }
if ((*p == UC('-')) || if ((*p == UC('-')) ||
(chars_format_t(options.format & chars_format::allow_leading_plus) && ((chars_format_t(options.format & chars_format::allow_leading_plus)) &&
(*p == UC('+')))) { (*p == UC('+')))) {
++p; ++p;
} }

View File

@ -58,7 +58,7 @@ enum class chars_format : chars_format_t {
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN #ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
no_infnan = 1 << 3, no_infnan = 1 << 3,
// RFC 8259: https://datatracker.ietf.org/doc/html/rfc8259#section-6 // RFC 8259: https://datatracker.ietf.org/doc/html/rfc8259#section-6
json = uint64_t(detail::basic_json_fmt) | general | no_infnan, json = chars_format_t(detail::basic_json_fmt) | general | no_infnan,
// Extension of RFC 8259 where, e.g., "inf" and "nan" are allowed. // Extension of RFC 8259 where, e.g., "inf" and "nan" are allowed.
json_or_infnan = chars_format_t(detail::basic_json_fmt) | general, json_or_infnan = chars_format_t(detail::basic_json_fmt) | general,
fortran = chars_format_t(detail::basic_fortran_fmt) | general, fortran = chars_format_t(detail::basic_fortran_fmt) | general,
@ -76,17 +76,12 @@ using from_chars_result = from_chars_result_t<char>;
template <typename UC> struct parse_options_t { template <typename UC> struct parse_options_t {
constexpr explicit parse_options_t( constexpr explicit parse_options_t(
chars_format_t const fmt = chars_format::general, UC const dot = UC('.'), chars_format const fmt = chars_format::general, UC const dot = UC('.'),
uint_fast8_t const b = 10) noexcept uint_fast8_t const b = 10) noexcept
: format(fmt), decimal_point(dot), : format(fmt), decimal_point(dot), base(b) {}
base(b){
#ifdef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
// static_assert(b >= 2 && b <= 36);
#endif
}
/** Which number formats are accepted */ /** Which number formats are accepted */
chars_format format; chars_format format;
/** The character used as decimal point */ /** The character used as decimal point */
UC decimal_point; UC decimal_point;
/** The base used for integers */ /** The base used for integers */

View File

@ -33,7 +33,7 @@ from_chars_result_t<UC>
bool const minusSign = (*first == UC('-')); bool const minusSign = (*first == UC('-'));
// C++17 20.19.3.(7.1) explicitly forbids '+' sign here // C++17 20.19.3.(7.1) explicitly forbids '+' sign here
if ((*first == UC('-')) || if ((*first == UC('-')) ||
(chars_format_t(fmt & chars_format::allow_leading_plus) && ((chars_format_t(fmt & chars_format::allow_leading_plus)) &&
(*first == UC('+')))) { (*first == UC('+')))) {
++first; ++first;
} }
@ -332,7 +332,7 @@ from_chars_float_advanced(UC const *first, UC const *last, T &value,
#endif #endif
parsed_number_string_t<UC> const pns = parsed_number_string_t<UC> const pns =
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN #ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
chars_format_t(options.format & detail::basic_json_fmt) (chars_format_t(options.format & detail::basic_json_fmt))
? parse_number_string<true, UC>(first, last, options) ? parse_number_string<true, UC>(first, last, options)
: :
#endif #endif
@ -364,9 +364,8 @@ from_chars(UC const *first, UC const *last, T &value, int const base) noexcept {
static_assert(is_supported_char_type<UC>::value, static_assert(is_supported_char_type<UC>::value,
"only char, wchar_t, char16_t and char32_t are supported"); "only char, wchar_t, char16_t and char32_t are supported");
parse_options_t<UC> const options( parse_options_t<UC> const options(chars_format::general, UC('.'),
static_cast<chars_format_t>(chars_format::general), UC('.'), static_cast<uint_fast8_t>(base));
static_cast<uint_fast8_t>(base));
return from_chars_advanced(first, last, value, options); return from_chars_advanced(first, last, value, options);
} }