PHP Класс diff_match_patch, diff_match_patch-php

Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$Diff_DualThreshold Double-ending is twice as fast, but less accurate.
$Diff_EditCost Cost of an empty edit operation in terms of edit characters.
$Diff_Timeout Number of seconds to map a diff before giving up (0 for infinity).
$Match_Distance 1.0 to the score (0.0 is a perfect match).
$Match_Threshold At what point is no match declared (0.0 = perfection, 1.0 = very loose).
$Patch_DeleteThreshold end points of a delete need to match.
$Patch_Margin Chunk size for context length.

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

Метод Описание
diff_charsToLines ( &$diffs, $lineArray ) Rehydrate the text in a diff from a string of line hashes to real lines of text.
diff_cleanupEfficiency ( &$diffs ) Reduce the number of edits by eliminating operationally trivial equalities.
diff_cleanupMerge ( &$diffs ) Reorder and merge like edit sections. Merge equalities.
diff_cleanupSemantic ( &$diffs ) Reduce the number of edits by eliminating semantically trivial equalities.
diff_cleanupSemanticLossless ( &$diffs ) Look for single edits surrounded on both sides by equalities which can be shifted sideways to align the edit to a word boundary.
diff_cleanupSemanticScore ( $one, $two ) : {number} Given two strings, compute a score representing whether the internal boundary falls on logical boundaries.
diff_commonPrefix ( $text1, $text2 ) : {number} Determine the common prefix of two strings
diff_commonSuffix ( $text1, $text2 ) : {number} Determine the common suffix of two strings
diff_compute ( $text1, $text2, $checklines ) : {Array.>} Find the differences between two texts. Assumes that the texts do not have any common prefix or suffix.
diff_fromDelta ( $text1, $delta ) : {Array.>} Given the original text1, and an encoded string which describes the operations required to transform text1 into text2, compute the full diff.
diff_halfMatch ( $text1, $text2 ) : {Array.?} Do the two texts share a mb_substring which is at least half the length of the longer text?
diff_halfMatchI ( $longtext, $shorttext, $i ) : {Array.?} Does a mb_substring of shorttext exist within longtext such that the mb_substring is at least half the length of longtext? Closure, but does not reference any external variables.
diff_levenshtein ( $diffs ) : {number} Compute the Levenshtein distance; the number of inserted, deleted or substituted characters.
diff_linesToChars ( $text1, $text2 ) : {Array.>} Split two texts into an array of strings. Reduce the texts to a string of hashes where each Unicode character represents one line.
diff_linesToCharsMunge ( $text, &$lineArray, &$lineHash ) : {string} Split a text into an array of strings. Reduce the texts to a string of hashes where each Unicode character represents one line.
diff_main ( $text1, $text2, $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_map ( $text1, $text2 ) : {Array.>?} Explore the intersection points between the two texts.
diff_path1 ( $v_map, $text1, $text2 ) : {Array.>} Work from the middle back to the start to determine the path.
diff_path2 ( $v_map, $text1, $text2 ) : {Array.>} Work from the middle back to the end to determine the path.
diff_prettyHtml ( $diffs ) : {string} Convert a diff array into a pretty HTML report.
diff_text1 ( $diffs ) : {string} Compute and return the source text (all equalities and deletions).
diff_text2 ( $diffs ) : {string} Compute and return the destination text (all equalities and insertions).
diff_toDelta ( $diffs ) : {string} Crush the diff into an encoded string which describes the operations required to transform text1 into text2.
diff_xIndex ( $diffs, $loc ) : {number} loc is a location in text1, compute and return the equivalent location in text2.
match_alphabet ( $pattern ) : {Object} Initialise the alphabet for the Bitap algorithm.
match_bitap ( $text, $pattern, $loc ) : {number} Locate the best instance of 'pattern' in 'text' near 'loc' using the Bitap algorithm.
match_bitapScore ( $e, $x, $pattern, $loc ) : {number} Compute and return the score for a match with e errors and x location.
match_main ( $text, $pattern, $loc ) : {number} Locate the best instance of 'pattern' in 'text' near 'loc'.
patch_addContext ( $patch, $text ) Increase the context until it is unique, but don't let the pattern expand beyond Match_MaxBits.
patch_addPadding ( &$patches ) : {string} Add some padding on text start and end so that edges can match something.
patch_apply ( $patches, $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_deepCopy ( $patches ) : {Array.} Given an array of patches, return another array that is identical.
patch_fromText ( $textline ) : {Array.} Parse a textual representation of patches and return a list of patch objects.
patch_make ( $a, $opt_b = null, $opt_c = null ) : {Array.} Compute a list of patches to turn text1 into text2.
patch_splitMax ( &$patches ) Look through the patches and break up any which are longer than the maximum limit of the match algorithm.
patch_toText ( $patches ) : {string} Take a list of patches and return a textual representation.

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

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

Rehydrate the text in a diff from a string of line hashes to real lines of text.
public diff_charsToLines ( &$diffs, $lineArray )

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

Reduce the number of edits by eliminating operationally trivial equalities.
public diff_cleanupEfficiency ( &$diffs )

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

Any edit section can move as long as it doesn't cross an equality.
public diff_cleanupMerge ( &$diffs )

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

Reduce the number of edits by eliminating semantically trivial equalities.
public diff_cleanupSemantic ( &$diffs )

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

e.g: The cat came. -> The cat came.
public diff_cleanupSemanticLossless ( &$diffs )

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

Scores range from 5 (best) to 0 (worst). Closure, makes reference to regex patterns defined above.
public diff_cleanupSemanticScore ( $one, $two ) : {number}
Результат {number}

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

Determine the common prefix of two strings
public diff_commonPrefix ( $text1, $text2 ) : {number}
Результат {number}

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

Determine the common suffix of two strings
public diff_commonSuffix ( $text1, $text2 ) : {number}
Результат {number}

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

Find the differences between two texts. Assumes that the texts do not have any common prefix or suffix.
public diff_compute ( $text1, $text2, $checklines ) : {Array.>}
Результат {Array.>}

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

Given the original text1, and an encoded string which describes the operations required to transform text1 into text2, compute the full diff.
public diff_fromDelta ( $text1, $delta ) : {Array.>}
Результат {Array.>}

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

Do the two texts share a mb_substring which is at least half the length of the longer text?
public diff_halfMatch ( $text1, $text2 ) : {Array.?}
Результат {Array.?}

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

Does a mb_substring of shorttext exist within longtext such that the mb_substring is at least half the length of longtext? Closure, but does not reference any external variables.
public diff_halfMatchI ( $longtext, $shorttext, $i ) : {Array.?}
Результат {Array.?}

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

Compute the Levenshtein distance; the number of inserted, deleted or substituted characters.
public diff_levenshtein ( $diffs ) : {number}
Результат {number}

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

Split two texts into an array of strings. Reduce the texts to a string of hashes where each Unicode character represents one line.
public diff_linesToChars ( $text1, $text2 ) : {Array.>}
Результат {Array.>}

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

Modifies linearray and linehash through being a closure.
public diff_linesToCharsMunge ( $text, &$lineArray, &$lineHash ) : {string}
Результат {string}

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 ( $text1, $text2, $checklines = true ) : {Array.>}
Результат {Array.>}

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

Explore the intersection points between the two texts.
public diff_map ( $text1, $text2 ) : {Array.>?}
Результат {Array.>?}

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

Work from the middle back to the start to determine the path.
public diff_path1 ( $v_map, $text1, $text2 ) : {Array.>}
Результат {Array.>}

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

Work from the middle back to the end to determine the path.
public diff_path2 ( $v_map, $text1, $text2 ) : {Array.>}
Результат {Array.>}

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

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

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

Compute and return the source text (all equalities and deletions).
public diff_text1 ( $diffs ) : {string}
Результат {string}

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

Compute and return the destination text (all equalities and insertions).
public diff_text2 ( $diffs ) : {string}
Результат {string}

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

E.g. =3\t-2\t+ing -> Keep 3 chars, delete 2 chars, insert 'ing'. Operations are tab-separated. Inserted text is escaped using %xx notation.
public diff_toDelta ( $diffs ) : {string}
Результат {string}

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

e.g. 'The cat' vs 'The big cat', 1->1, 5->8
public diff_xIndex ( $diffs, $loc ) : {number}
Результат {number}

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

Initialise the alphabet for the Bitap algorithm.
public match_alphabet ( $pattern ) : {Object}
Результат {Object}

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

Locate the best instance of 'pattern' in 'text' near 'loc' using the Bitap algorithm.
public match_bitap ( $text, $pattern, $loc ) : {number}
Результат {number}

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

Accesses loc and pattern through being a closure.
public match_bitapScore ( $e, $x, $pattern, $loc ) : {number}
Результат {number}

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

Locate the best instance of 'pattern' in 'text' near 'loc'.
public match_main ( $text, $pattern, $loc ) : {number}
Результат {number}

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

Increase the context until it is unique, but don't let the pattern expand beyond Match_MaxBits.
public patch_addContext ( $patch, $text )

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

Intended to be called only from within patch_apply.
public patch_addPadding ( &$patches ) : {string}
Результат {string}

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 ( $patches, $text ) : {Array.>}
Результат {Array.>}

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

Given an array of patches, return another array that is identical.
public patch_deepCopy ( $patches ) : {Array.}
Результат {Array.}

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

Parse a textual representation of patches and return a list of patch objects.
public patch_fromText ( $textline ) : {Array.}
Результат {Array.}

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 ( $a, $opt_b = null, $opt_c = null ) : {Array.}
Результат {Array.}

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

Look through the patches and break up any which are longer than the maximum limit of the match algorithm.
public patch_splitMax ( &$patches )

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

Take a list of patches and return a textual representation.
public patch_toText ( $patches ) : {string}
Результат {string}

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

$Diff_DualThreshold публичное свойство

Double-ending is twice as fast, but less accurate.
public $Diff_DualThreshold

$Diff_EditCost публичное свойство

Cost of an empty edit operation in terms of edit characters.
public $Diff_EditCost

$Diff_Timeout публичное свойство

Number of seconds to map a diff before giving up (0 for infinity).
public $Diff_Timeout

$Match_Distance публичное свойство

1.0 to the score (0.0 is a perfect match).
public $Match_Distance

$Match_Threshold публичное свойство

At what point is no match declared (0.0 = perfection, 1.0 = very loose).
public $Match_Threshold

$Patch_DeleteThreshold публичное свойство

end points of a delete need to match.
public $Patch_DeleteThreshold

$Patch_Margin публичное свойство

Chunk size for context length.
public $Patch_Margin