alignSearchReplace returns the count of leading and trailing lines that match between searchLines and repLines under TrimSpace equality. Between the prefix and suffix ranges lies the middle: inserted, deleted, or rewritten lines. TrimSpace matches what pass 3 uses for matching, so pair identificatio
(searchLines, repLines []string)
| 747 | // matches what pass 3 uses for matching, so pair identification |
| 748 | // stays consistent with how the region was found. |
| 749 | func alignSearchReplace(searchLines, repLines []string) (prefix, suffix int) { |
| 750 | eq := func(a, b string) bool { |
| 751 | aContent, _ := splitEnding(a) |
| 752 | bContent, _ := splitEnding(b) |
| 753 | return strings.TrimSpace(aContent) == strings.TrimSpace(bContent) |
| 754 | } |
| 755 | maxPrefix := len(searchLines) |
| 756 | if len(repLines) < maxPrefix { |
| 757 | maxPrefix = len(repLines) |
| 758 | } |
| 759 | for prefix < maxPrefix && eq(searchLines[prefix], repLines[prefix]) { |
| 760 | prefix++ |
| 761 | } |
| 762 | // Suffix must not overlap prefix on either side. |
| 763 | maxSuffix := maxPrefix - prefix |
| 764 | for suffix < maxSuffix && |
| 765 | eq(searchLines[len(searchLines)-1-suffix], repLines[len(repLines)-1-suffix]) { |
| 766 | suffix++ |
| 767 | } |
| 768 | return prefix, suffix |
| 769 | } |
| 770 | |
| 771 | // detectIndentUnit scans leading whitespace across the given lines |
| 772 | // and returns the smallest consistent indentation unit (one tab, or |
no test coverage detected