mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-06 08:47:45 +02:00
marge
git-svn-id: file:///svn/phpbb/trunk@8696 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
@@ -17,7 +17,7 @@ if (!defined('IN_PHPBB'))
|
||||
}
|
||||
|
||||
/**
|
||||
* Code from pear.php.net, Text_Diff-0.2.1 (beta) package
|
||||
* Code from pear.php.net, Text_Diff-1.0.0 package
|
||||
* http://pear.php.net/package/Text_Diff/
|
||||
*
|
||||
* Modified by phpBB Group to meet our coding standards
|
||||
@@ -28,6 +28,8 @@ if (!defined('IN_PHPBB'))
|
||||
* This class renders the diff in classic diff format. It is intended that
|
||||
* this class be customized via inheritance, to obtain fancier outputs.
|
||||
*
|
||||
* Copyright 2004-2008 The Horde Project (http://www.horde.org/)
|
||||
*
|
||||
* @package diff
|
||||
*/
|
||||
class diff_renderer
|
||||
@@ -105,7 +107,7 @@ class diff_renderer
|
||||
|
||||
unset($diff3);
|
||||
|
||||
$diff = &new diff($diff_1, $diff_2);
|
||||
$diff = new diff($diff_1, $diff_2);
|
||||
}
|
||||
|
||||
$nlead = $this->_leading_context_lines;
|
||||
@@ -116,19 +118,24 @@ class diff_renderer
|
||||
|
||||
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, 'diff_op_copy'))
|
||||
{
|
||||
// Do we have any diff blocks yet?
|
||||
if (is_array($block))
|
||||
{
|
||||
// How many lines to keep as context from the copy block.
|
||||
$keep = ($i == sizeof($diffs) - 1) ? $ntrail : $nlead + $ntrail;
|
||||
if (sizeof($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 diff_op_copy($context);
|
||||
}
|
||||
@@ -137,12 +144,15 @@ class diff_renderer
|
||||
$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, sizeof($context) - $nlead);
|
||||
$x0 = $xi - sizeof($context);
|
||||
$y0 = $yi - sizeof($context);
|
||||
@@ -219,6 +229,16 @@ class diff_renderer
|
||||
$ybeg .= ',' . ($ybeg + $ylen - 1);
|
||||
}
|
||||
|
||||
// this matches the GNU Diff behaviour
|
||||
if ($xlen && !$ylen)
|
||||
{
|
||||
$ybeg--;
|
||||
}
|
||||
else if (!$xlen)
|
||||
{
|
||||
$xbeg--;
|
||||
}
|
||||
|
||||
return $xbeg . ($xlen ? ($ylen ? 'c' : 'd') : 'a') . $ybeg;
|
||||
}
|
||||
|
||||
@@ -449,11 +469,11 @@ class diff_renderer_inline extends diff_renderer
|
||||
$splitted_text_1 = $this->_split_on_words($text1, $nl);
|
||||
$splitted_text_2 = $this->_split_on_words($text2, $nl);
|
||||
|
||||
$diff = &new diff($splitted_text_1, $splitted_text_2);
|
||||
$diff = new diff($splitted_text_1, $splitted_text_2);
|
||||
unset($splitted_text_1, $splitted_text_2);
|
||||
|
||||
// Get the diff in inline format.
|
||||
$renderer = &new diff_renderer_inline(array_merge($this->get_params(), array('split_level' => 'words')));
|
||||
$renderer = new diff_renderer_inline(array_merge($this->get_params(), array('split_level' => 'words')));
|
||||
|
||||
// Run the diff and get the output.
|
||||
return str_replace($nl, "\n", $renderer->render($diff)) . "\n";
|
||||
|
Reference in New Issue
Block a user