Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmarks/benchmark.cpp
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move the #include "event_counter.h" at the top of the file outside of the ifdef? That way it will compile on Windows too.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ int main(int argc, char **argv) {
<< std::endl;
#endif
}
if(argc > 1) {
if (argc > 1) {
fileload(argv[1]);
return EXIT_SUCCESS;
}
Expand Down
13 changes: 6 additions & 7 deletions include/fast_float/ascii_number.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ report_parse_error(UC const *p, parse_error error) {

// Assuming that you use no more than 19 digits, this will
// parse an ASCII string.
template <typename UC>
template <bool basic_json_fmt, typename UC>
fastfloat_really_inline FASTFLOAT_CONSTEXPR20 parsed_number_string_t<UC>
parse_number_string(UC const *p, UC const *pend,
parse_options_t<UC> options) noexcept {
Expand All @@ -292,15 +292,14 @@ parse_number_string(UC const *p, UC const *pend,
// assume p < pend, so dereference without checks;
answer.negative = (*p == UC('-'));
// C++17 20.19.3.(7.1) explicitly forbids '+' sign here
if ((*p == UC('-')) ||
(uint64_t(fmt & chars_format::allow_leading_plus) &&
!uint64_t(fmt & detail::basic_json_fmt) && *p == UC('+'))) {
if ((*p == UC('-')) || (uint64_t(fmt & chars_format::allow_leading_plus) &&
!basic_json_fmt && *p == UC('+'))) {
++p;
if (p == pend) {
return report_parse_error<UC>(
p, parse_error::missing_integer_or_dot_after_sign);
}
if (uint64_t(fmt & detail::basic_json_fmt)) {
if (basic_json_fmt) {
if (!is_integer(*p)) { // a sign must be followed by an integer
return report_parse_error<UC>(p,
parse_error::missing_integer_after_sign);
Expand Down Expand Up @@ -329,7 +328,7 @@ parse_number_string(UC const *p, UC const *pend,
UC const *const end_of_integer_part = p;
int64_t digit_count = int64_t(end_of_integer_part - start_digits);
answer.integer = span<UC const>(start_digits, size_t(digit_count));
if (uint64_t(fmt & detail::basic_json_fmt)) {
if (basic_json_fmt) {
// at least 1 digit in integer part, without leading zeros
if (digit_count == 0) {
return report_parse_error<UC>(p, parse_error::no_digits_in_integer_part);
Expand Down Expand Up @@ -358,7 +357,7 @@ parse_number_string(UC const *p, UC const *pend,
answer.fraction = span<UC const>(before, size_t(p - before));
digit_count -= exponent;
}
if (uint64_t(fmt & detail::basic_json_fmt)) {
if (basic_json_fmt) {
// at least 1 digit in fractional part
if (has_decimal_point && exponent == 0) {
return report_parse_error<UC>(p,
Expand Down
4 changes: 3 additions & 1 deletion include/fast_float/parse_number.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,9 @@ from_chars_float_advanced(UC const *first, UC const *last, T &value,
return answer;
}
parsed_number_string_t<UC> pns =
parse_number_string<UC>(first, last, options);
uint64_t(fmt & detail::basic_json_fmt)
? parse_number_string<true, UC>(first, last, options)
: parse_number_string<false, UC>(first, last, options);
if (!pns.valid) {
if (uint64_t(fmt & chars_format::no_infnan)) {
answer.ec = std::errc::invalid_argument;
Expand Down
2 changes: 1 addition & 1 deletion tests/json_fmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ int main() {
for (std::size_t i = 0; i < reject.size(); ++i) {
auto const &f = reject[i].input;
auto const &expected_reason = reject[i].reason;
auto answer = fast_float::parse_number_string(
auto answer = fast_float::parse_number_string<true>(
f.data(), f.data() + f.size(),
fast_float::parse_options(
fast_float::chars_format::json |
Expand Down
Loading