mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-02-01 16:58:05 +00:00
Follow JSON rules for what looks like a number in a CSV
This commit is contained in:
parent
86a4ce67a6
commit
68a55b8749
59
csv.cpp
59
csv.cpp
@ -92,3 +92,62 @@ void readcsv(const char *fn, std::vector<std::string> &header, std::map<std::str
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
// Follow JSON rules for what looks like a number
|
||||
bool is_number(std::string const &s) {
|
||||
const char *cp = s.c_str();
|
||||
char c = *(cp++);
|
||||
|
||||
if (c == '-' || (c >= '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;
|
||||
}
|
||||
|
1
csv.hpp
1
csv.hpp
@ -11,5 +11,6 @@ std::vector<std::string> csv_split(const char *s);
|
||||
std::string csv_dequote(std::string s);
|
||||
void readcsv(const char *fn, std::vector<std::string> &header, std::map<std::string, std::vector<std::string>> &mapping);
|
||||
std::string csv_getline(FILE *f);
|
||||
bool is_number(std::string const &s);
|
||||
|
||||
#endif
|
||||
|
@ -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);
|
||||
|
@ -207,7 +207,7 @@ void handle(std::string message, int z, unsigned x, unsigned y, std::map<std::st
|
||||
if (joinval.size() > 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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user