MCPcopy Create free account
hub / github.com/couchbase/fleece / diff_prettyHtml

Method diff_prettyHtml

Fleece/Support/diff_match_patch.hh:1415–1455  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1413 */
1414 public:
1415 static string_t diff_prettyHtml(const Diffs &diffs) {
1416 string_t html;
1417 string_t text;
1418 for (typename Diffs::const_iterator cur_diff = diffs.begin(); cur_diff != diffs.end(); ++cur_diff) {
1419 typename string_t::size_type n = (*cur_diff).text.size();
1420 typename string_t::const_pointer p, end;
1421 for (p = (*cur_diff).text.c_str(), end = p + n; p != end; ++p)
1422 switch (traits::to_wchar(*p)) {
1423 case L'&': n += 4; break;
1424 case L'<':
1425 case L'>': n += 3; break;
1426 case L'\n': n += 9; break;
1427 }
1428 if (n == (*cur_diff).text.size())
1429 text = (*cur_diff).text;
1430 else {
1431 text.clear();
1432 text.reserve(n);
1433 for (p = (*cur_diff).text.c_str(); p != end; ++p)
1434 switch (traits::to_wchar(*p)) {
1435 case L'&': text += traits::cs(L"&amp;"); break;
1436 case L'<': text += traits::cs(L"&lt;"); break;
1437 case L'>': text += traits::cs(L"&gt;"); break;
1438 case L'\n': text += traits::cs(L"&para;<br>"); break;
1439 default: text += *p;
1440 }
1441 }
1442 switch ((*cur_diff).operation) {
1443 case INSERT:
1444 html += traits::cs(L"<ins style=\"background:#e6ffe6;\">") + text + traits::cs(L"</ins>");
1445 break;
1446 case DELETE:
1447 html += traits::cs(L"<del style=\"background:#ffe6e6;\">") + text + traits::cs(L"</del>");
1448 break;
1449 case EQUAL:
1450 html += traits::cs(L"<span>") + text + traits::cs(L"</span>");
1451 break;
1452 }
1453 }
1454 return html;
1455 }
1456
1457 /**
1458 * Compute and return the source text (all equalities and deletions).

Callers

nothing calls this directly

Calls 4

beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected