PHP Class DiffMatchPatch\Diff

Author: Neil Fraser ([email protected])
Author: Daniil Skrobov ([email protected])
Afficher le fichier Open project: yetanotherape/diff-match-patch Class Usage Examples

Protected Properties

Свойство Type Description
$changes array
$editCost Cost of an empty edit operation in terms of edit characters.
$timeout Number of seconds to map a diff before giving up (0 for infinity).
$toolkit DiffToolkit

Méthodes publiques

Méthode Description
__construct ( string | null $text1 = null, string | null $text2 = null ) Init object and call main(), if texts passed.
cleanupEfficiency ( ) Reduce the number of edits by eliminating operationally trivial equalities.
cleanupMerge ( ) Reorder and merge like edit sections. Merge equalities.
cleanupSemantic ( ) Reduce the number of edits by eliminating semantically trivial equalities.
cleanupSemanticLossless ( ) Look for single edits surrounded on both sides by equalities which can be shifted sideways to align the edit to a word boundary.
fromDelta ( string $text1, string $delta ) Given the original text1, and an encoded string which describes the operations required to transform text1 into text2, compute the full diff.
getChanges ( ) : array
getEditCost ( ) : integer
getTimeout ( ) : float
getToolkit ( ) : DiffToolkit
levenshtein ( ) : integer Compute the Levenshtein distance; the number of inserted, deleted or substituted characters.
main ( string $text1, string $text2, boolean $checklines = true, integer $deadline = null ) : self Find the differences between two texts. Simplifies the problem by stripping any common prefix or suffix off the texts before diffing.
prettyHtml ( ) : string Convert a diff array into a pretty HTML report.
setChanges ( array $changes )
setEditCost ( integer $editCost )
setTimeout ( $timeout )
setToolkit ( DiffToolkit $toolkit )
text1 ( ) : string Compute and return the source text (all equalities and deletions).
text2 ( ) : string Compute and return the destination text (all equalities and insertions).
toDelta ( ) : string Crush the diff into an encoded string which describes the operations required to transform text1 into text2.
xIndex ( integer $loc ) : integer Compute and return location in text2 equivalent to the $loc in text1.

Méthodes protégées

Méthode Description
bisect ( string $text1, string $text2, integer $deadline ) : array Find the 'middle snake' of a diff, split the problem in two and return the recursively constructed diff.
bisectSplit ( string $text1, string $text2, integer $x, integer $y, integer $deadline ) : array Given the location of the 'middle snake', split the diff in two parts and recurse.
cleanupSemanticScore ( string $one, string $two ) : integer Given two strings, compute a score representing whether the internal boundary falls on logical boundaries.
compute ( string $text1, string $text2, boolean $checklines, integer $deadline ) : array Find the differences between two texts. Assumes that the texts do not have any common prefix or suffix.
lineMode ( string $text1, string $text2, integer $deadline ) : array Do a quick line-level diff on both strings, then rediff the parts for greater accuracy.

Method Details

__construct() public méthode

Init object and call main(), if texts passed.
public __construct ( string | null $text1 = null, string | null $text2 = null )
$text1 string | null
$text2 string | null

bisect() protected méthode

See Myers 1986 paper: An O(ND) Difference Algorithm and Its Variations.
protected bisect ( string $text1, string $text2, integer $deadline ) : array
$text1 string Old string to be diffed.
$text2 string New string to be diffed.
$deadline integer Time at which to bail if not yet complete.
Résultat array Array of diff arrays.

bisectSplit() protected méthode

Given the location of the 'middle snake', split the diff in two parts and recurse.
protected bisectSplit ( string $text1, string $text2, integer $x, integer $y, integer $deadline ) : array
$text1 string Old string to be diffed.
$text2 string New string to be diffed.
$x integer Index of split point in text1.
$y integer Index of split point in text2.
$deadline integer Time at which to bail if not yet complete.
Résultat array Array of diff arrays.

cleanupEfficiency() public méthode

TODO refactor this Cap's code
public cleanupEfficiency ( )

cleanupMerge() public méthode

Any edit section can move as long as it doesn't cross an equality.
public cleanupMerge ( )

cleanupSemantic() public méthode

TODO refactor this cap's code
public cleanupSemantic ( )

cleanupSemanticLossless() public méthode

e.g: The cat came. -> The cat came.

cleanupSemanticScore() protected méthode

Scores range from 6 (best) to 0 (worst).
protected cleanupSemanticScore ( string $one, string $two ) : integer
$one string First string.
$two string Second string.
Résultat integer The score.

compute() protected méthode

Find the differences between two texts. Assumes that the texts do not have any common prefix or suffix.
protected compute ( string $text1, string $text2, boolean $checklines, integer $deadline ) : array
$text1 string Old string to be diffed.
$text2 string New string to be diffed.
$checklines boolean Speedup flag. If false, then don't run a line-level diff first to identify the changed areas. If true, then run a faster, slightly less optimal diff.
$deadline integer Time when the diff should be complete by.
Résultat array Array of changes.

fromDelta() public méthode

Given the original text1, and an encoded string which describes the operations required to transform text1 into text2, compute the full diff.
public fromDelta ( string $text1, string $delta )
$text1 string Source string for the diff.
$delta string Delta text.

getChanges() public méthode

public getChanges ( ) : array
Résultat array

getEditCost() public méthode

public getEditCost ( ) : integer
Résultat integer

getTimeout() public méthode

public getTimeout ( ) : float
Résultat float

getToolkit() public méthode

public getToolkit ( ) : DiffToolkit
Résultat DiffToolkit

levenshtein() public méthode

Compute the Levenshtein distance; the number of inserted, deleted or substituted characters.
public levenshtein ( ) : integer
Résultat integer Number of changes.

lineMode() protected méthode

This speedup can produce non-minimal diffs.
protected lineMode ( string $text1, string $text2, integer $deadline ) : array
$text1 string Old string to be diffed.
$text2 string New string to be diffed.
$deadline integer Time when the diff should be complete by.
Résultat array Array of changes.

main() public méthode

Find the differences between two texts. Simplifies the problem by stripping any common prefix or suffix off the texts before diffing.
public main ( string $text1, string $text2, boolean $checklines = true, integer $deadline = null ) : self
$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.
$deadline integer Optional time when the diff should be complete by. Used internally for recursive calls. Users should set $this->timeout instead.
Résultat self

prettyHtml() public méthode

Convert a diff array into a pretty HTML report.
public prettyHtml ( ) : string
Résultat string HTML representation.

setChanges() public méthode

public setChanges ( array $changes )
$changes array

setEditCost() public méthode

public setEditCost ( integer $editCost )
$editCost integer

setTimeout() public méthode

public setTimeout ( $timeout )
$timeout

setToolkit() public méthode

public setToolkit ( DiffToolkit $toolkit )
$toolkit DiffToolkit

text1() public méthode

Compute and return the source text (all equalities and deletions).
public text1 ( ) : string
Résultat string Source text.

text2() public méthode

Compute and return the destination text (all equalities and insertions).
public text2 ( ) : string
Résultat string Destination text.

toDelta() public méthode

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 toDelta ( ) : string
Résultat string Delta text.

xIndex() public méthode

e.g. "The cat" vs "The big cat", 1->1, 5->8
public xIndex ( integer $loc ) : integer
$loc integer Location within text1.
Résultat integer Location within text2.

Property Details

$changes protected_oe property

protected array $changes
Résultat array

$editCost protected_oe property

Cost of an empty edit operation in terms of edit characters.
protected $editCost

$timeout protected_oe property

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

$toolkit protected_oe property

protected DiffToolkit,diffmatchpatch $toolkit
Résultat DiffToolkit