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

Unified Diff: runtime/lib/regexp.dart

Issue 9718015: Make failed capturing parenthesis produce null instead of "". (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: remove unneeded diffs in regexp_jsc.cc 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 | tests/co19/co19-runtime.status » ('j') | no next file with comments »
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..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;
}
« no previous file with comments | « no previous file | tests/co19/co19-runtime.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698