writelnAll method

void writelnAll(
  1. Iterable objects,
  2. [String separator = '']
)

Writes objects in sequence to the buffer.

Each object is followed by an optional separator and a newline symbol.

Usage

final b = StringBuffer();
b.writeAllQ([1, 2, 3], ',');
b.toString() == '1,\n'
                '2,\n'
                '3\n\'

Implementation

void writelnAll(Iterable objects, [String separator = '']) {
  var iterator = objects.iterator;
  if (!iterator.moveNext()) return;
  if (separator.isEmpty) {
    do {
      writeln(iterator.current);
    } while (iterator.moveNext());
  } else {
    write(iterator.current);
    while (iterator.moveNext()) {
      write(separator);
      write('\n');
      write(iterator.current);
    }
    write('\n');
  }
}