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 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.
34 public function __construct($from_lines, $to_lines, $mapped_from_lines, $mapped_to_lines) {
36 assert(sizeof($from_lines) == sizeof($mapped_from_lines));
37 assert(sizeof($to_lines) == sizeof($mapped_to_lines));
39 parent::__construct($mapped_from_lines, $mapped_to_lines);
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));
49 $closing = &$this->edits[$i]->closing;
50 if (is_array($closing)) {
51 $closing = array_slice($to_lines, $yi, sizeof($closing));
52 $yi += sizeof($closing);