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 part of dart.io; | 5 part of dart.io; |
6 | 6 |
7 // Constants used when working with native ports. | 7 // Constants used when working with native ports. |
8 // These must match the constants in runtime/bin/dartutils.h class CObject. | 8 // These must match the constants in runtime/bin/dartutils.h class CObject. |
9 const int _SUCCESS_RESPONSE = 0; | 9 const int _SUCCESS_RESPONSE = 0; |
10 const int _ILLEGAL_ARGUMENT_RESPONSE = 1; | 10 const int _ILLEGAL_ARGUMENT_RESPONSE = 1; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 newBuffer[i] = value; | 115 newBuffer[i] = value; |
116 j++; | 116 j++; |
117 } | 117 } |
118 return new _BufferAndStart(newBuffer, 0); | 118 return new _BufferAndStart(newBuffer, 0); |
119 } | 119 } |
120 | 120 |
121 | 121 |
122 class _IOCrypto { | 122 class _IOCrypto { |
123 external static Uint8List getRandomBytes(int count); | 123 external static Uint8List getRandomBytes(int count); |
124 } | 124 } |
125 | |
126 class _ASCII { | |
127 static int toLowerCaseByte(int x) { | |
128 // Optimzed version: | |
129 // - 0x41 is 'A' | |
kevmoo
2014/03/25 14:38:25
LOVE the explicit comments.
No guessing. Thanks!
Anders Johnsen
2014/03/25 15:00:22
Yeah, it helps understanding. Moved stuff around,
| |
130 // - 0x7f is ASCII mask | |
131 // - 26 is the number of alpha characters. | |
132 // - 0x20 is the delta between lower and upper chars. | |
133 return ((x - 0x41) & 0x7f) < 26 ? x | 0x20 : x; | |
134 } | |
135 | |
136 static String toLowerCase(String str) { | |
137 final length = str.length; | |
138 List result = new Uint8List(length); | |
139 for (int i = 0; i < length; i++) { | |
140 int codeUnit = str.codeUnitAt(i); | |
141 if (codeUnit > 127) { | |
142 throw new FormatException("ASCII string contains non-ASCII character."); | |
143 } | |
144 result[i] = toLowerCaseByte(codeUnit); | |
145 } | |
146 return new String.fromCharCodes(result); | |
147 } | |
148 } | |
OLD | NEW |