| 424 | */ |
| 425 | private: |
| 426 | static void diff_lineMode(string_t text1, string_t text2, clock_t deadline, Diffs& diffs) { |
| 427 | // Scan the text on a line-by-line basis first. |
| 428 | Lines linearray; |
| 429 | diff_linesToChars(text1, text2, linearray); |
| 430 | |
| 431 | diff_main(text1, text2, false, deadline, diffs); |
| 432 | |
| 433 | // Convert the diff back to original text. |
| 434 | diff_charsToLines(diffs, linearray); |
| 435 | // Eliminate freak matches (e.g. blank lines) |
| 436 | diff_cleanupSemantic(diffs); |
| 437 | |
| 438 | // Rediff any replacement blocks, this time character-by-character. |
| 439 | // Add a dummy entry at the end. |
| 440 | diffs.push_back(Diff(EQUAL, string_t())); |
| 441 | ssize_t count_delete = 0; |
| 442 | ssize_t count_insert = 0; |
| 443 | string_t text_delete; |
| 444 | string_t text_insert; |
| 445 | |
| 446 | for (typename Diffs::iterator cur_diff = diffs.begin(); cur_diff != diffs.end(); ++cur_diff) { |
| 447 | switch ((*cur_diff).operation) { |
| 448 | case INSERT: |
| 449 | count_insert++; |
| 450 | text_insert += (*cur_diff).text; |
| 451 | break; |
| 452 | case DELETE: |
| 453 | count_delete++; |
| 454 | text_delete += (*cur_diff).text; |
| 455 | break; |
| 456 | case EQUAL: |
| 457 | // Upon reaching an equality, check for prior redundancies. |
| 458 | if (count_delete >= 1 && count_insert >= 1) { |
| 459 | // Delete the offending records and add the merged ones. |
| 460 | typename Diffs::iterator last = cur_diff; |
| 461 | std::advance(cur_diff, -(count_delete + count_insert)); |
| 462 | cur_diff = diffs.erase(cur_diff, last); |
| 463 | |
| 464 | Diffs new_diffs; |
| 465 | diff_main(text_delete, text_insert, false, deadline, new_diffs); |
| 466 | diffs.splice(cur_diff++, new_diffs); |
| 467 | --cur_diff; |
| 468 | } |
| 469 | count_insert = 0; |
| 470 | count_delete = 0; |
| 471 | text_delete.clear(); |
| 472 | text_insert.clear(); |
| 473 | break; |
| 474 | } |
| 475 | } |
| 476 | diffs.pop_back(); // Remove the dummy entry at the end. |
| 477 | } |
| 478 | |
| 479 | /** |
| 480 | * Find the 'middle snake' of a diff, split the problem in two |