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

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

Issue 14696012: Make web-socket pass AutobanhTestSuite. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 7 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 | sdk/lib/io/websocket.dart » ('j') | sdk/lib/io/websocket.dart » ('J')
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 33328799a5e5b50a71c7af526ef24fbcf8dc7160..ec6d0e2d03e9efa6de3a67cc7661a0a4098e84a1 100644
--- a/sdk/lib/io/string_transformer.dart
+++ b/sdk/lib/io/string_transformer.dart
@@ -185,12 +185,34 @@ class StringEncoder implements StreamTransformer<String, List<int>> {
String _decodeString(List<int> bytes, [Encoding encoding = Encoding.UTF_8]) {
if (bytes.length == 0) return "";
var string;
+ var error;
var controller = new StreamController();
controller.stream
.transform(new StringDecoder(encoding))
- .listen((data) => string = data);
+ .listen((data) => string = data,
+ onError: (e) => error = e);
controller.add(bytes);
controller.close();
+ if (error != null) throw error;
+ assert(string != null);
+ return string;
+}
+
+
+// Utility function to synchronously decode a utf8-encoded list of bytes,
+// throwing on error.
+String _decodeUtf8Strict(List<int> bytes) {
+ if (bytes.length == 0) return "";
+ var string;
+ var error;
+ var controller = new StreamController();
+ controller.stream
+ .transform(new Utf8DecoderTransformer(null))
+ .listen((data) => string = data,
+ onError: (e) => error = e);
+ controller.add(bytes);
+ controller.close();
+ if (error != null) throw error;
assert(string != null);
return string;
}
« no previous file with comments | « no previous file | sdk/lib/io/websocket.dart » ('j') | sdk/lib/io/websocket.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698