| 67 | } |
| 68 | |
| 69 | static QList<Diff> squashEqualities(const QList<Diff> &diffList) |
| 70 | { |
| 71 | if (diffList.size() < 3) // we need at least 3 items |
| 72 | return diffList; |
| 73 | |
| 74 | QList<Diff> newDiffList; |
| 75 | Diff prevDiff = diffList.at(0); |
| 76 | Diff thisDiff = diffList.at(1); |
| 77 | Diff nextDiff = diffList.at(2); |
| 78 | int i = 2; |
| 79 | while (i < diffList.size()) { |
| 80 | if (prevDiff.command == Diff::Equal |
| 81 | && nextDiff.command == Diff::Equal) { |
| 82 | if (thisDiff.text.endsWith(prevDiff.text)) { |
| 83 | thisDiff.text = prevDiff.text |
| 84 | + thisDiff.text.left(thisDiff.text.size() |
| 85 | - prevDiff.text.size()); |
| 86 | nextDiff.text = prevDiff.text + nextDiff.text; |
| 87 | } else if (thisDiff.text.startsWith(nextDiff.text)) { |
| 88 | prevDiff.text += nextDiff.text; |
| 89 | thisDiff.text = thisDiff.text.mid(nextDiff.text.size()) |
| 90 | + nextDiff.text; |
| 91 | i++; |
| 92 | if (i < diffList.size()) |
| 93 | nextDiff = diffList.at(i); |
| 94 | newDiffList.append(prevDiff); |
| 95 | } else { |
| 96 | newDiffList.append(prevDiff); |
| 97 | } |
| 98 | } else { |
| 99 | newDiffList.append(prevDiff); |
| 100 | } |
| 101 | prevDiff = thisDiff; |
| 102 | thisDiff = nextDiff; |
| 103 | i++; |
| 104 | if (i < diffList.size()) |
| 105 | nextDiff = diffList.at(i); |
| 106 | } |
| 107 | newDiffList.append(prevDiff); |
| 108 | if (i == diffList.size()) |
| 109 | newDiffList.append(thisDiff); |
| 110 | return newDiffList; |
| 111 | } |
| 112 | |
| 113 | static QList<Diff> cleanupOverlaps(const QList<Diff> &diffList) |
| 114 | { |