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

Unified Diff: dart/frog/leg/lib/string_helper.dart

Issue 9852018: Minor tweaks to the core library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Doh! Created 8 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dart/frog/leg/lib/js_helper.dart ('k') | dart/tests/corelib/corelib-leg.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/frog/leg/lib/string_helper.dart
diff --git a/dart/frog/leg/lib/string_helper.dart b/dart/frog/leg/lib/string_helper.dart
index fa1bfb7db8040d771312210663467ab441e3fe87..fb37fae297f1e9914072a3f3802bbfc0de591db2 100644
--- a/dart/frog/leg/lib/string_helper.dart
+++ b/dart/frog/leg/lib/string_helper.dart
@@ -32,21 +32,27 @@ class StringMatch implements Match {
final String pattern;
}
-allMatchesInStringUnchecked(receiver, str) {
- var result = new List();
- var length = receiver.length;
- if (length === 0) {
- return result;
- }
-
- var strLength = str.length;
- for (var i = 0; i < strLength;) {
- var index = str.indexOf(receiver, i);
- if (index < 0) {
- return result;
+List<Match> allMatchesInStringUnchecked(needle, haystack) {
ngeoffray 2012/03/26 07:00:30 Could you type the parameters also?
ahe 2012/03/26 08:10:12 Done.
+ // Copied from StringBase.allMatches in
+ // ../../../runtime/lib/string.dart
+ List<Match> result = new List<Match>();
+ int length = haystack.length;
+ int patternLength = needle.length;
+ int startIndex = 0;
+ while (true) {
+ int position = haystack.indexOf(needle, startIndex);
+ if (position == -1) {
+ break;
+ }
+ result.add(new StringMatch(position, haystack, needle));
+ int endIndex = position + patternLength;
+ if (endIndex == length) {
+ break;
+ } else if (position == endIndex) {
+ ++startIndex; // empty match, advance and restart
+ } else {
+ startIndex = endIndex;
}
- result.add(new StringMatch(index, str, receiver));
- i = index + length;
}
return result;
}
« no previous file with comments | « dart/frog/leg/lib/js_helper.dart ('k') | dart/tests/corelib/corelib-leg.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698