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 |
11 factory StringBase._uninstantiable() { | 11 factory StringBase._uninstantiable() { |
12 throw const UnsupportedOperationException( | 12 throw const UnsupportedOperationException( |
13 "StringBase can't be instaniated"); | 13 "StringBase can't be instaniated"); |
14 } | 14 } |
15 | 15 |
16 int hashCode() native "String_hashCode"; | 16 int hashCode() native "String_hashCode"; |
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 _ObjectArray objectArray; |
24 if (charCodes is ObjectArray) { | 24 if (charCodes is _ObjectArray) { |
25 objectArray = charCodes; | 25 objectArray = charCodes; |
26 } else { | 26 } else { |
27 int len = charCodes.length; | 27 int len = charCodes.length; |
28 objectArray = new ObjectArray(len); | 28 objectArray = new _ObjectArray(len); |
29 for (int i = 0; i < len; i++) { | 29 for (int i = 0; i < len; i++) { |
30 objectArray[i] = charCodes[i]; | 30 objectArray[i] = charCodes[i]; |
31 } | 31 } |
32 } | 32 } |
33 return _createFromCodePoints(objectArray); | 33 return _createFromCodePoints(objectArray); |
34 } | 34 } |
35 | 35 |
36 static String _createFromCodePoints(ObjectArray<int> codePoints) | 36 static String _createFromCodePoints(_ObjectArray<int> codePoints) |
37 native "StringBase_createFromCodePoints"; | 37 native "StringBase_createFromCodePoints"; |
38 | 38 |
39 String operator [](int index) native "String_charAt"; | 39 String operator [](int index) native "String_charAt"; |
40 | 40 |
41 int charCodeAt(int index) native "String_charCodeAt"; | 41 int charCodeAt(int index) native "String_charCodeAt"; |
42 | 42 |
43 int get length native "String_getLength"; | 43 int get length native "String_getLength"; |
44 | 44 |
45 bool isEmpty() { | 45 bool isEmpty() { |
46 return this.length === 0; | 46 return this.length === 0; |
(...skipping 178 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 ObjectArray(numValues); | 235 var stringList = new _ObjectArray(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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
338 static String concatAll(List<String> strings) { | 338 static String concatAll(List<String> strings) { |
339 ObjectArray stringsArray; | 339 _ObjectArray stringsArray; |
340 if (strings is ObjectArray) { | 340 if (strings is _ObjectArray) { |
341 stringsArray = strings; | 341 stringsArray = strings; |
342 } else { | 342 } else { |
343 int len = strings.length; | 343 int len = strings.length; |
344 stringsArray = new ObjectArray(len); | 344 stringsArray = new _ObjectArray(len); |
345 for (int i = 0; i < len; i++) { | 345 for (int i = 0; i < len; i++) { |
346 stringsArray[i] = strings[i]; | 346 stringsArray[i] = strings[i]; |
347 } | 347 } |
348 } | 348 } |
349 return _concatAll(stringsArray); | 349 return _concatAll(stringsArray); |
350 } | 350 } |
351 | 351 |
352 static String _concatAll(ObjectArray<String> strings) | 352 static String _concatAll(_ObjectArray<String> strings) |
353 native "Strings_concatAll"; | 353 native "Strings_concatAll"; |
354 } | 354 } |
355 | 355 |
356 | 356 |
357 class OneByteString extends StringBase implements String { | 357 class OneByteString extends StringBase implements String { |
358 factory OneByteString._uninstantiable() { | 358 factory OneByteString._uninstantiable() { |
359 throw const UnsupportedOperationException( | 359 throw const UnsupportedOperationException( |
360 "OneByteString can only be allocated by the VM"); | 360 "OneByteString can only be allocated by the VM"); |
361 } | 361 } |
362 | 362 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 for (int g in groups) { | 479 for (int g in groups) { |
480 result.add(group(g)); | 480 result.add(group(g)); |
481 } | 481 } |
482 return result; | 482 return result; |
483 } | 483 } |
484 | 484 |
485 final int _start; | 485 final int _start; |
486 final String str; | 486 final String str; |
487 final String pattern; | 487 final String pattern; |
488 } | 488 } |
OLD | NEW |