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

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: Add types 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
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..e234b2b66396ef32c3403c57134bfe77dee52773 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(String needle, String haystack) {
+ // 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;
}

Powered by Google App Engine
This is Rietveld 408576698