aboutsummaryrefslogtreecommitdiff
path: root/src/google/protobuf/util/internal/json_objectwriter.cc
diff options
context:
space:
mode:
authorBo Yang <teboring@google.com>2016-09-19 13:45:07 -0700
committerBo Yang <teboring@google.com>2016-10-10 11:23:36 -0700
commitcc8ca5b6a5478b40546d4206392eb1471454460d (patch)
treec0b45abfa16d7d373a6ea8f7fe50f1de00ab938e /src/google/protobuf/util/internal/json_objectwriter.cc
parent337a028bb65ccca4dda768695950b5aba53ae2c9 (diff)
downloadprotobuf-cc8ca5b6a5478b40546d4206392eb1471454460d.tar.gz
protobuf-cc8ca5b6a5478b40546d4206392eb1471454460d.tar.bz2
protobuf-cc8ca5b6a5478b40546d4206392eb1471454460d.zip
Integrate internal changes
Diffstat (limited to 'src/google/protobuf/util/internal/json_objectwriter.cc')
-rw-r--r--src/google/protobuf/util/internal/json_objectwriter.cc21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/google/protobuf/util/internal/json_objectwriter.cc b/src/google/protobuf/util/internal/json_objectwriter.cc
index b84210c1..6e4edd88 100644
--- a/src/google/protobuf/util/internal/json_objectwriter.cc
+++ b/src/google/protobuf/util/internal/json_objectwriter.cc
@@ -147,7 +147,7 @@ JsonObjectWriter* JsonObjectWriter::RenderBytes(StringPiece name,
string base64;
if (use_websafe_base64_for_bytes_)
- WebSafeBase64Escape(value.ToString(), &base64);
+ WebSafeBase64EscapeWithPadding(value.ToString(), &base64);
else
Base64Escape(value, &base64);
@@ -164,19 +164,32 @@ JsonObjectWriter* JsonObjectWriter::RenderNull(StringPiece name) {
return RenderSimple(name, "null");
}
+JsonObjectWriter* JsonObjectWriter::RenderNullAsEmpty(StringPiece name) {
+ return RenderSimple(name, "");
+}
+
void JsonObjectWriter::WritePrefix(StringPiece name) {
bool not_first = !element()->is_first();
if (not_first) WriteChar(',');
if (not_first || !element()->is_root()) NewLine();
- if (!name.empty()) {
+ bool empty_key_ok = GetAndResetEmptyKeyOk();
+ if (!name.empty() || empty_key_ok) {
WriteChar('"');
- ArrayByteSource source(name);
- JsonEscaping::Escape(&source, &sink_);
+ if (!name.empty()) {
+ ArrayByteSource source(name);
+ JsonEscaping::Escape(&source, &sink_);
+ }
stream_->WriteString("\":");
if (!indent_string_.empty()) WriteChar(' ');
}
}
+bool JsonObjectWriter::GetAndResetEmptyKeyOk() {
+ bool retval = empty_name_ok_for_next_key_;
+ empty_name_ok_for_next_key_ = false;
+ return retval;
+}
+
} // namespace converter
} // namespace util
} // namespace protobuf