PHP Class diff_match_patch, diff_match_patch-php

Datei anzeigen Open project: nuxodin/diff_match_patch-php Class Usage Examples

Public Properties

Property Type Description
$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.

Public Methods

Method Description
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.

Method Details

diff_charsToLines() public method

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

diff_cleanupEfficiency() public method

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

diff_cleanupMerge() public method

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

diff_cleanupSemantic() public method

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

diff_cleanupSemanticLossless() public method

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

diff_cleanupSemanticScore() public method

Scores range from 5 (best) to 0 (worst). Closure, makes reference to regex patterns defined above.
public diff_cleanupSemanticScore ( $one, $two ) : {number}
return {number}

diff_commonPrefix() public method

Determine the common prefix of two strings
public diff_commonPrefix ( $text1, $text2 ) : {number}
return {number}

diff_commonSuffix() public method

Determine the common suffix of two strings
public diff_commonSuffix ( $text1, $text2 ) : {number}
return {number}

diff_compute() public method

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.>}
return {Array.>}

diff_fromDelta() public method

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.>}
return {Array.>}

diff_halfMatch() public method

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.?}
return {Array.?}

diff_halfMatchI() public method

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.?}
return {Array.?}

diff_levenshtein() public method

Compute the Levenshtein distance; the number of inserted, deleted or substituted characters.
public diff_levenshtein ( $diffs ) : {number}
return {number}

diff_linesToChars() public method

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.>}
return {Array.>}

diff_linesToCharsMunge() public method

Modifies linearray and linehash through being a closure.
public diff_linesToCharsMunge ( $text, &$lineArray, &$lineHash ) : {string}
return {string}

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 ( $text1, $text2, $checklines = true ) : {Array.>}
return {Array.>}

diff_map() public method

Explore the intersection points between the two texts.
public diff_map ( $text1, $text2 ) : {Array.>?}
return {Array.>?}

diff_path1() public method

Work from the middle back to the start to determine the path.
public diff_path1 ( $v_map, $text1, $text2 ) : {Array.>}
return {Array.>}

diff_path2() public method

Work from the middle back to the end to determine the path.
public diff_path2 ( $v_map, $text1, $text2 ) : {Array.>}
return {Array.>}

diff_prettyHtml() public method

Convert a diff array into a pretty HTML report.
public diff_prettyHtml ( $diffs ) : {string}
return {string}

diff_text1() public method

Compute and return the source text (all equalities and deletions).
public diff_text1 ( $diffs ) : {string}
return {string}

diff_text2() public method

Compute and return the destination text (all equalities and insertions).
public diff_text2 ( $diffs ) : {string}
return {string}

diff_toDelta() public method

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}
return {string}

diff_xIndex() public method

e.g. 'The cat' vs 'The big cat', 1->1, 5->8
public diff_xIndex ( $diffs, $loc ) : {number}
return {number}

match_alphabet() public method

Initialise the alphabet for the Bitap algorithm.
public match_alphabet ( $pattern ) : {Object}
return {Object}

match_bitap() public method

Locate the best instance of 'pattern' in 'text' near 'loc' using the Bitap algorithm.
public match_bitap ( $text, $pattern, $loc ) : {number}
return {number}

match_bitapScore() public method

Accesses loc and pattern through being a closure.
public match_bitapScore ( $e, $x, $pattern, $loc ) : {number}
return {number}

match_main() public method

Locate the best instance of 'pattern' in 'text' near 'loc'.
public match_main ( $text, $pattern, $loc ) : {number}
return {number}

patch_addContext() public method

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

patch_addPadding() public method

Intended to be called only from within patch_apply.
public patch_addPadding ( &$patches ) : {string}
return {string}

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 ( $patches, $text ) : {Array.>}
return {Array.>}

patch_deepCopy() public method

Given an array of patches, return another array that is identical.
public patch_deepCopy ( $patches ) : {Array.}
return {Array.}

patch_fromText() public method

Parse a textual representation of patches and return a list of patch objects.
public patch_fromText ( $textline ) : {Array.}
return {Array.}

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 ( $a, $opt_b = null, $opt_c = null ) : {Array.}
return {Array.}

patch_splitMax() public method

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() public method

Take a list of patches and return a textual representation.
public patch_toText ( $patches ) : {string}
return {string}

Property Details

$Diff_DualThreshold public_oe property

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

$Diff_EditCost public_oe property

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

$Diff_Timeout public_oe property

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

$Match_Distance public_oe property

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

$Match_Threshold public_oe property

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

$Patch_DeleteThreshold public_oe property

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

$Patch_Margin public_oe property

Chunk size for context length.
public $Patch_Margin