Class: diff_match_patch

Defined in: diff_match_patch_uncompressed.js.

Instance Methods

Instance Method Detail

diff_cleanupEfficiency
Reduce the number of edits by eliminating operationally trivial equalities.
Parameters:
!Array. diffs
Array of diff tuples.
diff_cleanupMerge

Reorder and merge like edit sections. Merge equalities. Any edit section can move as long as it doesn't cross an equality.

Parameters:
!Array. diffs
Array of diff tuples.
diff_cleanupSemantic
Reduce the number of edits by eliminating semantically trivial equalities.
Parameters:
!Array. diffs
Array of diff tuples.
diff_cleanupSemanticLossless

Look for single edits surrounded on both sides by equalities which can be shifted sideways to align the edit to a word boundary. e.g: The cat came. -> The cat came.

Parameters:
!Array. diffs
Array of diff tuples.
diff_commonPrefix
Determine the common prefix of two strings.
Parameters:
string text1
First string.
string text2
Second string.
Returns:
number

The number of characters common to the start of each string.

diff_commonSuffix
Determine the common suffix of two strings.
Parameters:
string text1
First string.
string text2
Second string.
Returns:
number The number of characters common to the end of each string.
diff_fromDelta

Given the original text1, and an encoded string which describes the operations required to transform text1 into text2, compute the full diff.

Parameters:
string text1
Source string for the diff.
string delta
Delta text.
Throws:
!Error
If invalid input.
Returns:
!Array. Array of diff tuples.
diff_levenshtein

Compute the Levenshtein distance; the number of inserted, deleted or substituted characters.

Parameters:
!Array. diffs
Array of diff tuples.
Returns:
number Number of changes.
diff_main

Find the differences between two texts. Simplifies the problem by stripping any common prefix or suffix off the texts before diffing.

Parameters:
string text1
Old string to be diffed.
string text2
New string to be diffed.
boolean= opt_checklines
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.
number opt_deadline
Optional time when the diff should be complete by. Used internally for recursive calls. Users should set DiffTimeout instead.
Returns:
!Array. Array of diff tuples.
diff_prettyHtml
Convert a diff array into a pretty HTML report.
Parameters:
!Array. diffs
Array of diff tuples.
Returns:
string HTML representation.
diff_text1
Compute and return the source text (all equalities and deletions).
Parameters:
!Array. diffs
Array of diff tuples.
Returns:
string Source text.
diff_text2
Compute and return the destination text (all equalities and insertions).
Parameters:
!Array. diffs
Array of diff tuples.
Returns:
string Destination text.
diff_toDelta

Crush the diff into an encoded string which describes the operations required to transform text1 into text2. 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.

Parameters:
!Array. diffs
Array of diff tuples.
Returns:
string Delta text.
diff_xIndex

loc is a location in text1, compute and return the equivalent location in text2. e.g. 'The cat' vs 'The big cat', 1->1, 5->8

Parameters:
!Array. diffs
Array of diff tuples.
number loc
Location within text1.
Returns:
number Location within text2.
match_main
Locate the best instance of 'pattern' in 'text' near 'loc'.
Parameters:
string text
The text to search.
string pattern
The pattern to search for.
number loc
The location to search around.
Returns:
number Best match index or -1.
patch_addPadding

Add some padding on text start and end so that edges can match something. Intended to be called only from within patch_apply.

Parameters:
!Array. patches
Array of patch objects.
Returns:
string The padding string added to each side.
patch_apply

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.

Parameters:
!Array. patches
Array of patch objects.
string text
Old text.
Returns:
!Array.>

Two element Array, containing the new text and an array of boolean values.

patch_deepCopy
Given an array of patches, return another array that is identical.
Parameters:
!Array. patches
Array of patch objects.
Returns:
!Array. Array of patch objects.
patch_fromText
Parse a textual representation of patches and return a list of patch objects.
Parameters:
string textline
Text representation of patches.
Throws:
!Error
If invalid input.
Returns:
!Array. Array of patch objects.
patch_make

Compute a list of patches to turn text1 into text2. 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

Parameters:
string|!Array. a
text1 (methods 1,3,4) or Array of diff tuples for text1 to text2 (method 2).
string|!Array. opt_b
text2 (methods 1,4) or Array of diff tuples for text1 to text2 (method 3) or undefined (method 2).
string|!Array. opt_c
Array of diff tuples for text1 to text2 (method 4) or undefined (methods 1,2,3).
Returns:
!Array. Array of patch objects.
patch_splitMax

Look through the patches and break up any which are longer than the maximum limit of the match algorithm. Intended to be called only from within patch_apply.

Parameters:
!Array. patches
Array of patch objects.
patch_toText
Take a list of patches and return a textual representation.
Parameters:
!Array. patches
Array of patch objects.
Returns:
string Text representation of patches.
Documentation generated by JsDoc Toolkit 2.4.0 on Wed Nov 30 2011 13:33:45 GMT+0100 (CET)