PHP Класс 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.
Автор: Neil Fraser ([email protected])
Автор: Daniil Skrobov ([email protected])
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$diff Diff
$match Match
$patch Patch

Открытые методы

Метод Описание
__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.

Описание методов

__construct() публичный Метод

public __construct ( )

__get() публичный Метод

Proxy getting properties to real objects.
public __get ( string $name ) : float
$name string Property name.
Результат float

__set() публичный Метод

Proxy setting properties to real objects.
public __set ( string $name, mixed $value ) : float
$name string Property name.
$value mixed Property value.
Результат float

diff_cleanupEfficiency() публичный Метод

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

diff_cleanupSemantic() публичный Метод

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

diff_levenshtein() публичный Метод

Compute the Levenshtein distance; the number of inserted, deleted or substituted characters.
public diff_levenshtein ( array $diffs ) : integer
$diffs array Array of diff arrays.
Результат integer Number of changes.

diff_main() публичный Метод

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.
Результат array Array of changes.

diff_prettyHtml() публичный Метод

Convert a diff array into a pretty HTML report.
public diff_prettyHtml ( array $diffs ) : string
$diffs array Array of diff arrays.
Результат string HTML representation.

match_main() публичный Метод

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.
Результат integer Best match index or -1.

patch_apply() публичный Метод

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.
Результат array Two element Array, containing the new text and an array of boolean values.

patch_fromText() публичный Метод

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.
Результат PatchObject[] Array of PatchObjects.

patch_make() публичный Метод

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).
Результат PatchObject[] Array of PatchObjects.

patch_toText() публичный Метод

Take a list of patches and return a textual representation.
public patch_toText ( PatchObject[] $patches ) : string
$patches PatchObject[] Array of PatchObjects.
Результат string Text representation of patches.

Описание свойств

$diff защищенное свойство

protected Diff,diffmatchpatch $diff
Результат Diff

$match защищенное свойство

protected Match,diffmatchpatch $match
Результат Match

$patch защищенное свойство

protected Patch,diffmatchpatch $patch
Результат Patch