mirror of
https://github.com/fastfloat/fast_float.git
synced 2025-12-06 16:56:57 +08:00
reduce size of from_chars_result_t to 4 bytes. Cleanup for usage FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN.
This commit is contained in:
parent
8d4ca6983a
commit
d32ae04b1b
@ -301,7 +301,7 @@ parse_number_string(UC const *p, UC const *pend,
|
||||
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
||||
answer.negative = (*p == UC('-'));
|
||||
// C++17 20.19.3.(7.1) explicitly forbids '+' sign here
|
||||
if ((*p == UC('-')) || (uint64_t(options.format & chars_format::allow_leading_plus) &&
|
||||
if ((*p == UC('-')) || (uint8_t(options.format & chars_format::allow_leading_plus) &&
|
||||
!basic_json_fmt && *p == UC('+'))) {
|
||||
++p;
|
||||
if (p == pend) {
|
||||
@ -385,10 +385,10 @@ parse_number_string(UC const *p, UC const *pend,
|
||||
}
|
||||
int32_t exp_number = 0; // explicit exponential part
|
||||
if (p != pend &&
|
||||
(uint64_t(options.format & chars_format::scientific) &&
|
||||
(uint8_t(options.format & chars_format::scientific) &&
|
||||
((UC('e') == *p) || (UC('E') == *p)))
|
||||
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
||||
|| (uint64_t(options.format & detail::basic_fortran_fmt) &&
|
||||
|| (uint8_t(options.format & detail::basic_fortran_fmt) &&
|
||||
(UC('d') == *p) || (UC('D') == *p))
|
||||
#endif
|
||||
) {
|
||||
@ -406,7 +406,7 @@ parse_number_string(UC const *p, UC const *pend,
|
||||
}
|
||||
}
|
||||
if ((p == pend) || !is_integer(*p)) {
|
||||
if (!uint64_t(options.format & chars_format::fixed)) {
|
||||
if (!uint8_t(options.format & chars_format::fixed)) {
|
||||
// The exponential part is invalid for scientific notation, so it must
|
||||
// be a trailing token for fixed notation. However, fixed notation is
|
||||
// disabled, so report a scientific notation error.
|
||||
@ -427,8 +427,8 @@ parse_number_string(UC const *p, UC const *pend,
|
||||
}
|
||||
} else {
|
||||
// If it scientific and not fixed, we have to bail out.
|
||||
if (uint64_t(options.format & chars_format::scientific) &&
|
||||
!uint64_t(options.format & chars_format::fixed)) {
|
||||
if (uint8_t(options.format & chars_format::scientific) &&
|
||||
!uint8_t(options.format & chars_format::fixed)) {
|
||||
return report_parse_error<UC>(p, parse_error::missing_exponential_part);
|
||||
}
|
||||
}
|
||||
@ -510,7 +510,7 @@ parse_int_string(UC const *p, UC const *pend, T &value,
|
||||
return answer;
|
||||
}
|
||||
if ((*p == UC('-')) ||
|
||||
(uint64_t(options.format & chars_format::allow_leading_plus) &&
|
||||
(uint8_t(options.format & chars_format::allow_leading_plus) &&
|
||||
(*p == UC('+')))) {
|
||||
++p;
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ from_chars(UC const *first, UC const *last, T &value,
|
||||
template <typename T, typename UC = char>
|
||||
FASTFLOAT_CONSTEXPR20 from_chars_result_t<UC>
|
||||
from_chars_advanced(UC const *first, UC const *last, T &value,
|
||||
parse_options_t<UC> const &options) noexcept;
|
||||
parse_options_t<UC> const options) noexcept;
|
||||
|
||||
/**
|
||||
* from_chars for integer types.
|
||||
|
||||
@ -310,7 +310,7 @@ from_chars_float_advanced(UC const *first, UC const *last, T &value,
|
||||
|
||||
from_chars_result_t<UC> answer;
|
||||
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
||||
if (uint64_t(options.format & chars_format::skip_white_space)) {
|
||||
if (uint8_t(options.format & chars_format::skip_white_space)) {
|
||||
while ((first != last) && fast_float::is_space(*first)) {
|
||||
first++;
|
||||
}
|
||||
@ -326,14 +326,14 @@ from_chars_float_advanced(UC const *first, UC const *last, T &value,
|
||||
#endif
|
||||
parsed_number_string_t<UC> const pns =
|
||||
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
||||
uint64_t(options.format & detail::basic_json_fmt)
|
||||
uint8_t(options.format & detail::basic_json_fmt)
|
||||
? parse_number_string<true, UC>(first, last, options)
|
||||
:
|
||||
#endif
|
||||
parse_number_string<false, UC>(first, last, options);
|
||||
if (!pns.valid) {
|
||||
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
||||
if (uint64_t(options.format & chars_format::no_infnan)) {
|
||||
if (uint8_t(options.format & chars_format::no_infnan)) {
|
||||
#endif
|
||||
answer.ec = std::errc::invalid_argument;
|
||||
answer.ptr = first;
|
||||
@ -373,7 +373,7 @@ from_chars_int_advanced(UC const *first, UC const *last, T &value,
|
||||
"only char, wchar_t, char16_t and char32_t are supported");
|
||||
|
||||
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
||||
if (uint64_t(options.format & chars_format::skip_white_space)) {
|
||||
if (uint8_t(options.format & chars_format::skip_white_space)) {
|
||||
while ((first != last) && fast_float::is_space(*first)) {
|
||||
first++;
|
||||
}
|
||||
@ -387,6 +387,7 @@ from_chars_int_advanced(UC const *first, UC const *last, T &value,
|
||||
#else
|
||||
// We are in parser code with external loop that checks bounds.
|
||||
FASTFLOAT_ASSUME(first < last);
|
||||
// base is already checked in the parse_options_t constructor.
|
||||
#endif
|
||||
|
||||
return parse_int_string(first, last, value, options);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user