| 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 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 var stringList = new List(numValues); | 235 var stringList = new List.fixedLength(numValues); |
| 236 for (int i = 0; i < numValues; i++) { | 236 for (int i = 0; i < numValues; i++) { |
| 237 stringList[i] = values[i].toString(); | 237 stringList[i] = values[i].toString(); |
| 238 } | 238 } |
| 239 return _concatAll(stringList); | 239 return _concatAll(stringList); |
| 240 } | 240 } |
| 241 | 241 |
| 242 Iterable<Match> allMatches(String str) { | 242 Iterable<Match> allMatches(String str) { |
| 243 List<Match> result = new List<Match>(); | 243 List<Match> result = new List<Match>(); |
| 244 int length = str.length; | 244 int length = str.length; |
| 245 int patternLength = this.length; | 245 int patternLength = this.length; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 continue; | 288 continue; |
| 289 } | 289 } |
| 290 result.add(this.substring(previousIndex, match.start)); | 290 result.add(this.substring(previousIndex, match.start)); |
| 291 startIndex = previousIndex = endIndex; | 291 startIndex = previousIndex = endIndex; |
| 292 } | 292 } |
| 293 return result; | 293 return result; |
| 294 } | 294 } |
| 295 | 295 |
| 296 List<String> splitChars() { | 296 List<String> splitChars() { |
| 297 int len = this.length; | 297 int len = this.length; |
| 298 final result = new List<String>(len); | 298 final result = new List<String>.fixedLength(len); |
| 299 for (int i = 0; i < len; i++) { | 299 for (int i = 0; i < len; i++) { |
| 300 result[i] = this[i]; | 300 result[i] = this[i]; |
| 301 } | 301 } |
| 302 return result; | 302 return result; |
| 303 } | 303 } |
| 304 | 304 |
| 305 List<int> get charCodes { | 305 List<int> get charCodes { |
| 306 int len = this.length; | 306 int len = this.length; |
| 307 final result = new List<int>(len); | 307 final result = new List<int>.fixedLength(len); |
| 308 for (int i = 0; i < len; i++) { | 308 for (int i = 0; i < len; i++) { |
| 309 result[i] = this.charCodeAt(i); | 309 result[i] = this.charCodeAt(i); |
| 310 } | 310 } |
| 311 return result; | 311 return result; |
| 312 } | 312 } |
| 313 | 313 |
| 314 String toUpperCase() native "String_toUpperCase"; | 314 String toUpperCase() native "String_toUpperCase"; |
| 315 | 315 |
| 316 String toLowerCase() native "String_toLowerCase"; | 316 String toLowerCase() native "String_toLowerCase"; |
| 317 | 317 |
| 318 // Implementations of Strings methods follow below. | 318 // Implementations of Strings methods follow below. |
| 319 static String join(List<String> strings, String separator) { | 319 static String join(List<String> strings, String separator) { |
| 320 final int length = strings.length; | 320 final int length = strings.length; |
| 321 if (length === 0) { | 321 if (length === 0) { |
| 322 return ""; | 322 return ""; |
| 323 } | 323 } |
| 324 | 324 |
| 325 List stringsList = strings; | 325 List stringsList = strings; |
| 326 if (separator.length != 0) { | 326 if (separator.length != 0) { |
| 327 stringsList = new List(2 * length - 1); | 327 stringsList = new List.fixedLength(2 * length - 1); |
| 328 stringsList[0] = strings[0]; | 328 stringsList[0] = strings[0]; |
| 329 int j = 1; | 329 int j = 1; |
| 330 for (int i = 1; i < length; i++) { | 330 for (int i = 1; i < length; i++) { |
| 331 stringsList[j++] = separator; | 331 stringsList[j++] = separator; |
| 332 stringsList[j++] = strings[i]; | 332 stringsList[j++] = strings[i]; |
| 333 } | 333 } |
| 334 } | 334 } |
| 335 return concatAll(stringsList); | 335 return concatAll(stringsList); |
| 336 } | 336 } |
| 337 | 337 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 for (int g in groups) { | 478 for (int g in groups) { |
| 479 result.add(group(g)); | 479 result.add(group(g)); |
| 480 } | 480 } |
| 481 return result; | 481 return result; |
| 482 } | 482 } |
| 483 | 483 |
| 484 final int start; | 484 final int start; |
| 485 final String str; | 485 final String str; |
| 486 final String pattern; | 486 final String pattern; |
| 487 } | 487 } |
| OLD | NEW |