PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Text » Text_Diff » Bug #5373

Engine that handles existing diffs/patches

Details

Request #5373Engine that handles existing diffs/patches
Submitted2005-09-12 21:07 UTC
Fromo dot persson at gmail dot com
Assignedyunosh
StatusClosed
PackageText_Diff
PHP Version5.1.0
Roadmaps(Not assigned)

Comments

[2005-09-12 21:07 UTC] o dot persson at gmail dot com

Description:
------------
Would be really nice to be able to pass an existing diff and take benefit from the rendering functionality offered by this package. I use this myself to parse the output from svn diff.

This is the dummy engine I use -- this could probably be solved in a better way. To use this class, ATM you need to explicitly instantiate the class:
<?php
$diff = file_get_contents('Text/Diff.php.patch');
$renderer = new Text_Diff_Renderer_inline();
$engine = new Text_Diff_Engine_string_diff($diff);
echo $renderer->render($engine);
?>

Test script:
---------------
class Text_Diff_Engine_string_diff extends Text_Diff
{
function __construct($diff, $dummy = false)
{
if ($dummy == false)
$this->_edits = $this->diff($diff);
}

function diff($diff, $dummy = null)
{
$diff = explode("\n", $diff);

$edits = array();
foreach ($diff as $line) {
switch ($line[0]) {
case ' ':
$edits[] = &new Text_Diff_Op_copy(array(substr($line, 1)));
break;

case '+':
$edits[] = &new Text_Diff_Op_add(array(substr($line, 1)));
break;

case '-':
$edits[] = &new Text_Diff_Op_delete(array(substr($line, 1)));
break;
}
}

return $edits;
}
}