| 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 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 native "OneByteString_splitWithCharCode"; | 668 native "OneByteString_splitWithCharCode"; |
| 669 | 669 |
| 670 List<String> split(Pattern pattern) { | 670 List<String> split(Pattern pattern) { |
| 671 if ((ClassID.getID(pattern) == ClassID.cidOneByteString) && | 671 if ((ClassID.getID(pattern) == ClassID.cidOneByteString) && |
| 672 (pattern.length == 1)) { | 672 (pattern.length == 1)) { |
| 673 return _splitWithCharCode(pattern.codeUnitAt(0)); | 673 return _splitWithCharCode(pattern.codeUnitAt(0)); |
| 674 } | 674 } |
| 675 return super.split(pattern); | 675 return super.split(pattern); |
| 676 } | 676 } |
| 677 | 677 |
| 678 // Loads up to 4 code units into a single integer. |
| 679 int _codeUnitsAt(int index, int count) { |
| 680 assert(index >= 0); |
| 681 assert(index + count - 1 < this.length); |
| 682 assert(0 < count && count <= 4); |
| 683 |
| 684 int codeUnits = 0; |
| 685 for (int i = 0; i < count; i++) { |
| 686 codeUnits |= this.codeUnitAt(index + i) << (i * 8); |
| 687 } |
| 688 |
| 689 return codeUnits; |
| 690 } |
| 691 |
| 678 // All element of 'strings' must be OneByteStrings. | 692 // All element of 'strings' must be OneByteStrings. |
| 679 static _concatAll(List<String> strings, int totalLength) { | 693 static _concatAll(List<String> strings, int totalLength) { |
| 680 // TODO(srdjan): Improve code below and raise or eliminate the limit. | 694 // TODO(srdjan): Improve code below and raise or eliminate the limit. |
| 681 if (totalLength > 128) { | 695 if (totalLength > 128) { |
| 682 // Native is quicker. | 696 // Native is quicker. |
| 683 return _StringBase._concatRangeNative(strings, 0, strings.length); | 697 return _StringBase._concatRangeNative(strings, 0, strings.length); |
| 684 } | 698 } |
| 685 var res = _OneByteString._allocate(totalLength); | 699 var res = _OneByteString._allocate(totalLength); |
| 686 final stringsLength = strings.length; | 700 final stringsLength = strings.length; |
| 687 int rIx = 0; | 701 int rIx = 0; |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 "_TwoByteString can only be allocated by the VM"); | 945 "_TwoByteString can only be allocated by the VM"); |
| 932 } | 946 } |
| 933 | 947 |
| 934 bool _isWhitespace(int codeUnit) { | 948 bool _isWhitespace(int codeUnit) { |
| 935 return _StringBase._isTwoByteWhitespace(codeUnit); | 949 return _StringBase._isTwoByteWhitespace(codeUnit); |
| 936 } | 950 } |
| 937 | 951 |
| 938 bool operator ==(Object other) { | 952 bool operator ==(Object other) { |
| 939 return super == other; | 953 return super == other; |
| 940 } | 954 } |
| 955 |
| 956 // Loads up to 2 code units into a single integer. |
| 957 int _codeUnitsAt(int index, int count) { |
| 958 assert(index >= 0); |
| 959 assert(index + count - 1 < this.length); |
| 960 assert(0 < count && count <= 2); |
| 961 |
| 962 int codeUnits = 0; |
| 963 for (int i = 0; i < count; i++) { |
| 964 codeUnits |= this.codeUnitAt(index + i) << (i * 16); |
| 965 } |
| 966 |
| 967 return codeUnits; |
| 968 } |
| 941 } | 969 } |
| 942 | 970 |
| 943 | 971 |
| 944 class _ExternalOneByteString extends _StringBase implements String { | 972 class _ExternalOneByteString extends _StringBase implements String { |
| 945 factory _ExternalOneByteString._uninstantiable() { | 973 factory _ExternalOneByteString._uninstantiable() { |
| 946 throw new UnsupportedError( | 974 throw new UnsupportedError( |
| 947 "_ExternalOneByteString can only be allocated by the VM"); | 975 "_ExternalOneByteString can only be allocated by the VM"); |
| 948 } | 976 } |
| 949 | 977 |
| 950 bool _isWhitespace(int codeUnit) { | 978 bool _isWhitespace(int codeUnit) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1010 class _CodeUnits extends Object with ListMixin<int>, | 1038 class _CodeUnits extends Object with ListMixin<int>, |
| 1011 UnmodifiableListMixin<int> { | 1039 UnmodifiableListMixin<int> { |
| 1012 /** The string that this is the code units of. */ | 1040 /** The string that this is the code units of. */ |
| 1013 String _string; | 1041 String _string; |
| 1014 | 1042 |
| 1015 _CodeUnits(this._string); | 1043 _CodeUnits(this._string); |
| 1016 | 1044 |
| 1017 int get length => _string.length; | 1045 int get length => _string.length; |
| 1018 int operator[](int i) => _string.codeUnitAt(i); | 1046 int operator[](int i) => _string.codeUnitAt(i); |
| 1019 } | 1047 } |
| OLD | NEW |