Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Unified Diff: sdk/lib/convert/encoding.dart

Issue 22872012: Remove Encoding-enum from dart:io and add interface in dart:convert. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix typo. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/convert/ascii.dart ('k') | sdk/lib/convert/latin1.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/convert/encoding.dart
diff --git a/sdk/lib/convert/encoding.dart b/sdk/lib/convert/encoding.dart
index 0f6126c25130921fea8c5d9e1a63eccf1b9023dc..cc67f6f176c54eaa237cb733b37e105b99ba6ca1 100644
--- a/sdk/lib/convert/encoding.dart
+++ b/sdk/lib/convert/encoding.dart
@@ -7,13 +7,70 @@ part of dart.convert;
/**
* Open-ended Encoding enum.
*/
-// TODO(floitsch): dart:io already has an Encoding class. If we can't
-// consolitate them, we need to remove `Encoding` here.
-abstract class _Encoding extends Codec<String, List<int>> {
- const _Encoding();
+abstract class Encoding extends Codec<String, List<int>> {
+ const Encoding();
- // TODO(floitsch): should we introduce a StringToByteEncoder and
- // a ByteToStringDecoder so that we have better typing?
-}
+ Future<String> decodeStream(Stream<List<int>> byteStream) {
+ return byteStream
+ .transform(decoder)
+ .fold(new StringBuffer(), (buffer, string) => buffer..write(string))
+ .then((buffer) => buffer.toString());
+ }
+
+ /**
+ * Name of the encoding.
+ *
+ * If the encoding is standardized, this is the lower-case version of one of
+ * the IANA official names for the character set (see
+ * http://www.iana.org/assignments/character-sets/character-sets.xml)
+ */
+ String get name;
+
+ // All aliases (in lowercase) of supported encoding from
+ // http://www.iana.org/assignments/character-sets/character-sets.xml.
+ static Map<String, Encoding> _nameToEncoding = <String, Encoding> {
+ // ISO_8859-1:1987.
+ "iso_8859-1:1987": LATIN1,
+ "iso-ir-100": LATIN1,
+ "iso_8859-1": LATIN1,
+ "iso-8859-1": LATIN1,
+ "latin1": LATIN1,
+ "l1": LATIN1,
+ "ibm819": LATIN1,
+ "cp819": LATIN1,
+ "csisolatin1": LATIN1,
-// TODO(floitsch): add other encodings, like ASCII and ISO_8859_1.
+ // US-ASCII.
+ "iso-ir-6": ASCII,
+ "ansi_x3.4-1968": ASCII,
+ "ansi_x3.4-1986": ASCII,
+ "iso_646.irv:1991": ASCII,
+ "iso646-us": ASCII,
+ "us-ascii": ASCII,
+ "us": ASCII,
+ "ibm367": ASCII,
+ "cp367": ASCII,
+ "csascii": ASCII,
+ "ascii": ASCII, // This is not in the IANA official names.
+
+ // UTF-8.
+ "csutf8": UTF8,
+ "utf-8": UTF8
+ };
+
+ /**
+ * Gets an [Encoding] object from the name of the character set
+ * name. The names used are the IANA official names for the
+ * character set (see
+ * http://www.iana.org/assignments/character-sets/character-sets.xml).
+ *
+ * The [name] passed is case insensitive.
+ *
+ * If character set is not supported [:null:] is returned.
+ */
+ static Encoding getByName(String name) {
+ if (name == null) return null;
+ name = name.toLowerCase();
+ return _nameToEncoding[name];
+ }
+}
« no previous file with comments | « sdk/lib/convert/ascii.dart ('k') | sdk/lib/convert/latin1.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698