diff --git a/tests/fortran.cpp b/tests/fortran.cpp index 5b8c95e..79429bd 100644 --- a/tests/fortran.cpp +++ b/tests/fortran.cpp @@ -4,15 +4,14 @@ #include #include #include - -#define FASTFLOAT_ALLOWS_LEADING_PLUS - #include "fast_float/fast_float.h" int main_readme() { const std::string input = "1d+4"; double result; - fast_float::parse_options options{fast_float::chars_format::fortran}; + fast_float::parse_options options{ + fast_float::chars_format::fortran | + fast_float::chars_format::allow_leading_plus}; auto answer = fast_float::from_chars_advanced( input.data(), input.data() + input.size(), result, options); if ((answer.ec != std::errc()) || ((result != 10000))) { @@ -32,7 +31,9 @@ int main() { "1d-1", "1d-2", "1d-3", "1d-4"}; const std::vector fmt3{"+1+4", "+1+3", "+1+2", "+1+1", "+1+0", "+1-1", "+1-2", "+1-3", "+1-4"}; - const fast_float::parse_options options{fast_float::chars_format::fortran}; + const fast_float::parse_options options{ + fast_float::chars_format::fortran | + fast_float::chars_format::allow_leading_plus}; for (auto const &f : fmt1) { auto d{std::distance(&fmt1[0], &f)}; diff --git a/tests/json_fmt.cpp b/tests/json_fmt.cpp index 53b6078..b7bfa91 100644 --- a/tests/json_fmt.cpp +++ b/tests/json_fmt.cpp @@ -2,16 +2,14 @@ #include #include #include - -// test that this option is ignored -#define FASTFLOAT_ALLOWS_LEADING_PLUS - #include "fast_float/fast_float.h" int main_readme() { const std::string input = "+.1"; // not valid double result; - fast_float::parse_options options{fast_float::chars_format::json}; + fast_float::parse_options options{ + fast_float::chars_format::json | + fast_float::chars_format::allow_leading_plus}; // should be ignored auto answer = fast_float::from_chars_advanced( input.data(), input.data() + input.size(), result, options); if (answer.ec == std::errc()) { @@ -24,7 +22,9 @@ int main_readme() { int main_readme2() { const std::string input = "inf"; // not valid in JSON double result; - fast_float::parse_options options{fast_float::chars_format::json}; + fast_float::parse_options options{ + fast_float::chars_format::json | + fast_float::chars_format::allow_leading_plus}; // should be ignored auto answer = fast_float::from_chars_advanced( input.data(), input.data() + input.size(), result, options); if (answer.ec == std::errc()) { @@ -38,7 +38,9 @@ int main_readme3() { const std::string input = "inf"; // not valid in JSON but we allow it with json_or_infnan double result; - fast_float::parse_options options{fast_float::chars_format::json_or_infnan}; + fast_float::parse_options options{ + fast_float::chars_format::json_or_infnan | + fast_float::chars_format::allow_leading_plus}; // should be ignored auto answer = fast_float::from_chars_advanced( input.data(), input.data() + input.size(), result, options); if (answer.ec != std::errc() || (!std::isinf(result))) { @@ -129,7 +131,9 @@ int main() { const auto &expected_reason = reject[i].reason; auto answer = fast_float::parse_number_string( f.data(), f.data() + f.size(), - fast_float::parse_options(fast_float::chars_format::json)); + fast_float::parse_options( + fast_float::chars_format::json | + fast_float::chars_format::allow_leading_plus)); // should be ignored if (answer.valid) { std::cerr << "json parse accepted invalid json " << f << std::endl; return EXIT_FAILURE; diff --git a/tests/rcppfastfloat_test.cpp b/tests/rcppfastfloat_test.cpp index 2e6985b..f2cad42 100644 --- a/tests/rcppfastfloat_test.cpp +++ b/tests/rcppfastfloat_test.cpp @@ -2,8 +2,6 @@ * See https://github.com/eddelbuettel/rcppfastfloat/issues/4 */ -#define FASTFLOAT_ALLOWS_LEADING_PLUS 1 -#define FASTFLOAT_SKIP_WHITE_SPACE 1 // important ! #include "fast_float/fast_float.h" #include #include @@ -61,7 +59,10 @@ bool eddelbuettel() { // answer contains a error code and a pointer to the end of the // parsed region (on success). auto const answer = fast_float::from_chars( - input.data(), input.data() + input.size(), result); + input.data(), input.data() + input.size(), result, + fast_float::chars_format::general | + fast_float::chars_format::allow_leading_plus | + fast_float::chars_format::skip_white_space); if (answer.ec != std::errc()) { std::cout << "could not parse" << std::endl; if (expected_success) {