Import std.text.diff
Diff
class
Public Class Diff
Diffing's operations.
Examples
Local runs = Diff.Lines("a\nb\nc\n", "a\nc\nd\n")
Expect(runs.Map(Function(run: DiffRun) => run.Kind) ==
[DiffKind.SAME, DiffKind.DELETED, DiffKind.SAME, DiffKind.INSERTED])
Local patch = Diff.Unified("a\nb\n", "a\nc\n")
Expect(patch.Contains("-b\n") && patch.Contains("+c\n"))-
The runs of lines that are the same in
aandb, deleted froma, and inserted forb, in order, as few lines as can be deleted and inserted. Where lines are replaced, the deleted ones come before the inserted ones. -
The runs of characters that are the same in
aandb, deleted froma, and inserted forb. -
@PanicsAtCaller Public Static Method Unified(a: String, b: String, fromName: String = "a", toName: String = "b", context: Int = 3): Stringstatic method #The unified diff of
aandb, as diff -u and git diff write it, withcontextlines of each change's around it, andfromNameandtoNamein its first two lines. "" when they're the same. Panics whencontextis negative. -
Public Static Method Merge(base: String, ours: String, theirs: String, oursName: String = "ours", theirsName: String = "theirs"): Mergedstatic method #oursandtheirs, both changed frombase, merged as git merge-file merges them: what each changed, and where both changed the same lines, or lines that touch, what they both made of them, or else a conflict, marked "<<<<<<< ours",ours' lines, "=======",theirs', and ">>>>>>> theirs", withoursNameandtheirsName, on lines that end in "\r\n" where the texts' lines do. A conflict holds only the lines that differ between the two, and two conflicts with at most 3 lines between them, or lines without an ASCII letter or digit, are one.Examples
Local merged = Diff.Merge("a\nb\nc\n", "A\nb\nc\n", "a\nb\nC\n") Expect(merged.Conflicts == 0 && merged.Text == "A\nb\nC\n")
Report an issue with this page or with FutureBlitz on GitHub.