1: <?php
2: /**
3: * Copyright 2007-2012 Horde LLC (http://www.horde.org/)
4: *
5: * See the enclosed file COPYING for license information (LGPL). If you did
6: * not receive this file, see http://www.horde.org/licenses/lgpl21.
7: *
8: * @package Text_Diff
9: * @author Geoffrey T. Dairiki <dairiki@dairiki.org>
10: */
11: class Horde_Text_Diff_Mapped extends Horde_Text_Diff
12: {
13: /**
14: * Computes a diff between sequences of strings.
15: *
16: * This can be used to compute things like case-insensitve diffs, or diffs
17: * which ignore changes in white-space.
18: *
19: * @param array $from_lines An array of strings.
20: * @param array $to_lines An array of strings.
21: * @param array $mapped_from_lines This array should have the same size
22: * number of elements as $from_lines. The
23: * elements in $mapped_from_lines and
24: * $mapped_to_lines are what is actually
25: * compared when computing the diff.
26: * @param array $mapped_to_lines This array should have the same number
27: * of elements as $to_lines.
28: */
29: public function __construct($from_lines, $to_lines,
30: $mapped_from_lines, $mapped_to_lines)
31: {
32: assert(count($from_lines) == count($mapped_from_lines));
33: assert(count($to_lines) == count($mapped_to_lines));
34:
35: parent::__construct($mapped_from_lines, $mapped_to_lines);
36:
37: $xi = $yi = 0;
38: for ($i = 0; $i < count($this->_edits); $i++) {
39: $orig = &$this->_edits[$i]->orig;
40: if (is_array($orig)) {
41: $orig = array_slice($from_lines, $xi, count($orig));
42: $xi += count($orig);
43: }
44:
45: $final = &$this->_edits[$i]->final;
46: if (is_array($final)) {
47: $final = array_slice($to_lines, $yi, count($final));
48: $yi += count($final);
49: }
50: }
51: }
52: }
53: