| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 part of dart.convert; | |
| 6 | |
| 7 /** | |
| 8 * Open-ended Encoding enum. | |
| 9 */ | |
| 10 abstract class Encoding extends Codec<String, List<int>> { | |
| 11 const Encoding(); | |
| 12 | |
| 13 Future<String> decodeStream(Stream<List<int>> byteStream) { | |
| 14 return byteStream | |
| 15 .transform(decoder) | |
| 16 .fold(new StringBuffer(), (buffer, string) => buffer..write(string)) | |
| 17 .then((buffer) => buffer.toString()); | |
| 18 } | |
| 19 | |
| 20 /** | |
| 21 * Name of the encoding. | |
| 22 * | |
| 23 * If the encoding is standardized, this is the lower-case version of one of | |
| 24 * the IANA official names for the character set (see | |
| 25 * http://www.iana.org/assignments/character-sets/character-sets.xml) | |
| 26 */ | |
| 27 String get name; | |
| 28 | |
| 29 // All aliases (in lowercase) of supported encoding from | |
| 30 // http://www.iana.org/assignments/character-sets/character-sets.xml. | |
| 31 static Map<String, Encoding> _nameToEncoding = <String, Encoding> { | |
| 32 // ISO_8859-1:1987. | |
| 33 "iso_8859-1:1987": LATIN1, | |
| 34 "iso-ir-100": LATIN1, | |
| 35 "iso_8859-1": LATIN1, | |
| 36 "iso-8859-1": LATIN1, | |
| 37 "latin1": LATIN1, | |
| 38 "l1": LATIN1, | |
| 39 "ibm819": LATIN1, | |
| 40 "cp819": LATIN1, | |
| 41 "csisolatin1": LATIN1, | |
| 42 | |
| 43 // US-ASCII. | |
| 44 "iso-ir-6": ASCII, | |
| 45 "ansi_x3.4-1968": ASCII, | |
| 46 "ansi_x3.4-1986": ASCII, | |
| 47 "iso_646.irv:1991": ASCII, | |
| 48 "iso646-us": ASCII, | |
| 49 "us-ascii": ASCII, | |
| 50 "us": ASCII, | |
| 51 "ibm367": ASCII, | |
| 52 "cp367": ASCII, | |
| 53 "csascii": ASCII, | |
| 54 "ascii": ASCII, // This is not in the IANA official names. | |
| 55 | |
| 56 // UTF-8. | |
| 57 "csutf8": UTF8, | |
| 58 "utf-8": UTF8 | |
| 59 }; | |
| 60 | |
| 61 /** | |
| 62 * Gets an [Encoding] object from the name of the character set | |
| 63 * name. The names used are the IANA official names for the | |
| 64 * character set (see | |
| 65 * http://www.iana.org/assignments/character-sets/character-sets.xml). | |
| 66 * | |
| 67 * The [name] passed is case insensitive. | |
| 68 * | |
| 69 * If character set is not supported [:null:] is returned. | |
| 70 */ | |
| 71 static Encoding getByName(String name) { | |
| 72 if (name == null) return null; | |
| 73 name = name.toLowerCase(); | |
| 74 return _nameToEncoding[name]; | |
| 75 } | |
| 76 } | |
| OLD | NEW |