mirror of
https://github.com/fastfloat/fast_float.git
synced 2025-12-07 17:26:51 +08:00
Expose parsed string (before computation) so it can be reused
This commit is contained in:
parent
7385c2053b
commit
8f94758c78
@ -96,6 +96,7 @@ typedef span<const char> byte_span;
|
||||
struct parsed_number_string {
|
||||
int64_t exponent{0};
|
||||
uint64_t mantissa{0};
|
||||
uint64_t integer_value{-1};
|
||||
const char *lastmatch{nullptr};
|
||||
bool negative{false};
|
||||
bool valid{false};
|
||||
@ -143,6 +144,7 @@ parsed_number_string parse_number_string(const char *p, const char *pend, parse_
|
||||
const char *const end_of_integer_part = p;
|
||||
int64_t digit_count = int64_t(end_of_integer_part - start_digits);
|
||||
answer.integer = byte_span(start_digits, size_t(digit_count));
|
||||
answer.integer_value = i;
|
||||
int64_t exponent = 0;
|
||||
if ((p != pend) && (*p == decimal_point)) {
|
||||
++p;
|
||||
|
||||
@ -62,6 +62,16 @@ FASTFLOAT_CONSTEXPR20
|
||||
from_chars_result from_chars_advanced(const char *first, const char *last,
|
||||
T &value, parse_options options) noexcept;
|
||||
|
||||
} // namespace fast_float
|
||||
}
|
||||
|
||||
#include "ascii_number.h" // parsed_number_string
|
||||
|
||||
namespace fast_float {
|
||||
template <typename T>
|
||||
FASTFLOAT_CONSTEXPR20
|
||||
from_chars_result from_chars_preparsed(parsed_number_string parsed, T& value) noexcept;
|
||||
}
|
||||
|
||||
// namespace fast_float
|
||||
#include "parse_number.h"
|
||||
#endif // FASTFLOAT_FAST_FLOAT_H
|
||||
|
||||
@ -141,24 +141,12 @@ from_chars_result from_chars(const char *first, const char *last,
|
||||
|
||||
template<typename T>
|
||||
FASTFLOAT_CONSTEXPR20
|
||||
from_chars_result from_chars_advanced(const char *first, const char *last,
|
||||
T &value, parse_options options) noexcept {
|
||||
|
||||
from_chars_result from_chars_preparsed(parsed_number_string pns, T& value) noexcept
|
||||
{
|
||||
static_assert (std::is_same<T, double>::value || std::is_same<T, float>::value, "only float and double are supported");
|
||||
|
||||
|
||||
|
||||
from_chars_result answer;
|
||||
#if FASTFLOAT_SKIP_WHITE_SPACE // disabled by default
|
||||
while ((first != last) && fast_float::is_space(uint8_t(*first))) {
|
||||
first++;
|
||||
}
|
||||
#endif
|
||||
if (first == last) {
|
||||
answer.ec = std::errc::invalid_argument;
|
||||
answer.ptr = first;
|
||||
return answer;
|
||||
}
|
||||
parsed_number_string pns = parse_number_string(first, last, options);
|
||||
if (!pns.valid) {
|
||||
return detail::parse_infnan(first, last, value);
|
||||
}
|
||||
@ -217,6 +205,26 @@ from_chars_result from_chars_advanced(const char *first, const char *last,
|
||||
return answer;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
FASTFLOAT_CONSTEXPR20
|
||||
from_chars_result from_chars_advanced(const char *first, const char *last,
|
||||
T &value, parse_options options) noexcept {
|
||||
|
||||
from_chars_result answer;
|
||||
#if FASTFLOAT_SKIP_WHITE_SPACE // disabled by default
|
||||
while ((first != last) && fast_float::is_space(uint8_t(*first))) {
|
||||
first++;
|
||||
}
|
||||
#endif
|
||||
if (first == last) {
|
||||
answer.ec = std::errc::invalid_argument;
|
||||
answer.ptr = first;
|
||||
return answer;
|
||||
}
|
||||
answer = from_chars_preparsed(parse_number_string(first, last, options), value);
|
||||
return answer;
|
||||
}
|
||||
|
||||
} // namespace fast_float
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user