Inheritances
Files
Overview
FRAMES
NO FRAMES

Class Text_Diff

Text_Diff
|- class Text_Diff
Subclasses : Text_MappedDiff
General API for generating and formatting diffs - the differences between
two sequences of strings.

The original PHP version of this code was written by Geoffrey T. Dairiki
, and is used/adapted with his permission.

$Horde: framework/Text_Diff/Diff.php,v 1.26 2008/01/04 10:07:49 jan Exp $

Copyright 2004 Geoffrey T. Dairiki
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.
PackageText_Diff
AuthorGeoffrey T. Dairiki

Summary

Instance fields
+ $_edits Array of changes
Instance methods
+ Text_Diff() Computes diffs between sequences of strings
+ _check() Checks a diff for validity.
+ _getTempDir() Determines the location of the system temporary directory
+ getDiff() Returns the array of differences
+ getFinal() Gets the final set of lines.
+ getOriginal() Gets the original set of lines.
+ isEmpty() Checks for an empty diff
+ lcs() Computes the length of the Longest Common Subsequence (LCS).
+ reverse() Computes a reversed diff.
+ trimNewlines() Removes trailing newlines from a line of text

Details

Instance fields

$_edits
var $_edits
Array of changes.
Var array

Instance methods

Text_Diff()
function Text_Diff( $engine
$params
)
Computes diffs between sequences of strings.
Parameters
string $engine Name of the diffing engine to use. 'auto'
will automatically select the best.
array $params Parameters to pass to the diffing engine.
Normally an array of two arrays, each
containing the lines from a file.
_check()
function _check( $from_lines
$to_lines
)
Checks a diff for validity.

This is here only for debugging purposes.
Parameters
$from_lines
$to_lines
_getTempDir()
function _getTempDir( )
Determines the location of the system temporary directory.
Returns string A directory name which can be used for temp files.
Returns false if one could not be found.
Static
Access protected
function getDiff( )
Returns the array of differences.
function getFinal( )
Gets the final set of lines.

This reconstructs the $to_lines parameter passed to the constructor.
Returns array The sequence of strings.
function getOriginal( )
Gets the original set of lines.

This reconstructs the $from_lines parameter passed to the constructor.
Returns array The original sequence of strings.
function isEmpty( )
Checks for an empty diff.
Returns boolean True if two sequences were identical.
function lcs( )
Computes the length of the Longest Common Subsequence (LCS).

This is mostly for diagnostic purposes.
Returns integer The length of the LCS.
function reverse( )
Computes a reversed diff.

Example:

$diff = new Text_Diff($lines1, $lines2);
$rev = $diff->reverse();
Returns 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()
method.
function trimNewlines( &$line
$key
)
Removes trailing newlines from a line of text. This is meant to be used
with array_walk().
Parameters
string $line The line to trim.
integer $key The index of the line in the array. Not used.