MCPcopy Create free account
hub / github.com/cogentcore/core / Compare

Method Compare

texteditor/difflib/difflib.go:554–585  ·  view source on GitHub ↗
(a []string, b []string)

Source from the content-addressed store, hash-verified

552}
553
554func (d *Differ) Compare(a []string, b []string) (diffs []string, err error) {
555 // Compare two sequences of lines; generate the resulting delta.
556
557 // Each sequence must contain individual single-line strings ending with
558 // newlines. Such sequences can be obtained from the `readlines()` method
559 // of file-like objects. The delta generated also consists of newline-
560 // terminated strings, ready to be printed as-is via the writeline()
561 // method of a file-like object.
562 diffs = []string{}
563 cruncher := NewMatcherWithJunk(a, b, true, d.Linejunk)
564 opcodes := cruncher.GetOpCodes()
565 for _, current := range opcodes {
566 alo := current.I1
567 ahi := current.I2
568 blo := current.J1
569 bhi := current.J2
570 var g []string
571 if current.Tag == 'r' {
572 g, _ = d.FancyReplace(a, alo, ahi, b, blo, bhi)
573 } else if current.Tag == 'd' {
574 g = d.Dump("-", a, alo, ahi)
575 } else if current.Tag == 'i' {
576 g = d.Dump("+", b, blo, bhi)
577 } else if current.Tag == 'e' {
578 g = d.Dump(" ", a, alo, ahi)
579 } else {
580 return nil, fmt.Errorf("unknown tag %q", current.Tag)
581 }
582 diffs = append(diffs, g...)
583 }
584 return diffs, nil
585}
586
587func (d *Differ) StructuredDump(tag byte, x []string, low int, high int) (out []DiffLine) {
588 size := high - low

Callers 6

BenchmarkDifferFunction · 0.95
TestDifferCompareFunction · 0.95
BuiltinTypesFunction · 0.45
MatchSeedStringFunction · 0.45
MatchSeedCompletionFunction · 0.45
ReportMethod · 0.45

Calls 5

FancyReplaceMethod · 0.95
DumpMethod · 0.95
NewMatcherWithJunkFunction · 0.70
ErrorfMethod · 0.65
GetOpCodesMethod · 0.45

Tested by 2

BenchmarkDifferFunction · 0.76
TestDifferCompareFunction · 0.76