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