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 /** |
| 16 * SYSTEM encoding is the current code page on Windows and UTF-8 on |
| 17 * Linux and Mac. |
| 18 */ |
| 19 static const Encoding SYSTEM = const Encoding._internal("system"); |
| 20 |
15 // All aliasses (in lowercase) of supported encoding from | 21 // All aliasses (in lowercase) of supported encoding from |
16 // http://www.iana.org/assignments/character-sets/character-sets.xml. | 22 // http://www.iana.org/assignments/character-sets/character-sets.xml. |
17 static Map<String, Encoding> _nameToEncoding = <String, Encoding> { | 23 static Map<String, Encoding> _nameToEncoding = <String, Encoding> { |
18 // ISO_8859-1:1987. | 24 // ISO_8859-1:1987. |
19 "iso_8859-1:1987": ISO_8859_1, | 25 "iso_8859-1:1987": ISO_8859_1, |
20 "iso-ir-100": ISO_8859_1, | 26 "iso-ir-100": ISO_8859_1, |
21 "iso_8859-1": ISO_8859_1, | 27 "iso_8859-1": ISO_8859_1, |
22 "iso-8859-1": ISO_8859_1, | 28 "iso-8859-1": ISO_8859_1, |
23 "latin1": ISO_8859_1, | 29 "latin1": ISO_8859_1, |
24 "l1": ISO_8859_1, | 30 "l1": ISO_8859_1, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 return _nameToEncoding[name]; | 66 return _nameToEncoding[name]; |
61 } | 67 } |
62 | 68 |
63 /** | 69 /** |
64 * Name of the encoding. This will be the lower-case version of one of the | 70 * Name of the encoding. This will be the lower-case version of one of the |
65 * IANA official names for the character set (see | 71 * IANA official names for the character set (see |
66 * http://www.iana.org/assignments/character-sets/character-sets.xml) | 72 * http://www.iana.org/assignments/character-sets/character-sets.xml) |
67 */ | 73 */ |
68 final String name; | 74 final String name; |
69 | 75 |
70 /** | |
71 * SYSTEM encoding is the current code page on Windows and UTF-8 on | |
72 * Linux and Mac. | |
73 */ | |
74 static const Encoding SYSTEM = const Encoding._internal("system"); | |
75 const Encoding._internal(String this.name); | 76 const Encoding._internal(String this.name); |
76 } | 77 } |
77 | 78 |
| 79 const UTF_8 = Encoding.UTF_8; |
| 80 const ISO_8859_1 = Encoding.ISO_8859_1; |
| 81 const ASCII = Encoding.ASCII; |
78 | 82 |
79 /** | 83 /** |
80 * Stream transformer that can decode a stream of bytes into a stream of | 84 * Stream transformer that can decode a stream of bytes into a stream of |
81 * strings using [encoding]. | 85 * strings using [encoding]. |
82 * | 86 * |
83 * Invalid or forbidden byte-sequences will not produce errors, but will instead | 87 * Invalid or forbidden byte-sequences will not produce errors, but will instead |
84 * insert [replacementChar] in the decoded strings. | 88 * insert [replacementChar] in the decoded strings. |
85 */ | 89 */ |
86 class StringDecoder implements StreamTransformer<List<int>, String> { | 90 class StringDecoder implements StreamTransformer<List<int>, String> { |
87 var _decoder; | 91 var _decoder; |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 | 365 |
362 // Utility class for decoding Windows current code page data delivered | 366 // Utility class for decoding Windows current code page data delivered |
363 // as a stream of bytes. | 367 // as a stream of bytes. |
364 class _WindowsCodePageDecoder extends StreamEventTransformer<List<int>, String>
{ | 368 class _WindowsCodePageDecoder extends StreamEventTransformer<List<int>, String>
{ |
365 void handleData(List<int> data, EventSink<String> sink) { | 369 void handleData(List<int> data, EventSink<String> sink) { |
366 sink.add(_decodeBytes(data)); | 370 sink.add(_decodeBytes(data)); |
367 } | 371 } |
368 | 372 |
369 external static String _decodeBytes(List<int> bytes); | 373 external static String _decodeBytes(List<int> bytes); |
370 } | 374 } |
OLD | NEW |