| 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 |
| 11 factory _StringBase._uninstantiable() { | 11 factory _StringBase._uninstantiable() { |
| 12 throw new UnsupportedError( | 12 throw new UnsupportedError( |
| 13 "_StringBase can't be instaniated"); | 13 "_StringBase can't be instaniated"); |
| 14 } | 14 } |
| 15 | 15 |
| 16 int get hashCode native "String_getHashCode"; | 16 int get hashCode native "String_getHashCode"; |
| 17 | 17 |
| 18 /** | 18 /** |
| 19 * Create the most efficient string representation for specified | 19 * Create the most efficient string representation for specified |
| 20 * [codePoints]. | 20 * [codePoints]. |
| 21 */ | 21 */ |
| 22 static String createFromCharCodes(List<int> charCodes) { | 22 static String createFromCharCodes(List<int> charCodes) { |
| 23 _ObjectArray objectArray; | 23 // TODO(ajohnsen): Add fast path once string_base is in core. |
| 24 if (charCodes is _ObjectArray) { | 24 int len = charCodes.length; |
| 25 objectArray = charCodes; | 25 var objectArray = new List(len); |
| 26 } else { | 26 for (int i = 0; i < len; i++) { |
| 27 int len = charCodes.length; | 27 objectArray[i] = charCodes[i]; |
| 28 objectArray = new _ObjectArray(len); | |
| 29 for (int i = 0; i < len; i++) { | |
| 30 objectArray[i] = charCodes[i]; | |
| 31 } | |
| 32 } | 28 } |
| 33 return _createFromCodePoints(objectArray); | 29 return _createFromCodePoints(objectArray); |
| 34 } | 30 } |
| 35 | 31 |
| 36 static String _createFromCodePoints(_ObjectArray<int> codePoints) | 32 static String _createFromCodePoints(List<int> codePoints) |
| 37 native "StringBase_createFromCodePoints"; | 33 native "StringBase_createFromCodePoints"; |
| 38 | 34 |
| 39 String operator [](int index) native "String_charAt"; | 35 String operator [](int index) native "String_charAt"; |
| 40 | 36 |
| 41 int charCodeAt(int index) native "String_charCodeAt"; | 37 int charCodeAt(int index) native "String_charCodeAt"; |
| 42 | 38 |
| 43 int get length native "String_getLength"; | 39 int get length native "String_getLength"; |
| 44 | 40 |
| 45 bool get isEmpty { | 41 bool get isEmpty { |
| 46 return this.length === 0; | 42 return this.length === 0; |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 } | 221 } |
| 226 return buffer.add(this.substring(startIndex)).toString(); | 222 return buffer.add(this.substring(startIndex)).toString(); |
| 227 } | 223 } |
| 228 | 224 |
| 229 /** | 225 /** |
| 230 * Convert all objects in [values] to strings and concat them | 226 * Convert all objects in [values] to strings and concat them |
| 231 * into a result string. | 227 * into a result string. |
| 232 */ | 228 */ |
| 233 static String _interpolate(List values) { | 229 static String _interpolate(List values) { |
| 234 int numValues = values.length; | 230 int numValues = values.length; |
| 235 var stringList = new _ObjectArray(numValues); | 231 var stringList = new List(numValues); |
| 236 for (int i = 0; i < numValues; i++) { | 232 for (int i = 0; i < numValues; i++) { |
| 237 stringList[i] = values[i].toString(); | 233 stringList[i] = values[i].toString(); |
| 238 } | 234 } |
| 239 return _concatAll(stringList); | 235 return _concatAll(stringList); |
| 240 } | 236 } |
| 241 | 237 |
| 242 Iterable<Match> allMatches(String str) { | 238 Iterable<Match> allMatches(String str) { |
| 243 List<Match> result = new List<Match>(); | 239 List<Match> result = new List<Match>(); |
| 244 int length = str.length; | 240 int length = str.length; |
| 245 int patternLength = this.length; | 241 int patternLength = this.length; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 int j = 1; | 325 int j = 1; |
| 330 for (int i = 1; i < length; i++) { | 326 for (int i = 1; i < length; i++) { |
| 331 stringsList[j++] = separator; | 327 stringsList[j++] = separator; |
| 332 stringsList[j++] = strings[i]; | 328 stringsList[j++] = strings[i]; |
| 333 } | 329 } |
| 334 } | 330 } |
| 335 return concatAll(stringsList); | 331 return concatAll(stringsList); |
| 336 } | 332 } |
| 337 | 333 |
| 338 static String concatAll(List<String> strings) { | 334 static String concatAll(List<String> strings) { |
| 339 _ObjectArray stringsArray; | 335 // TODO(ajohnsen): Add fast path once string_base is in core. |
| 340 if (strings is _ObjectArray) { | 336 int len = strings.length; |
| 341 stringsArray = strings; | 337 var stringsArray = new List(len); |
| 342 } else { | 338 for (int i = 0; i < len; i++) { |
| 343 int len = strings.length; | 339 stringsArray[i] = strings[i]; |
| 344 stringsArray = new _ObjectArray(len); | |
| 345 for (int i = 0; i < len; i++) { | |
| 346 stringsArray[i] = strings[i]; | |
| 347 } | |
| 348 } | 340 } |
| 349 return _concatAll(stringsArray); | 341 return _concatAll(stringsArray); |
| 350 } | 342 } |
| 351 | 343 |
| 352 static String _concatAll(_ObjectArray<String> strings) | 344 static String _concatAll(List<String> strings) |
| 353 native "Strings_concatAll"; | 345 native "Strings_concatAll"; |
| 354 } | 346 } |
| 355 | 347 |
| 356 | 348 |
| 357 class _OneByteString extends _StringBase implements String { | 349 class _OneByteString extends _StringBase implements String { |
| 358 factory _OneByteString._uninstantiable() { | 350 factory _OneByteString._uninstantiable() { |
| 359 throw new UnsupportedError( | 351 throw new UnsupportedError( |
| 360 "_OneByteString can only be allocated by the VM"); | 352 "_OneByteString can only be allocated by the VM"); |
| 361 } | 353 } |
| 362 | 354 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 for (int g in groups) { | 470 for (int g in groups) { |
| 479 result.add(group(g)); | 471 result.add(group(g)); |
| 480 } | 472 } |
| 481 return result; | 473 return result; |
| 482 } | 474 } |
| 483 | 475 |
| 484 final int start; | 476 final int start; |
| 485 final String str; | 477 final String str; |
| 486 final String pattern; | 478 final String pattern; |
| 487 } | 479 } |
| OLD | NEW |