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

Side by Side 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, 5 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 unified diff | Download patch
« no previous file with comments | « runtime/platform/text_buffer.cc ('k') | runtime/vm/json_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/assert.h" 5 #include "platform/assert.h"
6 6
7 #include "vm/dart_entry.h" 7 #include "vm/dart_entry.h"
8 #include "vm/debugger.h" 8 #include "vm/debugger.h"
9 #include "vm/json_stream.h" 9 #include "vm/json_stream.h"
10 #include "vm/message.h" 10 #include "vm/message.h"
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 intptr_t length = s.Length(); 815 intptr_t length = s.Length();
816 ASSERT(offset >= 0); 816 ASSERT(offset >= 0);
817 if (offset > length) { 817 if (offset > length) {
818 offset = length; 818 offset = length;
819 } 819 }
820 if (!Utils::RangeCheck(offset, count, length)) { 820 if (!Utils::RangeCheck(offset, count, length)) {
821 count = length - offset; 821 count = length - offset;
822 } 822 }
823 intptr_t limit = offset + count; 823 intptr_t limit = offset + count;
824 for (intptr_t i = offset; i < limit; i++) { 824 for (intptr_t i = offset; i < limit; i++) {
825 intptr_t code_unit = s.CharAt(i); 825 uint16_t code_unit = s.CharAt(i);
826 buffer_.EscapeAndAddCodeUnit(code_unit); 826 if (Utf16::IsTrailSurrogate(code_unit)) {
827 buffer_.EscapeAndAddUTF16CodeUnit(code_unit);
828 } else if (Utf16::IsLeadSurrogate(code_unit)) {
829 if (i + 1 == limit) {
830 buffer_.EscapeAndAddUTF16CodeUnit(code_unit);
831 } else {
832 uint16_t next_code_unit = s.CharAt(i+1);
833 if (Utf16::IsTrailSurrogate(next_code_unit)) {
834 uint32_t decoded = Utf16::Decode(code_unit, next_code_unit);
835 buffer_.EscapeAndAddCodeUnit(decoded);
836 i++;
837 } else {
838 buffer_.EscapeAndAddUTF16CodeUnit(code_unit);
839 }
840 }
841 } else {
842 buffer_.EscapeAndAddCodeUnit(code_unit);
843 }
827 } 844 }
828 // Return value indicates whether the string is truncated. 845 // Return value indicates whether the string is truncated.
829 return (offset > 0) || (limit < length); 846 return (offset > 0) || (limit < length);
830 } 847 }
831 848
832 849
833 JSONObject::JSONObject(const JSONArray* arr) : stream_(arr->stream_) { 850 JSONObject::JSONObject(const JSONArray* arr) : stream_(arr->stream_) {
834 stream_->OpenObject(); 851 stream_->OpenObject();
835 } 852 }
836 853
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 ASSERT(len == len2); 962 ASSERT(len == len2);
946 stream_->buffer_.AddChar('"'); 963 stream_->buffer_.AddChar('"');
947 stream_->AddEscapedUTF8String(p); 964 stream_->AddEscapedUTF8String(p);
948 stream_->buffer_.AddChar('"'); 965 stream_->buffer_.AddChar('"');
949 free(p); 966 free(p);
950 } 967 }
951 968
952 #endif // !PRODUCT 969 #endif // !PRODUCT
953 970
954 } // namespace dart 971 } // namespace dart
OLDNEW
« 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