mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-03 00:45:41 +02:00
Exclude long attribute values from tilestats output, as specified
This commit is contained in:
@@ -50,3 +50,75 @@ std::string check_utf8(std::string s) {
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
const char *utf8_next(const char *s, long *c) {
|
||||
if (s == NULL) {
|
||||
*c = -1;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (*s == '\0') {
|
||||
*c = -1;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((s[0] & 0x80) == 0x80) {
|
||||
if ((s[0] & 0xE0) == 0xC0) {
|
||||
if ((s[1] & 0xC0) != 0x80) {
|
||||
*c = 0xFFFD;
|
||||
s++;
|
||||
} else {
|
||||
*c = ((long) (s[0] & 0x1F) << 6) | ((long) (s[1] & 0x7F));
|
||||
s += 2;
|
||||
}
|
||||
} else if ((s[0] & 0xF0) == 0xE0) {
|
||||
if ((s[1] & 0xC0) != 0x80 || (s[2] & 0xC0) != 0x80) {
|
||||
*c = 0xFFFD;
|
||||
s++;
|
||||
} else {
|
||||
*c = ((long) (s[0] & 0x0F) << 12) | ((long) (s[1] & 0x7F) << 6) | ((long) (s[2] & 0x7F));
|
||||
s += 3;
|
||||
}
|
||||
} else if ((s[0] & 0xF8) == 0xF0) {
|
||||
if ((s[1] & 0xC0) != 0x80 || (s[2] & 0xC0) != 0x80 || (s[3] & 0xC0) != 0x80) {
|
||||
*c = 0xFFFD;
|
||||
s++;
|
||||
} else {
|
||||
*c = ((long) (s[0] & 0x0F) << 18) | ((long) (s[1] & 0x7F) << 12) | ((long) (s[2] & 0x7F) << 6) | ((long) (s[3] & 0x7F));
|
||||
s += 4;
|
||||
}
|
||||
} else {
|
||||
*c = 0xFFFD;
|
||||
s++;
|
||||
}
|
||||
} else {
|
||||
*c = s[0];
|
||||
s++;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string truncate16(std::string const &s, size_t runes) {
|
||||
const char *cp = s.c_str();
|
||||
const char *start = cp;
|
||||
const char *lastgood = cp;
|
||||
size_t len = 0;
|
||||
long c;
|
||||
|
||||
while ((cp = utf8_next(cp, &c)) != NULL) {
|
||||
if (c <= 0xFFFF) {
|
||||
len++;
|
||||
} else {
|
||||
len += 2;
|
||||
}
|
||||
|
||||
if (len <= runes) {
|
||||
lastgood = cp;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return std::string(s, 0, lastgood - start);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user