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 part of _interceptors; | 5 part of _interceptors; |
6 | 6 |
7 /** | 7 /** |
8 * The interceptor class for [String]. The compiler recognizes this | 8 * The interceptor class for [String]. The compiler recognizes this |
9 * class as an interceptor, and changes references to [:this:] to | 9 * class as an interceptor, and changes references to [:this:] to |
10 * actually use the receiver of the method, which is generated as an extra | 10 * actually use the receiver of the method, which is generated as an extra |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 if (pattern is String) { | 90 if (pattern is String) { |
91 return JS('JSExtendableArray', r'#.split(#)', this, pattern); | 91 return JS('JSExtendableArray', r'#.split(#)', this, pattern); |
92 } else if (pattern is JSSyntaxRegExp && regExpCaptureCount(pattern) == 0) { | 92 } else if (pattern is JSSyntaxRegExp && regExpCaptureCount(pattern) == 0) { |
93 var re = regExpGetNative(pattern); | 93 var re = regExpGetNative(pattern); |
94 return JS('JSExtendableArray', r'#.split(#)', this, re); | 94 return JS('JSExtendableArray', r'#.split(#)', this, re); |
95 } else { | 95 } else { |
96 return _defaultSplit(pattern); | 96 return _defaultSplit(pattern); |
97 } | 97 } |
98 } | 98 } |
99 | 99 |
100 String replaceRange(String replacement, int start, [int end]) { | |
101 checkString(replacement); | |
102 checkInt(start); | |
103 end = RangeError.checkValidRange(start, end, this.length); | |
104 checkInt(end); | |
105 var prefix = JS('String', '#.substring(0, #)', this, start); | |
106 var suffix = JS('String', '#.substring(#)', this, end); | |
107 return "$prefix$replacement$suffix"; | |
sra1
2015/02/23 18:58:27
There are use cases for an unchecked version.
rep
Lasse Reichstein Nielsen
2015/02/25 12:09:09
Done.
| |
108 } | |
109 | |
100 List<String> _defaultSplit(Pattern pattern) { | 110 List<String> _defaultSplit(Pattern pattern) { |
101 List<String> result = <String>[]; | 111 List<String> result = <String>[]; |
102 // End of most recent match. That is, start of next part to add to result. | 112 // End of most recent match. That is, start of next part to add to result. |
103 int start = 0; | 113 int start = 0; |
104 // Length of most recent match. | 114 // Length of most recent match. |
105 // Set >0, so no match on the empty string causes the result to be [""]. | 115 // Set >0, so no match on the empty string causes the result to be [""]. |
106 int length = 1; | 116 int length = 1; |
107 for (var match in pattern.allMatches(this)) { | 117 for (var match in pattern.allMatches(this)) { |
108 int matchStart = match.start; | 118 int matchStart = match.start; |
109 int matchEnd = match.end; | 119 int matchEnd = match.end; |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
455 Type get runtimeType => String; | 465 Type get runtimeType => String; |
456 | 466 |
457 int get length => JS('int', r'#.length', this); | 467 int get length => JS('int', r'#.length', this); |
458 | 468 |
459 String operator [](int index) { | 469 String operator [](int index) { |
460 if (index is !int) throw new ArgumentError(index); | 470 if (index is !int) throw new ArgumentError(index); |
461 if (index >= length || index < 0) throw new RangeError.value(index); | 471 if (index >= length || index < 0) throw new RangeError.value(index); |
462 return JS('String', '#[#]', this, index); | 472 return JS('String', '#[#]', this, index); |
463 } | 473 } |
464 } | 474 } |
OLD | NEW |