diff --git a/include/internal/data_type.h b/include/internal/data_type.h index b10d8690..f4789711 100644 --- a/include/internal/data_type.h +++ b/include/internal/data_type.h @@ -241,9 +241,9 @@ namespace csv { return DataType::CSV_NULL; bool ws_allowed = true, - neg_allowed = true, dot_allowed = true, digit_allowed = true, + is_negative = false, has_digit = false, prob_float = false; @@ -268,12 +268,12 @@ namespace csv { } break; case '-': - if (!neg_allowed) { + if (!ws_allowed) { // Ex: '510-123-4567' return DataType::CSV_STRING; } - neg_allowed = false; + is_negative = true; break; case '.': if (!dot_allowed) { @@ -297,7 +297,7 @@ namespace csv { return _process_potential_exponential( in.substr(exponent_start_idx), - neg_allowed ? integral_part + decimal_part : -(integral_part + decimal_part), + is_negative ? -(integral_part + decimal_part) : integral_part + decimal_part, out ); } @@ -331,7 +331,7 @@ namespace csv { if (has_digit) { long double number = integral_part + decimal_part; if (out) { - *out = neg_allowed ? number : -number; + *out = is_negative ? -number : number; } return prob_float ? DataType::CSV_DOUBLE : _determine_integral_type(number); diff --git a/single_include/csv.hpp b/single_include/csv.hpp index 9cebfc2b..da165928 100644 --- a/single_include/csv.hpp +++ b/single_include/csv.hpp @@ -5328,7 +5328,7 @@ namespace csv { } break; case '-': - if (!neg_allowed) { + if (!ws_allowed) { // Ex: '510-123-4567' return DataType::CSV_STRING; } diff --git a/single_include_test/csv.hpp b/single_include_test/csv.hpp index 9cebfc2b..da165928 100644 --- a/single_include_test/csv.hpp +++ b/single_include_test/csv.hpp @@ -5328,7 +5328,7 @@ namespace csv { } break; case '-': - if (!neg_allowed) { + if (!ws_allowed) { // Ex: '510-123-4567' return DataType::CSV_STRING; } diff --git a/tests/test_data_type.cpp b/tests/test_data_type.cpp index ff82369c..030e82d4 100644 --- a/tests/test_data_type.cpp +++ b/tests/test_data_type.cpp @@ -163,4 +163,10 @@ TEST_CASE("Parse Scientific Notation Malformed", "[sci_notation]") { SECTION("Butchered Parsing Attempt") { REQUIRE(data_type(butchered) == DataType::CSV_STRING); } -} \ No newline at end of file +} + +TEST_CASE( "Parse numbers with dash as string", "[regression_double]" ) { + std::string s("510-123-4567"); + long double out; + REQUIRE(data_type(s, &out) == DataType::CSV_STRING); +}