| 552 | } |
| 553 | |
| 554 | func (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 | |
| 587 | func (d *Differ) StructuredDump(tag byte, x []string, low int, high int) (out []DiffLine) { |
| 588 | size := high - low |