Qu

diff_lines

Builtin index · Collections & strings

result = diff_lines(a, b, [changed_only=false])

Input: a, b, changed_only · Output: result

What it is

A line diff of two texts. a and b are each a List of strings, or one string that is split into lines (CRLF or LF).

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = diff_lines(a, b, [changed_only=false])
a List or stringa and b are each a List of strings, or one string that is split into lines (CRLF or LF).
b List or stringa and b are each a List of strings, or one string that is split into lines (CRLF or LF).
changed_only optional (default false)changed_only=true leaves out the "equal" lines.
op —"equal", "insert" or "delete"
old numberthe 1-based line number in a, or none for an insert
new numberthe 1-based line number in b, or none for a delete
Returns a List of Records, one per line of the merged result, in order: op ("equal", "insert" or "delete"), old (the 1-based line number in a, or none for an insert), new (the 1-based line number in b, or none for a delete) and text. changed_only=true leaves out the "equal" lines. A longest-common-subsequence diff after trimming the shared head and tail, so a few edits in a long file are cheap; a huge, wholly different pair is refused with a clear error rather than exhausting memory. pdf.text_diff is the page-by-page version for PDFs, and diff is the numeric one.

Examples

No documentation example calls this form yet. The Collections & strings chapter is where one belongs.

How it works

diff_lines(a, b, [changed_only=]) -- a line diff of two texts (diff_ops.rs).

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.