PHP 클래스 DiffMatchPatch\Diff

저자: Neil Fraser ([email protected])
저자: Daniil Skrobov ([email protected])
파일 보기 프로젝트 열기: yetanotherape/diff-match-patch 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$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