Documentation ¶
Overview ¶
Package diff computes differences between text files or strings.
Index ¶
- Constants
- func Apply(src string, edits []Edit) (string, error)
- func ApplyBytes(src []byte, edits []Edit) ([]byte, error)
- func SortEdits(edits []Edit)
- func ToUnified(oldLabel, newLabel, content string, edits []Edit, contextLines int) (string, error)
- func Unified(oldLabel, newLabel, old, new string) string
- type Edit
- type OpKind
- type UnifiedDiff
Constants ¶
const DefaultContextLines = 3
DefaultContextLines is the number of unchanged lines of surrounding context displayed by Unified. Use ToUnified to specify a different value.
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 ApplyBytes ¶
ApplyBytes is like Apply, but it accepts a byte slice. The result is always a new array.
func SortEdits ¶
func SortEdits(edits []Edit)
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.)
Types ¶
type Edit ¶
type Edit struct {
Start, End int // byte offsets of the region to replace
New string // the replacement
}
An Edit describes the replacement of a portion of a text file.
func Bytes ¶
Bytes computes the differences between two byte slices. The resulting edits respect rune boundaries.
type OpKind ¶
type OpKind int
OpKind is used to denote the type of operation a line represents.
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 )
type UnifiedDiff ¶
type UnifiedDiff = unified
UnifiedDiff is a unified diff.
func ToUnifiedDiff ¶
func ToUnifiedDiff(fromName, toName string, content string, edits []Edit, contextLines int) (UnifiedDiff, error)
ToUnifiedDiff takes a file contents and a sequence of edits, and calculates a unified diff that represents those edits.
Directories ¶
Path | Synopsis |
---|---|
Package difftest supplies a set of tests that will operate on any implementation of a diff algorithm as exposed by diff "github.com/aymanbagabas/go-udiff"
|
Package difftest supplies a set of tests that will operate on any implementation of a diff algorithm as exposed by diff "github.com/aymanbagabas/go-udiff" |
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. |