Documentation

MappedDiff extends Diff
in package

This can be used to compute things like case-insensitve diffs, or diffs which ignore changes in white-space.

Tags
author

Geoffrey T. Dairiki dairiki@dairiki.org

category

Horde

copyright

2007-2017 Horde LLC

license

http://www.horde.org/licenses/lgpl21 LGPL-2.1

Table of Contents

$edits  : OperationList
__construct()  : mixed
Computes a diff 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.
fromFileLineArrays()  : Diff
Shortcut constructor, internally creating the Engine instance.
fromString()  : Diff
Shortcut constructor, internally creating the Engine instance.
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()  : 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

Methods

__construct()

Computes a diff between sequences of strings.

public __construct(OperationList $edits, array<string|int, mixed> $from_lines, array<string|int, mixed> $to_lines) : mixed

Parameters to pass to the diffing engine:

  • Two arrays, each containing the lines from a file.
  • Two arrays with the same size as the first parameters. The elements are what is actually compared when computing the diff.
Parameters
$edits : OperationList

from the mapped set

$from_lines : array<string|int, mixed>
$to_lines : array<string|int, mixed>
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

fromFileLineArrays()

Shortcut constructor, internally creating the Engine instance.

public static fromFileLineArrays([array<string|int, mixed> $fromLines = [] ][, array<string|int, mixed> $toLines = [] ][, string $engineClass = 'auto' ][, array<string|int, mixed> $engineParams = [] ]) : Diff

Default is Auto, meaning it will use XDiffEngine if available, otherwise resort to NativeEngine If you really care about what engine provides the OperationList, implement your own

Use this to create

  • NativeEngine
  • XDiffEngine
  • ShellEngine
  • "Auto": The most appropriate engine to deal with two arrays of file lines
  • Explicitly any other engine that initializes from two arrays of lines
Parameters
$fromLines : array<string|int, mixed> = []
$toLines : array<string|int, mixed> = []
$engineClass : string = 'auto'
$engineParams : array<string|int, mixed> = []
Return values
Diff

fromString()

Shortcut constructor, internally creating the Engine instance.

public static fromString(string $diff[, string $engineClass = 'auto' ][, mixed $engineParams = ['mode' => 'autodetect'] ]) : Diff

Default is Auto, meaning it will use XDiffEngine if available, otherwise resort to NativeEngine If you really care about what engine provides the OperationList, implement your own

Use this to create

  • StringEngine
  • "Auto": The most appropriate engine to deal with a single string diff source
  • Explicitly any other engine that initializes from a single string diff source
Parameters
$diff : string
$engineClass : string = 'auto'
$engineParams : mixed = ['mode' => 'autodetect']
Return values
Diff

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() : Diff

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

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