next method
Consumes and returns next operation.
Optional length
specifies maximum length of operation to return. Note
that actual length of returned operation may be less than specified value.
Implementation
Operation? next([num length = double.infinity]) {
assert(length != null);
if (_modificationCount != delta._modificationCount) {
throw new ConcurrentModificationError(delta);
}
if (_index < delta.length) {
final op = delta.elementAt(_index);
final opKey = op.key;
final opAttributes = op.attributes;
final _currentOffset = _offset;
num actualLength = math.min(op.length! - _currentOffset, length);
if (actualLength == op.length! - _currentOffset) {
_index++;
_offset = 0;
} else {
_offset += actualLength;
}
final String opData = op.isInsert
? op.data.substring(_currentOffset as int, _currentOffset + (actualLength as int))
: '';
final int opLength = (opData.isNotEmpty) ? opData.length : actualLength as int;
return Operation._(opKey, opLength, opData, opAttributes);
}
return Operation.retain(length as int?);
}