Chromium Code Reviews| 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 30 matching lines...) Expand all Loading... | |
| 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(Pattern from, String to) native | 45 String replaceFirst(Pattern from, String to) native |
| 46 "return this.replace(from, to);"; | 46 "return this.replace(from, to);"; |
| 47 | 47 |
| 48 String replaceAll(Pattern from, String to) native @""" | 48 String replaceAll(Pattern from, String to) native @""" |
| 49 if (typeof(from) == 'string' || from instanceof String) { | 49 if (typeof(from) == 'string' || from instanceof String) { |
| 50 from = new RegExp(from.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'g'); | 50 from = new RegExp(from.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'g'); |
| 51 to = to.replace(/\$/g, '$$$$'); // Escape sequences are fun! | |
|
jimhug
2011/12/14 22:14:47
I wanted to suggest that you use @'$$' to simplify
| |
| 51 } | 52 } |
| 52 return this.replace(from, to);"""; | 53 return this.replace(from, to);"""; |
| 53 | 54 |
| 54 List<String> split(Pattern pattern) native; | 55 List<String> split(Pattern pattern) native; |
| 55 | 56 |
| 56 /* | 57 /* |
| 57 Iterable<Match> allMatches(String str) { | 58 Iterable<Match> allMatches(String str) { |
| 58 List<Match> result = []; | 59 List<Match> result = []; |
| 59 if (this.isEmpty()) return result; | 60 if (this.isEmpty()) return result; |
| 60 int length = this.length; | 61 int length = this.length; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 result.add(group(g)); | 130 result.add(group(g)); |
| 130 } | 131 } |
| 131 return result; | 132 return result; |
| 132 } | 133 } |
| 133 | 134 |
| 134 final int _start; | 135 final int _start; |
| 135 final String str; | 136 final String str; |
| 136 final String pattern; | 137 final String pattern; |
| 137 } | 138 } |
| 138 */ | 139 */ |
| OLD | NEW |