Documentation
¶
Overview ¶
*
- Go language implementation of Google Diff, Match, and Patch library *
- Original library is Copyright (c) 2006 Google Inc.
- http://code.google.com/p/google-diff-match-patch/ *
- Copyright (c) 2012 Sergi Mansilla <sergi.mansilla@gmail.com>
- https://github.com/sergi/go-diff *
- See included LICENSE file for license details.
Index ¶
- func DiffCommonOverlap(s1, s2 string) int
- func DiffCommonPrefix(s1, s2 string) int
- func DiffCommonSuffix(s1, s2 string) int
- func DiffLevenshtein(diffs []Diff) int
- func DiffLinesToChars(s1, s2 string) (string, string, []string)
- func DiffLinesToRunes(s1, s2 string) ([]rune, []rune, []string)
- func DiffPrettyHtml(diffs []Diff) string
- func DiffText1(diffs []Diff) string
- func DiffText2(diffs []Diff) string
- func DiffToDelta(diffs []Diff) string
- func DiffXIndex(diffs []Diff, loc int) int
- func MatchAlphabet(pattern string) map[byte]int
- func PatchToText(patches []Patch) string
- type DMP
- func (dmp *DMP) Apply(ps []Patch, s string) (string, []bool)
- func (dmp *DMP) DiffBisect(s1, s2 string, deadline time.Time) []Diff
- func (dmp *DMP) DiffCleanupEfficiency(diffs []Diff) []Diff
- func (dmp *DMP) DiffHalfMatch(text1, text2 string) []string
- func (dmp *DMP) DiffMain(s1, s2 string, checkLines bool) []Diff
- func (dmp *DMP) DiffMainRunes(s1, s2 []rune, checkLines bool) []Diff
- func (dmp *DMP) MatchBitap(text, pattern string, loc int) int
- func (dmp *DMP) MatchMain(s, pattern string, loc int) int
- func (dmp *DMP) PatchAddContext(p Patch, s string) Patch
- func (dmp *DMP) PatchAddPadding(ps []Patch) string
- func (dmp *DMP) PatchMake(opt ...interface{}) []Patch
- func (dmp *DMP) PatchSplitMax(ps []Patch) []Patch
- type Diff
- type Element
- type Operation
- type Patch
- type Stack
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DiffCommonOverlap ¶
DiffCommonOverlap determines if the suffix of one string is the prefix of another.
func DiffCommonPrefix ¶
DiffCommonPrefix determines the common prefix length of two strings.
func DiffCommonSuffix ¶
DiffCommonSuffix determines the common suffix length of two strings.
func DiffLevenshtein ¶
DiffLevenshtein computes the Levenshtein distance; the number of inserted, deleted or substituted characters.
func DiffLinesToChars ¶
DiffLinesToChars split two texts into a list of strings. Reduces 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.
func DiffLinesToRunes ¶
DiffLinesToRunes splits two texts into a list of runes. Each rune represents one line.
func DiffPrettyHtml ¶
DiffPrettyHtml converts a []Diff into a pretty HTML report. It is intended as an example from which to write one's own display functions.
func DiffText2 ¶
DiffText2 computes and returns the destination text (all equalities and insertions).
func DiffToDelta ¶
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.
func DiffXIndex ¶
DiffXIndex. loc is a location in text1, comAdde and return the equivalent location in text2. e.g. "The cat" vs "The big cat", 1->1, 5->8
func MatchAlphabet ¶
MatchAlphabet initialises the alphabet for the Bitap algorithm.
func PatchToText ¶
PatchToText takes a list of patches and returns a textual representation.
Types ¶
type DMP ¶
type DMP struct { // Number of seconds to map a diff before giving up (0 for infinity). DiffTimeout time.Duration // Cost of an empty edit operation in terms of edit characters. DiffEditCost 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 Match_Threshold 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 }
func (*DMP) Apply ¶
Apply 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.
func (*DMP) DiffBisect ¶
DiffBisect finds the 'middle snake' of a diff, split the problem in two and return the recursively constructed diff. See Myers 1986 paper: An O(ND) Difference Algorithm and Its Variations.
func (*DMP) DiffCleanupEfficiency ¶
DiffCleanupEfficiency reduces the number of edits by eliminating operationally trivial equalities.
func (*DMP) DiffHalfMatch ¶
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 (*DMP) DiffMainRunes ¶
DiffMainRunes finds the differences between two rune sequences.
func (*DMP) MatchBitap ¶
MatchBitap locates the best instance of 'pattern' in 'text' near 'loc' using the Bitap algorithm. Returns -1 if no match found.
func (*DMP) MatchMain ¶
MatchMain locates the best instance of 'pattern' in 'text' near 'loc'. Returns -1 if no match found.
func (*DMP) PatchAddContext ¶
PatchAddContext increases the context until it is unique, but doesn't let the pattern expand beyond MatchMaxBits.
func (*DMP) PatchAddPadding ¶
PatchAddPadding adds some padding on text start and end so that edges can match something. Intended to be called only from within patch_apply.
func (*DMP) PatchSplitMax ¶
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 patch_apply.
type Diff ¶
Diff represents one diff operation
func DiffCharsToLines ¶
DiffCharsToLines rehydrates the text in a diff from a string of line hashes to real lines of text.
func DiffCleanupMerge ¶
DiffCleanupMerge reorders and merges like edit sections. Merge equalities. Any edit section can move as long as it doesn't cross an equality.
func DiffCleanupSemantic ¶
DiffCleanupSemantic reduces the number of edits by eliminating semantically trivial equalities.
func DiffCleanupSemanticLossless ¶
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.
func DiffFromDelta ¶
Diff_fromDelta. Given the original s, and an encoded string which describes the operations required to transform text1 into text2, comAdde the full diff.
type Patch ¶
type Patch struct {
// contains filtered or unexported fields
}
Patch represents one patch operation.
func PatchDeepCopy ¶
PatchDeepCopy returns an array that is identical to a given an array of patches.
func PatchFromText ¶
PatchFromText parses a textual representation of patches and returns a List of Patch objects.
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
func (*Stack) Peek ¶
func (s *Stack) Peek() (value interface{})
Peek returns the value of the element on the top of the stack but don't remove it. If the stack is empty, return nil
Source Files
¶
- bitap.go
- chars_to_lines.go
- cleanup_efficiency.go
- cleanup_merge.go
- cleanup_semantic.go
- commons.go
- concat.go
- diff.go
- diff_from_delta.go
- diff_half_match.go
- diff_text.go
- diff_to_delta.go
- diff_xindex.go
- dmp.go
- dmp_config.go
- doc.go
- index.go
- levenshtein.go
- lines_to_runes.go
- match_alphabet.go
- math_util.go
- op.go
- patch.go
- patch_add_context.go
- patch_add_padding.go
- patch_deep_copy.go
- patch_from_text.go
- patch_make2.go
- patch_split_max.go
- patch_to_text.go
- pretty_html.go
- regexps.go
- runes.go
- splice.go
- stack.go
- unescaper.go