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

Unified Diff: sdk/lib/io/string_transformer.dart

Issue 17573010: Add a static method decode to StringDecoder (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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 | « no previous file | tests/standalone/io/string_decoder_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/io/string_transformer.dart
diff --git a/sdk/lib/io/string_transformer.dart b/sdk/lib/io/string_transformer.dart
index f127b38ab39aaf010359ffbc4f292ed06b97fb9e..7dfd057e2f25f68e66890b39f3d7d61c5aac92c1 100644
--- a/sdk/lib/io/string_transformer.dart
+++ b/sdk/lib/io/string_transformer.dart
@@ -91,8 +91,33 @@ class StringDecoder implements StreamTransformer<List<int>, String> {
var _decoder;
/**
+ * Decodes a stream of bytes into a `String` with an optional
+ * [encoding] and [replacementChar].
+ *
+ * The default value for [encoding] is [Encoding.UTF_8].
+ *
+ * The default value for [replacementChar] is code point U+FFFD.
+ *
+ * Completes with the decoded `String` when the stream is done.
+ */
+ static Future<String> decode(Stream<List<int>> stream,
+ [Encoding encoding = Encoding.UTF_8,
+ int replacementChar]) {
Anders Johnsen 2013/06/24 12:57:16 Type in replacement char?
Søren Gjesse 2013/06/24 13:18:16 Done.
+ return stream
+ .transform(new StringDecoder(encoding, replacementChar ))
Anders Johnsen 2013/06/24 12:57:16 Extra space at end.
Søren Gjesse 2013/06/24 13:18:16 Done.
+ .fold(
Anders Johnsen 2013/06/24 12:57:16 Why not join, and an optional separator?
Søren Gjesse 2013/06/24 13:18:16 There is no join on streams.
+ new StringBuffer(),
+ (prev, data) => prev..write(data))
+ .then((sb) => sb.toString());
+ }
+
+ /**
* Create a new [StringDecoder] with an optional [encoding] and
* [replacementChar].
+ *
+ * The default value for [encoding] is [Encoding.UTF_8].
+ *
+ * The default value for [replacementChar] is code point U+FFFD.
*/
StringDecoder([Encoding encoding = Encoding.UTF_8, int replacementChar]) {
switch (encoding) {
« no previous file with comments | « no previous file | tests/standalone/io/string_decoder_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698