Updated to Drupal 8.5. Core Media not yet in use.
[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 array $from_lines
23    *   An array of strings.
24    *   (Typically these are lines from a file.)
25    * @param array $to_lines
26    *   An array of strings.
27    * @param array $mapped_from_lines
28    *   This array should have the same size number of elements as $from_lines.
29    *   The elements in $mapped_from_lines and $mapped_to_lines are what is
30    *   actually compared when computing the diff.
31    * @param array $mapped_to_lines
32    *   This array should have the same number of elements as $to_lines.
33    */
34   public function __construct($from_lines, $to_lines, $mapped_from_lines, $mapped_to_lines) {
35
36     assert(sizeof($from_lines) == sizeof($mapped_from_lines));
37     assert(sizeof($to_lines) == sizeof($mapped_to_lines));
38
39     parent::__construct($mapped_from_lines, $mapped_to_lines);
40
41     $xi = $yi = 0;
42     for ($i = 0; $i < sizeof($this->edits); $i++) {
43       $orig = &$this->edits[$i]->orig;
44       if (is_array($orig)) {
45         $orig = array_slice($from_lines, $xi, sizeof($orig));
46         $xi += sizeof($orig);
47       }
48
49       $closing = &$this->edits[$i]->closing;
50       if (is_array($closing)) {
51         $closing = array_slice($to_lines, $yi, sizeof($closing));
52         $yi += sizeof($closing);
53       }
54     }
55   }
56
57 }