PHP Class Horde_Text_Diff, horde

The original PHP version of this code was written by Geoffrey T. Dairiki , and is used/adapted with his permission. Copyright 2004 Geoffrey T. Dairiki Copyright 2004-2016 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.
Author: Geoffrey T. Dairiki ([email protected])
ファイルを表示 Open project: horde/horde Class Usage Examples

Protected Properties

Property Type Description
$_edits array Array of changes.

Public Methods

Method Description
__construct ( string $engine, array $params ) Computes diffs between sequences of strings.
countAddedLines ( ) : integer returns the number of new (added) lines in a given diff.
countDeletedLines ( ) : integer Returns the number of deleted (removed) lines in a given diff.
getDiff ( ) Returns the array of differences.
getFinal ( ) : array Gets the final set of lines.
getOriginal ( ) : array Gets the original set of lines.
isEmpty ( ) : boolean Checks for an empty diff.
lcs ( ) : integer Computes the length of the Longest Common Subsequence (LCS).
reverse ( ) : Horde_Text_Diff Computes a reversed diff.
trimNewlines ( string &$line, integer $key ) Removes trailing newlines from a line of text. This is meant to be used with array_walk().

Protected Methods

Method Description
_check ( $from_lines, $to_lines ) Checks a diff for validity.

Method Details

__construct() public method

Computes diffs between sequences of strings.
public __construct ( string $engine, array $params )
$engine string Name of the diffing engine to use. 'auto' will automatically select the best.
$params array Parameters to pass to the diffing engine. Normally an array of two arrays, each containing the lines from a file.

_check() protected method

This is here only for debugging purposes.
protected _check ( $from_lines, $to_lines )

countAddedLines() public method

returns the number of new (added) lines in a given diff.
public countAddedLines ( ) : integer
return integer The number of new lines

countDeletedLines() public method

Returns the number of deleted (removed) lines in a given diff.
public countDeletedLines ( ) : integer
return integer The number of deleted lines

getDiff() public method

Returns the array of differences.
public getDiff ( )

getFinal() public method

This reconstructs the $to_lines parameter passed to the constructor.
public getFinal ( ) : array
return array The sequence of strings.

getOriginal() public method

This reconstructs the $from_lines parameter passed to the constructor.
public getOriginal ( ) : array
return array The original sequence of strings.

isEmpty() public method

Checks for an empty diff.
public isEmpty ( ) : boolean
return boolean True if two sequences were identical.

lcs() public method

This is mostly for diagnostic purposes.
public lcs ( ) : integer
return integer The length of the LCS.

reverse() public method

Example: $diff = new Horde_Text_Diff($lines1, $lines2); $rev = $diff->reverse();
public reverse ( ) : Horde_Text_Diff
return 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.

trimNewlines() public static method

Removes trailing newlines from a line of text. This is meant to be used with array_walk().
public static trimNewlines ( string &$line, integer $key )
$line string The line to trim.
$key integer The index of the line in the array. Not used.

Property Details

$_edits protected_oe property

Array of changes.
protected array $_edits
return array