MCPcopy Create free account
hub / github.com/Lotus6/AutoRepeater / diff_halfMatchI

Method diff_halfMatchI

src/burp/Utils/diff_match_patch.java:732–759  ·  view source on GitHub ↗

Does a substring of shorttext exist within longtext such that the substring is at least half the length of longtext? @param longtext Longer string. @param shorttext Shorter string. @param i Start index of quarter length substring within longtext. @return Five element String array, containing the pr

(String longtext, String shorttext, int i)

Source from the content-addressed store, hash-verified

730 * no match.
731 */
732 private String[] diff_halfMatchI(String longtext, String shorttext, int i) {
733 // Start with a 1/4 length substring at position i as a seed.
734 String seed = longtext.substring(i, i + longtext.length() / 4);
735 int j = -1;
736 String best_common = "";
737 String best_longtext_a = "", best_longtext_b = "";
738 String best_shorttext_a = "", best_shorttext_b = "";
739 while ((j = shorttext.indexOf(seed, j + 1)) != -1) {
740 int prefixLength = diff_commonPrefix(longtext.substring(i),
741 shorttext.substring(j));
742 int suffixLength = diff_commonSuffix(longtext.substring(0, i),
743 shorttext.substring(0, j));
744 if (best_common.length() < suffixLength + prefixLength) {
745 best_common = shorttext.substring(j - suffixLength, j)
746 + shorttext.substring(j, j + prefixLength);
747 best_longtext_a = longtext.substring(0, i - suffixLength);
748 best_longtext_b = longtext.substring(i + prefixLength);
749 best_shorttext_a = shorttext.substring(0, j - suffixLength);
750 best_shorttext_b = shorttext.substring(j + prefixLength);
751 }
752 }
753 if (best_common.length() * 2 >= longtext.length()) {
754 return new String[]{best_longtext_a, best_longtext_b,
755 best_shorttext_a, best_shorttext_b, best_common};
756 } else {
757 return null;
758 }
759 }
760
761 /**
762 * Reduce the number of edits by eliminating semantically trivial equalities.

Callers 1

diff_halfMatchMethod · 0.95

Calls 2

diff_commonPrefixMethod · 0.95
diff_commonSuffixMethod · 0.95

Tested by

no test coverage detected