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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 class RegExpWrapper {
6 final re;
7
8 // TODO(ahe): This constructor is clearly not const. We need some
9 // better way to handle constant regular expressions. One might
10 // question if regular expressions are really constant as we have
11 // tests that expect an exception from the constructor.
12 const RegExpWrapper(pattern, multiLine, ignoreCase, global)
13 : re = makeRegExp(pattern, "${multiLine == true ? 'm' : ''}${
14 ignoreCase == true ? 'i' : ''}${
15 global == true ? 'g' : ''}");
16
17 exec(str) {
18 var result = JS('List', @'$0.exec($1)', re, checkString(str));
19 if (JS('bool', @'$0 === null', result)) return null;
20 return result;
21 }
22
23 lastIndex() => JS('List', @'$0.lastIndex', re);
24
25 test(str) => JS('List', @'$0.test($1)', re, checkString(str));
26
27 static matchStart(m) => JS('int', @'$0.index', m);
28
29 static makeRegExp(pattern, flags) {
30 checkString(pattern);
31 try {
32 return JS('Object', @'new RegExp($0, $1)', pattern, flags);
33 } catch (var e) {
34 throw new IllegalJSRegExpException(pattern,
35 JS('String', @'String($0)', e));
36 }
37 }
38 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698