Edit File by line
/home/barbar84/public_h.../wp-inclu.../Text/Diff/Engine
File: xdiff.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Class used internally by Diff to actually compute the diffs.
[2] Fix | Delete
*
[3] Fix | Delete
* This class uses the xdiff PECL package (http://pecl.php.net/package/xdiff)
[4] Fix | Delete
* to compute the differences between the two input arrays.
[5] Fix | Delete
*
[6] Fix | Delete
* Copyright 2004-2010 The Horde Project (http://www.horde.org/)
[7] Fix | Delete
*
[8] Fix | Delete
* See the enclosed file COPYING for license information (LGPL). If you did
[9] Fix | Delete
* not receive this file, see http://opensource.org/licenses/lgpl-license.php.
[10] Fix | Delete
*
[11] Fix | Delete
* @author Jon Parise <jon@horde.org>
[12] Fix | Delete
* @package Text_Diff
[13] Fix | Delete
*/
[14] Fix | Delete
class Text_Diff_Engine_xdiff {
[15] Fix | Delete
[16] Fix | Delete
/**
[17] Fix | Delete
*/
[18] Fix | Delete
function diff($from_lines, $to_lines)
[19] Fix | Delete
{
[20] Fix | Delete
array_walk($from_lines, array('Text_Diff', 'trimNewlines'));
[21] Fix | Delete
array_walk($to_lines, array('Text_Diff', 'trimNewlines'));
[22] Fix | Delete
[23] Fix | Delete
/* Convert the two input arrays into strings for xdiff processing. */
[24] Fix | Delete
$from_string = implode("\n", $from_lines);
[25] Fix | Delete
$to_string = implode("\n", $to_lines);
[26] Fix | Delete
[27] Fix | Delete
/* Diff the two strings and convert the result to an array. */
[28] Fix | Delete
$diff = xdiff_string_diff($from_string, $to_string, count($to_lines));
[29] Fix | Delete
$diff = explode("\n", $diff);
[30] Fix | Delete
[31] Fix | Delete
/* Walk through the diff one line at a time. We build the $edits
[32] Fix | Delete
* array of diff operations by reading the first character of the
[33] Fix | Delete
* xdiff output (which is in the "unified diff" format).
[34] Fix | Delete
*
[35] Fix | Delete
* Note that we don't have enough information to detect "changed"
[36] Fix | Delete
* lines using this approach, so we can't add Text_Diff_Op_changed
[37] Fix | Delete
* instances to the $edits array. The result is still perfectly
[38] Fix | Delete
* valid, albeit a little less descriptive and efficient. */
[39] Fix | Delete
$edits = array();
[40] Fix | Delete
foreach ($diff as $line) {
[41] Fix | Delete
if (!strlen($line)) {
[42] Fix | Delete
continue;
[43] Fix | Delete
}
[44] Fix | Delete
switch ($line[0]) {
[45] Fix | Delete
case ' ':
[46] Fix | Delete
$edits[] = new Text_Diff_Op_copy(array(substr($line, 1)));
[47] Fix | Delete
break;
[48] Fix | Delete
[49] Fix | Delete
case '+':
[50] Fix | Delete
$edits[] = new Text_Diff_Op_add(array(substr($line, 1)));
[51] Fix | Delete
break;
[52] Fix | Delete
[53] Fix | Delete
case '-':
[54] Fix | Delete
$edits[] = new Text_Diff_Op_delete(array(substr($line, 1)));
[55] Fix | Delete
break;
[56] Fix | Delete
}
[57] Fix | Delete
}
[58] Fix | Delete
[59] Fix | Delete
return $edits;
[60] Fix | Delete
}
[61] Fix | Delete
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function