| 964 | } |
| 965 | |
| 966 | QList<Diff> Differ::preprocess1AndDiff(const QString &text1, const QString &text2) |
| 967 | { |
| 968 | if (text1.isNull() && text2.isNull()) |
| 969 | return {}; |
| 970 | |
| 971 | if (text1 == text2) { |
| 972 | QList<Diff> diffList; |
| 973 | if (!text1.isEmpty()) |
| 974 | diffList.append(Diff(Diff::Equal, text1)); |
| 975 | return diffList; |
| 976 | } |
| 977 | |
| 978 | QString newText1 = text1; |
| 979 | QString newText2 = text2; |
| 980 | QString prefix; |
| 981 | QString suffix; |
| 982 | const int prefixCount = commonPrefix(text1, text2); |
| 983 | if (prefixCount) { |
| 984 | prefix = text1.left(prefixCount); |
| 985 | newText1 = text1.mid(prefixCount); |
| 986 | newText2 = text2.mid(prefixCount); |
| 987 | } |
| 988 | const int suffixCount = commonSuffix(newText1, newText2); |
| 989 | if (suffixCount) { |
| 990 | suffix = newText1.right(suffixCount); |
| 991 | newText1 = newText1.left(newText1.size() - suffixCount); |
| 992 | newText2 = newText2.left(newText2.size() - suffixCount); |
| 993 | } |
| 994 | QList<Diff> diffList = preprocess2AndDiff(newText1, newText2); |
| 995 | if (prefixCount) |
| 996 | diffList.prepend(Diff(Diff::Equal, prefix)); |
| 997 | if (suffixCount) |
| 998 | diffList.append(Diff(Diff::Equal, suffix)); |
| 999 | return diffList; |
| 1000 | } |
| 1001 | |
| 1002 | QList<Diff> Differ::preprocess2AndDiff(const QString &text1, const QString &text2) |
| 1003 | { |
nothing calls this directly
no test coverage detected