Chromium Code Reviews| 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; |
| } |