| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 //String.prototype.get$length = function() { | 5 //String.prototype.get$length = function() { |
| 6 // return this.length; | 6 // return this.length; |
| 7 //} | 7 //} |
| 8 | 8 |
| 9 // TODO(jimhug): Unify with code from compiler/lib/implementation. | 9 // TODO(jimhug): Unify with code from compiler/lib/implementation. |
| 10 class StringImplementation implements String native "String" { | 10 class StringImplementation implements String native "String" { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 String trim() native; | 39 String trim() native; |
| 40 | 40 |
| 41 // TODO(jmesserly): should support pattern too. | 41 // TODO(jmesserly): should support pattern too. |
| 42 bool contains(Pattern pattern, int startIndex) native | 42 bool contains(Pattern pattern, int startIndex) native |
| 43 "return this.indexOf(pattern, startIndex) >= 0;"; | 43 "return this.indexOf(pattern, startIndex) >= 0;"; |
| 44 | 44 |
| 45 String _replaceFirst(String from, String to) native | 45 String _replaceFirst(String from, String to) native |
| 46 "return this.replace(from, to);"; | 46 "return this.replace(from, to);"; |
| 47 | 47 |
| 48 String _replaceFirstRegExp(RegExp from, String to) native | 48 String _replaceFirstRegExp(RegExp from, String to) native |
| 49 "console.log(require('util').inspect(from)); return this.replace(from.re, to
);"; | 49 "return this.replace(from.re, to);"; |
| 50 | 50 |
| 51 String replaceFirst(Pattern from, String to) { | 51 String replaceFirst(Pattern from, String to) { |
| 52 if (from is String) return _replaceFirst(from, to); | 52 if (from is String) return _replaceFirst(from, to); |
| 53 if (from is RegExp) return _replaceFirstRegExp(from, to); | 53 if (from is RegExp) return _replaceFirstRegExp(from, to); |
| 54 for (match in from.allMatches(this)) { | 54 for (match in from.allMatches(this)) { |
| 55 // We just care about the first match | 55 // We just care about the first match |
| 56 return substring(0, match.start()) + to + substring(match.end()); | 56 return substring(0, match.start()) + to + substring(match.end()); |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 | 59 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 result.add(group(g)); | 142 result.add(group(g)); |
| 143 } | 143 } |
| 144 return result; | 144 return result; |
| 145 } | 145 } |
| 146 | 146 |
| 147 final int _start; | 147 final int _start; |
| 148 final String str; | 148 final String str; |
| 149 final String pattern; | 149 final String pattern; |
| 150 } | 150 } |
| 151 */ | 151 */ |
| OLD | NEW |