Chromium Code Reviews| Index: sdk/lib/io/common.dart |
| diff --git a/sdk/lib/io/common.dart b/sdk/lib/io/common.dart |
| index ea355801147789b965aafbea16516674ce4680f8..9d9a81826ec1b706c9ee9ea4d252093f3a9cc263 100644 |
| --- a/sdk/lib/io/common.dart |
| +++ b/sdk/lib/io/common.dart |
| @@ -122,3 +122,27 @@ _BufferAndStart _ensureFastAndSerializableByteData( |
| class _IOCrypto { |
| external static Uint8List getRandomBytes(int count); |
| } |
| + |
| +class _ASCII { |
| + static int toLowerCaseByte(int x) { |
| + // Optimzed version: |
| + // - 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,
|
| + // - 0x7f is ASCII mask |
| + // - 26 is the number of alpha characters. |
| + // - 0x20 is the delta between lower and upper chars. |
| + return ((x - 0x41) & 0x7f) < 26 ? x | 0x20 : x; |
| + } |
| + |
| + static String toLowerCase(String str) { |
| + final length = str.length; |
| + List result = new Uint8List(length); |
| + for (int i = 0; i < length; i++) { |
| + int codeUnit = str.codeUnitAt(i); |
| + if (codeUnit > 127) { |
| + throw new FormatException("ASCII string contains non-ASCII character."); |
| + } |
| + result[i] = toLowerCaseByte(codeUnit); |
| + } |
| + return new String.fromCharCodes(result); |
| + } |
| +} |