diff --git a/csv.cpp b/csv.cpp index 50f09c0..9a3acb3 100644 --- a/csv.cpp +++ b/csv.cpp @@ -92,3 +92,62 @@ void readcsv(const char *fn, std::vector &header, std::map= '0' && c <= '9')) { + if (c == '-') { + c = *(cp++); + } + + if (c == '0') { + ; + } else if (c >= '1' && c <= '9') { + c = *cp; + + while (c >= '0' && c <= '9') { + cp++; + c = *cp; + } + } + + if (*cp == '.') { + cp++; + + c = *cp; + if (c < '0' || c > '9') { + return false; + } + while (c >= '0' && c <= '9') { + cp++; + c = *cp; + } + } + + c = *cp; + if (c == 'e' || c == 'E') { + cp++; + + c = *cp; + if (c == '+' || c == '-') { + cp++; + } + + c = *cp; + if (c < '0' || c > '9') { + return false; + } + while (c >= '0' && c <= '9') { + cp++; + c = *cp; + } + } + + return true; + } + + return false; +} diff --git a/csv.hpp b/csv.hpp index 25b3862..6c5c4bb 100644 --- a/csv.hpp +++ b/csv.hpp @@ -11,5 +11,6 @@ std::vector csv_split(const char *s); std::string csv_dequote(std::string s); void readcsv(const char *fn, std::vector &header, std::map> &mapping); std::string csv_getline(FILE *f); +bool is_number(std::string const &s); #endif diff --git a/jsontool.cpp b/jsontool.cpp index ad0291c..7c4e61d 100644 --- a/jsontool.cpp +++ b/jsontool.cpp @@ -190,10 +190,6 @@ void out(std::string const &s, int type, json_object *properties) { std::string prev_joinkey; -bool is_number(std::string const &s) { - return false; // XXX -} - void join_csv(json_object *j) { if (header.size() == 0) { std::string s = csv_getline(csvfile); diff --git a/tile-join.cpp b/tile-join.cpp index c7382e7..998a971 100644 --- a/tile-join.cpp +++ b/tile-join.cpp @@ -207,7 +207,7 @@ void handle(std::string message, int z, unsigned x, unsigned y, std::map 0) { if (joinval[0] == '"') { joinval = csv_dequote(joinval); - } else if ((joinval[0] >= '0' && joinval[0] <= '9') || joinval[0] == '-') { + } else if (is_number(joinval)) { attr_type = mvt_double; } }