package diffmatchpatch

Import Path
	github.com/sergi/go-diff/diffmatchpatch (on go.dev)

Dependency Relation
	imports 11 packages, and imported by one package

Involved Source Files diff.go Package diffmatchpatch offers robust algorithms to perform the operations required for synchronizing plain text. match.go mathutil.go operation_string.go patch.go stringutil.go
Package-Level Type Names (total 4, all are exported)
/* sort exporteds by: | */
Diff represents one diff operation Text string Type Operation func (*DiffMatchPatch).DiffBisect(text1, text2 string, deadline time.Time) []Diff func (*DiffMatchPatch).DiffCharsToLines(diffs []Diff, lineArray []string) []Diff func (*DiffMatchPatch).DiffCleanupEfficiency(diffs []Diff) []Diff func (*DiffMatchPatch).DiffCleanupMerge(diffs []Diff) []Diff func (*DiffMatchPatch).DiffCleanupSemantic(diffs []Diff) []Diff func (*DiffMatchPatch).DiffCleanupSemanticLossless(diffs []Diff) []Diff func (*DiffMatchPatch).DiffFromDelta(text1 string, delta string) (diffs []Diff, err error) func (*DiffMatchPatch).DiffMain(text1, text2 string, checklines bool) []Diff func (*DiffMatchPatch).DiffMainRunes(text1, text2 []rune, checklines bool) []Diff func (*DiffMatchPatch).DiffCharsToLines(diffs []Diff, lineArray []string) []Diff func (*DiffMatchPatch).DiffCleanupEfficiency(diffs []Diff) []Diff func (*DiffMatchPatch).DiffCleanupMerge(diffs []Diff) []Diff func (*DiffMatchPatch).DiffCleanupSemantic(diffs []Diff) []Diff func (*DiffMatchPatch).DiffCleanupSemanticLossless(diffs []Diff) []Diff func (*DiffMatchPatch).DiffLevenshtein(diffs []Diff) int func (*DiffMatchPatch).DiffPrettyHtml(diffs []Diff) string func (*DiffMatchPatch).DiffPrettyText(diffs []Diff) string func (*DiffMatchPatch).DiffText1(diffs []Diff) string func (*DiffMatchPatch).DiffText2(diffs []Diff) string func (*DiffMatchPatch).DiffToDelta(diffs []Diff) string func (*DiffMatchPatch).DiffXIndex(diffs []Diff, loc int) int
DiffMatchPatch holds the configuration for diff-match-patch operations. Cost of an empty edit operation in terms of edit characters. Number of seconds to map a diff before giving up (0 for infinity). 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). The number of bits in an int. At what point is no match declared (0.0 = perfection, 1.0 = very loose). 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. Chunk size for context length. DiffBisect finds the 'middle snake' of a diff, split the problem in two and return the recursively constructed diff. If an invalid UTF-8 sequence is encountered, it will be replaced by the Unicode replacement character. See Myers 1986 paper: An O(ND) Difference Algorithm and Its Variations. DiffCharsToLines rehydrates the text in a diff from a string of line hashes to real lines of text. DiffCleanupEfficiency reduces the number of edits by eliminating operationally trivial equalities. DiffCleanupMerge reorders and merges like edit sections. Merge equalities. Any edit section can move as long as it doesn't cross an equality. DiffCleanupSemantic reduces the number of edits by eliminating semantically trivial equalities. DiffCleanupSemanticLossless looks for single edits surrounded on both sides by equalities which can be shifted sideways to align the edit to a word boundary. E.g: The c<ins>at c</ins>ame. -> The <ins>cat </ins>came. DiffCommonOverlap determines if the suffix of one string is the prefix of another. DiffCommonPrefix determines the common prefix length of two strings. DiffCommonSuffix determines the common suffix length of two strings. DiffFromDelta given the original text1, and an encoded string which describes the operations required to transform text1 into text2, comAdde the full diff. 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. DiffLevenshtein computes the Levenshtein distance that is the number of inserted, deleted or substituted characters. DiffLinesToChars splits two texts into a list of strings, and educes the texts to a string of hashes where each Unicode character represents one line. It's slightly faster to call DiffLinesToRunes first, followed by DiffMainRunes. DiffLinesToRunes splits two texts into a list of runes. DiffMain finds the differences between two texts. If an invalid UTF-8 sequence is encountered, it will be replaced by the Unicode replacement character. DiffMainRunes finds the differences between two rune sequences. If an invalid UTF-8 sequence is encountered, it will be replaced by the Unicode replacement character. DiffPrettyHtml converts a []Diff into a pretty HTML report. It is intended as an example from which to write one's own display functions. DiffPrettyText converts a []Diff into a colored text report. DiffText1 computes and returns the source text (all equalities and deletions). DiffText2 computes and returns the destination text (all equalities and insertions). DiffToDelta crushes the diff into an encoded string which describes the operations required to transform text1 into text2. E.g. =3\t-2\t+ing -> Keep 3 chars, delete 2 chars, insert 'ing'. Operations are tab-separated. Inserted text is escaped using %xx notation. DiffXIndex returns the equivalent location in s2. MatchAlphabet initialises the alphabet for the Bitap algorithm. MatchBitap locates the best instance of 'pattern' in 'text' near 'loc' using the Bitap algorithm. Returns -1 if no match was found. MatchMain locates the best instance of 'pattern' in 'text' near 'loc'. Returns -1 if no match found. PatchAddContext increases the context until it is unique, but doesn't let the pattern expand beyond MatchMaxBits. PatchAddPadding adds some padding on text start and end so that edges can match something. Intended to be called only from within patchApply. PatchApply merges a set of patches onto the text. Returns a patched text, as well as an array of true/false values indicating which patches were applied. PatchDeepCopy returns an array that is identical to a given an array of patches. PatchFromText parses a textual representation of patches and returns a List of Patch objects. PatchMake computes a list of patches. PatchSplitMax looks through the patches and breaks up any which are longer than the maximum limit of the match algorithm. Intended to be called only from within patchApply. PatchToText takes a list of patches and returns a textual representation. func New() *DiffMatchPatch
Operation defines the operation of a diff item. ( T) String() string T : fmt.Stringer const DiffDelete const DiffEqual const DiffInsert
Patch represents one patch operation. Length1 int Length2 int Start1 int Start2 int String emulates GNU diff's format. Header: @@ -382,8 +481,9 @@ Indices are printed as 1-based, not 0-based. *T : fmt.Stringer func (*DiffMatchPatch).PatchAddContext(patch Patch, text string) Patch func (*DiffMatchPatch).PatchDeepCopy(patches []Patch) []Patch func (*DiffMatchPatch).PatchFromText(textline string) ([]Patch, error) func (*DiffMatchPatch).PatchMake(opt ...interface{}) []Patch func (*DiffMatchPatch).PatchSplitMax(patches []Patch) []Patch func (*DiffMatchPatch).PatchAddContext(patch Patch, text string) Patch func (*DiffMatchPatch).PatchAddPadding(patches []Patch) string func (*DiffMatchPatch).PatchApply(patches []Patch, text string) (string, []bool) func (*DiffMatchPatch).PatchDeepCopy(patches []Patch) []Patch func (*DiffMatchPatch).PatchSplitMax(patches []Patch) []Patch func (*DiffMatchPatch).PatchToText(patches []Patch) string
Package-Level Functions (total 13, in which 1 are exported)
New creates a new DiffMatchPatch object with default parameters.
Package-Level Variables (total 7, none are exported)
Package-Level Constants (total 5, in which 4 are exported)
DiffDelete item represents a delete diff.
DiffEqual item represents an equal diff.
DiffInsert item represents an insert diff.
IndexSeparator is used to seperate the array indexes in an index string