subspan method

List<SourceSpan> subspan(
  1. int start, [
  2. int? end
])
inherited

Returns a list of spans from start (inclusive) to end (exclusive).

Implementation

List<SourceSpan> subspan(int start, [int? end]) {
  if (end != null && start == end) {
    return [];
  }

  final from = _toCoordinate(start);
  final to = end == null ? _endCoordinate : _toCoordinate(end);

  if (from.index == to.index) {
    return [
      source[from.index].subspan(from.offset, to.offset),
    ];
  }

  final segments = [source[from.index].subspan(from.offset)];

  if (to == _endCoordinate) {
    segments.addAll(source.getRange(
      from.index + 1,
      _endCoordinate.index + (_endsWithLf ? 0 : 1),
    ));
  } else {
    for (var i = from.index + 1; i < to.index; i++) {
      segments.add(source[i]);
    }
    if (to.offset != 0) {
      segments.add(source[to.index].subspan(0, to.offset));
    }
  }

  return segments;
}