Source for file Diff.php
Documentation is available at Diff.php
* General API for generating and formatting diffs - the differences between
* two sequences of strings.
* The PHP diff code used in this package was originally written by Geoffrey
* T. Dairiki and is used with his permission.
* $Horde: framework/Text_Diff/Diff.php,v 1.16 2005/12/27 22:15:21 jan Exp $
* @author Geoffrey T. Dairiki <dairiki@dairiki.org>
* Computes diffs between sequences of strings.
* @param array $from_lines An array of strings. Typically these are
* @param array $to_lines An array of strings.
// Backward compatibility workaround.
$params = array ($engine, $params);
require_once 'Text/Diff/Engine/' . $engine . '.php';
$class = 'Text_Diff_Engine_' . $engine;
$diff_engine = &new $class();
* Returns the array of differences.
* Computes a reversed diff.
* $diff = &new Text_Diff($lines1, $lines2);
* $rev = $diff->reverse();
* @return Text_Diff A Diff object representing the inverse of the
* original diff. Note that we purposely don't return a
* reference here, since this essentially is a clone()
foreach ($this->_edits as $edit) {
$rev->_edits [] = $edit->reverse ();
* Checks for an empty diff.
* @return boolean True if two sequences were identical.
foreach ($this->_edits as $edit) {
if (!is_a($edit, 'Text_Diff_Op_copy')) {
* Computes the length of the Longest Common Subsequence (LCS).
* This is mostly for diagnostic purposes.
* @return integer The length of the LCS.
foreach ($this->_edits as $edit) {
if (is_a($edit, 'Text_Diff_Op_copy')) {
$lcs += count($edit->orig );
* Gets the original set of lines.
* This reconstructs the $from_lines parameter passed to the constructor.
* @return array The original sequence of strings.
foreach ($this->_edits as $edit) {
* Gets the final set of lines.
* This reconstructs the $to_lines parameter passed to the constructor.
* @return array The sequence of strings.
foreach ($this->_edits as $edit) {
* Removes trailing newlines from a line of text. This is meant to be used
* @param string $line The line to trim.
* @param integer $key The index of the line in the array. Not used.
* Checks a diff for validity.
* This is here only for debugging purposes.
function _check ($from_lines, $to_lines)
trigger_error("Reconstructed original doesn't match", E_USER_ERROR );
trigger_error("Reconstructed final doesn't match", E_USER_ERROR );
foreach ($this->_edits as $edit) {
* $Horde: framework/Text_Diff/Diff.php,v 1.16 2005/12/27 22:15:21 jan Exp $
* @author Geoffrey T. Dairiki <dairiki@dairiki.org>
* Computes a diff between sequences of strings.
* This can be used to compute things like case-insensitve diffs, or diffs
* which ignore changes in white-space.
* @param array $from_lines An array of strings.
* @param array $to_lines An array of strings.
* @param array $mapped_from_lines This array should have the same size
* number of elements as $from_lines. The
* elements in $mapped_from_lines and
* $mapped_to_lines are what is actually
* compared when computing the diff.
* @param array $mapped_to_lines This array should have the same number
* of elements as $to_lines.
$mapped_from_lines, $mapped_to_lines)
parent ::Text_Diff($mapped_from_lines, $mapped_to_lines);
for ($i = 0; $i < count($this->_edits); $i++ ) {
$orig = &$this->_edits[$i]->orig;
$final = &$this->_edits[$i]->final;
* @author Geoffrey T. Dairiki <dairiki@dairiki.org>
return $this->orig ? count($this->orig) : 0;
return $this->final ? count($this->final) : 0;
* @author Geoffrey T. Dairiki <dairiki@dairiki.org>
class Text_Diff_Op_copy extends Text_Diff_Op {
function Text_Diff_Op_copy ($orig, $final = false )
$reverse = &new Text_Diff_Op_copy ($this->final, $this->orig);
* @author Geoffrey T. Dairiki <dairiki@dairiki.org>
class Text_Diff_Op_delete extends Text_Diff_Op {
function Text_Diff_Op_delete ($lines)
$reverse = &new Text_Diff_Op_add ($this->orig);
* @author Geoffrey T. Dairiki <dairiki@dairiki.org>
class Text_Diff_Op_add extends Text_Diff_Op {
function Text_Diff_Op_add ($lines)
$reverse = &new Text_Diff_Op_delete ($this->final);
* @author Geoffrey T. Dairiki <dairiki@dairiki.org>
class Text_Diff_Op_change extends Text_Diff_Op {
function Text_Diff_Op_change ($orig, $final)
$reverse = &new Text_Diff_Op_change ($this->final, $this->orig);
Documentation generated on Mon, 11 Mar 2019 14:32:38 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|