Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 class RegExpWrapper { | 5 class RegExpWrapper { |
| 6 final re; | 6 final re; |
| 7 | 7 |
| 8 // TODO(ahe): This constructor is clearly not const. We need some | 8 // TODO(ahe): This constructor is clearly not const. We need some |
| 9 // better way to handle constant regular expressions. One might | 9 // better way to handle constant regular expressions. One might |
| 10 // question if regular expressions are really constant as we have | 10 // question if regular expressions are really constant as we have |
| 11 // tests that expect an exception from the constructor. | 11 // tests that expect an exception from the constructor. |
| 12 const RegExpWrapper(pattern, multiLine, ignoreCase, global) | 12 const RegExpWrapper(pattern, multiLine, ignoreCase, global) |
| 13 : re = makeRegExp(pattern, "${multiLine == true ? 'm' : ''}${ | 13 : re = makeRegExp(pattern, "${multiLine == true ? 'm' : ''}${ |
| 14 ignoreCase == true ? 'i' : ''}${ | 14 ignoreCase == true ? 'i' : ''}${ |
| 15 global == true ? 'g' : ''}"); | 15 global == true ? 'g' : ''}"); |
| 16 | 16 |
| 17 RegExpWrapper.fromRegExp(other, global) | |
| 18 // TODO(ahe): Use redirection. | |
|
ngeoffray
2012/02/21 12:15:53
Should be supported now.
| |
| 19 : re = makeRegExp(other.pattern, "${other.multiLine == true ? 'm' : ''}${ | |
| 20 other.ignoreCase == true ? 'i' : ''}${ | |
| 21 global == true ? 'g' : ''}"); | |
| 22 | |
| 17 exec(str) { | 23 exec(str) { |
| 18 var result = JS('List', @'$0.exec($1)', re, checkString(str)); | 24 var result = JS('List', @'$0.exec($1)', re, checkString(str)); |
| 19 if (JS('bool', @'$0 === null', result)) return null; | 25 if (JS('bool', @'$0 === null', result)) return null; |
| 20 return result; | 26 return result; |
| 21 } | 27 } |
| 22 | 28 |
| 23 lastIndex() => JS('List', @'$0.lastIndex', re); | 29 test(str) => JS('bool', @'$0.test($1)', re, checkString(str)); |
| 24 | |
| 25 test(str) => JS('List', @'$0.test($1)', re, checkString(str)); | |
| 26 | 30 |
| 27 static matchStart(m) => JS('int', @'$0.index', m); | 31 static matchStart(m) => JS('int', @'$0.index', m); |
| 28 | 32 |
| 29 static makeRegExp(pattern, flags) { | 33 static makeRegExp(pattern, flags) { |
| 30 checkString(pattern); | 34 checkString(pattern); |
| 31 try { | 35 try { |
| 32 return JS('Object', @'new RegExp($0, $1)', pattern, flags); | 36 return JS('Object', @'new RegExp($0, $1)', pattern, flags); |
| 33 } catch (var e) { | 37 } catch (var e) { |
| 34 throw new IllegalJSRegExpException(pattern, | 38 throw new IllegalJSRegExpException(pattern, |
| 35 JS('String', @'String($0)', e)); | 39 JS('String', @'String($0)', e)); |
| 36 } | 40 } |
| 37 } | 41 } |
| 38 } | 42 } |
| 43 | |
| 44 stringify(x) => x === null ? "" : x.toString(); | |
| OLD | NEW |