Documentation ¶
Overview ¶
Package diff implement text comparison.
Index ¶
- Constants
- Variables
- func Bytes(old, new []byte, atx, aty int) (adds, dels text.Chunks)
- func BytesRatio(old, new []byte, minTokenLen int) (ratio float32, m int, maxlen int)
- func IsEqual(oldb, newb []byte) (equal bool)
- func ReadLines(f string) (lines text.Lines, e error)
- type Data
- type LineChange
- type LineChanges
Constants ¶
const ( // LevelLines define that we want only lines change set. LevelLines = iota // LevelWords define that we want the change not only capture the // different per line, but also changes inside the line. LevelWords )
const ( // DefMatchLen minimum number of bytes used for searching the next // matched chunk in line. DefMatchLen = 5 // DefMatchRatio define default minimum match ratio to be considered as // change. DefMatchRatio = 0.7 )
Variables ¶
var ( // DefDelimiter define default delimiter for new line. DefDelimiter = byte('\n') )
Functions ¶
func Bytes ¶
Bytes given two similar lines, find and return the differences (additions and deletion) between them.
Case 1: addition on new or deletion on old.
old: 00000 new: 00000111
or
old: 00000111 new: 00000
Case 2: addition on new line
old: 000000 new: 0001000
Case 3: deletion on old line (reverse of case 2)
old: 0001000 new: 000000
Case 4: change happened in the beginning
old: 11000 new: 22000
Case 5: both changed
old: 0001000 new: 0002000
func BytesRatio ¶
BytesRatio compare two slice of bytes and return ratio of matching bytes. The ratio in in range of 0.0 to 1.0, where 1.0 if both are similar, and 0.0 if no matchs even found. `minTokenLen` define the minimum length of token for searching in both of slice.
Types ¶
type Data ¶
Data represent additions, deletions, and changes between two text. If no difference found, the IsMatched will be true.
func (*Data) GetAllAdds ¶
GetAllAdds return chunks of additions including in line changes.
func (*Data) GetAllDels ¶
GetAllDels return chunks of deletions including in line changes.
func (*Data) PushChange ¶
PushChange set to diff data.
type LineChange ¶
LineChange represent one change in text.
func NewLineChange ¶
func NewLineChange(old, new text.Line) *LineChange
NewLineChange create a pointer to new LineChange object.
func (LineChange) String ¶
func (change LineChange) String() string
String return formatted content of LineChange.
type LineChanges ¶
type LineChanges []LineChange
LineChanges represents a set of change in text.
func (*LineChanges) GetAllAdds ¶
func (changes *LineChanges) GetAllAdds() (allAdds text.Chunks)
GetAllAdds return all addition chunks.
func (*LineChanges) GetAllDels ¶
func (changes *LineChanges) GetAllDels() (allDels text.Chunks)
GetAllDels return all deleted chunks.