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

Side by Side Diff: runtime/lib/string.cc

Issue 11414249: Move various top-level Unicode definitions into classes and methods. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years 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 | « no previous file | runtime/vm/object.cc » ('j') | runtime/vm/object.cc » ('J')
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/bootstrap_natives.h" 5 #include "vm/bootstrap_natives.h"
6 6
7 #include "vm/exceptions.h" 7 #include "vm/exceptions.h"
8 #include "vm/native_entry.h" 8 #include "vm/native_entry.h"
9 #include "vm/object.h" 9 #include "vm/object.h"
10 #include "vm/symbols.h" 10 #include "vm/symbols.h"
11 #include "vm/unicode.h"
11 12
12 namespace dart { 13 namespace dart {
13 14
14 DEFINE_NATIVE_ENTRY(StringBase_createFromCodePoints, 1) { 15 DEFINE_NATIVE_ENTRY(StringBase_createFromCodePoints, 1) {
15 GET_NATIVE_ARGUMENT(Array, a, arguments->NativeArgAt(0)); 16 GET_NATIVE_ARGUMENT(Array, a, arguments->NativeArgAt(0));
16 // TODO(srdjan): Check that parameterized type is an int. 17 // TODO(srdjan): Check that parameterized type is an int.
17 Zone* zone = isolate->current_zone(); 18 Zone* zone = isolate->current_zone();
18 intptr_t array_len = a.Length(); 19 intptr_t array_len = a.Length();
19 20
20 // Unbox the array and determine the maximum element width. 21 // Unbox the array and determine the maximum element width.
21 bool is_one_byte_string = true; 22 bool is_one_byte_string = true;
22 intptr_t utf16_len = array_len; 23 intptr_t utf16_len = array_len;
23 int32_t* utf32_array = zone->Alloc<int32_t>(array_len); 24 int32_t* utf32_array = zone->Alloc<int32_t>(array_len);
24 Object& index_object = Object::Handle(isolate); 25 Object& index_object = Object::Handle(isolate);
25 for (intptr_t i = 0; i < array_len; i++) { 26 for (intptr_t i = 0; i < array_len; i++) {
26 index_object = a.At(i); 27 index_object = a.At(i);
27 if (!index_object.IsSmi()) { 28 if (!index_object.IsSmi()) {
28 GrowableArray<const Object*> args; 29 GrowableArray<const Object*> args;
29 args.Add(&index_object); 30 args.Add(&index_object);
30 Exceptions::ThrowByType(Exceptions::kArgument, args); 31 Exceptions::ThrowByType(Exceptions::kArgument, args);
31 } 32 }
32 intptr_t value = Smi::Cast(index_object).Value(); 33 intptr_t value = Smi::Cast(index_object).Value();
33 if (value < 0) { 34 if (value < 0) {
siva 2012/11/30 02:42:53 We could change this check to: if (Utf::IsOutOfRan
cshapiro 2012/11/30 03:21:24 Right. Done and done.
34 GrowableArray<const Object*> args; 35 GrowableArray<const Object*> args;
35 Exceptions::ThrowByType(Exceptions::kArgument, args); 36 Exceptions::ThrowByType(Exceptions::kArgument, args);
36 } else { 37 } else {
37 if (value > 0xFF) { 38 if (!Utf::IsLatin1(value)) {
38 is_one_byte_string = false; 39 is_one_byte_string = false;
39 } 40 }
40 if (value > 0xFFFF) { 41 if (!Utf::IsBmp(value)) {
siva 2012/11/30 02:42:53 if (Utf::IsSupplementary(value)) { ... } might
cshapiro 2012/11/30 03:21:24 A great idea. Done!
41 utf16_len += 1; 42 utf16_len += 1;
42 } 43 }
43 } 44 }
44 utf32_array[i] = value; 45 utf32_array[i] = value;
45 } 46 }
46 if (is_one_byte_string) { 47 if (is_one_byte_string) {
47 return OneByteString::New(utf32_array, array_len, Heap::kNew); 48 return OneByteString::New(utf32_array, array_len, Heap::kNew);
48 } 49 }
49 return TwoByteString::New(utf16_len, utf32_array, array_len, Heap::kNew); 50 return TwoByteString::New(utf16_len, utf32_array, array_len, Heap::kNew);
50 } 51 }
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 if (!elem.IsString()) { 160 if (!elem.IsString()) {
160 GrowableArray<const Object*> args; 161 GrowableArray<const Object*> args;
161 args.Add(&elem); 162 args.Add(&elem);
162 Exceptions::ThrowByType(Exceptions::kArgument, args); 163 Exceptions::ThrowByType(Exceptions::kArgument, args);
163 } 164 }
164 } 165 }
165 return String::ConcatAll(strings); 166 return String::ConcatAll(strings);
166 } 167 }
167 168
168 } // namespace dart 169 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/object.cc » ('j') | runtime/vm/object.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698