writeAllQ method Null safety

void writeAllQ(
  1. Iterable objects,
  2. {Punctuation delimiter = Punctuation.singleQuotationMark,
  3. String separator = ', '}
)

Writes objects in sequence to the buffer.

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

Usage:

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

Implementation

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

  if (separator.isEmpty) {
    do {
      write(delimiter.value);
      write(iterator.current);
      write(delimiter.value);
    } while (iterator.moveNext());
  } else {
    write(delimiter.value);
    write(iterator.current);
    write(delimiter.value);
    while (iterator.moveNext()) {
      write(separator);
      write(delimiter.value);
      write(iterator.current);
      write(delimiter.value);
    }
  }
}