slice method

Delta slice(
  1. int start, [
  2. int? end
])

Returns slice of this delta from start index (inclusive) to end (exclusive).

Implementation

Delta slice(int start, [int? end]) {
  final delta = new Delta();
  var index = 0;
  var opIterator = new DeltaIterator(this);

  num actualEnd = end ?? double.infinity;

  while (index < actualEnd && opIterator.hasNext) {
    Operation op;
    if (index < start) {
      op = opIterator.next(start - index)!;
    } else {
      op = opIterator.next(actualEnd - index)!;
      delta.push(op);
    }
    index += op.length!;
  }
  return delta;
}