Skip to content

Commit 48252a6

Browse files
committed
check feature macros in once place
1 parent 0bbba96 commit 48252a6

File tree

3 files changed

+18
-25
lines changed

3 files changed

+18
-25
lines changed

include/fast_float/ascii_number.h

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -283,23 +283,18 @@ template <typename UC>
283283
fastfloat_really_inline FASTFLOAT_CONSTEXPR20 parsed_number_string_t<UC>
284284
parse_number_string(UC const *p, UC const *pend,
285285
parse_options_t<UC> options) noexcept {
286-
chars_format const fmt = options.format;
286+
chars_format const fmt = detail::adjust_for_feature_macros(options.format);
287287
UC const decimal_point = options.decimal_point;
288288

289289
parsed_number_string_t<UC> answer;
290290
answer.valid = false;
291291
answer.too_many_digits = false;
292292
// assume p < pend, so dereference without checks;
293293
answer.negative = (*p == UC('-'));
294-
#ifdef FASTFLOAT_ALLOWS_LEADING_PLUS // disabled by default
295-
if ((*p == UC('-')) ||
296-
(!uint64_t(fmt & detail::basic_json_fmt) && *p == UC('+'))) {
297-
#else
298294
// C++17 20.19.3.(7.1) explicitly forbids '+' sign here
299295
if ((*p == UC('-')) ||
300296
(uint64_t(fmt & chars_format::allow_leading_plus) &&
301297
!uint64_t(fmt & detail::basic_json_fmt) && *p == UC('+'))) {
302-
#endif
303298
++p;
304299
if (p == pend) {
305300
return report_parse_error<UC>(
@@ -479,7 +474,7 @@ template <typename T, typename UC>
479474
fastfloat_really_inline FASTFLOAT_CONSTEXPR20 from_chars_result_t<UC>
480475
parse_int_string(UC const *p, UC const *pend, T &value,
481476
parse_options_t<UC> options) {
482-
chars_format const fmt = options.format;
477+
chars_format const fmt = detail::adjust_for_feature_macros(options.format);
483478
int const base = options.base;
484479

485480
from_chars_result_t<UC> answer;
@@ -492,12 +487,8 @@ parse_int_string(UC const *p, UC const *pend, T &value,
492487
answer.ptr = first;
493488
return answer;
494489
}
495-
#ifdef FASTFLOAT_ALLOWS_LEADING_PLUS // disabled by default
496-
if ((*p == UC('-')) || (*p == UC('+'))) {
497-
#else
498490
if ((*p == UC('-')) ||
499491
(uint64_t(fmt & chars_format::allow_leading_plus) && (*p == UC('+')))) {
500-
#endif
501492
++p;
502493
}
503494

include/fast_float/float_common.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,20 @@ operator^=(chars_format &lhs, chars_format rhs) noexcept {
841841
return lhs = (lhs ^ rhs);
842842
}
843843

844+
namespace detail {
845+
// adjust for deprecated feature macros
846+
constexpr chars_format adjust_for_feature_macros(chars_format fmt) {
847+
return fmt
848+
#ifdef FASTFLOAT_ALLOWS_LEADING_PLUS
849+
| chars_format::allow_leading_plus
850+
#endif
851+
#ifdef FASTFLOAT_SKIP_WHITE_SPACE
852+
| chars_format::skip_white_space
853+
#endif
854+
;
855+
}
856+
} // namespace detail
857+
844858
} // namespace fast_float
845859

846860
#endif

include/fast_float/parse_number.h

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,10 @@ from_chars_result_t<UC>
2727
answer.ec = std::errc(); // be optimistic
2828
// assume first < last, so dereference without checks;
2929
bool const minusSign = (*first == UC('-'));
30-
#ifdef FASTFLOAT_ALLOWS_LEADING_PLUS // disabled by default
31-
if ((*first == UC('-')) || (*first == UC('+'))) {
32-
#else
3330
// C++17 20.19.3.(7.1) explicitly forbids '+' sign here
3431
if ((*first == UC('-')) ||
3532
(uint64_t(fmt & chars_format::allow_leading_plus) &&
3633
(*first == UC('+')))) {
37-
#endif
3834
++first;
3935
}
4036
if (last - first >= 3) {
@@ -294,18 +290,14 @@ from_chars_float_advanced(UC const *first, UC const *last, T &value,
294290
static_assert(is_supported_char_type<UC>(),
295291
"only char, wchar_t, char16_t and char32_t are supported");
296292

297-
chars_format const fmt = options.format;
293+
chars_format const fmt = detail::adjust_for_feature_macros(options.format);
298294

299295
from_chars_result_t<UC> answer;
300-
#ifndef FASTFLOAT_SKIP_WHITE_SPACE // disabled by default
301296
if (uint64_t(fmt & chars_format::skip_white_space)) {
302-
#endif
303297
while ((first != last) && fast_float::is_space(uint8_t(*first))) {
304298
first++;
305299
}
306-
#ifndef FASTFLOAT_SKIP_WHITE_SPACE // disabled by default
307300
}
308-
#endif
309301
if (first == last) {
310302
answer.ec = std::errc::invalid_argument;
311303
answer.ptr = first;
@@ -349,19 +341,15 @@ from_chars_int_advanced(UC const *first, UC const *last, T &value,
349341
static_assert(is_supported_char_type<UC>(),
350342
"only char, wchar_t, char16_t and char32_t are supported");
351343

352-
chars_format const fmt = options.format;
344+
chars_format const fmt = detail::adjust_for_feature_macros(options.format);
353345
int const base = options.base;
354346

355347
from_chars_result_t<UC> answer;
356-
#ifndef FASTFLOAT_SKIP_WHITE_SPACE // disabled by default
357348
if (uint64_t(fmt & chars_format::skip_white_space)) {
358-
#endif
359349
while ((first != last) && fast_float::is_space(uint8_t(*first))) {
360350
first++;
361351
}
362-
#ifndef FASTFLOAT_SKIP_WHITE_SPACE // disabled by default
363352
}
364-
#endif
365353
if (first == last || base < 2 || base > 36) {
366354
answer.ec = std::errc::invalid_argument;
367355
answer.ptr = first;

0 commit comments

Comments
 (0)