PHP Class DiffMatchPatch\DiffMatchPatch

Computes the difference between two texts to create a patch. Applies the patch onto another text, allowing for errors. This class implements the same API as all other google-diff-match-patch libs. It was created for compatibility reason only.
Author: Neil Fraser ([email protected])
Author: Daniil Skrobov ([email protected])
Show file Open project: yetanotherape/diff-match-patch Class Usage Examples

Protected Properties

Property Type Description
$diff Diff
$match Match
$patch Patch

Public Methods

Method Description
__construct ( )
__get ( string $name ) : float Proxy getting properties to real objects.
__set ( string $name, mixed $value ) : float Proxy setting properties to real objects.
diff_cleanupEfficiency ( array &$diffs ) Reduce the number of edits by eliminating operationally trivial equalities.
diff_cleanupSemantic ( array &$diffs ) Reduce the number of edits by eliminating semantically trivial equalities.
diff_levenshtein ( array $diffs ) : integer Compute the Levenshtein distance; the number of inserted, deleted or substituted characters.
diff_main ( string $text1, string $text2, boolean $checklines = true ) : array Find the differences between two texts. Simplifies the problem by stripping any common prefix or suffix off the texts before diffing.
diff_prettyHtml ( array $diffs ) : string Convert a diff array into a pretty HTML report.
match_main ( string $text, string $pattern, integer $loc ) : integer Locate the best instance of 'pattern' in 'text' near 'loc'.
patch_apply ( PatchObject[] $patches, string $text ) : array Merge a set of patches onto the text. Return a patched text, as well as a list of true/false values indicating which patches were applied.
patch_fromText ( string $text ) : PatchObject[] Parse a textual representation of patches and return a list of patch objects.
patch_make ( string | array $a, string | array | null $b = null, array | null $c = null ) : PatchObject[] Compute a list of patches to turn text1 into text2.
patch_toText ( PatchObject[] $patches ) : string Take a list of patches and return a textual representation.

Method Details

__construct() public method

public __construct ( )

__get() public method

Proxy getting properties to real objects.
public __get ( string $name ) : float
$name string Property name.
return float

__set() public method

Proxy setting properties to real objects.
public __set ( string $name, mixed $value ) : float
$name string Property name.
$value mixed Property value.
return float

diff_cleanupEfficiency() public method

Modifies $diffs.
public diff_cleanupEfficiency ( array &$diffs )
$diffs array Array of diff arrays.

diff_cleanupSemantic() public method

Modifies $diffs.
public diff_cleanupSemantic ( array &$diffs )
$diffs array Array of diff arrays.

diff_levenshtein() public method

Compute the Levenshtein distance; the number of inserted, deleted or substituted characters.
public diff_levenshtein ( array $diffs ) : integer
$diffs array Array of diff arrays.
return integer Number of changes.

diff_main() public method

Find the differences between two texts. Simplifies the problem by stripping any common prefix or suffix off the texts before diffing.
public diff_main ( string $text1, string $text2, boolean $checklines = true ) : array
$text1 string Old string to be diffed.
$text2 string New string to be diffed.
$checklines boolean Optional speedup flag. If present and false, then don't run a line-level diff first to identify the changed areas. Defaults to true, which does a faster, slightly less optimal diff.
return array Array of changes.

diff_prettyHtml() public method

Convert a diff array into a pretty HTML report.
public diff_prettyHtml ( array $diffs ) : string
$diffs array Array of diff arrays.
return string HTML representation.

match_main() public method

Locate the best instance of 'pattern' in 'text' near 'loc'.
public match_main ( string $text, string $pattern, integer $loc ) : integer
$text string The text to search.
$pattern string The pattern to search for.
$loc integer The location to search around.
return integer Best match index or -1.

patch_apply() public method

Merge a set of patches onto the text. Return a patched text, as well as a list of true/false values indicating which patches were applied.
public patch_apply ( PatchObject[] $patches, string $text ) : array
$patches PatchObject[] Array of PatchObjects.
$text string Old text.
return array Two element Array, containing the new text and an array of boolean values.

patch_fromText() public method

Parse a textual representation of patches and return a list of patch objects.
public patch_fromText ( string $text ) : PatchObject[]
$text string Text representation of patches.
return PatchObject[] Array of PatchObjects.

patch_make() public method

Use diffs if provided, otherwise compute it ourselves. There are four ways to call this function, depending on what data is available to the caller: Method 1: a = text1, b = text2 Method 2: a = diffs Method 3 (optimal): a = text1, b = diffs Method 4 (deprecated, use method 3): a = text1, b = text2, c = diffs
public patch_make ( string | array $a, string | array | null $b = null, array | null $c = null ) : PatchObject[]
$a string | array text1 (methods 1,3,4) or Array of diff arrays for text1 to text2 (method 2).
$b string | array | null text2 (methods 1,4) or Array of diff arrays for text1 to text2 (method 3) or null (method 2).
$c array | null Array of diff arrays for text1 to text2 (method 4) or null (methods 1,2,3).
return PatchObject[] Array of PatchObjects.

patch_toText() public method

Take a list of patches and return a textual representation.
public patch_toText ( PatchObject[] $patches ) : string
$patches PatchObject[] Array of PatchObjects.
return string Text representation of patches.

Property Details

$diff protected property

protected Diff,diffmatchpatch $diff
return Diff

$match protected property

protected Match,diffmatchpatch $match
return Match

$patch protected property

protected Patch,diffmatchpatch $patch
return Patch