| 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 StringMatch implements Match { | 5 class StringMatch implements Match { |
| 6 const StringMatch(int this._start, | 6 const StringMatch(int this._start, |
| 7 String this.str, | 7 String this.str, |
| 8 String this.pattern); | 8 String this.pattern); |
| 9 | 9 |
| 10 int start() => _start; | 10 int start() => _start; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 var quoter = | 81 var quoter = |
| 82 new RegExpWrapper(@'[-[\]{}()*+?.,\\^$|#\s]', false, false, true).re; | 82 new RegExpWrapper(@'[-[\]{}()*+?.,\\^$|#\s]', false, false, true).re; |
| 83 var quoted = JS('String', @'#.replace(#, "\\$&")', from, quoter); | 83 var quoted = JS('String', @'#.replace(#, "\\$&")', from, quoter); |
| 84 var re = new RegExpWrapper(quoted, false, false, true).re; | 84 var re = new RegExpWrapper(quoted, false, false, true).re; |
| 85 return JS('String', @'#.replace(#, #)', receiver, re, to); | 85 return JS('String', @'#.replace(#, #)', receiver, re, to); |
| 86 } | 86 } |
| 87 } else if (from is RegExp) { | 87 } else if (from is RegExp) { |
| 88 var re = new RegExpWrapper.fromRegExp(from, true).re; | 88 var re = new RegExpWrapper.fromRegExp(from, true).re; |
| 89 return JS('String', @'#.replace(#, #)', receiver, re, to); | 89 return JS('String', @'#.replace(#, #)', receiver, re, to); |
| 90 } else { | 90 } else { |
| 91 checkNull(from); |
| 91 // TODO(floitsch): implement generic String.replace (with patterns). | 92 // TODO(floitsch): implement generic String.replace (with patterns). |
| 92 throw "StringImplementation.replaceAll(Pattern) UNIMPLEMENTED"; | 93 throw "StringImplementation.replaceAll(Pattern) UNIMPLEMENTED"; |
| 93 } | 94 } |
| 94 } | 95 } |
| 95 | 96 |
| 96 stringReplaceFirstUnchecked(receiver, from, to) { | 97 stringReplaceFirstUnchecked(receiver, from, to) { |
| 97 if (from is String) { | 98 if (from is String) { |
| 98 return JS('String', @'#.replace(#, #)', receiver, from, to); | 99 return JS('String', @'#.replace(#, #)', receiver, from, to); |
| 99 } else if (from is RegExp) { | 100 } else if (from is RegExp) { |
| 100 var re = new RegExpWrapper.fromRegExp(from, false).re; | 101 var re = new RegExpWrapper.fromRegExp(from, false).re; |
| 101 return JS('String', @'#.replace(#, #)', receiver, re, to); | 102 return JS('String', @'#.replace(#, #)', receiver, re, to); |
| 102 } else { | 103 } else { |
| 104 checkNull(from); |
| 103 // TODO(floitsch): implement generic String.replace (with patterns). | 105 // TODO(floitsch): implement generic String.replace (with patterns). |
| 104 throw "StringImplementation.replace(Pattern) UNIMPLEMENTED"; | 106 throw "StringImplementation.replace(Pattern) UNIMPLEMENTED"; |
| 105 } | 107 } |
| 106 } | 108 } |
| 107 | 109 |
| 108 stringSplitUnchecked(receiver, pattern) { | 110 stringSplitUnchecked(receiver, pattern) { |
| 109 if (pattern is String) { | 111 if (pattern is String) { |
| 110 return JS('List', @'#.split(#)', receiver, pattern); | 112 return JS('List', @'#.split(#)', receiver, pattern); |
| 111 } else if (pattern is RegExp) { | 113 } else if (pattern is RegExp) { |
| 112 var re = new RegExpWrapper.fromRegExp(pattern, false).re; | 114 var re = new RegExpWrapper.fromRegExp(pattern, false).re; |
| 113 return JS('List', @'#.split(#)', receiver, re); | 115 return JS('List', @'#.split(#)', receiver, re); |
| 114 } else { | 116 } else { |
| 115 throw "StringImplementation.split(Pattern) UNIMPLEMENTED"; | 117 throw "StringImplementation.split(Pattern) UNIMPLEMENTED"; |
| 116 } | 118 } |
| 117 } | 119 } |
| OLD | NEW |