~joebordes/chive/chive_lib_upgrade

« back to all changes in this revision

Viewing changes to yii/gii/components/Pear/Text/Diff/Mapped.php

  • Committer: Joe Bordes
  • Date: 2011-08-22 18:24:26 UTC
  • Revision ID: joe@tsolucio.com-20110822182426-zrvpiuyvm20ybjki
Update yii framework 1.1.8 and associated libraries.
Update About page to reflect changes.
Basic testing.

Show diffs side-by-side

added added

removed removed

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