diff --git a/plugins/input/csv/csv_datasource.cpp b/plugins/input/csv/csv_datasource.cpp index 8b609b059..c02f1e20b 100644 --- a/plugins/input/csv/csv_datasource.cpp +++ b/plugins/input/csv/csv_datasource.cpp @@ -694,10 +694,7 @@ void csv_datasource::parse_csv(T & stream, desc_.add_descriptor(mapnik::attribute_descriptor(fld_name,mapnik::String)); } } - else if ((value[0] >= '0' && value[0] <= '9') || - value[0] == '-' || - value[0] == '+' || - value[0] == '.') + else if (csv_utils::is_likely_number(value)) { bool has_e = value.find("e") != std::string::npos; if (has_dot || has_e) diff --git a/plugins/input/csv/csv_utils.hpp b/plugins/input/csv/csv_utils.hpp index 3fdcaa3c8..fd9143fee 100644 --- a/plugins/input/csv/csv_utils.hpp +++ b/plugins/input/csv/csv_utils.hpp @@ -26,9 +26,15 @@ #include #include +#include namespace csv_utils { + static inline bool is_likely_number(std::string const& value) + { + return( strspn( value.c_str(), "e-.+0123456789" ) == value.size() ); + } + static inline void fix_json_quoting(std::string & csv_line) { std::string wrapping_char;