format method

void format(
  1. String input, {
  2. bool leadingSpace = true,
  3. bool trailingNewline = true,
})

Replaces the newlines and tabs of input and adds it to the stream.

Implementation

void format(String input,
    {bool leadingSpace = true, bool trailingNewline = true}) {
  final List<String> lines = input.split('\n');
  for (int i = 0; i < lines.length; ++i) {
    final String line = lines[i];
    if (i == 0 && !leadingSpace) {
      add(line.replaceAll('\t', tab));
    } else if (line.isNotEmpty) {
      write(line.replaceAll('\t', tab));
    }
    if (trailingNewline || i < lines.length - 1) {
      addln('');
    }
  }
}