\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-2017 Horde LLC (http://www.horde.org/)

See the enclosed file LICENSE for license information (LGPL). If you did not receive this file, see http://www.horde.org/licenses/lgpl21.

Summary

Methods
Properties
Constants
__construct()
getDiff()
countAddedLines()
countDeletedLines()
reverse()
isEmpty()
lcs()
getOriginal()
getFinal()
trimNewlines()
No public properties found
No constants found
_check()
$_edits
N/A
No private methods found
No private properties found
N/A

Properties

$_edits

$_edits : array

Array of changes.

Type

array

Methods

__construct()

__construct(string  $engine, array  $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.

getDiff()

getDiff() 

Returns the array of differences.

countAddedLines()

countAddedLines() : integer

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

Returns

integer —

The number of new lines

countDeletedLines()

countDeletedLines() : integer

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

Returns

integer —

The number of deleted lines

reverse()

reverse() : \Horde_Text_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.

isEmpty()

isEmpty() : boolean

Checks for an empty diff.

Returns

boolean —

True if two sequences were identical.

lcs()

lcs() : integer

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

This is mostly for diagnostic purposes.

Returns

integer —

The length of the LCS.

getOriginal()

getOriginal() : array

Gets the original set of lines.

This reconstructs the $from_lines parameter passed to the constructor.

Returns

array —

The original sequence of strings.

getFinal()

getFinal() : array

Gets the final set of lines.

This reconstructs the $to_lines parameter passed to the constructor.

Returns

array —

The sequence of strings.

trimNewlines()

trimNewlines(string  $line, integer  $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.

_check()

_check(  $from_lines,   $to_lines) 

Checks a diff for validity.

This is here only for debugging purposes.

Parameters

$from_lines
$to_lines