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

Unified Diff: sdk/lib/_internal/compiler/js_lib/regexp_helper.dart

Issue 677013002: Make dart2js String.split match the VM version. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Tweak docs. Created 6 years, 2 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 | « sdk/lib/_internal/compiler/js_lib/js_string.dart ('k') | sdk/lib/core/string.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/compiler/js_lib/regexp_helper.dart
diff --git a/sdk/lib/_internal/compiler/js_lib/regexp_helper.dart b/sdk/lib/_internal/compiler/js_lib/regexp_helper.dart
index 7f930ebf170db0e25da4322808c609eb09090e11..4bdf754f718bd2d2aa1f7d328b7b53c0bcfd6ae1 100644
--- a/sdk/lib/_internal/compiler/js_lib/regexp_helper.dart
+++ b/sdk/lib/_internal/compiler/js_lib/regexp_helper.dart
@@ -22,12 +22,31 @@ regExpGetGlobalNative(JSSyntaxRegExp regexp) {
return nativeRegexp;
}
+/**
+ * Computes the number of captures in a regexp.
+ *
+ * This currently involves creating a new RegExp object with a different
+ * source and running it against the empty string (the last part is usually
+ * fast).
+ *
+ * The JSSyntaxRegExp could cache the result, and set the cache any time
+ * it finds a match.
+ */
+int regExpCaptureCount(JSSyntaxRegExp regexp) {
+ var nativeAnchoredRegExp = regexp._nativeAnchoredVersion;
+ var match = JS('JSExtendableArray', "#.exec('')", nativeAnchoredRegExp);
+ // The native-anchored regexp always have one capture more than the original,
+ // and always matches the empty string.
+ return match.length - 2;
+}
+
class JSSyntaxRegExp implements RegExp {
final String pattern;
final _nativeRegExp;
var _nativeGlobalRegExp;
var _nativeAnchoredRegExp;
+ String toString() => "RegExp/$pattern/";
JSSyntaxRegExp(String source,
{ bool multiLine: false,
« no previous file with comments | « sdk/lib/_internal/compiler/js_lib/js_string.dart ('k') | sdk/lib/core/string.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698