| 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); |
| 60 // TODO(srdjan): Also skip copying of wide typed arrays. | 61 // TODO(srdjan): Also skip copying of wide typed arrays. |
| 61 final ccid = ClassID.getID(charCodes); | 62 final ccid = ClassID.getID(charCodes); |
| 62 bool isOneByteString = false; | 63 bool isOneByteString = false; |
| 63 if ((ccid != ClassID.cidArray) && | 64 if ((ccid != ClassID.cidArray) && |
| 64 (ccid != ClassID.cidGrowableObjectArray) && | 65 (ccid != ClassID.cidGrowableObjectArray) && |
| 65 (ccid != ClassID.cidImmutableArray)) { | 66 (ccid != ClassID.cidImmutableArray)) { |
| 66 if ((charCodes is Uint8List) || (charCodes is Int8List)) { | 67 if ((charCodes is Uint8List) || (charCodes is Int8List)) { |
| 67 isOneByteString = true; | 68 isOneByteString = true; |
| 68 } else { | 69 } else { |
| 69 charCodes = new List.from(charCodes, growable: false); | 70 charCodes = new List.from(charCodes, growable: false); |
| 70 } | 71 } |
| 71 } | 72 } |
| 72 int codeCount = charCodes.length; | 73 if ((end == null) || (end > charCodes.length)) { |
| 73 if (start < 0 || start > codeCount) { | 74 end = charCodes.length; |
| 74 throw new RangeError.range(start, 0, codeCount); | |
| 75 } | 75 } |
| 76 if (end == null) { | 76 if (end <= start) return ""; |
| 77 end = codeCount; | |
| 78 } else if (end < start || end > codeCount) { | |
| 79 throw new RangeError.range(end, start, codeCount); | |
| 80 } | |
| 81 final len = end - start; | 77 final len = end - start; |
| 82 if (!isOneByteString) { | 78 if (!isOneByteString) { |
| 83 for (int i = start; i < end; i++) { | 79 for (int i = start; i < end; i++) { |
| 84 int e = charCodes[i]; | 80 int e = charCodes[i]; |
| 85 if (e is! _Smi) throw new ArgumentError(e); | 81 if (e is! _Smi) throw new ArgumentError(e); |
| 86 // Is e Latin1? | 82 // Is e Latin1? |
| 87 if ((e < 0) || (e > 0xFF)) { | 83 if ((e < 0) || (e > 0xFF)) { |
| 88 return _createFromCodePoints(charCodes, start, end); | 84 return _createFromCodePoints(charCodes, start, end); |
| 89 } | 85 } |
| 90 } | 86 } |
| (...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1035 class _CodeUnits extends Object with ListMixin<int>, | 1031 class _CodeUnits extends Object with ListMixin<int>, |
| 1036 UnmodifiableListMixin<int> { | 1032 UnmodifiableListMixin<int> { |
| 1037 /** The string that this is the code units of. */ | 1033 /** The string that this is the code units of. */ |
| 1038 String _string; | 1034 String _string; |
| 1039 | 1035 |
| 1040 _CodeUnits(this._string); | 1036 _CodeUnits(this._string); |
| 1041 | 1037 |
| 1042 int get length => _string.length; | 1038 int get length => _string.length; |
| 1043 int operator[](int i) => _string.codeUnitAt(i); | 1039 int operator[](int i) => _string.codeUnitAt(i); |
| 1044 } | 1040 } |
| OLD | NEW |