PHP Class DiffMatchPatch\Patch

Author: Neil Fraser ([email protected])
Author: Daniil Skrobov ([email protected])
Exibir arquivo Open project: yetanotherape/diff-match-patch

Protected Properties

Property Type Description
$deleteTreshold When deleting a large block of text (over ~64 characters), how close do the contents have to be to match the expected contents. (0.0 = perfection, 1.0 = very loose). Note that Match->threshold controls how closely the end points of a delete need to match.
$diff Diff
$margin Chunk size for context length.
$match Match

Public Methods

Method Description
__construct ( Diff $diff = null, Match $match = null )
addContext ( PatchObject $patch, string $text ) Increase the context until it is unique, but don't let the pattern expand beyond Match->maxBits.
addPadding ( PatchObject[] &$patches ) : string Add some padding on text start and end so that edges can match something.
apply ( PatchObject[] $patches, string $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.
fromText ( string $patchText ) : PatchObject[] Parse a textual representation of patches and return a list of patch objects.
getDeleteTreshold ( ) : float
getMargin ( ) : integer
make ( string | array $a, string | array | null $b = null, array | null $c = null ) : PatchObject[] Compute a list of patches to turn text1 into text2.
setDeleteTreshold ( float $deleteTreshold )
setMargin ( integer $margin )
splitMax ( PatchObject[] &$patches ) Look through the patches and break up any which are longer than the maximum limit of the match algorithm.
toText ( PatchObject[] $patches ) : string Take a list of patches and return a textual representation.

Protected Methods

Method Description
deepCopy ( PatchObject[] $patches ) : PatchObject[] Given an array of patches, return another array that is identical.
getDiff ( ) : Diff
getMatch ( ) : Match

Method Details

__construct() public method

public __construct ( Diff $diff = null, Match $match = null )
$diff Diff
$match Match

addContext() public method

Increase the context until it is unique, but don't let the pattern expand beyond Match->maxBits.
public addContext ( PatchObject $patch, string $text )
$patch PatchObject The patch to grow.
$text string Source text.

addPadding() public method

Intended to be called only from within patch_apply. Modifies $patches. TODO try to fix it!
public addPadding ( PatchObject[] &$patches ) : string
$patches PatchObject[] Array of PatchObjects.
return string The padding string added to each side.

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 apply ( PatchObject[] $patches, string $text ) : array
$patches PatchObject[] Array of PatchObjects.
$text string Old text.
return array Two element Array, containing the new text and an array of boolean values.

deepCopy() protected method

Given an array of patches, return another array that is identical.
protected deepCopy ( PatchObject[] $patches ) : PatchObject[]
$patches PatchObject[] Array of PatchObjects.
return PatchObject[] Array of PatchObjects.

fromText() public method

Parse a textual representation of patches and return a list of patch objects.
public fromText ( string $patchText ) : PatchObject[]
$patchText string Text representation of patches.
return PatchObject[] Array of PatchObjects.

getDeleteTreshold() public method

public getDeleteTreshold ( ) : float
return float

getDiff() protected method

protected getDiff ( ) : Diff
return Diff

getMargin() public method

public getMargin ( ) : integer
return integer

getMatch() protected method

protected getMatch ( ) : Match
return Match

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 make ( string | array $a, string | array | null $b = null, array | null $c = null ) : PatchObject[]
$a string | array text1 (methods 1,3,4) or Array of diff arrays for text1 to text2 (method 2).
$b string | array | null text2 (methods 1,4) or Array of diff arrays for text1 to text2 (method 3) or null (method 2).
$c array | null Array of diff arrays for text1 to text2 (method 4) or null (methods 1,2,3).
return PatchObject[] Array of PatchObjects.

setDeleteTreshold() public method

public setDeleteTreshold ( float $deleteTreshold )
$deleteTreshold float

setMargin() public method

public setMargin ( integer $margin )
$margin integer

splitMax() public method

Intended to be called only from within apply(). Modifies $patches. TODO try to fix it!
public splitMax ( PatchObject[] &$patches )
$patches PatchObject[] Array of PatchObjects.

toText() public method

Take a list of patches and return a textual representation.
public toText ( PatchObject[] $patches ) : string
$patches PatchObject[] Array of PatchObjects.
return string Text representation of patches.

Property Details

$deleteTreshold protected_oe property

When deleting a large block of text (over ~64 characters), how close do the contents have to be to match the expected contents. (0.0 = perfection, 1.0 = very loose). Note that Match->threshold controls how closely the end points of a delete need to match.
protected $deleteTreshold

$diff protected_oe property

protected Diff,diffmatchpatch $diff
return Diff

$margin protected_oe property

Chunk size for context length.
protected $margin

$match protected_oe property

protected Match,diffmatchpatch $match
return Match