short_numbers: leave hexadecimal input to the hex parser With chars_format::hex | chars_format::fixed (or general), the short path parsed "10" as ten instead of sixteen, and rejected "ff" as not starting a number. The hinted tests now also run the hex formats.
diff --git a/include/fast_float/parse_number.h b/include/fast_float/parse_number.h index 1a2da08..d985af9 100644 --- a/include/fast_float/parse_number.h +++ b/include/fast_float/parse_number.h
@@ -385,11 +385,13 @@ return false; } fmt = adjust_for_feature_macros(fmt); - // JSON and JavaScript have stricter rules (e.g., no "01" or "5."). The - // short parser cannot tell a decimal point that is a digit (e.g., V8 passes - // '0' so that parseInt stops after the integer part) from the digit itself. + // JSON and JavaScript have stricter rules (e.g., no "01" or "5."), and + // hexadecimal numbers have their own parser. The short parser cannot tell a + // decimal point that is a digit (e.g., V8 passes '0' so that parseInt stops + // after the integer part) from the digit itself. if (!uint64_t(fmt & chars_format::fixed) || - uint64_t(fmt & (basic_json_fmt | basic_javascript_fmt)) || + uint64_t(fmt & + (basic_json_fmt | basic_javascript_fmt | chars_format::hex)) || is_integer(decimal_point) || first == last) { return false; }
diff --git a/tests/performance_hints_test.cpp b/tests/performance_hints_test.cpp index d127f19..9429d86 100644 --- a/tests/performance_hints_test.cpp +++ b/tests/performance_hints_test.cpp
@@ -39,6 +39,9 @@ chars_format::scientific, chars_format::fixed, chars_format::json, + chars_format::hex, + chars_format::hex | chars_format::general, + chars_format::hex | chars_format::fixed, chars_format::json_or_infnan, chars_format::fortran, chars_format::javascript, @@ -330,7 +333,9 @@ // not numbers "auto", "none", "px", "x", "a1", "e5", "E5", "true", "undefined", "inherit", "Infinity", "infinity", "INF", "inf", "NaN", "nan", "nan(1)", - "i", "n", "Nope", "infx", " 1", "\t1", "_1", "(1)", "#1"}; + "i", "n", "Nope", "infx", " 1", "\t1", "_1", "(1)", "#1", + // hexadecimal digits + "10", "ff", "1.8", "a.b", "1p4", "-1p-1", "dead.bee", "FFFFFFFF"}; for (std::string const &s : cases) { if (!check_all(s)) { return EXIT_FAILURE;