A class containing functions for computing diffs and formatting the output.

Created by Stephen Morley - http://stephenmorley.org/ - and released under the terms of the CC0 1.0 Universal legal code: http://creativecommons.org/publicdomain/zero/1.0/legalcode

package Default

 Methods

Returns the diff for two strings.

compare(string $string1, string $string2, boolean $compareCharacters = false
Static

The return value is an array, each of whose values is an array containing two values: a line (or character, if $compareCharacters is true), and one of the constants DIFF::UNMODIFIED (the line or character is in both strings), DIFF::DELETED (the line or character is only in the first string), and DIFF::INSERTED (the line or character is only in the second string).

Parameters

$string1

string

the first string

$string2

string

the second string

$compareCharacters

boolean

true to compare characters, and false to compare lines; this optional parameter defaults to false

Returns the table of longest common subsequence lengths for the specified sequences.

computeTable(mixed $sequence1, mixed $sequence2, mixed $start, mixed $end1, mixed $end2) 
Static

Parameters

$sequence1

mixed

the first sequence

$sequence2

mixed

the second sequence

$start

mixed

the starting index

$end1

mixed

the ending index for the first sequence

$end2

mixed

the ending index for the second sequence

Returns the partial diff for the specificed sequences, in reverse order.

generatePartialDiff(mixed $table, mixed $sequence1, mixed $sequence2, mixed $start) 
Static

Parameters

$table

mixed

the table returned by the computeTable function

$sequence1

mixed

the first sequence

$sequence2

mixed

the second sequence

$start

mixed

the starting index

 Constants

 

DELETED

DELETED = 1 
 

INSERTED

INSERTED = 2 
 

UNMODIFIED

UNMODIFIED = 0