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

Side by Side Diff: runtime/vm/unicode.cc

Issue 563043003: Don't crash when generating error messages with malformed strings. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/dart_api_impl_test.cc ('k') | tests/corelib/throw_half_surrogate_pair_test.dart » ('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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 "vm/unicode.h" 5 #include "vm/unicode.h"
6 6
7 #include "vm/allocation.h" 7 #include "vm/allocation.h"
8 #include "vm/globals.h" 8 #include "vm/globals.h"
9 #include "vm/object.h" 9 #include "vm/object.h"
10 10
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 String::CodePointIterator it(str); 131 String::CodePointIterator it(str);
132 while (it.Next()) { 132 while (it.Next()) {
133 int32_t ch = it.Current(); 133 int32_t ch = it.Current();
134 length += Utf8::Length(ch); 134 length += Utf8::Length(ch);
135 } 135 }
136 return length; 136 return length;
137 } 137 }
138 138
139 139
140 intptr_t Utf8::Encode(int32_t ch, char* dst) { 140 intptr_t Utf8::Encode(int32_t ch, char* dst) {
141 ASSERT(!Utf16::IsSurrogate(ch));
142 static const int kMask = ~(1 << 6); 141 static const int kMask = ~(1 << 6);
143 if (ch <= kMaxOneByteChar) { 142 if (ch <= kMaxOneByteChar) {
144 dst[0] = ch; 143 dst[0] = ch;
145 return 1; 144 return 1;
146 } 145 }
147 if (ch <= kMaxTwoByteChar) { 146 if (ch <= kMaxTwoByteChar) {
148 dst[0] = 0xC0 | (ch >> 6); 147 dst[0] = 0xC0 | (ch >> 6);
149 dst[1] = 0x80 | (ch & kMask); 148 dst[1] = 0x80 | (ch & kMask);
150 return 2; 149 return 2;
151 } 150 }
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 295
297 296
298 void Utf16::Encode(int32_t codepoint, uint16_t* dst) { 297 void Utf16::Encode(int32_t codepoint, uint16_t* dst) {
299 ASSERT(codepoint > Utf16::kMaxCodeUnit); 298 ASSERT(codepoint > Utf16::kMaxCodeUnit);
300 ASSERT(dst != NULL); 299 ASSERT(dst != NULL);
301 dst[0] = (Utf16::kLeadSurrogateOffset + (codepoint >> 10)); 300 dst[0] = (Utf16::kLeadSurrogateOffset + (codepoint >> 10));
302 dst[1] = (0xDC00 + (codepoint & 0x3FF)); 301 dst[1] = (0xDC00 + (codepoint & 0x3FF));
303 } 302 }
304 303
305 } // namespace dart 304 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl_test.cc ('k') | tests/corelib/throw_half_surrogate_pair_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698