Documentation

Horde_Text_Diff
in package

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.

Tags
author

Geoffrey T. Dairiki dairiki@dairiki.org

Table of Contents

$_edits  : array<string|int, mixed>
Array of changes.
__construct()  : mixed
Computes diffs between sequences of strings.
countAddedLines()  : int
returns the number of new (added) lines in a given diff.
countDeletedLines()  : int
Returns the number of deleted (removed) lines in a given diff.
getDiff()  : mixed
Returns the array of differences.
getFinal()  : array<string|int, mixed>
Gets the final set of lines.
getOriginal()  : array<string|int, mixed>
Gets the original set of lines.
isEmpty()  : bool
Checks for an empty diff.
lcs()  : int
Computes the length of the Longest Common Subsequence (LCS).
reverse()  : Horde_Text_Diff
Computes a reversed diff.
trimNewlines()  : mixed
Removes trailing newlines from a line of text. This is meant to be used with array_walk().
_check()  : mixed
Checks a diff for validity.

Properties

$_edits

Array of changes.

protected array<string|int, mixed> $_edits

Methods

__construct()

Computes diffs between sequences of strings.

public __construct(string $engine, array<string|int, mixed> $params) : mixed
Parameters
$engine : string

Name of the diffing engine to use. 'auto' will automatically select the best.

$params : array<string|int, mixed>

Parameters to pass to the diffing engine. Normally an array of two arrays, each containing the lines from a file.

Return values
mixed

countAddedLines()

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

public countAddedLines() : int
Return values
int

The number of new lines

countDeletedLines()

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

public countDeletedLines() : int
Return values
int

The number of deleted lines

getDiff()

Returns the array of differences.

public getDiff() : mixed
Return values
mixed

getFinal()

Gets the final set of lines.

public getFinal() : array<string|int, mixed>

This reconstructs the $to_lines parameter passed to the constructor.

Return values
array<string|int, mixed>

The sequence of strings.

getOriginal()

Gets the original set of lines.

public getOriginal() : array<string|int, mixed>

This reconstructs the $from_lines parameter passed to the constructor.

Return values
array<string|int, mixed>

The original sequence of strings.

isEmpty()

Checks for an empty diff.

public isEmpty() : bool
Return values
bool

True if two sequences were identical.

lcs()

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

public lcs() : int

This is mostly for diagnostic purposes.

Return values
int

The length of the LCS.

reverse()

Computes a reversed diff.

public reverse() : Horde_Text_Diff

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

Return values
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()

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

public static trimNewlines(string &$line, int $key) : mixed
Parameters
$line : string

The line to trim.

$key : int

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

Return values
mixed

_check()

Checks a diff for validity.

protected _check(mixed $from_lines, mixed $to_lines) : mixed

This is here only for debugging purposes.

Parameters
$from_lines : mixed
$to_lines : mixed
Return values
mixed

Search results