Index: sdk/lib/_internal/compiler/implementation/lib/regexp_helper.dart |
diff --git a/sdk/lib/_internal/compiler/implementation/lib/regexp_helper.dart b/sdk/lib/_internal/compiler/implementation/lib/regexp_helper.dart |
index d2feaa81ee5643a83bdcfab971d401199ca6684d..0e923a3986a17a6771f6be2d6cb1319204be486d 100644 |
--- a/sdk/lib/_internal/compiler/implementation/lib/regexp_helper.dart |
+++ b/sdk/lib/_internal/compiler/implementation/lib/regexp_helper.dart |
@@ -114,15 +114,15 @@ class JSSyntaxRegExp implements RegExp { |
} |
class _MatchImplementation implements Match { |
- final String pattern; |
+ final Pattern pattern; |
final String str; |
final int start; |
final int end; |
final List<String> _groups; |
const _MatchImplementation( |
- String this.pattern, |
- String this.str, |
+ this.pattern, |
+ this.str, |
int this.start, |
int this.end, |
List<String> this._groups); |
@@ -150,23 +150,46 @@ class _AllMatchesIterable extends IterableBase<Match> { |
} |
class _AllMatchesIterator implements Iterator<Match> { |
- final RegExp _re; |
- final String _str; |
+ final RegExp _regExp; |
+ final RegExp _globalRegExp; |
+ String _str; |
Match _current; |
_AllMatchesIterator(JSSyntaxRegExp re, String this._str) |
- : _re = new JSSyntaxRegExp._globalVersionOf(re); |
+ : _regExp = re, |
+ _globalRegExp = new JSSyntaxRegExp._globalVersionOf(re); |
Match get current => _current; |
bool moveNext() { |
+ if (_str == null) return false; |
// firstMatch actually acts as nextMatch because of |
// hidden global flag. |
if (_current != null && _current.start == _current.end) { |
// Advance implicit start-position if last match was empty. |
- JS("void", "#.lastIndex++", regExpGetNative(_re)); |
+ JS("void", "#.lastIndex++", regExpGetNative(_globalRegExp)); |
+ } |
+ List<String> m = |
+ JS('=List|Null', r'#.exec(#)', regExpGetNative(_globalRegExp), _str); |
+ if (m == null) { |
+ _current = null; |
+ _str = null; // Marks iteration as ended. |
+ return false; |
} |
- _current = _re.firstMatch(_str); |
- return _current != null; |
+ var matchStart = JS('int', r'#.index', m); |
+ var matchEnd = matchStart + m[0].length; |
+ _current = new _MatchImplementation(_regExp, _str, matchStart, matchEnd, m); |
+ return true; |
} |
} |
+ |
+Match firstMatchAfter(JSSyntaxRegExp re, String str, int start) { |
+ JSSyntaxRegExp global = new JSSyntaxRegExp._globalVersionOf(re); |
+ JS("void", "#.lastIndex = #", regExpGetNative(global), start); |
+ List<String> m = |
+ JS('=List|Null', r'#.exec(#)', regExpGetNative(global), checkString(str)); |
+ if (m == null) return null; |
+ var matchStart = JS('int', r'#.index', m); |
+ var matchEnd = matchStart + m[0].length; |
+ return new _MatchImplementation(re, str, matchStart, matchEnd, m); |
+} |