OLD | NEW |
---|---|
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 Loading... | |
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 uint32_t code_unit = s.CharAt(i); |
826 buffer_.EscapeAndAddCodeUnit(code_unit); | 826 ASSERT(!Utf16::IsTrailSurrogate(code_unit)); |
827 if (Utf16::IsLeadSurrogate(code_unit)) { | |
828 uint32_t trail = s.CharAt(++i); | |
rmacnak
2016/06/21 16:56:56
A Dart string may have unmatched surrogates, so th
cbernaschina
2016/06/21 21:24:43
Done.
| |
829 buffer_.EscapeAndAddCodeUnit(Utf16::Decode(code_unit, trail)); | |
830 } else { | |
831 buffer_.EscapeAndAddCodeUnit(code_unit); | |
832 } | |
827 } | 833 } |
828 // Return value indicates whether the string is truncated. | 834 // Return value indicates whether the string is truncated. |
829 return (offset > 0) || (limit < length); | 835 return (offset > 0) || (limit < length); |
830 } | 836 } |
831 | 837 |
832 | 838 |
833 JSONObject::JSONObject(const JSONArray* arr) : stream_(arr->stream_) { | 839 JSONObject::JSONObject(const JSONArray* arr) : stream_(arr->stream_) { |
834 stream_->OpenObject(); | 840 stream_->OpenObject(); |
835 } | 841 } |
836 | 842 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
945 ASSERT(len == len2); | 951 ASSERT(len == len2); |
946 stream_->buffer_.AddChar('"'); | 952 stream_->buffer_.AddChar('"'); |
947 stream_->AddEscapedUTF8String(p); | 953 stream_->AddEscapedUTF8String(p); |
948 stream_->buffer_.AddChar('"'); | 954 stream_->buffer_.AddChar('"'); |
949 free(p); | 955 free(p); |
950 } | 956 } |
951 | 957 |
952 #endif // !PRODUCT | 958 #endif // !PRODUCT |
953 | 959 |
954 } // namespace dart | 960 } // namespace dart |
OLD | NEW |