atrsimilar_diff_build

Versions
6.1
atrsimilar_diff_build(&$tokens, $matrix, $length)

▾ 1 function calls atrsimilar_diff_build()

atrsimilar_diff in atr/modules/atrsimilar/includes/atrsimilar.review.inc
Compute the differences between two strings.

Code

atr/modules/atrsimilar/includes/atrsimilar.review.inc, line 203

<?php
function atrsimilar_diff_build(&$tokens, $matrix, $length) {
  $tokens[0] = array_map('atrsimilar_expand_token', $tokens[0]);
  $tokens[1] = array_map('atrsimilar_expand_token', $tokens[1]);

  // We traverse the matrix starting with the cell in the bottom right corner
  // with coordinates ($length[0] -1, $length[1] -1). After every loop the
  // 'pointer' moves one position up and to the left, which is the desired
  // behaviour if the two tokens for a particular set of coordinates match. If
  // they don't, we modify the next set of coordinates by changing $i and $j.
  for ($i = $length[0] - 1, $j = $length[1] - 1; $i >= 0 && $j >= 0; $i--, $j--) {
    // Check if the current token has changed or not.
    if ($tokens[0][$i]['string'] !== $tokens[1][$j]['string']) {
      $tokens[0][$i]['common'] = $tokens[1][$j]['common'] = FALSE;
      if (($i > 0 && $j > 0 && ($matrix[$i][$j - 1] < $matrix[$i - 1][$j]))) {
        $j++;
      }
      else {
        $i++;
      }
    }
    else {
      // These tokens are common, so mark them.
      $tokens[0][$i]['common'] = $tokens[1][$j]['common'] = TRUE;

    }
  }
}
?>