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

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

Issue 19000006: First version of Codecs and Converters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comment. Created 7 years, 5 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/json.dart ('k') | tests/lib/codec/codec1_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/convert/utf.dart
diff --git a/sdk/lib/convert/utf.dart b/sdk/lib/convert/utf.dart
new file mode 100644
index 0000000000000000000000000000000000000000..09692f0ec87b6102aead2cd6037b8a2988fc51f9
--- /dev/null
+++ b/sdk/lib/convert/utf.dart
@@ -0,0 +1,31 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+part of dart.convert;
+
+/**
+ * A [Utf8Encoder] converts strings to their UTF-8 code units (a list of
+ * unsigned 8-bit integers).
+ */
+class Utf8Encoder extends Converter<String, List<int>> {
+ /**
+ * Converts [string] to its UTF-8 code units (a list of
+ * unsigned 8-bit integers).
+ */
+ List<int> convert(String string) => OLD_UTF_LIB.encodeUtf8(string);
+}
+
+/**
+ * A [Utf8Decoder] converts UTF-8 code units (lists of unsigned 8-bit integers)
+ * to a string.
+ */
+class Utf8Decoder extends Converter<List<int>, String> {
+ /**
+ * Converts the UTF-8 [codeUnits] (a list of unsigned 8-bit integers) to the
+ * corresponding string.
+ */
+ // TODO(floitsch): allow to configure the decoder (for example the replacement
+ // character).
+ String convert(List<int> codeUnits) => OLD_UTF_LIB.decodeUtf8(codeUnits);
+}
« no previous file with comments | « sdk/lib/convert/json.dart ('k') | tests/lib/codec/codec1_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698