writelnAllQ method Null safety

void writelnAllQ(
  1. Iterable objects,
  2. {String separator1 = '',
  3. String separator2 = '',
  4. Punctuation delimiter = Punctuation.singleQuotationMark}
)

Writes objects in sequence to the buffer.

  • delimiter: Each object is followed by separator1 and enclosed with escaped quotation marks specified by delimiter.
  • separator1: Optional separator String.
  • separator2: Optional separator String.

Usage: final b = StringBuffer(); b.writelnAllQ(1, 2, 3, separator1: ',', separator2: ';'); b.toString() == ''1,';\n' ''2,';\n' ''3'\n'

Implementation

void writelnAllQ(
  Iterable objects, {
  String separator1 = '',
  String separator2 = '',
  Punctuation delimiter = Punctuation.singleQuotationMark,
}) {
  var iterator = objects.iterator;
  if (!iterator.moveNext()) return;

  if (separator1.isEmpty && separator2.isEmpty) {
    do {
      write(delimiter.value);
      write(iterator.current);
      write(delimiter.value);
      write('\n');
    } while (iterator.moveNext());
  } else {
    write(delimiter.value);
    write(iterator.current);
    while (iterator.moveNext()) {
      write(separator1);
      write(delimiter.value);
      write(separator2);
      write('\n');
      write(delimiter.value);
      write(iterator.current);
    }
    write(delimiter.value);
    write('\n');
  }
}