void TableDiff::printWordDiff(const String & text1, const String & text2) { WordVector words1, words2; explodeWords(text1, words1); explodeWords(text2, words2); WordDiff worddiff(words1, words2, MAX_WORD_LEVEL_DIFF_COMPLEXITY); //debugPrintWordDiff(worddiff); // print twice; first for left side, then for right side result += "<tr>\n" " <td class=\"diff-marker\">−</td>\n" " <td class=\"diff-deletedline\"><div>"; printWordDiffSide(worddiff, false); result += "</div></td>\n" " <td class=\"diff-marker\">+</td>\n" " <td class=\"diff-addedline\"><div>"; printWordDiffSide(worddiff, true); result += "</div></td>\n" "</tr>\n"; }
void InlineDiff::printWordDiff(const String& text1, const String& text2, bool printLeft, bool printRight, const String & srcAnchor, const String & dstAnchor, bool moveDirectionDownwards) { WordVector words1, words2; TextUtil::explodeWords(text1, words1); TextUtil::explodeWords(text2, words2); WordDiff worddiff(words1, words2, MAX_WORD_LEVEL_DIFF_COMPLEXITY); String word; bool moved = printLeft != printRight, isMoveSrc = moved && printLeft, isMoveDest = moved && printRight; if (moved) { result += String("<div class=\"mw-diff-inline-moved mw-diff-inline-moved-") + (printLeft ? "source" : "destination") + " mw-diff-inline-moved-" + (moveDirectionDownwards ? "downwards" : "upwards") + "\">"; result += "<a name=\"" + srcAnchor + "\"></a>"; if (!moveDirectionDownwards) { result += "<a class=\"mw-diff-movedpara-" + String(printLeft ? "left" : "right") + "\" data-title-tag=\"" + (printRight ? "new" : "old") + "\" href=\"#" + dstAnchor + "\">" + "▲" + "</a>"; } } else { result += "<div class=\"mw-diff-inline-changed\">"; } for (unsigned i = 0; i < worddiff.size(); ++i) { DiffOp<Word> & op = worddiff[i]; int n, j; if (op.op == DiffOp<Word>::copy) { n = op.from.size(); for (j=0; j<n; j++) { op.from[j]->get_whole(word); printText(word); } } else if (op.op == DiffOp<Word>::del) { n = op.from.size(); if (!isMoveSrc) result += "<del>"; for (j=0; j<n; j++) { op.from[j]->get_whole(word); printText(word); } if (!isMoveSrc) result += "</del>"; } else if (op.op == DiffOp<Word>::add) { if (isMoveSrc) continue; n = op.to.size(); result += "<ins>"; for (j=0; j<n; j++) { op.to[j]->get_whole(word); printText(word); } result += "</ins>"; } else if (op.op == DiffOp<Word>::change) { n = op.from.size(); if (!isMoveSrc) result += "<del>"; for (j=0; j<n; j++) { op.from[j]->get_whole(word); printText(word); } if (isMoveSrc) continue; result += "</del>"; n = op.to.size(); result += "<ins>"; for (j=0; j<n; j++) { op.to[j]->get_whole(word); printText(word); } result += "</ins>"; } } if (moved && moveDirectionDownwards) { result += "<a class=\"mw-diff-movedpara-" + String(printLeft ? "left" : "right") + "\" data-title-tag=\"" + (printRight ? "new" : "old") + "\" href=\"#" + dstAnchor + "\">" + "▼" + "</a>"; } result += "</div>\n"; }