| 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 implementations, | 6 * [StringBase] contains common methods used by concrete String implementations, |
| 7 * e.g., OneByteString. | 7 * e.g., OneByteString. |
| 8 */ | 8 */ |
| 9 class StringBase { | 9 class StringBase { |
| 10 | 10 |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 } | 225 } |
| 226 return buffer.add(this.substring(startIndex)).toString(); | 226 return buffer.add(this.substring(startIndex)).toString(); |
| 227 } | 227 } |
| 228 | 228 |
| 229 /** | 229 /** |
| 230 * Convert all objects in [values] to strings and concat them | 230 * Convert all objects in [values] to strings and concat them |
| 231 * into a result string. | 231 * into a result string. |
| 232 */ | 232 */ |
| 233 static String _interpolate(List values) { | 233 static String _interpolate(List values) { |
| 234 int numValues = values.length; | 234 int numValues = values.length; |
| 235 List<String> stringList = new List<String>(numValues); | 235 var stringList = new ObjectArray(numValues); |
| 236 int resultLength = 0; | |
| 237 for (int i = 0; i < numValues; i++) { | 236 for (int i = 0; i < numValues; i++) { |
| 238 String str = values[i].toString(); | 237 stringList[i] = values[i].toString(); |
| 239 resultLength += str.length; | |
| 240 stringList[i] = str; | |
| 241 } | 238 } |
| 242 List<int> codepoints = new List<int>(resultLength); | 239 return _concatAll(stringList); |
| 243 int intArrayIx = 0; | |
| 244 for (int i = 0; i < numValues; i++) { | |
| 245 String str = stringList[i]; | |
| 246 int strLength = str.length; | |
| 247 for (int k = 0; k < strLength; k++) { | |
| 248 codepoints[intArrayIx++] = str.charCodeAt(k); | |
| 249 } | |
| 250 } | |
| 251 return StringBase.createFromCharCodes(codepoints); | |
| 252 } | 240 } |
| 253 | 241 |
| 254 Iterable<Match> allMatches(String str) { | 242 Iterable<Match> allMatches(String str) { |
| 255 List<Match> result = new List<Match>(); | 243 List<Match> result = new List<Match>(); |
| 256 int length = str.length; | 244 int length = str.length; |
| 257 int patternLength = this.length; | 245 int patternLength = this.length; |
| 258 int startIndex = 0; | 246 int startIndex = 0; |
| 259 while (true) { | 247 while (true) { |
| 260 int position = str.indexOf(this, startIndex); | 248 int position = str.indexOf(this, startIndex); |
| 261 if (position == -1) { | 249 if (position == -1) { |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 for (int g in groups) { | 479 for (int g in groups) { |
| 492 result.add(group(g)); | 480 result.add(group(g)); |
| 493 } | 481 } |
| 494 return result; | 482 return result; |
| 495 } | 483 } |
| 496 | 484 |
| 497 final int _start; | 485 final int _start; |
| 498 final String str; | 486 final String str; |
| 499 final String pattern; | 487 final String pattern; |
| 500 } | 488 } |
| OLD | NEW |