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
a591ca2fb8
commit
7c96e3a8be
@ -582,7 +582,9 @@ parse_int_string(UC const *p, UC const *pend, T &value,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
#ifdef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
||||||
|
value = T(i);
|
||||||
|
#else
|
||||||
if (negative) {
|
if (negative) {
|
||||||
#ifdef FASTFLOAT_VISUAL_STUDIO
|
#ifdef FASTFLOAT_VISUAL_STUDIO
|
||||||
#pragma warning(push)
|
#pragma warning(push)
|
||||||
@ -600,9 +602,7 @@ parse_int_string(UC const *p, UC const *pend, T &value,
|
|||||||
#pragma warning(pop)
|
#pragma warning(pop)
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
#endif
|
|
||||||
value = T(i);
|
value = T(i);
|
||||||
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -33,29 +33,29 @@
|
|||||||
|
|
||||||
namespace fast_float {
|
namespace fast_float {
|
||||||
|
|
||||||
enum class chars_format : uint64_t;
|
enum class chars_format : uint8_t;
|
||||||
|
|
||||||
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
||||||
namespace detail {
|
namespace detail {
|
||||||
constexpr chars_format basic_json_fmt = chars_format(1 << 5);
|
constexpr chars_format basic_json_fmt = chars_format(1 << 4);
|
||||||
constexpr chars_format basic_fortran_fmt = chars_format(1 << 6);
|
constexpr chars_format basic_fortran_fmt = chars_format(1 << 5);
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum class chars_format : uint64_t {
|
enum class chars_format : uint8_t {
|
||||||
scientific = 1 << 0,
|
scientific = 1 << 0,
|
||||||
fixed = 1 << 2,
|
fixed = 1 << 1,
|
||||||
general = fixed | scientific,
|
general = fixed | scientific,
|
||||||
hex = 1 << 3,
|
hex = 1 << 2,
|
||||||
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
||||||
no_infnan = 1 << 4,
|
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 = uint64_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 = uint64_t(detail::basic_json_fmt) | general,
|
json_or_infnan = uint64_t(detail::basic_json_fmt) | general,
|
||||||
fortran = uint64_t(detail::basic_fortran_fmt) | general,
|
fortran = uint64_t(detail::basic_fortran_fmt) | general,
|
||||||
allow_leading_plus = 1 << 7,
|
allow_leading_plus = 1 << 6,
|
||||||
skip_white_space = 1 << 8,
|
skip_white_space = 1 << 7,
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -70,14 +70,18 @@ template <typename UC> struct parse_options_t {
|
|||||||
FASTFLOAT_CONSTEXPR20 explicit parse_options_t(
|
FASTFLOAT_CONSTEXPR20 explicit parse_options_t(
|
||||||
chars_format fmt = chars_format::general, UC dot = UC('.'),
|
chars_format fmt = chars_format::general, UC dot = UC('.'),
|
||||||
int const b = 10) noexcept
|
int const b = 10) noexcept
|
||||||
: format(fmt), decimal_point(dot), base(b) {}
|
: format(fmt), decimal_point(dot), base(uint8_t(b)) {
|
||||||
|
#ifdef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
||||||
|
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 */
|
||||||
uint32_t base; /* only allowed from 2 to 36 */
|
uint8_t base; /* only allowed from 2 to 36 */
|
||||||
FASTFLOAT_ASSUME(base >= 2 && base <= 36);
|
FASTFLOAT_ASSUME(base >= 2 && base <= 36);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -378,20 +378,16 @@ from_chars_int_advanced(UC const *first, UC const *last, T &value,
|
|||||||
first++;
|
first++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
if (first == last || options.base < 2 || options.base > 36) {
|
||||||
// We are in parser code with external loop that checks bounds.
|
|
||||||
FASTFLOAT_ASSUME(first < last);
|
|
||||||
#endif
|
|
||||||
if (
|
|
||||||
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
|
||||||
first == last ||
|
|
||||||
#endif
|
|
||||||
options.base < 2 || options.base > 36) {
|
|
||||||
from_chars_result_t<UC> answer;
|
from_chars_result_t<UC> answer;
|
||||||
answer.ec = std::errc::invalid_argument;
|
answer.ec = std::errc::invalid_argument;
|
||||||
answer.ptr = first;
|
answer.ptr = first;
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
// We are in parser code with external loop that checks bounds.
|
||||||
|
FASTFLOAT_ASSUME(first < last);
|
||||||
|
#endif
|
||||||
|
|
||||||
return parse_int_string(first, last, value, options);
|
return parse_int_string(first, last, value, options);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user