Chromium Code Reviews| 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 45ab03c85aa57d738c66c9740c750559c7926247..0cc05959b05efccc58662a1ec81221bbba0ee296 100644 |
| --- a/sdk/lib/_internal/compiler/implementation/lib/regexp_helper.dart |
| +++ b/sdk/lib/_internal/compiler/implementation/lib/regexp_helper.dart |
| @@ -33,6 +33,12 @@ class JSSyntaxRegExp implements RegExp { |
| other.isCaseSensitive, |
| true); |
| + JSSyntaxRegExp._anchoredVersionOf(JSSyntaxRegExp other) |
| + : this._internal(other.pattern + "|()", |
| + other.isMultiLine, |
| + other.isCaseSensitive, |
| + true); |
| + |
| static makeNative( |
| String pattern, bool multiLine, bool caseSensitive, bool global) { |
| checkString(pattern); |
| @@ -82,6 +88,26 @@ class JSSyntaxRegExp implements RegExp { |
| return new _AllMatchesIterable(this, str); |
| } |
| + Match matchPrefix(String string, [int start = 0]) { |
| + if (start < 0 || start > string.length) { |
| + throw new RangeError.range(start, 0, string.length); |
| + } |
| + // An "anchored version" of a regexp is created by adding "|()" to the |
| + // source. This means that the regexp always matches at the first position |
| + // that it tries, and you can see if the original regexp matched, or it |
| + // was the added zero-width match that matched, by looking at the last |
| + // capture. If it is a String, the match participated, otherwise it didn't. |
| + JSSyntaxRegExp regexp = new JSSyntaxRegExp._anchoredVersionOf(this); |
| + if (start > 0) { |
| + JS("void", "#.lastIndex = #", regExpGetNative(regexp), start); |
| + } |
| + _MatchImplementation match = regexp.firstMatch(string); |
| + if (match == null) return null; |
|
Lasse Reichstein Nielsen
2013/06/12 09:24:05
This line is really a sanity check - it can't happ
|
| + if (match._groups[match._groups.length - 1] is String) return null; |
|
floitsch
2013/06/11 12:45:24
isn't the groups entry 'null' if it hasn't matched
Lasse Reichstein Nielsen
2013/06/12 09:24:05
That's my assumption too - a non participating cap
|
| + match._groups.length -= 1; |
| + return match; |
| + } |
| + |
| String get pattern => _pattern; |
| bool get isMultiLine => _isMultiLine; |
| bool get isCaseSensitive => _isCaseSensitive; |