OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /** | 7 /** |
8 * String encodings. | 8 * String encodings. |
9 */ | 9 */ |
10 class Encoding { | 10 class Encoding { |
11 static const Encoding UTF_8 = const Encoding._internal("utf-8"); | 11 static const Encoding UTF_8 = const Encoding._internal("utf-8"); |
12 static const Encoding ISO_8859_1 = const Encoding._internal("iso-8859-1"); | 12 static const Encoding ISO_8859_1 = const Encoding._internal("iso-8859-1"); |
13 static const Encoding ASCII = const Encoding._internal("us-ascii"); | 13 static const Encoding ASCII = const Encoding._internal("us-ascii"); |
14 | 14 |
15 /** | 15 /** |
16 * Gets an [Encoding] object from the name of the character set | |
17 * name. The names used are the IANA official names for the | |
18 * character set (see | |
19 * http://www.iana.org/assignments/character-sets/character-sets.xml). | |
20 * | |
21 * The [name] passed is case insensitive. | |
22 * | |
23 * If character set is not supported [:null:] is returned. | |
24 */ | |
25 static Encoding fromName(String name) { | |
26 if (name == null) return null; | |
27 name = name.toLowerCase(); | |
28 if (name == "iso-8859-1" || name == "iso_8859-1" || name == "latin1") { | |
29 return ISO_8859_1; | |
30 } else if (name == "utf-8") { | |
31 return UTF_8; | |
32 } else if (name == "us-ascii" || name == "ascii") { | |
33 return ASCII; | |
34 } else { | |
35 return null; | |
36 } | |
nweiz
2013/03/07 19:32:05
It would be nice if we could support all the chara
Søren Gjesse
2013/03/08 09:47:46
Done.
| |
37 } | |
38 | |
39 /** | |
16 * Name of the encoding. This will be the lower-case version of one of the | 40 * Name of the encoding. This will be the lower-case version of one of the |
17 * IANA official names for the character set (see | 41 * IANA official names for the character set (see |
18 * http://www.iana.org/assignments/character-sets/character-sets.xml) | 42 * http://www.iana.org/assignments/character-sets/character-sets.xml) |
19 */ | 43 */ |
20 final String name; | 44 final String name; |
21 | 45 |
22 /** | 46 /** |
23 * SYSTEM encoding is the current code page on Windows and UTF-8 on | 47 * SYSTEM encoding is the current code page on Windows and UTF-8 on |
24 * Linux and Mac. | 48 * Linux and Mac. |
25 */ | 49 */ |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
313 | 337 |
314 // Utility class for decoding Windows current code page data delivered | 338 // Utility class for decoding Windows current code page data delivered |
315 // as a stream of bytes. | 339 // as a stream of bytes. |
316 class _WindowsCodePageDecoder extends StreamEventTransformer<List<int>, String> { | 340 class _WindowsCodePageDecoder extends StreamEventTransformer<List<int>, String> { |
317 void handleData(List<int> data, StreamSink<String> sink) { | 341 void handleData(List<int> data, StreamSink<String> sink) { |
318 sink.add(_decodeBytes(data)); | 342 sink.add(_decodeBytes(data)); |
319 } | 343 } |
320 | 344 |
321 external static String _decodeBytes(List<int> bytes); | 345 external static String _decodeBytes(List<int> bytes); |
322 } | 346 } |
OLD | NEW |