mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-03-30 18:24:31 +00:00
Update Text_Diff. Props simek. Fixes #9467
git-svn-id: https://develop.svn.wordpress.org/trunk@13211 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* $Horde: framework/Text_Diff/Diff/Engine/native.php,v 1.10 2008/01/04 10:27:53 jan Exp $
|
||||
* Class used internally by Text_Diff to actually compute the diffs.
|
||||
*
|
||||
* Class used internally by Text_Diff to actually compute the diffs. This
|
||||
* class is implemented using native PHP code.
|
||||
* This class is implemented using native PHP code.
|
||||
*
|
||||
* The algorithm used here is mostly lifted from the perl module
|
||||
* Algorithm::Diff (version 1.06) by Ned Konz, which is available at:
|
||||
@@ -19,7 +18,7 @@
|
||||
* Geoffrey T. Dairiki <dairiki@dairiki.org>. The original PHP version of this
|
||||
* code was written by him, and is used/adapted with his permission.
|
||||
*
|
||||
* Copyright 2004-2008 The Horde Project (http://www.horde.org/)
|
||||
* Copyright 2004-2010 The Horde Project (http://www.horde.org/)
|
||||
*
|
||||
* See the enclosed file COPYING for license information (LGPL). If you did
|
||||
* not receive this file, see http://opensource.org/licenses/lgpl-license.php.
|
||||
|
||||
@@ -5,9 +5,7 @@
|
||||
* This class uses the Unix `diff` program via shell_exec to compute the
|
||||
* differences between the two input arrays.
|
||||
*
|
||||
* $Horde: framework/Text_Diff/Diff/Engine/shell.php,v 1.8 2008/01/04 10:07:50 jan Exp $
|
||||
*
|
||||
* Copyright 2007-2008 The Horde Project (http://www.horde.org/)
|
||||
* Copyright 2007-2010 The Horde Project (http://www.horde.org/)
|
||||
*
|
||||
* See the enclosed file COPYING for license information (LGPL). If you did
|
||||
* not receive this file, see http://opensource.org/licenses/lgpl-license.php.
|
||||
|
||||
@@ -10,10 +10,8 @@
|
||||
* echo $renderer->render($diff);
|
||||
* </code>
|
||||
*
|
||||
* $Horde: framework/Text_Diff/Diff/Engine/string.php,v 1.7 2008/01/04 10:07:50 jan Exp $
|
||||
*
|
||||
* Copyright 2005 Örjan Persson <o@42mm.org>
|
||||
* Copyright 2005-2008 The Horde Project (http://www.horde.org/)
|
||||
* Copyright 2005-2010 The Horde Project (http://www.horde.org/)
|
||||
*
|
||||
* See the enclosed file COPYING for license information (LGPL). If you did
|
||||
* not receive this file, see http://opensource.org/licenses/lgpl-license.php.
|
||||
@@ -39,6 +37,19 @@ class Text_Diff_Engine_string {
|
||||
*/
|
||||
function diff($diff, $mode = 'autodetect')
|
||||
{
|
||||
// Detect line breaks.
|
||||
$lnbr = "\n";
|
||||
if (strpos($diff, "\r\n") !== false) {
|
||||
$lnbr = "\r\n";
|
||||
} elseif (strpos($diff, "\r") !== false) {
|
||||
$lnbr = "\r";
|
||||
}
|
||||
|
||||
// Make sure we have a line break at the EOF.
|
||||
if (substr($diff, -strlen($lnbr)) != $lnbr) {
|
||||
$diff .= $lnbr;
|
||||
}
|
||||
|
||||
if ($mode != 'autodetect' && $mode != 'context' && $mode != 'unified') {
|
||||
return PEAR::raiseError('Type of diff is unsupported');
|
||||
}
|
||||
@@ -48,17 +59,20 @@ class Text_Diff_Engine_string {
|
||||
$unified = strpos($diff, '---');
|
||||
if ($context === $unified) {
|
||||
return PEAR::raiseError('Type of diff could not be detected');
|
||||
} elseif ($context === false || $context === false) {
|
||||
} elseif ($context === false || $unified === false) {
|
||||
$mode = $context !== false ? 'context' : 'unified';
|
||||
} else {
|
||||
$mode = $context < $unified ? 'context' : 'unified';
|
||||
}
|
||||
}
|
||||
|
||||
// split by new line and remove the diff header
|
||||
$diff = explode("\n", $diff);
|
||||
array_shift($diff);
|
||||
array_shift($diff);
|
||||
// Split by new line and remove the diff header, if there is one.
|
||||
$diff = explode($lnbr, $diff);
|
||||
if (($mode == 'context' && strpos($diff[0], '***') === 0) ||
|
||||
($mode == 'unified' && strpos($diff[0], '---') === 0)) {
|
||||
array_shift($diff);
|
||||
array_shift($diff);
|
||||
}
|
||||
|
||||
if ($mode == 'context') {
|
||||
return $this->parseContextDiff($diff);
|
||||
|
||||
@@ -5,9 +5,7 @@
|
||||
* This class uses the xdiff PECL package (http://pecl.php.net/package/xdiff)
|
||||
* to compute the differences between the two input arrays.
|
||||
*
|
||||
* $Horde: framework/Text_Diff/Diff/Engine/xdiff.php,v 1.6 2008/01/04 10:07:50 jan Exp $
|
||||
*
|
||||
* Copyright 2004-2008 The Horde Project (http://www.horde.org/)
|
||||
* Copyright 2004-2010 The Horde Project (http://www.horde.org/)
|
||||
*
|
||||
* See the enclosed file COPYING for license information (LGPL). If you did
|
||||
* not receive this file, see http://opensource.org/licenses/lgpl-license.php.
|
||||
@@ -42,6 +40,9 @@ class Text_Diff_Engine_xdiff {
|
||||
* valid, albeit a little less descriptive and efficient. */
|
||||
$edits = array();
|
||||
foreach ($diff as $line) {
|
||||
if (!strlen($line)) {
|
||||
continue;
|
||||
}
|
||||
switch ($line[0]) {
|
||||
case ' ':
|
||||
$edits[] = &new Text_Diff_Op_copy(array(substr($line, 1)));
|
||||
|
||||
Reference in New Issue
Block a user