Documentation
¶
Overview ¶
Package diff computes differences between text files or strings.
Index ¶
- func Apply[S1, S2 text.String](src S1, edits []Edit[S2]) (S1, error)
- func ApplyTo[S text.String](dst io.Writer, src io.Reader, srcLen int, edits []Edit[S]) (int64, error)
- func SortEdits[S text.String](edits []Edit[S])
- func ToUnified[S text.String](oldLabel, newLabel string, content S, edits []Edit[S]) (string, error)
- func Unified[S text.String](oldLabel, newLabel string, old, new S) string
- type Edit
- type OpKind
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Apply ¶
Apply applies a sequence of edits to the src buffer and returns the result. Edits are applied in order of start offset; edits with the same start offset are applied in they order they were provided.
Apply returns an error if any edit is out of bounds, or if any pair of edits is overlapping.
func ApplyTo ¶
func ApplyTo[S text.String](dst io.Writer, src io.Reader, srcLen int, edits []Edit[S]) (int64, error)
ApplyTo applies a sequence of edits to the src Reader and writes the result to the dst Writer. Edits are applied in order of start offset; edits with the same start offset are applied in they order they were provided.
ApplyTo returns an error if any edit is out of bounds, or if any pair of edits is overlapping.
func SortEdits ¶
SortEdits orders a slice of Edits by (start, end) offset. This ordering puts insertions (end = start) before deletions (end > start) at the same point, but uses a stable sort to preserve the order of multiple insertions at the same point. (Apply detects multiple deletions at the same point as an error.)
func ToUnified ¶
func ToUnified[S text.String](oldLabel, newLabel string, content S, edits []Edit[S]) (string, error)
ToUnified applies the edits to content and returns a unified diff. The old and new labels are the names of the content and result files. It returns an error if the edits are inconsistent; see ApplyEdits.
Types ¶
type Edit ¶
Edit represents a change to a section of a document. The text within the specified span should be replaced by the supplied new text.
func Binary ¶
Binary computes the differences between two texts. The texts are treated as binary data. The resulting edits do not respect rune boundaries.
func Text ¶
Text computes the differences between two texts. The resulting edits respect rune boundaries.
type OpKind ¶
type OpKind int
OpKind is used to denote the type of operation a line represents. TODO(adonovan): hide this once the myers package no longer references it.
const ( // Delete is the operation kind for a line that is present in the input // but not in the output. Delete OpKind = iota // Insert is the operation kind for a line that is new in the output. Insert // Equal is the operation kind for a line that is the same in the input and // output, often used to provide context around edited lines. Equal )
Directories
¶
Path | Synopsis |
---|---|
Package difftest supplies a set of tests that will operate on any implementation of a diff algorithm as exposed by "github.com/pgavlin/diff"
|
Package difftest supplies a set of tests that will operate on any implementation of a diff algorithm as exposed by "github.com/pgavlin/diff" |
package lcs contains code to find longest-common-subsequences (and diffs)
|
package lcs contains code to find longest-common-subsequences (and diffs) |
Package myers implements the Myers diff algorithm.
|
Package myers implements the Myers diff algorithm. |
Package testenv contains helper functions for skipping tests based on which tools are present in the environment.
|
Package testenv contains helper functions for skipping tests based on which tools are present in the environment. |