Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(629)

Unified Diff: runtime/vm/json_stream.cc

Issue 558853004: Preserve the contents of Dart strings with unmatched surrogate halfs by avoiding a UTF16 -> UTF8 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: sync and build Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/json_stream.h ('k') | runtime/vm/json_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
}
« no previous file with comments | « runtime/vm/json_stream.h ('k') | runtime/vm/json_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698