-
+ A08BD863F9C64F28C0560FFE55E05CCF91179804F79CD6C69C0EC40A3DECB02E2F9345A786E26A2A3BB90DC4BB583B6B37E6BC6B5FEDBC5579E381A0A0FE267D
mp-wp/wp-includes/Text/Diff/Engine/xdiff.php
(0 . 0)(1 . 63)
69934 <?php
69935 /**
69936 * Class used internally by Diff to actually compute the diffs.
69937 *
69938 * This class uses the xdiff PECL package (http://pecl.php.net/package/xdiff)
69939 * to compute the differences between the two input arrays.
69940 *
69941 * $Horde: framework/Text_Diff/Diff/Engine/xdiff.php,v 1.6 2008/01/04 10:07:50 jan Exp $
69942 *
69943 * Copyright 2004-2008 The Horde Project (http://www.horde.org/)
69944 *
69945 * See the enclosed file COPYING for license information (LGPL). If you did
69946 * not receive this file, see http://opensource.org/licenses/lgpl-license.php.
69947 *
69948 * @author Jon Parise <jon@horde.org>
69949 * @package Text_Diff
69950 */
69951 class Text_Diff_Engine_xdiff {
69952
69953 /**
69954 */
69955 function diff($from_lines, $to_lines)
69956 {
69957 array_walk($from_lines, array('Text_Diff', 'trimNewlines'));
69958 array_walk($to_lines, array('Text_Diff', 'trimNewlines'));
69959
69960 /* Convert the two input arrays into strings for xdiff processing. */
69961 $from_string = implode("\n", $from_lines);
69962 $to_string = implode("\n", $to_lines);
69963
69964 /* Diff the two strings and convert the result to an array. */
69965 $diff = xdiff_string_diff($from_string, $to_string, count($to_lines));
69966 $diff = explode("\n", $diff);
69967
69968 /* Walk through the diff one line at a time. We build the $edits
69969 * array of diff operations by reading the first character of the
69970 * xdiff output (which is in the "unified diff" format).
69971 *
69972 * Note that we don't have enough information to detect "changed"
69973 * lines using this approach, so we can't add Text_Diff_Op_changed
69974 * instances to the $edits array. The result is still perfectly
69975 * valid, albeit a little less descriptive and efficient. */
69976 $edits = array();
69977 foreach ($diff as $line) {
69978 switch ($line[0]) {
69979 case ' ':
69980 $edits[] = &new Text_Diff_Op_copy(array(substr($line, 1)));
69981 break;
69982
69983 case '+':
69984 $edits[] = &new Text_Diff_Op_add(array(substr($line, 1)));
69985 break;
69986
69987 case '-':
69988 $edits[] = &new Text_Diff_Op_delete(array(substr($line, 1)));
69989 break;
69990 }
69991 }
69992
69993 return $edits;
69994 }
69995
69996 }