compareLines method
Compares two iterables of lines from source
to target
.
The optional arguments sourceLabel
and targetLabel
are used by some
differs to print additional information about where the data is coming
from, i.e. the filename and the last modification date.
Implementation
@override
Iterable<String> compareLines(
Iterable<String> source, Iterable<String> target,
{String? sourceLabel, String? targetLabel}) sync* {
final matcher = SequenceMatcher(source: source, target: target);
for (final operation in matcher.operations) {
final sourceRange = _range(operation.sourceStart, operation.sourceEnd);
final targetRange = _range(operation.targetStart, operation.targetEnd);
switch (operation.type) {
case OperationType.replace:
yield '${sourceRange}c$targetRange';
yield* _dump('<', source, operation.sourceStart, operation.sourceEnd);
yield '---';
yield* _dump('>', target, operation.targetStart, operation.targetEnd);
case OperationType.delete:
yield '${sourceRange}d$targetRange';
yield* _dump('<', source, operation.sourceStart, operation.sourceEnd);
case OperationType.insert:
yield '${sourceRange}a$targetRange';
yield* _dump('>', target, operation.targetStart, operation.targetEnd);
case OperationType.equal:
break;
}
}
}