Index: runtime/vm/json_stream.cc |
diff --git a/runtime/vm/json_stream.cc b/runtime/vm/json_stream.cc |
index b77b01f3d4e67a57bdb32bfb34a18cc07167750e..d87ca013a0ec521825c860880c3dccaf37f8f781 100644 |
--- a/runtime/vm/json_stream.cc |
+++ b/runtime/vm/json_stream.cc |
@@ -217,11 +217,12 @@ void JSONStream::PrintValue(const char* s) { |
} |
-void JSONStream::PrintValue(const char* s, intptr_t len) { |
+bool JSONStream::PrintValueStr(const String& s, intptr_t limit) { |
PrintCommaIfNeeded(); |
buffer_.AddChar('"'); |
- AddEscapedUTF8String(s, len); |
+ bool did_truncate = AddDartString(s, limit); |
buffer_.AddChar('"'); |
+ return did_truncate; |
} |
@@ -310,9 +311,11 @@ void JSONStream::PrintProperty(const char* name, const char* s) { |
} |
-void JSONStream::PrintProperty(const char* name, const char* s, intptr_t len) { |
+bool JSONStream::PrintPropertyStr(const char* name, |
+ const String& s, |
+ intptr_t limit) { |
PrintPropertyName(name); |
- PrintValue(s, len); |
+ return PrintValueStr(s, limit); |
} |
@@ -441,7 +444,7 @@ void JSONStream::AddEscapedUTF8String(const char* s, intptr_t len) { |
int32_t ch = 0; |
int32_t ch_len = Utf8::Decode(&s8[i], len - i, &ch); |
ASSERT(ch_len != 0); |
- buffer_.AddEscapedChar(ch); |
+ buffer_.EscapeAndAddCodeUnit(ch); |
// Move i forward. |
i += ch_len; |
} |
@@ -449,6 +452,26 @@ void JSONStream::AddEscapedUTF8String(const char* s, intptr_t len) { |
} |
+bool JSONStream::AddDartString(const String& s, intptr_t limit) { |
+ bool did_truncate = false; |
+ intptr_t length = s.Length(); |
+ if (limit == -1) { |
+ limit = length; |
+ } |
+ if (length <= limit) { |
+ limit = length; |
+ } else { |
+ did_truncate = true; |
+ } |
+ |
+ for (intptr_t i = 0; i < limit; i++) { |
+ intptr_t code_unit = s.CharAt(i); |
+ buffer_.EscapeAndAddCodeUnit(code_unit); |
+ } |
+ return did_truncate; |
+} |
+ |
+ |
JSONObject::JSONObject(const JSONArray* arr) : stream_(arr->stream_) { |
stream_->OpenObject(); |
} |