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.
diffBisect finds the 'middle snake' of a diff, splits the problem in two and returns the recursively constructed diff.
See Myers's 1986 paper: An O(ND) Difference Algorithm and Its Variations.
(*T) diffBisectSplit(runes1, runes2 []rune, x, y int, deadline time.Time) []Diff
diffCompute finds the differences between two rune slices. Assumes that the texts do not have any common prefix or suffix.
(*T) diffHalfMatch(text1, text2 []rune) [][]rune
diffHalfMatchI checks if a substring of shorttext exist within longtext such that the substring is at least half the length of longtext?
Returns a slice containing the prefix of longtext, the suffix of longtext, the prefix of shorttext, the suffix of shorttext and the common middle, or null if there was no match.
diffLineMode does a quick line-level diff on both []runes, then rediff the parts for greater accuracy. This speedup can produce non-minimal diffs.
diffLinesToStrings splits two texts into a list of strings. Each string represents one line.
diffLinesToStringsMunge splits a text into an array of strings, and reduces the texts to a []string.
(*T) diffMainRunes(text1, text2 []rune, checklines bool, deadline time.Time) []Diff
matchBitapScore computes and returns the score for a match with e errors and x location.
patchMake2 computes a list of patches to turn text1 into text2.
text2 is not provided, diffs are the delta between text1 and text2.
func New() *DiffMatchPatch
Package-Level Functions (total 13, in which 1 are exported)
New creates a new DiffMatchPatch object with default parameters.
commonPrefixLength returns the length of the common prefix of two rune slices.
commonSuffixLength returns the length of the common suffix of two rune slices.
diffCleanupSemanticScore computes a score representing whether the internal boundary falls on logical boundaries.
Scores range from 6 (best) to 0 (worst). Closure, but does not reference any external variables.
indexOf returns the first index of pattern in str, starting at str[i].
Define some regex patterns for matching boundaries.
Define some regex patterns for matching boundaries.
Define some regex patterns for matching boundaries.
Define some regex patterns for matching boundaries.
unescaper unescapes selected chars for compatibility with JavaScript's encodeURI.
In speed critical applications this could be dropped since the receiving application will certainly decode these fine. Note that this function is case-sensitive. Thus "%3F" would not be unescaped. But this is ok because it is only called with the output of HttpUtility.UrlEncode which returns lowercase hex. Example: "%3f" -> "?", "%24" -> "$", etc.
Define some regex patterns for matching boundaries.
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
The pages are generated with Goldsv0.3.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.