| 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 return _StringBase.createFromCharCodes(charCodes); | 7 return _StringBase.createFromCharCodes(charCodes); |
| 8 } | 8 } |
| 9 | 9 |
| 10 /* patch */ factory String.fromCharCode(int charCode) { | 10 /* patch */ factory String.fromCharCode(int charCode) { |
| (...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 native "OneByteString_splitWithCharCode"; | 676 native "OneByteString_splitWithCharCode"; |
| 677 | 677 |
| 678 List<String> split(Pattern pattern) { | 678 List<String> split(Pattern pattern) { |
| 679 if ((ClassID.getID(pattern) == ClassID.cidOneByteString) && | 679 if ((ClassID.getID(pattern) == ClassID.cidOneByteString) && |
| 680 (pattern.length == 1)) { | 680 (pattern.length == 1)) { |
| 681 return _splitWithCharCode(pattern.codeUnitAt(0)); | 681 return _splitWithCharCode(pattern.codeUnitAt(0)); |
| 682 } | 682 } |
| 683 return super.split(pattern); | 683 return super.split(pattern); |
| 684 } | 684 } |
| 685 | 685 |
| 686 int _oneCodeUnitAt(int index) => _codeUnitsAt(index, 1); |
| 687 int _twoCodeUnitsAt(int index) => _codeUnitsAt(index, 2); |
| 688 int _fourCodeUnitsAt(int index) => _codeUnitsAt(index, 4); |
| 689 |
| 690 // Loads up to 4 code units into a single integer. |
| 691 int _codeUnitsAt(int index, int count) { |
| 692 assert(index >= 0); |
| 693 assert(index + count - 1 < this.length); |
| 694 assert(0 < count && count <= 4); |
| 695 |
| 696 int codeUnits = 0; |
| 697 for (int i = 0; i < count; i++) { |
| 698 codeUnits |= this.codeUnitAt(index + i) << (i * 8); |
| 699 } |
| 700 |
| 701 return codeUnits; |
| 702 } |
| 703 |
| 686 // All element of 'strings' must be OneByteStrings. | 704 // All element of 'strings' must be OneByteStrings. |
| 687 static _concatAll(List<String> strings, int totalLength) { | 705 static _concatAll(List<String> strings, int totalLength) { |
| 688 // TODO(srdjan): Improve code below and raise or eliminate the limit. | 706 // TODO(srdjan): Improve code below and raise or eliminate the limit. |
| 689 if (totalLength > 128) { | 707 if (totalLength > 128) { |
| 690 // Native is quicker. | 708 // Native is quicker. |
| 691 return _StringBase._concatRangeNative(strings, 0, strings.length); | 709 return _StringBase._concatRangeNative(strings, 0, strings.length); |
| 692 } | 710 } |
| 693 var res = _OneByteString._allocate(totalLength); | 711 var res = _OneByteString._allocate(totalLength); |
| 694 final stringsLength = strings.length; | 712 final stringsLength = strings.length; |
| 695 int rIx = 0; | 713 int rIx = 0; |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 939 "_TwoByteString can only be allocated by the VM"); | 957 "_TwoByteString can only be allocated by the VM"); |
| 940 } | 958 } |
| 941 | 959 |
| 942 bool _isWhitespace(int codeUnit) { | 960 bool _isWhitespace(int codeUnit) { |
| 943 return _StringBase._isTwoByteWhitespace(codeUnit); | 961 return _StringBase._isTwoByteWhitespace(codeUnit); |
| 944 } | 962 } |
| 945 | 963 |
| 946 bool operator ==(Object other) { | 964 bool operator ==(Object other) { |
| 947 return super == other; | 965 return super == other; |
| 948 } | 966 } |
| 967 |
| 968 int _oneCodeUnitAt(int index) => _codeUnitsAt(index, 1); |
| 969 int _twoCodeUnitsAt(int index) => _codeUnitsAt(index, 2); |
| 970 |
| 971 // Loads up to 2 code units into a single integer. |
| 972 int _codeUnitsAt(int index, int count) { |
| 973 assert(index >= 0); |
| 974 assert(index + count - 1 < this.length); |
| 975 assert(0 < count && count <= 2); |
| 976 |
| 977 int codeUnits = 0; |
| 978 for (int i = 0; i < count; i++) { |
| 979 codeUnits |= this.codeUnitAt(index + i) << (i * 16); |
| 980 } |
| 981 |
| 982 return codeUnits; |
| 983 } |
| 949 } | 984 } |
| 950 | 985 |
| 951 | 986 |
| 952 class _ExternalOneByteString extends _StringBase implements String { | 987 class _ExternalOneByteString extends _StringBase implements String { |
| 953 factory _ExternalOneByteString._uninstantiable() { | 988 factory _ExternalOneByteString._uninstantiable() { |
| 954 throw new UnsupportedError( | 989 throw new UnsupportedError( |
| 955 "_ExternalOneByteString can only be allocated by the VM"); | 990 "_ExternalOneByteString can only be allocated by the VM"); |
| 956 } | 991 } |
| 957 | 992 |
| 958 bool _isWhitespace(int codeUnit) { | 993 bool _isWhitespace(int codeUnit) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1018 class _CodeUnits extends Object with ListMixin<int>, | 1053 class _CodeUnits extends Object with ListMixin<int>, |
| 1019 UnmodifiableListMixin<int> { | 1054 UnmodifiableListMixin<int> { |
| 1020 /** The string that this is the code units of. */ | 1055 /** The string that this is the code units of. */ |
| 1021 String _string; | 1056 String _string; |
| 1022 | 1057 |
| 1023 _CodeUnits(this._string); | 1058 _CodeUnits(this._string); |
| 1024 | 1059 |
| 1025 int get length => _string.length; | 1060 int get length => _string.length; |
| 1026 int operator[](int i) => _string.codeUnitAt(i); | 1061 int operator[](int i) => _string.codeUnitAt(i); |
| 1027 } | 1062 } |
| OLD | NEW |