Version 3.0.5

This commit is contained in:
Neo committed 2025-12-19 00:31:03 -08:00
1 parent 19b38c7c74
commit 1d4720f3e2
3755 files changed
+508378 -664541

No files matched your search

+47 -18
View File
@@ -5,7 +5,12 @@
* This class renders the diff in classic diff format. It is intended that
* this class be customized via inheritance, to obtain fancier outputs.
*
* $Horde: framework/Text_Diff/Diff/Renderer.php,v 1.8 2005/05/02 19:44:53 chuck Exp $
* $Horde: framework/Text_Diff/Diff/Renderer.php,v 1.5.10.10 2008/01/04 10:37:27 jan Exp $
*
* Copyright 2004-2008 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.
*
* @package Text_Diff
*/
@@ -47,7 +52,14 @@ class Text_Diff_Renderer {
*/
function getParams()
{
return get_object_vars($this);
$params = array();
foreach (get_object_vars($this) as $k => $v) {
if ($k[0] == '_') {
$params[substr($k, 1)] = $v;
}
}
return $params;
}
/**
@@ -68,31 +80,47 @@ class Text_Diff_Renderer {
$output = $this->_startDiff();
foreach ($diff->getDiff() as $edit) {
$diffs = $diff->getDiff();
foreach ($diffs as $i => $edit) {
/* If these are unchanged (copied) lines, and we want to keep
* leading or trailing context lines, extract them from the copy
* block. */
if (is_a($edit, 'Text_Diff_Op_copy')) {
/* Do we have any diff blocks yet? */
if (is_array($block)) {
if (count($edit->orig) <= $nlead + $ntrail) {
/* How many lines to keep as context from the copy
* block. */
$keep = $i == count($diffs) - 1 ? $ntrail : $nlead + $ntrail;
if (count($edit->orig) <= $keep) {
/* We have less lines in the block than we want for
* context => keep the whole block. */
$block[] = $edit;
} else {
if ($ntrail) {
/* Create a new block with as many lines as we need
* for the trailing context. */
$context = array_slice($edit->orig, 0, $ntrail);
$block[] = &new Text_Diff_Op_copy($context);
$block[] = new Text_Diff_Op_copy($context);
}
/* @todo */
$output .= $this->_block($x0, $ntrail + $xi - $x0,
$y0, $ntrail + $yi - $y0,
$block);
$block = false;
}
}
/* Keep the copy block as the context for the next block. */
$context = $edit->orig;
} else {
/* Don't we have any diff blocks yet? */
if (!is_array($block)) {
/* Extract context lines from the preceding copy block. */
$context = array_slice($context, count($context) - $nlead);
$x0 = $xi - count($context);
$y0 = $yi - count($context);
$block = array();
if ($context) {
$block[] = &new Text_Diff_Op_copy($context);
$block[] = new Text_Diff_Op_copy($context);
}
}
$block[] = $edit;
@@ -161,6 +189,13 @@ class Text_Diff_Renderer {
$ybeg .= ',' . ($ybeg + $ylen - 1);
}
// this matches the GNU Diff behaviour
if ($xlen && !$ylen) {
$ybeg--;
} elseif (!$xlen) {
$xbeg--;
}
return $xbeg . ($xlen ? ($ylen ? 'c' : 'd') : 'a') . $ybeg;
}
@@ -173,31 +208,25 @@ class Text_Diff_Renderer {
{
return '';
}
/**
* Added by Matt Mecham
* Space between prefix and string result
* 25-07-2005
*
*/
function _lines($lines, $prefix = ' ')
{
return $prefix . ' ' . implode("\n$prefix", $lines) . "\n";
return $prefix . implode("\n$prefix", $lines) . "\n";
}
function _context($lines)
{
return $this->_lines($lines);
return $this->_lines($lines, ' ');
}
function _added($lines)
{
return $this->_lines($lines, '>');
return $this->_lines($lines, '> ');
}
function _deleted($lines)
{
return $this->_lines($lines, '<');
return $this->_lines($lines, '< ');
}
function _changed($orig, $final)
@@ -205,4 +234,4 @@ class Text_Diff_Renderer {
return $this->_deleted($orig) . "---\n" . $this->_added($final);
}
}
}