| 304 | |
| 305 | |
| 306 | QList<Diff> diff_match_patch::diff_lineMode(QString text1, QString text2, |
| 307 | clock_t deadline) { |
| 308 | // Scan the text on a line-by-line basis first. |
| 309 | const QList<QVariant> b = diff_linesToChars(text1, text2); |
| 310 | text1 = b[0].toString(); |
| 311 | text2 = b[1].toString(); |
| 312 | QStringList linearray = b[2].toStringList(); |
| 313 | |
| 314 | QList<Diff> diffs = diff_main(text1, text2, false, deadline); |
| 315 | |
| 316 | // Convert the diff back to original text. |
| 317 | diff_charsToLines(diffs, linearray); |
| 318 | // Eliminate freak matches (e.g. blank lines) |
| 319 | diff_cleanupSemantic(diffs); |
| 320 | |
| 321 | // Rediff any replacement blocks, this time character-by-character. |
| 322 | // Add a dummy entry at the end. |
| 323 | diffs.append(Diff(EQUAL, "")); |
| 324 | int count_delete = 0; |
| 325 | int count_insert = 0; |
| 326 | QString text_delete = ""; |
| 327 | QString text_insert = ""; |
| 328 | |
| 329 | QMutableListIterator<Diff> pointer(diffs); |
| 330 | Diff *thisDiff = pointer.hasNext() ? &pointer.next() : NULL; |
| 331 | while (thisDiff != NULL) { |
| 332 | switch (thisDiff->operation) { |
| 333 | case INSERT: |
| 334 | count_insert++; |
| 335 | text_insert += thisDiff->text; |
| 336 | break; |
| 337 | case DELETE: |
| 338 | count_delete++; |
| 339 | text_delete += thisDiff->text; |
| 340 | break; |
| 341 | case EQUAL: |
| 342 | // Upon reaching an equality, check for prior redundancies. |
| 343 | if (count_delete >= 1 && count_insert >= 1) { |
| 344 | // Delete the offending records and add the merged ones. |
| 345 | pointer.previous(); |
| 346 | for (int j = 0; j < count_delete + count_insert; j++) { |
| 347 | pointer.previous(); |
| 348 | pointer.remove(); |
| 349 | } |
| 350 | foreach(Diff newDiff, |
| 351 | diff_main(text_delete, text_insert, false, deadline)) { |
| 352 | pointer.insert(newDiff); |
| 353 | } |
| 354 | } |
| 355 | count_insert = 0; |
| 356 | count_delete = 0; |
| 357 | text_delete = ""; |
| 358 | text_insert = ""; |
| 359 | break; |
| 360 | } |
| 361 | thisDiff = pointer.hasNext() ? &pointer.next() : NULL; |
| 362 | } |
| 363 | diffs.removeLast(); // Remove the dummy entry at the end. |