| 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 dart._js_helper; | 5 part of dart._js_helper; |
| 6 | 6 |
| 7 int stringIndexOfStringUnchecked(receiver, other, startIndex) { | 7 int stringIndexOfStringUnchecked(receiver, other, startIndex) { |
| 8 return JS('int', '#.indexOf(#, #)', receiver, other, startIndex); | 8 return JS('int', '#.indexOf(#, #)', receiver, other, startIndex); |
| 9 } | 9 } |
| 10 | 10 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 String _stringIdentity(String string) => string; | 171 String _stringIdentity(String string) => string; |
| 172 | 172 |
| 173 String stringReplaceAllFuncUnchecked(String receiver, Pattern pattern, | 173 String stringReplaceAllFuncUnchecked(String receiver, Pattern pattern, |
| 174 String onMatch(Match match), String onNonMatch(String nonMatch)) { | 174 String onMatch(Match match), String onNonMatch(String nonMatch)) { |
| 175 if (onMatch == null) onMatch = _matchString; | 175 if (onMatch == null) onMatch = _matchString; |
| 176 if (onNonMatch == null) onNonMatch = _stringIdentity; | 176 if (onNonMatch == null) onNonMatch = _stringIdentity; |
| 177 if (pattern is String) { | 177 if (pattern is String) { |
| 178 return stringReplaceAllStringFuncUnchecked( | 178 return stringReplaceAllStringFuncUnchecked( |
| 179 receiver, pattern, onMatch, onNonMatch); | 179 receiver, pattern, onMatch, onNonMatch); |
| 180 } | 180 } |
| 181 // Placing the Pattern test here is indistingishable from placing it at the | 181 // Placing the Pattern test here is indistinguishable from placing it at the |
| 182 // top of the method but it saves an extra check on the `pattern is String` | 182 // top of the method but it saves an extra check on the `pattern is String` |
| 183 // path. | 183 // path. |
| 184 if (pattern is! Pattern) { | 184 if (pattern is! Pattern) { |
| 185 throw new ArgumentError.value(pattern, 'pattern', 'is not a Pattern'); | 185 throw new ArgumentError.value(pattern, 'pattern', 'is not a Pattern'); |
| 186 } | 186 } |
| 187 StringBuffer buffer = new StringBuffer(); | 187 StringBuffer buffer = new StringBuffer(); |
| 188 int startIndex = 0; | 188 int startIndex = 0; |
| 189 for (Match match in pattern.allMatches(receiver)) { | 189 for (Match match in pattern.allMatches(receiver)) { |
| 190 buffer.write(onNonMatch(receiver.substring(startIndex, match.start))); | 190 buffer.write(onNonMatch(receiver.substring(startIndex, match.start))); |
| 191 buffer.write(onMatch(match)); | 191 buffer.write(onMatch(match)); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 String stringJoinUnchecked(array, separator) { | 278 String stringJoinUnchecked(array, separator) { |
| 279 return JS('String', r'#.join(#)', array, separator); | 279 return JS('String', r'#.join(#)', array, separator); |
| 280 } | 280 } |
| 281 | 281 |
| 282 String stringReplaceRangeUnchecked( | 282 String stringReplaceRangeUnchecked( |
| 283 String receiver, int start, int end, String replacement) { | 283 String receiver, int start, int end, String replacement) { |
| 284 var prefix = JS('String', '#.substring(0, #)', receiver, start); | 284 var prefix = JS('String', '#.substring(0, #)', receiver, start); |
| 285 var suffix = JS('String', '#.substring(#)', receiver, end); | 285 var suffix = JS('String', '#.substring(#)', receiver, end); |
| 286 return "$prefix$replacement$suffix"; | 286 return "$prefix$replacement$suffix"; |
| 287 } | 287 } |
| OLD | NEW |