| 619 | var CARET = []byte("^") |
| 620 | |
| 621 | func (d *Differ) Compare(a [][]byte, b [][]byte) (diffs [][]byte, err error) { |
| 622 | // Compare two sequences of lines; generate the resulting delta. |
| 623 | |
| 624 | // Each sequence must contain individual single-line strings ending with |
| 625 | // newlines. Such sequences can be obtained from the `readlines()` method |
| 626 | // of file-like objects. The delta generated also consists of newline- |
| 627 | // terminated strings, ready to be printed as-is via the writeline() |
| 628 | // method of a file-like object. |
| 629 | diffs = [][]byte{} |
| 630 | cruncher := NewMatcherWithJunk(a, b, true, d.Linejunk) |
| 631 | opcodes := cruncher.GetOpCodes() |
| 632 | for _, current := range opcodes { |
| 633 | alo := current.I1 |
| 634 | ahi := current.I2 |
| 635 | blo := current.J1 |
| 636 | bhi := current.J2 |
| 637 | var g [][]byte |
| 638 | if current.Tag == 'r' { |
| 639 | g, _ = d.FancyReplace(a, alo, ahi, b, blo, bhi) |
| 640 | } else if current.Tag == 'd' { |
| 641 | g = d.Dump(MINUS, a, alo, ahi) |
| 642 | } else if current.Tag == 'i' { |
| 643 | g = d.Dump(PLUS, b, blo, bhi) |
| 644 | } else if current.Tag == 'e' { |
| 645 | g = d.Dump(SPACE, a, alo, ahi) |
| 646 | } else { |
| 647 | return nil, fmt.Errorf("unknown tag %q", current.Tag) |
| 648 | } |
| 649 | diffs = append(diffs, g...) |
| 650 | } |
| 651 | return diffs, nil |
| 652 | } |
| 653 | |
| 654 | func (d *Differ) StructuredDump(tag byte, x [][]byte, low int, high int) (out []DiffLine) { |
| 655 | size := high - low |