betweenSplit method

  1. @useResult
List<String>? betweenSplit(
  1. String start,
  2. String end, {
  3. bool endOptional = true,
  4. bool trim = true,
})

Returns a list of all sections found between start and end delimiters, or null if none are found.

When endOptional is true (default), content after the last start delimiter is included even without a closing end. When trim is true (default), each extracted section is trimmed.

Implementation

@useResult
List<String>? betweenSplit(
  String start,
  String end, {
  bool endOptional = true,
  bool trim = true,
}) {
  if (isEmpty) {
    return null;
  }

  final BetweenResult? found = betweenResult(
    start,
    end,
    endOptional: endOptional,
    trim: trim,
  );
  if (found == null) {
    return null;
  }

  if (found.content.isEmpty) {
    return null;
  }

  final List<String>? next = found.remaining?.betweenSplit(
    start,
    end,
    endOptional: endOptional,
    trim: trim,
  );

  return <String>[found.content, ...?next];
}