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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 String _matchString(Match match) => match[0]; | 138 String _matchString(Match match) => match[0]; |
139 String _stringIdentity(String string) => string; | 139 String _stringIdentity(String string) => string; |
140 | 140 |
141 stringReplaceAllFuncUnchecked(receiver, pattern, onMatch, onNonMatch) { | 141 stringReplaceAllFuncUnchecked(receiver, pattern, onMatch, onNonMatch) { |
142 if (onMatch == null) onMatch = _matchString; | 142 if (onMatch == null) onMatch = _matchString; |
143 if (onNonMatch == null) onNonMatch = _stringIdentity; | 143 if (onNonMatch == null) onNonMatch = _stringIdentity; |
144 if (pattern is String) { | 144 if (pattern is String) { |
145 return stringReplaceAllStringFuncUnchecked(receiver, pattern, | 145 return stringReplaceAllStringFuncUnchecked(receiver, pattern, |
146 onMatch, onNonMatch); | 146 onMatch, onNonMatch); |
147 } | 147 } |
148 // Pattern test here is indistingishable from at the top of the method but we | 148 // Placing the Pattern test here is indistingishable from placing it at the |
149 // don't need to do it on the `pattern is String` path. | 149 // top of the method but it saves an extra check on the `pattern is String` |
| 150 // path. |
150 if (pattern is! Pattern) { | 151 if (pattern is! Pattern) { |
151 throw new ArgumentError("${pattern} is not a Pattern"); | 152 throw new ArgumentError.value(pattern, 'pattern', 'is not a Pattern'); |
152 } | 153 } |
153 StringBuffer buffer = new StringBuffer(); | 154 StringBuffer buffer = new StringBuffer(); |
154 int startIndex = 0; | 155 int startIndex = 0; |
155 for (Match match in pattern.allMatches(receiver)) { | 156 for (Match match in pattern.allMatches(receiver)) { |
156 buffer.write(onNonMatch(receiver.substring(startIndex, match.start))); | 157 buffer.write(onNonMatch(receiver.substring(startIndex, match.start))); |
157 buffer.write(onMatch(match)); | 158 buffer.write(onMatch(match)); |
158 startIndex = match.end; | 159 startIndex = match.end; |
159 } | 160 } |
160 buffer.write(onNonMatch(receiver.substring(startIndex))); | 161 buffer.write(onNonMatch(receiver.substring(startIndex))); |
161 return buffer.toString(); | 162 return buffer.toString(); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 stringJoinUnchecked(array, separator) { | 243 stringJoinUnchecked(array, separator) { |
243 return JS('String', r'#.join(#)', array, separator); | 244 return JS('String', r'#.join(#)', array, separator); |
244 } | 245 } |
245 | 246 |
246 String stringReplaceRangeUnchecked(String receiver, | 247 String stringReplaceRangeUnchecked(String receiver, |
247 int start, int end, String replacement) { | 248 int start, int end, String replacement) { |
248 var prefix = JS('String', '#.substring(0, #)', receiver, start); | 249 var prefix = JS('String', '#.substring(0, #)', receiver, start); |
249 var suffix = JS('String', '#.substring(#)', receiver, end); | 250 var suffix = JS('String', '#.substring(#)', receiver, end); |
250 return "$prefix$replacement$suffix"; | 251 return "$prefix$replacement$suffix"; |
251 } | 252 } |
OLD | NEW |