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

Side by Side Diff: sdk/lib/io/io_sink.dart

Issue 1263963003: Fix some TODOs (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 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 unified diff | Download patch
« no previous file with comments | « runtime/lib/string_buffer_patch.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart.io; 5 part of dart.io;
6 6
7 /** 7 /**
8 * Helper class to wrap a [StreamConsumer<List<int>>] and provide 8 * Helper class to wrap a [StreamConsumer<List<int>>] and provide
9 * utility functions for writing to the StreamConsumer directly. The 9 * utility functions for writing to the StreamConsumer directly. The
10 * [IOSink] buffers the input given by all [StringSink] methods and will delay 10 * [IOSink] buffers the input given by all [StringSink] methods and will delay
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 Encoding get encoding => _encoding; 266 Encoding get encoding => _encoding;
267 267
268 void set encoding(Encoding value) { 268 void set encoding(Encoding value) {
269 if (!_encodingMutable) { 269 if (!_encodingMutable) {
270 throw new StateError("IOSink encoding is not mutable"); 270 throw new StateError("IOSink encoding is not mutable");
271 } 271 }
272 _encoding = value; 272 _encoding = value;
273 } 273 }
274 274
275 void write(Object obj) { 275 void write(Object obj) {
276 // This comment is copied from runtime/lib/string_buffer_patch.dart. 276 String string = '$obj';
277 // TODO(srdjan): The following four lines could be replaced by
278 // '$obj', but apparently this is too slow on the Dart VM.
279 String string;
280 if (obj is String) {
281 string = obj;
282 } else {
283 string = obj.toString();
284 if (string is! String) {
285 throw new ArgumentError('toString() did not return a string');
286 }
287 }
288 if (string.isEmpty) return; 277 if (string.isEmpty) return;
289 add(_encoding.encode(string)); 278 add(_encoding.encode(string));
290 } 279 }
291 280
292 void writeAll(Iterable objects, [String separator = ""]) { 281 void writeAll(Iterable objects, [String separator = ""]) {
293 Iterator iterator = objects.iterator; 282 Iterator iterator = objects.iterator;
294 if (!iterator.moveNext()) return; 283 if (!iterator.moveNext()) return;
295 if (separator.isEmpty) { 284 if (separator.isEmpty) {
296 do { 285 do {
297 write(iterator.current); 286 write(iterator.current);
298 } while (iterator.moveNext()); 287 } while (iterator.moveNext());
299 } else { 288 } else {
300 write(iterator.current); 289 write(iterator.current);
301 while (iterator.moveNext()) { 290 while (iterator.moveNext()) {
302 write(separator); 291 write(separator);
303 write(iterator.current); 292 write(iterator.current);
304 } 293 }
305 } 294 }
306 } 295 }
307 296
308 void writeln([Object obj = ""]) { 297 void writeln([Object obj = ""]) {
309 write(obj); 298 write(obj);
310 write("\n"); 299 write("\n");
311 } 300 }
312 301
313 void writeCharCode(int charCode) { 302 void writeCharCode(int charCode) {
314 write(new String.fromCharCode(charCode)); 303 write(new String.fromCharCode(charCode));
315 } 304 }
316 } 305 }
OLDNEW
« no previous file with comments | « runtime/lib/string_buffer_patch.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698