| OLD | NEW |
| (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 List regExpExec(JSSyntaxRegExp regExp, String str) { | |
| 6 var nativeRegExp = regExpGetNative(regExp); | |
| 7 var result = JS('List', @'#.exec(#)', nativeRegExp, str); | |
| 8 if (JS('bool', @'# === null', result)) return null; | |
| 9 return result; | |
| 10 } | |
| 11 | |
| 12 bool regExpTest(JSSyntaxRegExp regExp, String str) { | |
| 13 var nativeRegExp = regExpGetNative(regExp); | |
| 14 return JS('bool', @'#.test(#)', nativeRegExp, str); | |
| 15 } | |
| 16 | |
| 17 regExpGetNative(JSSyntaxRegExp regExp) { | |
| 18 var r = JS('var', @'#._re', regExp); | |
| 19 if (r === null) { | |
| 20 r = JS('var', @'#._re = #', regExp, regExpMakeNative(regExp)); | |
| 21 } | |
| 22 return r; | |
| 23 } | |
| 24 | |
| 25 regExpAttachGlobalNative(JSSyntaxRegExp regExp) { | |
| 26 JS('var', @'#._re = #', regExp, regExpMakeNative(regExp, global: true)); | |
| 27 } | |
| 28 | |
| 29 regExpMakeNative(JSSyntaxRegExp regExp, [bool global = false]) { | |
| 30 String pattern = regExp.pattern; | |
| 31 bool multiLine = regExp.multiLine; | |
| 32 bool ignoreCase = regExp.ignoreCase; | |
| 33 checkString(pattern); | |
| 34 StringBuffer sb = new StringBuffer(); | |
| 35 if (multiLine) sb.add('m'); | |
| 36 if (ignoreCase) sb.add('i'); | |
| 37 if (global) sb.add('g'); | |
| 38 try { | |
| 39 return JS('Object', @'new RegExp(#, #)', pattern, sb.toString()); | |
| 40 } catch (var e) { | |
| 41 throw new IllegalJSRegExpException(pattern, | |
| 42 JS('String', @'String(#)', e)); | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 int regExpMatchStart(m) => JS('int', @'#.index', m); | |
| OLD | NEW |