3 namespace Drupal\Component\Diff;
9 * @subpackage DifferenceEngine
11 class MappedDiff extends Diff {
16 * Computes diff between sequences of strings.
18 * This can be used to compute things like
19 * case-insensitive diffs, or diffs which ignore
20 * changes in white-space.
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.
33 public function __construct($from_lines, $to_lines, $mapped_from_lines, $mapped_to_lines) {
35 assert(sizeof($from_lines) == sizeof($mapped_from_lines));
36 assert(sizeof($to_lines) == sizeof($mapped_to_lines));
38 parent::__construct($mapped_from_lines, $mapped_to_lines);
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));
48 $closing = &$this->edits[$i]->closing;
49 if (is_array($closing)) {
50 $closing = array_slice($to_lines, $yi, sizeof($closing));
51 $yi += sizeof($closing);