Skip to content

Commit 92c79d0

Browse files
authored
Merge pull request #249 from zejal/main
from_chars_advanced overload function taking parsed_number_string_t
2 parents c8b3ca0 + 85911ab commit 92c79d0

File tree

1 file changed

+41
-22
lines changed

1 file changed

+41
-22
lines changed

include/fast_float/parse_number.h

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -187,35 +187,20 @@ from_chars_result_t<UC> from_chars(UC const * first, UC const * last,
187187
return from_chars_caller<T>::call(first, last, value, parse_options_t<UC>(fmt));
188188
}
189189

190+
/**
191+
* This function overload takes parsed_number_string_t structure that is created and populated
192+
* either by from_chars_advanced function taking chars range and parsing options
193+
* or other parsing custom function implemented by user.
194+
*/
190195
template<typename T, typename UC>
191196
FASTFLOAT_CONSTEXPR20
192-
from_chars_result_t<UC> from_chars_advanced(UC const * first, UC const * last,
193-
T &value, parse_options_t<UC> options) noexcept {
197+
from_chars_result_t<UC> from_chars_advanced(parsed_number_string_t<UC>& pns,
198+
T &value) noexcept {
194199

195200
static_assert (is_supported_float_type<T>(), "only some floating-point types are supported");
196201
static_assert (is_supported_char_type<UC>(), "only char, wchar_t, char16_t and char32_t are supported");
197202

198203
from_chars_result_t<UC> answer;
199-
#ifdef FASTFLOAT_SKIP_WHITE_SPACE // disabled by default
200-
while ((first != last) && fast_float::is_space(uint8_t(*first))) {
201-
first++;
202-
}
203-
#endif
204-
if (first == last) {
205-
answer.ec = std::errc::invalid_argument;
206-
answer.ptr = first;
207-
return answer;
208-
}
209-
parsed_number_string_t<UC> pns = parse_number_string<UC>(first, last, options);
210-
if (!pns.valid) {
211-
if (options.format & chars_format::no_infnan) {
212-
answer.ec = std::errc::invalid_argument;
213-
answer.ptr = first;
214-
return answer;
215-
} else {
216-
return detail::parse_infnan(first, last, value);
217-
}
218-
}
219204

220205
answer.ec = std::errc(); // be optimistic
221206
answer.ptr = pns.lastmatch;
@@ -276,6 +261,40 @@ from_chars_result_t<UC> from_chars_advanced(UC const * first, UC const * last,
276261
return answer;
277262
}
278263

264+
template<typename T, typename UC>
265+
FASTFLOAT_CONSTEXPR20
266+
from_chars_result_t<UC> from_chars_advanced(UC const * first, UC const * last,
267+
T &value, parse_options_t<UC> options) noexcept {
268+
269+
static_assert (is_supported_float_type<T>(), "only some floating-point types are supported");
270+
static_assert (is_supported_char_type<UC>(), "only char, wchar_t, char16_t and char32_t are supported");
271+
272+
from_chars_result_t<UC> answer;
273+
#ifdef FASTFLOAT_SKIP_WHITE_SPACE // disabled by default
274+
while ((first != last) && fast_float::is_space(uint8_t(*first))) {
275+
first++;
276+
}
277+
#endif
278+
if (first == last) {
279+
answer.ec = std::errc::invalid_argument;
280+
answer.ptr = first;
281+
return answer;
282+
}
283+
parsed_number_string_t<UC> pns = parse_number_string<UC>(first, last, options);
284+
if (!pns.valid) {
285+
if (options.format & chars_format::no_infnan) {
286+
answer.ec = std::errc::invalid_argument;
287+
answer.ptr = first;
288+
return answer;
289+
} else {
290+
return detail::parse_infnan(first, last, value);
291+
}
292+
}
293+
294+
// call overload that takes parsed_number_string_t directly.
295+
return from_chars_advanced(pns, value);
296+
}
297+
279298

280299
template <typename T, typename UC, typename>
281300
FASTFLOAT_CONSTEXPR20

0 commit comments

Comments
 (0)