Index: runtime/lib/regexp.dart |
diff --git a/runtime/lib/regexp.dart b/runtime/lib/regexp.dart |
index e2f777e9ad5319301e855eb3cd85c489fba206be..eea2f4bcba328396d563952c3f90e808677f9804 100644 |
--- a/runtime/lib/regexp.dart |
+++ b/runtime/lib/regexp.dart |
@@ -14,26 +14,34 @@ class JSRegExpMatch implements Match { |
} |
int _start(int group) { |
- return _match[(group * _kMatchPair)]; |
+ return _match[(group * MATCH_PAIR)]; |
} |
int _end(int group) { |
- return _match[(group * _kMatchPair) + 1]; |
+ return _match[(group * MATCH_PAIR) + 1]; |
} |
String group(int group) { |
- return str.substringUnchecked_(_start(group), _end(group)); |
+ if (group < 0 || group > regexp._groupCount) { |
+ throw new IndexOutOfRangeException(group); |
+ } |
+ int startIndex = _start(group); |
+ int endIndex = _end(group); |
+ if (startIndex == -1) { |
+ assert(endIndex == -1); |
+ return null; |
+ } |
+ return str.substringUnchecked_(startIndex, endIndex); |
} |
String operator [](int group) { |
- return str.substringUnchecked_(_start(group), _end(group)); |
+ return this.group(group); |
} |
List<String> groups(List<int> groups) { |
var groupsList = new List<String>(groups.length); |
for (int i = 0; i < groups.length; i++) { |
- int grp_idx = groups[i]; |
- groupsList[i] = str.substringUnchecked_(_start(grp_idx), _end(grp_idx)); |
+ groupsList[i] = group(groups[i]); |
} |
return groupsList; |
} |
@@ -45,7 +53,7 @@ class JSRegExpMatch implements Match { |
final RegExp regexp; |
final String str; |
final List<int> _match; |
- static final int _kMatchPair = 2; |
+ static final int MATCH_PAIR = 2; |
} |