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 /** | 5 /** |
6 * [_StringBase] contains common methods used by concrete String | 6 * [_StringBase] contains common methods used by concrete String |
7 * implementations, e.g., _OneByteString. | 7 * implementations, e.g., _OneByteString. |
8 */ | 8 */ |
9 class _StringBase { | 9 class _StringBase { |
10 | 10 |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 throw new ArgumentError("${pattern} is not a Pattern"); | 212 throw new ArgumentError("${pattern} is not a Pattern"); |
213 } | 213 } |
214 if (replacement is! String) { | 214 if (replacement is! String) { |
215 throw new ArgumentError("${replacement} is not a String"); | 215 throw new ArgumentError("${replacement} is not a String"); |
216 } | 216 } |
217 StringBuffer buffer = new StringBuffer(); | 217 StringBuffer buffer = new StringBuffer(); |
218 int startIndex = 0; | 218 int startIndex = 0; |
219 Iterator iterator = pattern.allMatches(this).iterator(); | 219 Iterator iterator = pattern.allMatches(this).iterator(); |
220 if (iterator.hasNext) { | 220 if (iterator.hasNext) { |
221 Match match = iterator.next(); | 221 Match match = iterator.next(); |
222 buffer.add(this.substring(startIndex, match.start)).add(replacement); | 222 buffer..add(this.substring(startIndex, match.start)) |
| 223 ..add(replacement); |
223 startIndex = match.end; | 224 startIndex = match.end; |
224 } | 225 } |
225 return buffer.add(this.substring(startIndex)).toString(); | 226 return (buffer..add(this.substring(startIndex))).toString(); |
226 } | 227 } |
227 | 228 |
228 String replaceAll(Pattern pattern, String replacement) { | 229 String replaceAll(Pattern pattern, String replacement) { |
229 if (pattern is! Pattern) { | 230 if (pattern is! Pattern) { |
230 throw new ArgumentError("${pattern} is not a Pattern"); | 231 throw new ArgumentError("${pattern} is not a Pattern"); |
231 } | 232 } |
232 if (replacement is! String) { | 233 if (replacement is! String) { |
233 throw new ArgumentError("${replacement} is not a String"); | 234 throw new ArgumentError("${replacement} is not a String"); |
234 } | 235 } |
235 StringBuffer buffer = new StringBuffer(); | 236 StringBuffer buffer = new StringBuffer(); |
236 int startIndex = 0; | 237 int startIndex = 0; |
237 for (Match match in pattern.allMatches(this)) { | 238 for (Match match in pattern.allMatches(this)) { |
238 buffer.add(this.substring(startIndex, match.start)).add(replacement); | 239 buffer..add(this.substring(startIndex, match.start)) |
| 240 ..add(replacement); |
239 startIndex = match.end; | 241 startIndex = match.end; |
240 } | 242 } |
241 return buffer.add(this.substring(startIndex)).toString(); | 243 return (buffer..add(this.substring(startIndex))).toString(); |
242 } | 244 } |
243 | 245 |
244 /** | 246 /** |
245 * Convert all objects in [values] to strings and concat them | 247 * Convert all objects in [values] to strings and concat them |
246 * into a result string. | 248 * into a result string. |
247 */ | 249 */ |
248 static String _interpolate(List values) { | 250 static String _interpolate(List values) { |
249 int numValues = values.length; | 251 int numValues = values.length; |
250 var stringList = new List(numValues); | 252 var stringList = new List(numValues); |
251 for (int i = 0; i < numValues; i++) { | 253 for (int i = 0; i < numValues; i++) { |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 for (int g in groups) { | 510 for (int g in groups) { |
509 result.add(group(g)); | 511 result.add(group(g)); |
510 } | 512 } |
511 return result; | 513 return result; |
512 } | 514 } |
513 | 515 |
514 final int start; | 516 final int start; |
515 final String str; | 517 final String str; |
516 final String pattern; | 518 final String pattern; |
517 } | 519 } |
OLD | NEW |