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-2010 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.

package Text_Diff
author Geoffrey T. Dairiki

 Methods

PHP4 constructor.

Text_Diff($engine, $params) 

Parameters

$engine

$params

Computes diffs between sequences of strings.

__construct(string $engine, array $params) 

Parameters

$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.

Checks a diff for validity.

_check($from_lines, $to_lines) 

This is here only for debugging purposes.

Parameters

$from_lines

$to_lines

Determines the location of the system temporary directory.

_getTempDir() : string
Static
static
access protected

Returns

stringA directory name which can be used for temp files. Returns false if one could not be found.

returns the number of new (added) lines in a given diff.

countAddedLines() : integer
since Text_Diff 1.1.0

Returns

integerThe number of new lines

Returns the number of deleted (removed) lines in a given diff.

countDeletedLines() : integer
since Text_Diff 1.1.0

Returns

integerThe number of deleted lines

Returns the array of differences.

getDiff() 

Gets the final set of lines.

getFinal() : array

This reconstructs the $to_lines parameter passed to the constructor.

Returns

arrayThe sequence of strings.

Gets the original set of lines.

getOriginal() : array

This reconstructs the $from_lines parameter passed to the constructor.

Returns

arrayThe original sequence of strings.

Checks for an empty diff.

isEmpty() : boolean

Returns

booleanTrue if two sequences were identical.

Computes the length of the Longest Common Subsequence (LCS).

lcs() : integer

This is mostly for diagnostic purposes.

Returns

integerThe length of the LCS.

Computes a reversed diff.

reverse() : \Text_Diff

Example: $diff = new Text_Diff($lines1, $lines2); $rev = $diff->reverse();

Returns

\Text_DiffA 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.

Removes trailing newlines from a line of text. This is meant to be used with array_walk().

trimNewlines(string $line, integer $key) 
Static

Parameters

$line

string

The line to trim.

$key

integer

The index of the line in the array. Not used.

 Properties

 

Array of changes.

$_edits : array

Default