computeDiff method
List<DiffHunk>
computeDiff(
- String oldText,
- String newText, {
- DiffAlgorithm algorithm = DiffAlgorithm.myers,
- int? contextLines,
Compute the diff between oldText and newText.
Returns a list of DiffHunks representing the changes. The algorithm
parameter selects the diff strategy (currently Myers is the only fully
implemented variant; the others fall back to Myers).
Implementation
List<DiffHunk> computeDiff(
String oldText,
String newText, {
DiffAlgorithm algorithm = DiffAlgorithm.myers,
int? contextLines,
}) {
final ctx = contextLines ?? defaultContextLines;
final oldLines = oldText.isEmpty ? <String>[] : oldText.split('\n');
final newLines = newText.isEmpty ? <String>[] : newText.split('\n');
final edits = _myersDiff(oldLines, newLines);
return _editsToHunks(edits, oldLines, newLines, ctx);
}