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

Unified Diff: dart/frog/leg/lib/regexp_helper.dart

Issue 9423042: Copy JSSyntaxRegExp from frog. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 10 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
Index: dart/frog/leg/lib/regexp_helper.dart
diff --git a/dart/frog/leg/lib/regexp_helper.dart b/dart/frog/leg/lib/regexp_helper.dart
new file mode 100644
index 0000000000000000000000000000000000000000..32fae10e31d655d23a8bb644efdd82669d7773b6
--- /dev/null
+++ b/dart/frog/leg/lib/regexp_helper.dart
@@ -0,0 +1,38 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+class RegExpWrapper {
+ final re;
+
+ // TODO(ahe): This constructor is clearly not const. We need some
+ // better way to handle constant regular expressions. One might
+ // question if regular expressions are really constant as we have
+ // tests that expect an exception from the constructor.
+ const RegExpWrapper(pattern, multiLine, ignoreCase, global)
+ : re = makeRegExp(pattern, "${multiLine == true ? 'm' : ''}${
+ ignoreCase == true ? 'i' : ''}${
+ global == true ? 'g' : ''}");
+
+ exec(str) {
+ var result = JS('List', @'$0.exec($1)', re, checkString(str));
+ if (JS('bool', @'$0 === null', result)) return null;
+ return result;
+ }
+
+ lastIndex() => JS('List', @'$0.lastIndex', re);
+
+ test(str) => JS('List', @'$0.test($1)', re, checkString(str));
+
+ static matchStart(m) => JS('int', @'$0.index', m);
+
+ static makeRegExp(pattern, flags) {
+ checkString(pattern);
+ try {
+ return JS('Object', @'new RegExp($0, $1)', pattern, flags);
+ } catch (var e) {
+ throw new IllegalJSRegExpException(pattern,
+ JS('String', @'String($0)', e));
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698