Example #1
0
File: diff.php Project: jvinhit/php
 /**
  * Computes a diff between sequences of strings.
  *
  * This can be used to compute things like case-insensitve diffs, or diffs
  * which ignore changes in white-space.
  *
  * @param array $from_lines         An array of strings.
  * @param array $to_lines           An array of strings.
  * @param array $mapped_from_lines  This array should have the same size number of elements as $from_lines.
  *                                  The elements in $mapped_from_lines and $mapped_to_lines are what is actually
  *                                  compared when computing the diff.
  * @param array $mapped_to_lines    This array should have the same number of elements as $to_lines.
  */
 function mapped_diff(&$from_lines, &$to_lines, &$mapped_from_lines, &$mapped_to_lines)
 {
     if (sizeof($from_lines) != sizeof($mapped_from_lines) || sizeof($to_lines) != sizeof($mapped_to_lines)) {
         return false;
     }
     parent::diff($mapped_from_lines, $mapped_to_lines);
     $xi = $yi = 0;
     for ($i = 0; $i < sizeof($this->_edits); $i++) {
         $orig =& $this->_edits[$i]->orig;
         if (is_array($orig)) {
             $orig = array_slice($from_lines, $xi, sizeof($orig));
             $xi += sizeof($orig);
         }
         $final =& $this->_edits[$i]->final;
         if (is_array($final)) {
             $final = array_slice($to_lines, $yi, sizeof($final));
             $yi += sizeof($final);
         }
     }
 }