mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-02-08 03:50:25 +00:00
Follow JSON rules for what looks like a number in a CSV
This commit is contained in:
parent
6467a5b70d
commit
1960eb8dae
59
csv.cpp
59
csv.cpp
@ -92,3 +92,62 @@ void readcsv(char *fn, std::vector<std::string> &header, std::map<std::string, s
|
|||||||
exit(EXIT_FAILURE);
|
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;
|
||||||
|
}
|
||||||
|
2
csv.hpp
2
csv.hpp
@ -10,5 +10,7 @@
|
|||||||
std::vector<std::string> csv_split(char *s);
|
std::vector<std::string> csv_split(char *s);
|
||||||
std::string csv_dequote(std::string s);
|
std::string csv_dequote(std::string s);
|
||||||
void readcsv(char *fn, std::vector<std::string> &header, std::map<std::string, std::vector<std::string>> &mapping);
|
void readcsv(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
|
#endif
|
||||||
|
@ -213,7 +213,7 @@ void handle(std::string message, int z, unsigned x, unsigned y, std::map<std::st
|
|||||||
if (joinval.size() > 0) {
|
if (joinval.size() > 0) {
|
||||||
if (joinval[0] == '"') {
|
if (joinval[0] == '"') {
|
||||||
joinval = csv_dequote(joinval);
|
joinval = csv_dequote(joinval);
|
||||||
} else if ((joinval[0] >= '0' && joinval[0] <= '9') || joinval[0] == '-') {
|
} else if (is_number(joinval)) {
|
||||||
attr_type = mvt_double;
|
attr_type = mvt_double;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user