package diff
import "git.sr.ht/~shulhan/pakakeh.go/lib/text/diff"
Package diff implement text comparison.
Index ¶
- Constants
- Variables
- func Bytes(old, new []byte, atx, aty int) (adds, dels text.Chunks)
- func BytesRatio(old, newline []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
- func Files(oldf, newf string, level int) (diffs Data, e error)
- func Lines(oldlines, newlines text.Lines, level int) (diffs Data)
- func Text(before, after []byte, level int) (diffs Data)
- func (diffs *Data) GetAllAdds() (chunks text.Chunks)
- func (diffs *Data) GetAllDels() (chunks text.Chunks)
- func (diffs *Data) PushAdd(new text.Line)
- func (diffs *Data) PushChange(old, new text.Line)
- func (diffs *Data) PushDel(old text.Line)
- func (diffs Data) String() (s string)
- 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.
func IsEqual ¶
IsEqual compare two slice of bytes and return true if equal or false otherwise.
func ReadLines ¶
ReadLines return lines in the file `f`.
Types ¶
type Data ¶
Data represent additions, deletions, and changes between two text. If no difference found, the IsMatched will be true.
func Files ¶
Files compare two files.
func Lines ¶
Lines search the difference between two Lines.
func Text ¶
Text search the difference between two texts.
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) PushAdd ¶
PushAdd will add new line to diff set.
func (*Data) PushChange ¶
PushChange set to diff data.
func (*Data) PushDel ¶
PushDel will add deletion line to diff set.
func (Data) String ¶
String return formatted 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.
Source Files ¶
diff.go diffinterface.go linechange.go linechanges.go
- Version
- v0.60.0 (latest)
- Published
- Feb 1, 2025
- Platform
- linux/amd64
- Imports
- 9 packages
- Last checked
- 9 hours ago –
Tools for package owners.