diffHalfMatchI checks if a substring of shorttext exist within longtext such that the substring is at least half the length of longtext? Returns a slice containing the prefix of longtext, the suffix of longtext, the prefix of shorttext, the suffix of shorttext and the common middle, or null if there
(l, s []rune, i int)
| 563 | // diffHalfMatchI checks if a substring of shorttext exist within longtext such that the substring is at least half the length of longtext? |
| 564 | // Returns a slice containing the prefix of longtext, the suffix of longtext, the prefix of shorttext, the suffix of shorttext and the common middle, or null if there was no match. |
| 565 | func (dmp *DiffMatchPatch) diffHalfMatchI(l, s []rune, i int) [][]rune { |
| 566 | var bestCommonA []rune |
| 567 | var bestCommonB []rune |
| 568 | var bestCommonLen int |
| 569 | var bestLongtextA []rune |
| 570 | var bestLongtextB []rune |
| 571 | var bestShorttextA []rune |
| 572 | var bestShorttextB []rune |
| 573 | |
| 574 | // Start with a 1/4 length substring at position i as a seed. |
| 575 | seed := l[i : i+len(l)/4] |
| 576 | |
| 577 | for j := runesIndexOf(s, seed, 0); j != -1; j = runesIndexOf(s, seed, j+1) { |
| 578 | prefixLength := commonPrefixLength(l[i:], s[j:]) |
| 579 | suffixLength := commonSuffixLength(l[:i], s[:j]) |
| 580 | |
| 581 | if bestCommonLen < suffixLength+prefixLength { |
| 582 | bestCommonA = s[j-suffixLength : j] |
| 583 | bestCommonB = s[j : j+prefixLength] |
| 584 | bestCommonLen = len(bestCommonA) + len(bestCommonB) |
| 585 | bestLongtextA = l[:i-suffixLength] |
| 586 | bestLongtextB = l[i+prefixLength:] |
| 587 | bestShorttextA = s[:j-suffixLength] |
| 588 | bestShorttextB = s[j+prefixLength:] |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | if bestCommonLen*2 < len(l) { |
| 593 | return nil |
| 594 | } |
| 595 | |
| 596 | return [][]rune{ |
| 597 | bestLongtextA, |
| 598 | bestLongtextB, |
| 599 | bestShorttextA, |
| 600 | bestShorttextB, |
| 601 | append(bestCommonA, bestCommonB...), |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | // DiffCleanupSemantic reduces the number of edits by eliminating semantically trivial equalities. |
| 606 | func (dmp *DiffMatchPatch) DiffCleanupSemantic(diffs []Diff) []Diff { |
no test coverage detected