Skip to content

Commit 20544ba

Browse files
committed
support UTF-8 in old Writers
We had already fixed Value to hold UTF-8 properly, but only the newer StreamWriter was writing UTF-8 properly. Old FasterWriter etc. were using asCString() instead of asString() in Value::writeValue(). Hopefully this change does not break any existing code. Seems unlikely. issue #240
1 parent 9cb88d2 commit 20544ba

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

Diff for: src/lib_json/json_writer.cpp

+16-3
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,14 @@ void FastWriter::writeValue(const Value& value) {
317317
document_ += valueToString(value.asDouble());
318318
break;
319319
case stringValue:
320-
document_ += valueToQuotedString(value.asCString());
320+
{
321+
// Is NULL possible for value.string_?
322+
char const* str;
323+
char const* end;
324+
bool ok = value.getString(&str, &end);
325+
if (ok) document_ += valueToQuotedStringN(str, static_cast<unsigned>(end-str));
321326
break;
327+
}
322328
case booleanValue:
323329
document_ += valueToString(value.asBool());
324330
break;
@@ -382,7 +388,7 @@ void StyledWriter::writeValue(const Value& value) {
382388
break;
383389
case stringValue:
384390
{
385-
// Is NULL is possible for value.string_?
391+
// Is NULL possible for value.string_?
386392
char const* str;
387393
char const* end;
388394
bool ok = value.getString(&str, &end);
@@ -599,8 +605,15 @@ void StyledStreamWriter::writeValue(const Value& value) {
599605
pushValue(valueToString(value.asDouble()));
600606
break;
601607
case stringValue:
602-
pushValue(valueToQuotedString(value.asCString()));
608+
{
609+
// Is NULL possible for value.string_?
610+
char const* str;
611+
char const* end;
612+
bool ok = value.getString(&str, &end);
613+
if (ok) pushValue(valueToQuotedStringN(str, static_cast<unsigned>(end-str)));
614+
else pushValue("");
603615
break;
616+
}
604617
case booleanValue:
605618
pushValue(valueToString(value.asBool()));
606619
break;

0 commit comments

Comments
 (0)