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.
-
The same in both texts.
-
Deleted from the first.
-
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.
-
What kind of run it is.
-
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.
-
The merged text.
-
How many conflicts in it are marked.
Diff
class
Public Class Diff
Diffing's operations.
-
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.
Report an issue with this page or with FutureBlitz on GitHub.