Skip to content
FutureBlitz

    Install

    Import std.text.diff

    std.text.diff

    std.text.diff: what changed between two texts, by Myers' algorithm, which finds the fewest lines, or characters, to delete and insert. Diff.Lines and Diff.Chars give the runs of what's the same, deleted, and inserted; Diff.Unified the text that diff -u and git diff show; and Diff.Merge a three-way merge, as git merge-file makes it, with conflict markers where both sides changed the same lines differently. A line keeps its line break, "\n", "\r\n", or "\r", and a text's last line can have none.

    std/text/diff.fb

    Types

    DiffKind enum

    Public Enum DiffKind

    What a run of a diff is.

    std/text/diff.fb, line 19

    • SAME enum member #

      The same in both texts.

    • DELETED enum member #

      Deleted from the first.

    • INSERTED enum member #

      Inserted for the second.

    DiffRun struct

    Public Struct DiffRun

    A run of a diff: what kind it is, and its text, whole lines for Diff.Lines.

    std/text/diff.fb, line 29

    • Public ReadOnly Field Kind: DiffKind field #

      What kind of run it is.

    • Public ReadOnly Field Text: String field #

      Its text, whole lines for Diff.Lines.

    Merged struct

    Public Struct Merged

    A three-way merge: its text, and how many conflicts in it are marked.

    std/text/diff.fb, line 37

    • Public ReadOnly Field Text: String field #

      The merged text.

    • Public ReadOnly Field Conflicts: Int field #

      How many conflicts in it are marked.

    Diff class

    Public Class Diff

    Diffing's operations.

    std/text/diff.fb, line 54

    • 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.

    Report an issue with this page or with FutureBlitz on GitHub.