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.convert; | 5 part of dart.convert; |
6 | 6 |
7 /** | 7 /** |
8 * An instance of the default implementation of the [Latin1Codec]. | 8 * An instance of the default implementation of the [Latin1Codec]. |
9 * | 9 * |
10 * This instance provides a convenient access to the most common ISO Latin 1 | 10 * This instance provides a convenient access to the most common ISO Latin 1 |
11 * use cases. | 11 * use cases. |
12 * | 12 * |
13 * Examples: | 13 * Examples: |
14 * | 14 * |
15 * var encoded = LATIN1.encode("blåbærgrød"); | 15 * var encoded = LATIN1.encode("blåbærgrød"); |
16 * var decoded = LATIN1.decode([0x62, 0x6c, 0xe5, 0x62, 0xe6, | 16 * var decoded = LATIN1.decode([0x62, 0x6c, 0xe5, 0x62, 0xe6, |
17 * 0x72, 0x67, 0x72, 0xf8, 0x64]); | 17 * 0x72, 0x67, 0x72, 0xf8, 0x64]); |
18 */ | 18 */ |
19 const LATIN1 = const Latin1Codec(); | 19 const LATIN1 = const Latin1Codec(); |
20 | 20 |
21 const int _LATIN1_MASK = 0xFF; | 21 const int _LATIN1_MASK = 0xFF; |
22 | 22 |
23 /** | 23 /** |
24 * A [LatinCodec] encodes strings to ISO Latin-1 (aka ISO-8859-1) bytes | 24 * A [LatinCodec] encodes strings to ISO Latin-1 (aka ISO-8859-1) bytes |
25 * and decodes Latin-1 bytes to strings. | 25 * and decodes Latin-1 bytes to strings. |
26 */ | 26 */ |
27 class Latin1Codec extends _Encoding { | 27 class Latin1Codec extends Encoding { |
28 final bool _allowInvalid; | 28 final bool _allowInvalid; |
29 /** | 29 /** |
30 * Instantiates a new [Latin1Codec]. | 30 * Instantiates a new [Latin1Codec]. |
31 * | 31 * |
32 * If [allowInvalid] is true, the [decode] method and the converter | 32 * If [allowInvalid] is true, the [decode] method and the converter |
33 * returned by [decoder] will default to allowing invalid values. Invalid | 33 * returned by [decoder] will default to allowing invalid values. Invalid |
34 * values are decoded into the Unicode Replacement character (U+FFFD). | 34 * values are decoded into the Unicode Replacement character (U+FFFD). |
35 * Calls to the [decode] method can override this default. | 35 * Calls to the [decode] method can override this default. |
36 * | 36 * |
37 * Encoders will not accept invalid (non Latin-1) characters. | 37 * Encoders will not accept invalid (non Latin-1) characters. |
38 */ | 38 */ |
39 const Latin1Codec({bool allowInvalid: false}) : _allowInvalid = allowInvalid; | 39 const Latin1Codec({bool allowInvalid: false}) : _allowInvalid = allowInvalid; |
40 | 40 |
| 41 String get name => "iso-8859-1"; |
| 42 |
41 /** | 43 /** |
42 * Decodes the Latin-1 [bytes] (a list of unsigned 8-bit integers) to the | 44 * Decodes the Latin-1 [bytes] (a list of unsigned 8-bit integers) to the |
43 * corresponding string. | 45 * corresponding string. |
44 * | 46 * |
45 * If [bytes] contains values that are not in the range 0 .. 255, the decoder | 47 * If [bytes] contains values that are not in the range 0 .. 255, the decoder |
46 * will eventually throw a [FormatException]. | 48 * will eventually throw a [FormatException]. |
47 * | 49 * |
48 * If [allowInvalid] is not provided, it defaults to the value used to create | 50 * If [allowInvalid] is not provided, it defaults to the value used to create |
49 * this [Latin1Codec]. | 51 * this [Latin1Codec]. |
50 */ | 52 */ |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 } | 151 } |
150 } | 152 } |
151 } | 153 } |
152 if (start < end) { | 154 if (start < end) { |
153 _addSliceToSink(source, start, end, isLast); | 155 _addSliceToSink(source, start, end, isLast); |
154 } else if (isLast) { | 156 } else if (isLast) { |
155 close(); | 157 close(); |
156 } | 158 } |
157 } | 159 } |
158 } | 160 } |
OLD | NEW |