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 */ const factory String.fromEnvironment(String name, | 10 /* patch */ const factory String.fromEnvironment(String name, |
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
771 } else { | 771 } else { |
772 for (int i = 0; i < delta; i++) { | 772 for (int i = 0; i < delta; i++) { |
773 for (int j = 0; j < padLength; j++) { | 773 for (int j = 0; j < padLength; j++) { |
774 result._setAt(index++, padding.codeUnitAt(j)); | 774 result._setAt(index++, padding.codeUnitAt(j)); |
775 } | 775 } |
776 } | 776 } |
777 } | 777 } |
778 return result; | 778 return result; |
779 } | 779 } |
780 | 780 |
781 int _nextLowerCase(int offset) { | |
Søren Gjesse
2014/03/25 15:28:05
Shouldn't this be called _nextUpperCase/_nextUpper
| |
782 final length = this.length; | |
783 while (offset < length) { | |
784 int codeUnit = this.codeUnitAt(offset); | |
srdjan
2014/03/25 15:46:31
final codeUnit
| |
785 if (((codeUnit - 0x41) & 0xff) < 26) { | |
786 // Optimzed ASCII check: | |
srdjan
2014/03/25 15:46:31
s/Optimzed/Optimized/
| |
787 // - 0x41 is 'A' | |
788 // - 0xff is LATIN1 mask | |
789 // - 26 is the number of characters in this range. | |
790 return offset; | |
791 } else if ((((codeUnit - 0xc0) & 0xff) < 32) && codeUnit != 0xd7) { | |
792 // Optimzed remaining LATIN1 check: | |
srdjan
2014/03/25 15:46:31
ditto
| |
793 // - 0xc0 is first character > 127 | |
794 // - 0xff is LATIN1 mask | |
795 // - 32 is the number of characters in this range. | |
796 // - 0xd7 is an exception in the this range. | |
797 return offset; | |
798 } | |
799 offset++; | |
800 } | |
801 return -1; | |
802 } | |
803 | |
804 String toLowerCase() { | |
805 int next = _nextLowerCase(0); | |
806 if (next == -1) return this; | |
807 final length = this.length; | |
808 _OneByteString result = _OneByteString._allocate(length); | |
809 int offset = 0; | |
810 do { | |
811 // Copy all up to the next one. | |
812 while (offset < next) { | |
813 result._setAt(offset, this.codeUnitAt(offset)); | |
814 offset++; | |
815 } | |
816 // 0x20 is the delta between lower and upper, in both ranges. It's | |
817 // possible to 'or' instead of 'add', due to the layout. | |
818 result._setAt(offset, this.codeUnitAt(offset) | 0x20); | |
srdjan
2014/03/25 15:46:31
What is the advantage of using OR instead of ADD?
Anders Johnsen
2014/03/25 19:35:50
No need for SMI overflow checks?
| |
819 offset++; | |
820 next = _nextLowerCase(offset); | |
821 } while (next != -1); | |
822 // Remaining characters. | |
823 while (offset < length) { | |
824 result._setAt(offset, this.codeUnitAt(offset)); | |
825 offset++; | |
826 } | |
827 return result; | |
sra1
2014/03/25 16:00:33
In the case of a one character string, the VM migh
Anders Johnsen
2014/03/25 19:35:50
Done.
| |
828 | |
829 } | |
830 | |
781 // Allocates a string of given length, expecting its content to be | 831 // Allocates a string of given length, expecting its content to be |
782 // set using _setAt. | 832 // set using _setAt. |
783 static _OneByteString _allocate(int length) native "OneByteString_allocate"; | 833 static _OneByteString _allocate(int length) native "OneByteString_allocate"; |
784 | 834 |
785 | 835 |
786 static _OneByteString _allocateFromOneByteList(List<int> list) | 836 static _OneByteString _allocateFromOneByteList(List<int> list) |
787 native "OneByteString_allocateFromOneByteList"; | 837 native "OneByteString_allocateFromOneByteList"; |
788 | 838 |
789 // This is internal helper method. Code point value must be a valid | 839 // This is internal helper method. Code point value must be a valid |
790 // Latin1 value (0..0xFF), index must be valid. | 840 // Latin1 value (0..0xFF), index must be valid. |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
881 class _CodeUnits extends Object with ListMixin<int>, | 931 class _CodeUnits extends Object with ListMixin<int>, |
882 UnmodifiableListMixin<int> { | 932 UnmodifiableListMixin<int> { |
883 /** The string that this is the code units of. */ | 933 /** The string that this is the code units of. */ |
884 String _string; | 934 String _string; |
885 | 935 |
886 _CodeUnits(this._string); | 936 _CodeUnits(this._string); |
887 | 937 |
888 int get length => _string.length; | 938 int get length => _string.length; |
889 int operator[](int i) => _string.codeUnitAt(i); | 939 int operator[](int i) => _string.codeUnitAt(i); |
890 } | 940 } |
OLD | NEW |