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

Method diff_xIndex

Fleece/Support/diff_match_patch.hh:1378–1407  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1376 */
1377 public:
1378 static ssize_t diff_xIndex(const Diffs &diffs, ssize_t loc) {
1379 ssize_t chars1 = 0;
1380 ssize_t chars2 = 0;
1381 ssize_t last_chars1 = 0;
1382 ssize_t last_chars2 = 0;
1383 typename Diffs::const_iterator last_diff = diffs.end(), cur_diff;
1384 for (cur_diff = diffs.begin(); cur_diff != diffs.end(); ++cur_diff) {
1385 if ((*cur_diff).operation != INSERT) {
1386 // Equality or deletion.
1387 chars1 += (*cur_diff).text.length();
1388 }
1389 if ((*cur_diff).operation != DELETE) {
1390 // Equality or insertion.
1391 chars2 += (*cur_diff).text.length();
1392 }
1393 if (chars1 > loc) {
1394 // Overshot the location.
1395 last_diff = cur_diff;
1396 break;
1397 }
1398 last_chars1 = chars1;
1399 last_chars2 = chars2;
1400 }
1401 if (last_diff != diffs.end() && (*last_diff).operation == DELETE) {
1402 // The location was deleted.
1403 return last_chars2;
1404 }
1405 // Add the remaining character length.
1406 return last_chars2 + (loc - last_chars1);
1407 }
1408
1409 /**
1410 * Convert a Diff list into a pretty HTML report.

Callers

nothing calls this directly

Calls 3

lengthMethod · 0.80
endMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected