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

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

Issue 11414273: Added native to split OneByteString with a char code as pattern. (Closed) Base URL: http://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/lib/string_base.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) 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"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 ASSERT(receiver.IsOneByteString()); 67 ASSERT(receiver.IsOneByteString());
68 GET_NATIVE_ARGUMENT(Smi, start_obj, arguments->NativeArgAt(1)); 68 GET_NATIVE_ARGUMENT(Smi, start_obj, arguments->NativeArgAt(1));
69 GET_NATIVE_ARGUMENT(Smi, end_obj, arguments->NativeArgAt(2)); 69 GET_NATIVE_ARGUMENT(Smi, end_obj, arguments->NativeArgAt(2));
70 70
71 const intptr_t start = start_obj.Value(); 71 const intptr_t start = start_obj.Value();
72 const intptr_t end = end_obj.Value(); 72 const intptr_t end = end_obj.Value();
73 return OneByteString::New(receiver, start, end - start, Heap::kNew); 73 return OneByteString::New(receiver, start, end - start, Heap::kNew);
74 } 74 }
75 75
76 76
77 DEFINE_NATIVE_ENTRY(OneByteString_splitWithCharCode, 2) {
78 const String& receiver = String::CheckedHandle(arguments->NativeArgAt(0));
79 ASSERT(receiver.IsOneByteString());
80 GET_NATIVE_ARGUMENT(Smi, smi_split_code, arguments->NativeArgAt(1));
81 const intptr_t len = receiver.Length();
82 const intptr_t split_code = smi_split_code.Value();
83 const GrowableObjectArray& result = GrowableObjectArray::Handle(
84 GrowableObjectArray::New(4, Heap::kNew));
85 String& str = String::Handle();
86 intptr_t start = 0;
87 intptr_t i = 0;
88 for (; i < len; i++) {
89 if (split_code == receiver.CharAt(i)) {
90 str = String::SubString(receiver, start, (i - start));
91 result.Add(str);
92 start = i + 1;
93 }
94 }
95 str = String::SubString(receiver, start, (i - start));
96 result.Add(str);
97 return result.raw();
98 }
99
100
77 DEFINE_NATIVE_ENTRY(String_getHashCode, 1) { 101 DEFINE_NATIVE_ENTRY(String_getHashCode, 1) {
78 const String& receiver = String::CheckedHandle(arguments->NativeArgAt(0)); 102 const String& receiver = String::CheckedHandle(arguments->NativeArgAt(0));
79 intptr_t hash_val = receiver.Hash(); 103 intptr_t hash_val = receiver.Hash();
80 ASSERT(hash_val > 0); 104 ASSERT(hash_val > 0);
81 ASSERT(Smi::IsValid(hash_val)); 105 ASSERT(Smi::IsValid(hash_val));
82 return Smi::New(hash_val); 106 return Smi::New(hash_val);
83 } 107 }
84 108
85 109
86 DEFINE_NATIVE_ENTRY(String_getLength, 1) { 110 DEFINE_NATIVE_ENTRY(String_getLength, 1) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 if (!elem.IsString()) { 184 if (!elem.IsString()) {
161 GrowableArray<const Object*> args; 185 GrowableArray<const Object*> args;
162 args.Add(&elem); 186 args.Add(&elem);
163 Exceptions::ThrowByType(Exceptions::kArgument, args); 187 Exceptions::ThrowByType(Exceptions::kArgument, args);
164 } 188 }
165 } 189 }
166 return String::ConcatAll(strings); 190 return String::ConcatAll(strings);
167 } 191 }
168 192
169 } // namespace dart 193 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/string_base.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698