mirror of
https://github.com/fastfloat/fast_float.git
synced 2025-12-06 16:56:57 +08:00
cleanup for parse_number_string
This commit is contained in:
parent
437a80ccfd
commit
5ae2fba79d
@ -268,7 +268,7 @@ template <typename UC> struct parsed_number_string_t {
|
|||||||
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
||||||
bool negative{false};
|
bool negative{false};
|
||||||
#endif
|
#endif
|
||||||
bool valid{false};
|
bool invalid{false};
|
||||||
bool too_many_digits{false};
|
bool too_many_digits{false};
|
||||||
// contains the range of the significant digits
|
// contains the range of the significant digits
|
||||||
span<UC const> integer{}; // non-nullable
|
span<UC const> integer{}; // non-nullable
|
||||||
@ -283,7 +283,7 @@ template <typename UC>
|
|||||||
fastfloat_really_inline FASTFLOAT_CONSTEXPR20 parsed_number_string_t<UC>
|
fastfloat_really_inline FASTFLOAT_CONSTEXPR20 parsed_number_string_t<UC>
|
||||||
report_parse_error(UC const *p, parse_error error) noexcept {
|
report_parse_error(UC const *p, parse_error error) noexcept {
|
||||||
parsed_number_string_t<UC> answer;
|
parsed_number_string_t<UC> answer;
|
||||||
answer.valid = false;
|
answer.invalid = true;
|
||||||
answer.lastmatch = p;
|
answer.lastmatch = p;
|
||||||
answer.error = error;
|
answer.error = error;
|
||||||
return answer;
|
return answer;
|
||||||
@ -299,7 +299,8 @@ parse_number_string(UC const *p, UC const *pend,
|
|||||||
// Consider refactoring the 'parse_number_string' function.
|
// Consider refactoring the 'parse_number_string' function.
|
||||||
// FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN fix this.
|
// FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN fix this.
|
||||||
parsed_number_string_t<UC> answer;
|
parsed_number_string_t<UC> answer;
|
||||||
FASTFLOAT_ASSUME(p < pend); // so dereference without checks;
|
// so dereference without checks
|
||||||
|
FASTFLOAT_ASSUME(p < pend);
|
||||||
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
||||||
answer.negative = (*p == UC('-'));
|
answer.negative = (*p == UC('-'));
|
||||||
if (answer.negative ||
|
if (answer.negative ||
|
||||||
@ -312,15 +313,15 @@ parse_number_string(UC const *p, UC const *pend,
|
|||||||
p, parse_error::missing_integer_or_dot_after_sign);
|
p, parse_error::missing_integer_or_dot_after_sign);
|
||||||
}
|
}
|
||||||
FASTFLOAT_IF_CONSTEXPR17(basic_json_fmt) {
|
FASTFLOAT_IF_CONSTEXPR17(basic_json_fmt) {
|
||||||
if (!is_integer(*p)) { // a sign must be followed by an integer
|
// a sign must be followed by an integer
|
||||||
|
if (!is_integer(*p)) {
|
||||||
return report_parse_error<UC>(p,
|
return report_parse_error<UC>(p,
|
||||||
parse_error::missing_integer_after_sign);
|
parse_error::missing_integer_after_sign);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!is_integer(*p) &&
|
// a sign must be followed by an integer or the dot
|
||||||
(*p != options.decimal_point)) { // a sign must be followed by an
|
if (!is_integer(*p) && (*p != options.decimal_point)) {
|
||||||
// integer or the dot
|
|
||||||
return report_parse_error<UC>(
|
return report_parse_error<UC>(
|
||||||
p, parse_error::missing_integer_or_dot_after_sign);
|
p, parse_error::missing_integer_or_dot_after_sign);
|
||||||
}
|
}
|
||||||
@ -459,7 +460,6 @@ parse_number_string(UC const *p, UC const *pend,
|
|||||||
|
|
||||||
// We parsed all parts of the number, let's save progress.
|
// We parsed all parts of the number, let's save progress.
|
||||||
answer.lastmatch = p;
|
answer.lastmatch = p;
|
||||||
answer.valid = true;
|
|
||||||
|
|
||||||
// Now we can check for errors.
|
// Now we can check for errors.
|
||||||
|
|
||||||
|
|||||||
@ -337,7 +337,7 @@ from_chars_float_advanced(UC const *first, UC const *last, T &value,
|
|||||||
:
|
:
|
||||||
#endif
|
#endif
|
||||||
parse_number_string<false, UC>(first, last, options);
|
parse_number_string<false, UC>(first, last, options);
|
||||||
if (!pns.valid) {
|
if (pns.invalid) {
|
||||||
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
||||||
if (chars_format_t(options.format & chars_format::no_infnan)) {
|
if (chars_format_t(options.format & chars_format::no_infnan)) {
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user