Chromium Code Reviews| 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 patch class String { | 5 patch class String { |
| 6 /* patch */ factory String.fromCharCodes(Iterable<int> charCodes, | 6 /* patch */ factory String.fromCharCodes(Iterable<int> charCodes, |
| 7 [int start = 0, int end]) { | 7 [int start = 0, int end]) { |
| 8 return _StringBase.createFromCharCodes(charCodes, start, end); | 8 return _StringBase.createFromCharCodes(charCodes, start, end); |
| 9 } | 9 } |
| 10 | 10 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 | 50 |
| 51 int get hashCode native "String_getHashCode"; | 51 int get hashCode native "String_getHashCode"; |
| 52 | 52 |
| 53 /** | 53 /** |
| 54 * Create the most efficient string representation for specified | 54 * Create the most efficient string representation for specified |
| 55 * [codePoints]. | 55 * [codePoints]. |
| 56 */ | 56 */ |
| 57 static String createFromCharCodes(Iterable<int> charCodes, | 57 static String createFromCharCodes(Iterable<int> charCodes, |
| 58 int start, int end) { | 58 int start, int end) { |
| 59 if (charCodes == null) throw new ArgumentError(charCodes); | 59 if (charCodes == null) throw new ArgumentError(charCodes); |
| 60 if (start < 0) throw new RangeError.value(start); | |
| 61 // TODO(srdjan): Also skip copying of wide typed arrays. | 60 // TODO(srdjan): Also skip copying of wide typed arrays. |
| 62 final ccid = ClassID.getID(charCodes); | 61 final ccid = ClassID.getID(charCodes); |
| 63 bool isOneByteString = false; | 62 bool isOneByteString = false; |
| 64 if ((ccid != ClassID.cidArray) && | 63 if ((ccid != ClassID.cidArray) && |
| 65 (ccid != ClassID.cidGrowableObjectArray) && | 64 (ccid != ClassID.cidGrowableObjectArray) && |
| 66 (ccid != ClassID.cidImmutableArray)) { | 65 (ccid != ClassID.cidImmutableArray)) { |
| 67 if ((charCodes is Uint8List) || (charCodes is Int8List)) { | 66 if ((charCodes is Uint8List) || (charCodes is Int8List)) { |
| 68 isOneByteString = true; | 67 isOneByteString = true; |
| 69 } else { | 68 } else { |
| 70 charCodes = new List.from(charCodes, growable: false); | 69 charCodes = new List.from(charCodes, growable: false); |
|
Søren Gjesse
2014/09/26 11:43:00
If the iterable is long (maybe even infinite) then
| |
| 71 } | 70 } |
| 72 } | 71 } |
| 73 if ((end == null) || (end > charCodes.length)) { | 72 int codeCount = charCodes.length; |
| 74 end = charCodes.length; | 73 if (start < 0 || start > codeCount) { |
| 74 throw new RangeError.range(start, 0, codeCount); | |
| 75 } | 75 } |
| 76 if (end <= start) return ""; | 76 if (end == null) { |
| 77 end = codeCount; | |
| 78 } else if (end < start || end > codeCount) { | |
| 79 throw new RangeError.range(end, start, codeCount); | |
| 80 } | |
| 77 final len = end - start; | 81 final len = end - start; |
| 78 if (!isOneByteString) { | 82 if (!isOneByteString) { |
| 79 for (int i = start; i < end; i++) { | 83 for (int i = start; i < end; i++) { |
| 80 int e = charCodes[i]; | 84 int e = charCodes[i]; |
| 81 if (e is! _Smi) throw new ArgumentError(e); | 85 if (e is! _Smi) throw new ArgumentError(e); |
| 82 // Is e Latin1? | 86 // Is e Latin1? |
| 83 if ((e < 0) || (e > 0xFF)) { | 87 if ((e < 0) || (e > 0xFF)) { |
| 84 return _createFromCodePoints(charCodes, start, end); | 88 return _createFromCodePoints(charCodes, start, end); |
| 85 } | 89 } |
| 86 } | 90 } |
| (...skipping 939 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1026 class _CodeUnits extends Object with ListMixin<int>, | 1030 class _CodeUnits extends Object with ListMixin<int>, |
| 1027 UnmodifiableListMixin<int> { | 1031 UnmodifiableListMixin<int> { |
| 1028 /** The string that this is the code units of. */ | 1032 /** The string that this is the code units of. */ |
| 1029 String _string; | 1033 String _string; |
| 1030 | 1034 |
| 1031 _CodeUnits(this._string); | 1035 _CodeUnits(this._string); |
| 1032 | 1036 |
| 1033 int get length => _string.length; | 1037 int get length => _string.length; |
| 1034 int operator[](int i) => _string.codeUnitAt(i); | 1038 int operator[](int i) => _string.codeUnitAt(i); |
| 1035 } | 1039 } |
| OLD | NEW |