Skip to content
FutureBlitz

    Install

    Import std.text.diff

    Diff

    std.text.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"))

    std/text/diff.fb, line 76

    • Public Static Method Lines(a: String, b: String): DiffRun[] static method #

      The runs of lines that are the same in a and b, deleted from a, and inserted for b, in order, as few lines as can be deleted and inserted. Where lines are replaced, the deleted ones come before the inserted ones.

    • Public Static Method Chars(a: String, b: String): DiffRun[] static method #

      The runs of characters that are the same in a and b, deleted from a, and inserted for b.

    • @PanicsAtCaller Public Static Method Unified(a: String, b: String, fromName: String = "a", toName: String = "b", context: Int = 3): String static method #

      The unified diff of a and b, as diff -u and git diff write it, with context lines of each change's around it, and fromName and toName in its first two lines. "" when they're the same. Panics when context is negative.

    • Public Static Method Merge(base: String, ours: String, theirs: String, oursName: String = "ours", theirsName: String = "theirs"): Merged static method #

      ours and theirs, both changed from base, 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", with oursName and theirsName, 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.