| 468 | }, |
| 469 | // compare is the fuzzy string comparison algorithm |
| 470 | compare = function diffview_report_charcomp_compare(start : number): [number, number, number, boolean]{ |
| 471 | let x: number = 0, |
| 472 | y: number = 0, |
| 473 | whitespace: boolean = false, |
| 474 | wordtest: boolean = false, |
| 475 | store: compareStore = []; |
| 476 | const max: number = Math.max(dataA.length, dataB.length), |
| 477 | sorta = function diffview_report_charcomp_compare_sorta(a : number[], b : number[]): 1 | -1 { |
| 478 | if(a[1] - a[0] < b[1] - b[0]) { |
| 479 | return 1; |
| 480 | } |
| 481 | return -1; |
| 482 | }, |
| 483 | sortb = function diffview_report_charcomp_compare_sortb(a : number[], b : number[]): 1 | -1 { |
| 484 | if(a[0] + a[1] > b[0] + b[1]) { |
| 485 | return 1; |
| 486 | } |
| 487 | return -1; |
| 488 | }, |
| 489 | whitetest: RegExp = (/^(\s+)$/); |
| 490 | // first gather a list of all matching indexes into an array |
| 491 | x = start; |
| 492 | do { |
| 493 | y = start; |
| 494 | do { |
| 495 | if (dataA[x] === dataB[y] || dataB[x] === dataA[y]) { |
| 496 | store.push([x, y]); |
| 497 | if (dataA[y] === dataB[x] && dataA[y + 1] === dataB[x + 1] && whitetest.test(dataB[x - 1]) === true) { |
| 498 | wordtest = true; |
| 499 | store = [[x, y]]; |
| 500 | } |
| 501 | if (dataA[x] === dataB[y] && dataA[x + 1] === dataB[y + 1] && whitetest.test(dataB[y - 1]) === true) { |
| 502 | wordtest = true; |
| 503 | store = [[x, y]]; |
| 504 | } |
| 505 | break; |
| 506 | } |
| 507 | y = y + 1; |
| 508 | } while (y < max); |
| 509 | if (wordtest === true) { |
| 510 | break; |
| 511 | } |
| 512 | x = x + 1; |
| 513 | } while (x < dataMinLength); |
| 514 | // if there are no character matches then quit out |
| 515 | if (store.length === 0) { |
| 516 | return [dataMinLength, max, 0, whitespace]; |
| 517 | } |
| 518 | // take the list of matches and sort it first sort by size of change with |
| 519 | // shortest up front second sort by sum of change start and end the second sort |
| 520 | // results in the smallest change from the earliest point |
| 521 | store.sort(sorta); |
| 522 | if (dataMinLength - start < 5000) { |
| 523 | store.sort(sortb); |
| 524 | } |
| 525 | // x should always be the shorter index (change start) |
| 526 | if (store[0][0] < store[0][1]) { |
| 527 | x = store[0][0]; |