Skip to content

Commit c2b988e

Browse files
committed
Merge pull request #241 from cdunn2001/fix-more-utf8
support UTF-8 (specifically, embedded zeroes) in old Writers
2 parents 779b5bc + e255ce3 commit c2b988e

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)