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

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

Issue 11419086: Use a signed 32-bit integer for representing code points. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: add missing files Created 8 years, 1 month 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/unicode.h ('k') | runtime/vm/unicode_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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 } 286 }
287 if ((i < array_len) && (j == len)) { 287 if ((i < array_len) && (j == len)) {
288 return false; // output overflow 288 return false; // output overflow
289 } 289 }
290 return true; // success 290 return true; // success
291 } 291 }
292 292
293 293
294 bool Utf8::DecodeToUTF32(const uint8_t* utf8_array, 294 bool Utf8::DecodeToUTF32(const uint8_t* utf8_array,
295 intptr_t array_len, 295 intptr_t array_len,
296 uint32_t* dst, 296 int32_t* dst,
297 intptr_t len) { 297 intptr_t len) {
298 intptr_t i = 0; 298 intptr_t i = 0;
299 intptr_t j = 0; 299 intptr_t j = 0;
300 intptr_t num_bytes; 300 intptr_t num_bytes;
301 for (; (i < array_len) && (j < len); i += num_bytes, ++j) { 301 for (; (i < array_len) && (j < len); i += num_bytes, ++j) {
302 int32_t ch; 302 int32_t ch;
303 num_bytes = Utf8::Decode(&utf8_array[i], (array_len - i), &ch); 303 num_bytes = Utf8::Decode(&utf8_array[i], (array_len - i), &ch);
304 if (ch == -1) { 304 if (ch == -1) {
305 return false; // invalid input 305 return false; // invalid input
306 } 306 }
307 dst[j] = ch; 307 dst[j] = ch;
308 } 308 }
309 if ((i < array_len) && (j == len)) { 309 if ((i < array_len) && (j == len)) {
310 return false; // output overflow 310 return false; // output overflow
311 } 311 }
312 return true; // success 312 return true; // success
313 } 313 }
314 314
315 315
316 void Utf16::Encode(int32_t codepoint, uint16_t* dst) { 316 void Utf16::Encode(int32_t codepoint, uint16_t* dst) {
317 ASSERT(codepoint > kMaxBmpCodepoint); 317 ASSERT(codepoint > kMaxBmpCodepoint);
318 ASSERT(dst != NULL); 318 ASSERT(dst != NULL);
319 dst[0] = (Utf16::kLeadSurrogateOffset + (codepoint >> 10)); 319 dst[0] = (Utf16::kLeadSurrogateOffset + (codepoint >> 10));
320 dst[1] = (0xDC00 + (codepoint & 0x3FF)); 320 dst[1] = (0xDC00 + (codepoint & 0x3FF));
321 } 321 }
322 322
323 } // namespace dart 323 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/unicode.h ('k') | runtime/vm/unicode_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698