Output JSON strings as natural UTF-8 text without escapes (#4710)

* Added support for the non-escaped print of utf-8 string.

* EscapeString: the first invalid symbol resets print_natural_utf8 flag to false.

* Move the test to ParseAndGenerateTextTest. Fixes.

* Removed dependence between `natural_utf8` and `allow_non_utf8` flags.
This commit is contained in:
Vladimir Glavnyy
2018-05-04 02:10:45 +07:00
committed by Wouter van Oortmerssen
parent 85faa46fb3
commit 12c4c2238c
9 changed files with 55 additions and 16 deletions

View File

@@ -495,14 +495,14 @@ class Reference {
if (type_ == TYPE_STRING) {
String str(Indirect(), byte_width_);
if (strings_quoted) {
flatbuffers::EscapeString(str.c_str(), str.length(), &s, true);
flatbuffers::EscapeString(str.c_str(), str.length(), &s, true, false);
} else {
s.append(str.c_str(), str.length());
}
} else if (IsKey()) {
auto str = AsKey();
if (keys_quoted) {
flatbuffers::EscapeString(str, strlen(str), &s, true);
flatbuffers::EscapeString(str, strlen(str), &s, true, false);
} else {
s += str;
}