Class Horde_Text_Diff
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
dairiki@dairiki.org, and is used/adapted with his permission.
Copyright 2004 Geoffrey T. Dairiki dairiki@dairiki.org
Copyright 2004-2012 Horde LLC (http://www.horde.org/)
See the enclosed file COPYING for license information (LGPL). If you did
not receive this file, see http://www.horde.org/licenses/lgpl21.
Methods summary
public
|
#
__construct( string $engine, array $params )
Computes diffs between sequences of strings.
Computes diffs between sequences of strings.
Parameters
- $engine
- <p>Name of the diffing engine to use. 'auto'
will automatically select the best.</p>
- $params
- <p>Parameters to pass to the diffing engine.
Normally an array of two arrays, each
containing the lines from a file.</p>
|
public
|
#
getDiff( )
Returns the array of differences.
Returns the array of differences.
|
public
integer
|
#
countAddedLines( )
returns the number of new (added) lines in a given diff.
returns the number of new (added) lines in a given diff.
Returns
integer The number of new lines
Since
Text_Diff 1.1.0
|
public
integer
|
#
countDeletedLines( )
Returns the number of deleted (removed) lines in a given diff.
Returns the number of deleted (removed) lines in a given diff.
Returns
integer The number of deleted lines
Since
Text_Diff 1.1.0
|
public
Horde_Text_Diff
|
#
reverse( )
Computes a reversed diff.
Computes a reversed diff.
Example:
$diff = new Horde_Text_Diff($lines1, $lines2);
$rev = $diff->reverse();
Returns
Horde_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.
|
public
boolean
|
#
isEmpty( )
Checks for an empty diff.
Checks for an empty diff.
Returns
boolean True if two sequences were identical.
|
public
integer
|
#
lcs( )
Computes the length of the Longest Common Subsequence (LCS).
Computes the length of the Longest Common Subsequence (LCS).
This is mostly for diagnostic purposes.
Returns
integer The length of the LCS.
|
public
array
|
#
getOriginal( )
Gets the original set of lines.
Gets the original set of lines.
This reconstructs the $from_lines parameter passed to the constructor.
Returns
array The original sequence of strings.
|
public
array
|
#
getFinal( )
Gets the final set of lines.
Gets the final set of lines.
This reconstructs the $to_lines parameter passed to the constructor.
Returns
array The sequence of strings.
|
public static
|
#
trimNewlines( string & $line, integer $key )
Removes trailing newlines from a line of text. This is meant to be used
with array_walk().
Removes trailing newlines from a line of text. This is meant to be used
with array_walk().
Parameters
- $line
- The line to trim.
- $key
- The index of the line in the array. Not used.
|