| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 | 66 |
| 67 String splitMapJoin(Pattern from, | 67 String splitMapJoin(Pattern from, |
| 68 {String onMatch(Match match), | 68 {String onMatch(Match match), |
| 69 String onNonMatch(String nonMatch)}) { | 69 String onNonMatch(String nonMatch)}) { |
| 70 return stringReplaceAllFuncUnchecked(this, from, onMatch, onNonMatch); | 70 return stringReplaceAllFuncUnchecked(this, from, onMatch, onNonMatch); |
| 71 } | 71 } |
| 72 | 72 |
| 73 String replaceFirst(Pattern from, String to, [int startIndex = 0]) { | 73 String replaceFirst(Pattern from, String to, [int startIndex = 0]) { |
| 74 checkString(to); | 74 checkString(to); |
| 75 checkInt(startIndex); | 75 checkInt(startIndex); |
| 76 RangeError.checkValueInInterval(startIndex, 0, this.length, "startIndex"); | 76 if (startIndex < 0 || startIndex > this.length) { |
| 77 throw new RangeError.range(startIndex, 0, this.length); |
| 78 } |
| 77 return stringReplaceFirstUnchecked(this, from, to, startIndex); | 79 return stringReplaceFirstUnchecked(this, from, to, startIndex); |
| 78 } | 80 } |
| 79 | 81 |
| 80 String replaceFirstMapped(Pattern from, String replace(Match match), | |
| 81 [int startIndex = 0]) { | |
| 82 checkNull(replace); | |
| 83 checkInt(startIndex); | |
| 84 RangeError.checkValueInInterval(startIndex, 0, this.length, "startIndex"); | |
| 85 return stringReplaceFirstMappedUnchecked(this, from, replace, startIndex); | |
| 86 } | |
| 87 | |
| 88 List<String> split(Pattern pattern) { | 82 List<String> split(Pattern pattern) { |
| 89 checkNull(pattern); | 83 checkNull(pattern); |
| 90 if (pattern is String) { | 84 if (pattern is String) { |
| 91 return JS('JSExtendableArray', r'#.split(#)', this, pattern); | 85 return JS('JSExtendableArray', r'#.split(#)', this, pattern); |
| 92 } else if (pattern is JSSyntaxRegExp && regExpCaptureCount(pattern) == 0) { | 86 } else if (pattern is JSSyntaxRegExp && regExpCaptureCount(pattern) == 0) { |
| 93 var re = regExpGetNative(pattern); | 87 var re = regExpGetNative(pattern); |
| 94 return JS('JSExtendableArray', r'#.split(#)', this, re); | 88 return JS('JSExtendableArray', r'#.split(#)', this, re); |
| 95 } else { | 89 } else { |
| 96 return _defaultSplit(pattern); | 90 return _defaultSplit(pattern); |
| 97 } | 91 } |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 Type get runtimeType => String; | 449 Type get runtimeType => String; |
| 456 | 450 |
| 457 int get length => JS('int', r'#.length', this); | 451 int get length => JS('int', r'#.length', this); |
| 458 | 452 |
| 459 String operator [](int index) { | 453 String operator [](int index) { |
| 460 if (index is !int) throw new ArgumentError(index); | 454 if (index is !int) throw new ArgumentError(index); |
| 461 if (index >= length || index < 0) throw new RangeError.value(index); | 455 if (index >= length || index < 0) throw new RangeError.value(index); |
| 462 return JS('String', '#[#]', this, index); | 456 return JS('String', '#[#]', this, index); |
| 463 } | 457 } |
| 464 } | 458 } |
| OLD | NEW |