Line data Source code
1 : // Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file 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. 4 : 5 : class PrintSink implements StringSink { 6 : final _buffer = StringBuffer(); 7 : 8 0 : @override 9 : void write(Object? obj) { 10 0 : _buffer.write(obj); 11 0 : _flush(); 12 : } 13 : 14 0 : @override 15 : void writeAll(Iterable objects, [String separator = '']) { 16 0 : _buffer.writeAll(objects, separator); 17 0 : _flush(); 18 : } 19 : 20 0 : @override 21 : void writeCharCode(int charCode) { 22 0 : _buffer.writeCharCode(charCode); 23 0 : _flush(); 24 : } 25 : 26 0 : @override 27 : void writeln([Object? obj = '']) { 28 0 : _buffer.writeln(obj ?? ''); 29 0 : _flush(); 30 : } 31 : 32 : /// [print] if the content available ends with a newline. 33 0 : void _flush() { 34 0 : if ('$_buffer'.endsWith('\n')) { 35 0 : print(_buffer); 36 0 : _buffer.clear(); 37 : } 38 : } 39 : }