Skip to content

Commit b3189a0

Browse files
authored
avoid isprint, because it is locale specific (open-source-parsers#1189)
* avoid isprint `std::isprint` is locale-specific and the JSON-spec is not. In particular, isprint('\t') is true in Windows CP1252. Has bitten others, e.g. laurikari/tre#64 Fixes open-source-parsers#1187 * semicolon (rookie mistake!)
1 parent 9be5895 commit b3189a0

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/lib_json/json_writer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,11 @@ String valueToString(double value, unsigned int precision,
175175

176176
String valueToString(bool value) { return value ? "true" : "false"; }
177177

178-
static bool isAnyCharRequiredQuoting(char const* s, size_t n) {
178+
static bool doesAnyCharRequireEscaping(char const* s, size_t n) {
179179
assert(s || !n);
180180

181181
return std::any_of(s, s + n, [](unsigned char c) {
182-
return c == '\\' || c == '"' || !std::isprint(c);
182+
return c == '\\' || c == '"' || c < 0x20 || c > 0x7F;
183183
});
184184
}
185185

@@ -275,7 +275,7 @@ static String valueToQuotedStringN(const char* value, unsigned length,
275275
if (value == nullptr)
276276
return "";
277277

278-
if (!isAnyCharRequiredQuoting(value, length))
278+
if (!doesAnyCharRequireEscaping(value, length))
279279
return String("\"") + value + "\"";
280280
// We have to walk value and escape any special characters.
281281
// Appending to String is not efficient, but this should be rare.

0 commit comments

Comments
 (0)