| OLD | NEW |
| 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.convert; | 5 part of dart.convert; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * This class provides an interface for converters to | 8 * This class provides an interface for converters to |
| 9 * efficiently transmit String data. | 9 * efficiently transmit String data. |
| 10 * | 10 * |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 class _ClosableStringSink implements ClosableStringSink { | 85 class _ClosableStringSink implements ClosableStringSink { |
| 86 final _StringSinkCloseCallback _callback; | 86 final _StringSinkCloseCallback _callback; |
| 87 final StringSink _sink; | 87 final StringSink _sink; |
| 88 | 88 |
| 89 _ClosableStringSink(this._sink, this._callback); | 89 _ClosableStringSink(this._sink, this._callback); |
| 90 | 90 |
| 91 void close() => _callback(); | 91 void close() => _callback(); |
| 92 | 92 |
| 93 void writeCharCode(int charCode) => _sink.writeCharCode(charCode); | 93 void writeCharCode(int charCode) => _sink.writeCharCode(charCode); |
| 94 void write(Object o) => _sink.write(o); | 94 void write(Object o) => _sink.write(o); |
| 95 void writeln([Object o]) => _sink.writeln(o); | 95 void writeln([Object o = ""]) => _sink.writeln(o); |
| 96 void writeAll(Iterable objects, [String separator]) | 96 void writeAll(Iterable objects, [String separator = ""]) |
| 97 => _sink.writeAll(objects, separator); | 97 => _sink.writeAll(objects, separator); |
| 98 } | 98 } |
| 99 | 99 |
| 100 /** | 100 /** |
| 101 * This class wraps an existing [StringConversionSink] and exposes a | 101 * This class wraps an existing [StringConversionSink] and exposes a |
| 102 * [ClosableStringSink] interface. The wrapped sink only needs to implement | 102 * [ClosableStringSink] interface. The wrapped sink only needs to implement |
| 103 * `add` and `close`. | 103 * `add` and `close`. |
| 104 */ | 104 */ |
| 105 // TODO(floitsch): make this class public? | 105 // TODO(floitsch): make this class public? |
| 106 class _StringConversionSinkAsStringSinkAdapter implements ClosableStringSink { | 106 class _StringConversionSinkAsStringSinkAdapter implements ClosableStringSink { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 121 _buffer.writeCharCode(charCode); | 121 _buffer.writeCharCode(charCode); |
| 122 if (_buffer.length > _MIN_STRING_SIZE) _flush(); | 122 if (_buffer.length > _MIN_STRING_SIZE) _flush(); |
| 123 } | 123 } |
| 124 | 124 |
| 125 void write(Object o) { | 125 void write(Object o) { |
| 126 if (_buffer.isNotEmpty) _flush(); | 126 if (_buffer.isNotEmpty) _flush(); |
| 127 String str = o.toString(); | 127 String str = o.toString(); |
| 128 _chunkedSink.add(o.toString()); | 128 _chunkedSink.add(o.toString()); |
| 129 } | 129 } |
| 130 | 130 |
| 131 void writeln([Object o]) { | 131 void writeln([Object o = ""]) { |
| 132 _buffer.writeln(o); | 132 _buffer.writeln(o); |
| 133 if (_buffer.length > _MIN_STRING_SIZE) _flush(); | 133 if (_buffer.length > _MIN_STRING_SIZE) _flush(); |
| 134 } | 134 } |
| 135 | 135 |
| 136 void writeAll(Iterable objects, [String separator]) { | 136 void writeAll(Iterable objects, [String separator = ""]) { |
| 137 if (_buffer.isNotEmpty) _flush(); | 137 if (_buffer.isNotEmpty) _flush(); |
| 138 Iterator iterator = objects.iterator; | 138 Iterator iterator = objects.iterator; |
| 139 if (!iterator.moveNext()) return; | 139 if (!iterator.moveNext()) return; |
| 140 if (separator.isEmpty) { | 140 if (separator.isEmpty) { |
| 141 do { | 141 do { |
| 142 _chunkedSink.add(iterator.current.toString()); | 142 _chunkedSink.add(iterator.current.toString()); |
| 143 } while (iterator.moveNext()); | 143 } while (iterator.moveNext()); |
| 144 } else { | 144 } else { |
| 145 _chunkedSink.add(iterator.current.toString()); | 145 _chunkedSink.add(iterator.current.toString()); |
| 146 while (iterator.moveNext()) { | 146 while (iterator.moveNext()) { |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 _decoder.convert(chunk, startIndex, endIndex); | 330 _decoder.convert(chunk, startIndex, endIndex); |
| 331 if (_buffer.isNotEmpty) { | 331 if (_buffer.isNotEmpty) { |
| 332 String accumulated = _buffer.toString(); | 332 String accumulated = _buffer.toString(); |
| 333 _chunkedSink.addSlice(accumulated, 0, accumulated.length, isLast); | 333 _chunkedSink.addSlice(accumulated, 0, accumulated.length, isLast); |
| 334 _buffer.clear(); | 334 _buffer.clear(); |
| 335 return; | 335 return; |
| 336 } | 336 } |
| 337 if (isLast) close(); | 337 if (isLast) close(); |
| 338 } | 338 } |
| 339 } | 339 } |
| OLD | NEW |