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

Unified 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, 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/lib/string_base.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/string.cc
===================================================================
--- runtime/lib/string.cc (revision 15607)
+++ runtime/lib/string.cc (working copy)
@@ -74,6 +74,30 @@
}
+DEFINE_NATIVE_ENTRY(OneByteString_splitWithCharCode, 2) {
+ const String& receiver = String::CheckedHandle(arguments->NativeArgAt(0));
+ ASSERT(receiver.IsOneByteString());
+ GET_NATIVE_ARGUMENT(Smi, smi_split_code, arguments->NativeArgAt(1));
+ const intptr_t len = receiver.Length();
+ const intptr_t split_code = smi_split_code.Value();
+ const GrowableObjectArray& result = GrowableObjectArray::Handle(
+ GrowableObjectArray::New(4, Heap::kNew));
+ String& str = String::Handle();
+ intptr_t start = 0;
+ intptr_t i = 0;
+ for (; i < len; i++) {
+ if (split_code == receiver.CharAt(i)) {
+ str = String::SubString(receiver, start, (i - start));
+ result.Add(str);
+ start = i + 1;
+ }
+ }
+ str = String::SubString(receiver, start, (i - start));
+ result.Add(str);
+ return result.raw();
+}
+
+
DEFINE_NATIVE_ENTRY(String_getHashCode, 1) {
const String& receiver = String::CheckedHandle(arguments->NativeArgAt(0));
intptr_t hash_val = receiver.Hash();
« 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