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

Unified Diff: runtime/vm/json_stream.cc

Issue 2081433002: Use official JSON encoding for stream (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Fixed & Added UTF-32 characters tests Created 4 years, 6 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/platform/text_buffer.cc ('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 f1a0d875d1e60ab9a0164ea12794ab2d3f1a9dd1..f94e32a465250e39107a13014413ca57fa472aac 100644
--- a/runtime/vm/json_stream.cc
+++ b/runtime/vm/json_stream.cc
@@ -822,8 +822,25 @@ bool JSONStream::AddDartString(const String& s,
}
intptr_t limit = offset + count;
for (intptr_t i = offset; i < limit; i++) {
- intptr_t code_unit = s.CharAt(i);
- buffer_.EscapeAndAddCodeUnit(code_unit);
+ uint16_t code_unit = s.CharAt(i);
+ if (Utf16::IsTrailSurrogate(code_unit)) {
+ buffer_.EscapeAndAddUTF16CodeUnit(code_unit);
+ } else if (Utf16::IsLeadSurrogate(code_unit)) {
+ if (i + 1 == limit) {
+ buffer_.EscapeAndAddUTF16CodeUnit(code_unit);
+ } else {
+ uint16_t next_code_unit = s.CharAt(i+1);
+ if (Utf16::IsTrailSurrogate(next_code_unit)) {
+ uint32_t decoded = Utf16::Decode(code_unit, next_code_unit);
+ buffer_.EscapeAndAddCodeUnit(decoded);
+ i++;
+ } else {
+ buffer_.EscapeAndAddUTF16CodeUnit(code_unit);
+ }
+ }
+ } else {
+ buffer_.EscapeAndAddCodeUnit(code_unit);
+ }
}
// Return value indicates whether the string is truncated.
return (offset > 0) || (limit < length);
« no previous file with comments | « runtime/platform/text_buffer.cc ('k') | runtime/vm/json_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698