Documentation
¶
Overview ¶
Package diff includes text diffing functions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Levenshtein ¶
Levenshtein computes the Levenshtein distance that is the number of inserted, deleted or substituted characters.
func PrettyHTML ¶
PrettyHTML converts a []Diff into a pretty HTML report. It is intended as an example from which to write one's own display functions.
func PrettyText ¶
PrettyText converts a []Diff into a colored text report.
Types ¶
type MatchPatch ¶
type MatchPatch struct {
// Number of seconds to map a diff before giving up (0 for infinity).
Timeout time.Duration
// Cost of an empty edit operation in terms of edit characters.
EditCost int
// How far to search for a match (0 = exact location, 1000+ = broad match). A match this many characters away from the expected location will add 1.0 to the score (0.0 is a perfect match).
MatchDistance int
// When deleting a large block of text (over ~64 characters), how close do the contents have to be to match the expected contents. (0.0 = perfection, 1.0 = very loose). Note that MatchThreshold controls how closely the end points of a delete need to match.
PatchDeleteThreshold float64
// Chunk size for context length.
PatchMargin int
// The number of bits in an int.
MatchMaxBits int
// At what point is no match declared (0.0 = perfection, 1.0 = very loose).
MatchThreshold float64
}
MatchPatch holds the configuration for diff-match-patch operations.
func (*MatchPatch) Diff ¶
func (dmp *MatchPatch) Diff(text1, text2 string, checklines bool) []Diff
Diff finds the differences between two texts.
If an invalid UTF-8 sequence is encountered, it will be replaced by the Unicode replacement character.
`checklines` indicates if we should do a line level diff, or treat the text as an atomic unit.
func (*MatchPatch) DiffHalfMatch ¶
func (dmp *MatchPatch) DiffHalfMatch(text1, text2 string) []string
DiffHalfMatch checks whether the two texts share a substring which is at least half the length of the longer text. This speedup can produce non-minimal diffs.
func (*MatchPatch) DiffRunes ¶
func (dmp *MatchPatch) DiffRunes(text1, text2 []rune, checklines bool) []Diff
DiffRunes finds the differences between two rune sequences.
If an invalid UTF-8 sequence is encountered, it will be replaced by the Unicode replacement character.
`checklines` indicates if we should do a line level diff, or treat the text as an atomic unit.
type Operation ¶
type Operation int8
Operation defines the operation of a diff item.
const ( // DiffDelete item represents a delete diff. DiffDelete Operation = -1 // DiffInsert item represents an insert diff. DiffInsert Operation = 1 // DiffEqual item represents an equal diff. DiffEqual Operation = 0 //IndexSeparator is used to separate the array indexes in an index string IndexSeparator = "," )
Operation constants.