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

Unified Diff: runtime/lib/regexp.dart

Issue 9689089: Improve the replaceFirst, replaceAll and split methods. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: address review comments 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 | « no previous file | runtime/lib/string.dart » ('j') | tests/corelib/src/StringPatternTest.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/regexp.dart
diff --git a/runtime/lib/regexp.dart b/runtime/lib/regexp.dart
index e2f777e9ad5319301e855eb3cd85c489fba206be..2f12f60c93b82f5ff384ca2e34ca38768d73767a 100644
--- a/runtime/lib/regexp.dart
+++ b/runtime/lib/regexp.dart
@@ -64,19 +64,25 @@ class JSSyntaxRegExp implements RegExp {
}
Iterable<Match> allMatches(String str) {
- var jsregexMatches = new List<JSRegExpMatch>();
- List match = _ExecuteMatch(str, 0);
- if (match !== null) {
- jsregexMatches.add(new JSRegExpMatch(this, str, match));
- while (true) {
- match = _ExecuteMatch(str, match[1]);
- if (match === null) {
- break;
- }
- jsregexMatches.add(new JSRegExpMatch(this, str, match));
+ List<Match> result = new List<Match>();
+ int length = str.length;
+ int startIndex = 0;
+ while (true) {
+ List match = _ExecuteMatch(str, startIndex);
+ if (match == null) {
+ break;
+ }
+ result.add(new JSRegExpMatch(this, str, match));
+ int endIndex = match[1];
+ if (endIndex == length) {
+ break;
+ } else if (match[0] == endIndex) {
+ ++startIndex; // empty match, advance and restart
+ } else {
+ startIndex = endIndex;
}
}
- return jsregexMatches;
+ return result;
}
bool hasMatch(String str) {
« no previous file with comments | « no previous file | runtime/lib/string.dart » ('j') | tests/corelib/src/StringPatternTest.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698