trim method

String trim(
  1. String contents
)

Implementation

String trim(String contents) {
  String eol = discoverEol(contents);

  for (Converter converter in preConverters) {
    contents = converter.convert(contents);
  }

  if (lineConverters.isNotEmpty) {
    // TODO: remove this once converters are cloned
    for (var converter in lineConverters) {
      converter.convert(null);
    }

    List<String> lines = contents.split(eol);
    List<String> results = [];

    for (String line in lines) {
      String? result = line;
      for (var converter in lineConverters) {
        result = converter.convert(result);
        if (result == null) break;
      }

      if (result != null) {
        results.add(result);
      }
    }

    contents = results.join(eol);
  }

  for (var converter in postConverters) {
    contents = converter.convert(contents);
  }

  return contents;
}