PHP Класс DiffMatchPatch\Diff

Автор: Neil Fraser ([email protected])
Автор: Daniil Skrobov ([email protected])
Показать файл Открыть проект Примеры использования класса

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

Свойство Тип Описание
$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

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

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

Защищенные методы

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

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

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

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() защищенный Метод

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

bisectSplit() защищенный Метод

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

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

TODO refactor this Cap's code
public cleanupEfficiency ( )

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

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

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

TODO refactor this cap's code
public cleanupSemantic ( )

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

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

cleanupSemanticScore() защищенный Метод

Scores range from 6 (best) to 0 (worst).
protected cleanupSemanticScore ( string $one, string $two ) : integer
$one string First string.
$two string Second string.
Результат integer The score.

compute() защищенный Метод

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

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

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 getChanges ( ) : array
Результат array

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

public getEditCost ( ) : integer
Результат integer

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

public getTimeout ( ) : float
Результат float

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

public getToolkit ( ) : DiffToolkit
Результат DiffToolkit

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

Compute the Levenshtein distance; the number of inserted, deleted or substituted characters.
public levenshtein ( ) : integer
Результат integer Number of changes.

lineMode() защищенный Метод

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

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

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.
Результат self

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

Convert a diff array into a pretty HTML report.
public prettyHtml ( ) : string
Результат string HTML representation.

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

public setChanges ( array $changes )
$changes array

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

public setEditCost ( integer $editCost )
$editCost integer

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

public setTimeout ( $timeout )
$timeout

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

public setToolkit ( DiffToolkit $toolkit )
$toolkit DiffToolkit

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

Compute and return the source text (all equalities and deletions).
public text1 ( ) : string
Результат string Source text.

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

Compute and return the destination text (all equalities and insertions).
public text2 ( ) : string
Результат string Destination text.

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 toDelta ( ) : string
Результат string Delta text.

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

e.g. "The cat" vs "The big cat", 1->1, 5->8
public xIndex ( integer $loc ) : integer
$loc integer Location within text1.
Результат integer Location within text2.

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

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

protected array $changes
Результат array

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

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

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

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

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

protected DiffToolkit,diffmatchpatch $toolkit
Результат DiffToolkit