mirror of
https://github.com/fastfloat/fast_float.git
synced 2025-12-06 16:56:57 +08:00
* added chars_format_t for performance reason.
This commit is contained in:
parent
f3db77a07c
commit
b0bae17b10
@ -303,7 +303,7 @@ 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('-')) ||
|
||||||
(uint8_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) {
|
||||||
@ -390,11 +390,11 @@ 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.
|
||||||
int16_t exp_number = 0; // explicit exponential part
|
int16_t exp_number = 0; // explicit exponential part
|
||||||
if ((p != pend) && (uint8_t(options.format & chars_format::scientific) &&
|
if ((p != pend) && (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
|
||||||
|| (uint8_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
|
||||||
@ -419,7 +419,7 @@ parse_number_string(UC const *p, UC const *pend,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((p == pend) || !is_integer(*p)) {
|
if ((p == pend) || !is_integer(*p)) {
|
||||||
if (!uint8_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 must
|
// The exponential part is invalid for scientific notation, so it must
|
||||||
// be a trailing token for fixed notation. However, fixed notation is
|
// be a trailing token for fixed notation. However, fixed notation is
|
||||||
// disabled, so report a scientific notation error.
|
// disabled, so report a scientific notation error.
|
||||||
@ -443,8 +443,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 (uint8_t(options.format & chars_format::scientific) &&
|
if (chars_format_t(options.format & chars_format::scientific) &&
|
||||||
!uint8_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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -527,7 +527,7 @@ parse_int_string(UC const *p, UC const *pend, T &value,
|
|||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
if ((*p == UC('-')) ||
|
if ((*p == UC('-')) ||
|
||||||
(uint8_t(options.format & chars_format::allow_leading_plus) &&
|
(chars_format_t(options.format & chars_format::allow_leading_plus) &&
|
||||||
(*p == UC('+')))) {
|
(*p == UC('+')))) {
|
||||||
++p;
|
++p;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,7 +33,11 @@
|
|||||||
|
|
||||||
namespace fast_float {
|
namespace fast_float {
|
||||||
|
|
||||||
enum class chars_format : uint8_t;
|
// because library only support 32 and 64 bit architectures,
|
||||||
|
// we should use 32 bit value here
|
||||||
|
typedef uint32_t chars_format_t;
|
||||||
|
|
||||||
|
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
|
||||||
namespace detail {
|
namespace detail {
|
||||||
@ -42,7 +46,7 @@ constexpr chars_format basic_fortran_fmt = chars_format(1 << 5);
|
|||||||
} // namespace detail
|
} // namespace detail
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum class chars_format : uint8_t {
|
enum class chars_format : chars_format_t {
|
||||||
scientific = 1 << 0,
|
scientific = 1 << 0,
|
||||||
fixed = 1 << 1,
|
fixed = 1 << 1,
|
||||||
general = fixed | scientific,
|
general = fixed | scientific,
|
||||||
@ -69,8 +73,8 @@ using from_chars_result = from_chars_result_t<char>;
|
|||||||
template <typename UC> struct parse_options_t {
|
template <typename UC> struct parse_options_t {
|
||||||
FASTFLOAT_CONSTEXPR20 explicit parse_options_t(
|
FASTFLOAT_CONSTEXPR20 explicit parse_options_t(
|
||||||
chars_format const fmt = chars_format::general, UC const dot = UC('.'),
|
chars_format const fmt = chars_format::general, UC const dot = UC('.'),
|
||||||
int const b = 10) noexcept
|
chars_format_t const b = 10) noexcept
|
||||||
: format(fmt), decimal_point(dot), base(uint8_t(b)) {
|
: format(fmt), decimal_point(dot), base(b) {
|
||||||
#ifdef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
#ifdef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
||||||
// static_assert(b >= 2 && b <= 36);
|
// static_assert(b >= 2 && b <= 36);
|
||||||
#endif
|
#endif
|
||||||
@ -81,7 +85,7 @@ template <typename UC> struct parse_options_t {
|
|||||||
/** The character used as decimal point */
|
/** The character used as decimal point */
|
||||||
UC const decimal_point;
|
UC const decimal_point;
|
||||||
/** The base used for integers */
|
/** The base used for integers */
|
||||||
uint8_t const base; /* only allowed from 2 to 36 */
|
uint32_t const base; /* only allowed from 2 to 36 */
|
||||||
FASTFLOAT_ASSUME(base >= 2 && base <= 36);
|
FASTFLOAT_ASSUME(base >= 2 && base <= 36);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -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('-')) ||
|
||||||
(uint64_t(fmt & chars_format::allow_leading_plus) &&
|
(chars_format_t(fmt & chars_format::allow_leading_plus) &&
|
||||||
(*first == UC('+')))) {
|
(*first == UC('+')))) {
|
||||||
++first;
|
++first;
|
||||||
}
|
}
|
||||||
@ -310,7 +310,7 @@ from_chars_float_advanced(UC const *first, UC const *last, T &value,
|
|||||||
|
|
||||||
from_chars_result_t<UC> answer;
|
from_chars_result_t<UC> answer;
|
||||||
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
||||||
if (uint8_t(options.format & chars_format::skip_white_space)) {
|
if (chars_format_t(options.format & chars_format::skip_white_space)) {
|
||||||
while ((first != last) && fast_float::is_space(*first)) {
|
while ((first != last) && fast_float::is_space(*first)) {
|
||||||
++first;
|
++first;
|
||||||
}
|
}
|
||||||
@ -326,14 +326,14 @@ 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
|
||||||
uint8_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
|
||||||
parse_number_string<false, UC>(first, last, options);
|
parse_number_string<false, UC>(first, last, options);
|
||||||
if (!pns.valid) {
|
if (!pns.valid) {
|
||||||
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
||||||
if (uint8_t(options.format & chars_format::no_infnan)) {
|
if (chars_format_t(options.format & chars_format::no_infnan)) {
|
||||||
#endif
|
#endif
|
||||||
answer.ec = std::errc::invalid_argument;
|
answer.ec = std::errc::invalid_argument;
|
||||||
answer.ptr = first;
|
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");
|
"only char, wchar_t, char16_t and char32_t are supported");
|
||||||
|
|
||||||
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
||||||
if (uint8_t(options.format & chars_format::skip_white_space)) {
|
if (chars_format_t(options.format & chars_format::skip_white_space)) {
|
||||||
while ((first != last) && fast_float::is_space(*first)) {
|
while ((first != last) && fast_float::is_space(*first)) {
|
||||||
++first;
|
++first;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user