d49cc0df6227d6924b0112ec3923ceec81eddefa
[yaffs-website] / web / core / lib / Drupal / Component / Diff / MappedDiff.php
1 <?php
2
3 namespace Drupal\Component\Diff;
4
5 /**
6  * FIXME: bad name.
7  * @todo document
8  * @private
9  * @subpackage DifferenceEngine
10  */
11 class MappedDiff extends Diff {
12
13   /**
14    * Constructor.
15    *
16    * Computes diff between sequences of strings.
17    *
18    * This can be used to compute things like
19    * case-insensitive diffs, or diffs which ignore
20    * changes in white-space.
21    *
22    * @param $from_lines array An array of strings.
23    *   (Typically these are lines from a file.)
24    * @param $to_lines array An array of strings.
25    * @param $mapped_from_lines array This array should
26    *   have the same size number of elements as $from_lines.
27    *   The elements in $mapped_from_lines and
28    *   $mapped_to_lines are what is actually compared
29    *   when computing the diff.
30    * @param $mapped_to_lines array This array should
31    *   have the same number of elements as $to_lines.
32    */
33   public function __construct($from_lines, $to_lines, $mapped_from_lines, $mapped_to_lines) {
34
35     assert(sizeof($from_lines) == sizeof($mapped_from_lines));
36     assert(sizeof($to_lines) == sizeof($mapped_to_lines));
37
38     parent::__construct($mapped_from_lines, $mapped_to_lines);
39
40     $xi = $yi = 0;
41     for ($i = 0; $i < sizeof($this->edits); $i++) {
42       $orig = &$this->edits[$i]->orig;
43       if (is_array($orig)) {
44         $orig = array_slice($from_lines, $xi, sizeof($orig));
45         $xi += sizeof($orig);
46       }
47
48       $closing = &$this->edits[$i]->closing;
49       if (is_array($closing)) {
50         $closing = array_slice($to_lines, $yi, sizeof($closing));
51         $yi += sizeof($closing);
52       }
53     }
54   }
55
56 }