Class: diff_match_patch
Defined in: diff_match_patch_uncompressed.js.
Instance Methods
- diff_cleanupEfficiency
- diff_cleanupMerge
- diff_cleanupSemantic
- diff_cleanupSemanticLossless
- diff_commonPrefix
- diff_commonSuffix
- diff_fromDelta
- diff_levenshtein
- diff_main
- diff_prettyHtml
- diff_text1
- diff_text2
- diff_toDelta
- diff_xIndex
- match_main
- patch_addPadding
- patch_apply
- patch_deepCopy
- patch_fromText
- patch_make
- patch_splitMax
- patch_toText
Instance Method Detail
- Parameters:
- !Array. diffs
- Array of diff tuples.
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.
- Parameters:
- !Array. diffs
- Array of diff tuples.
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.
- Parameters:
- string text1
- First string.
- string text2
- Second string.
- Returns:
- number
The number of characters common to the start of each string.
- Parameters:
- string text1
- First string.
- string text2
- Second string.
- Returns:
- number The number of characters common to the end of each string.
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.
Compute the Levenshtein distance; the number of inserted, deleted or substituted characters.
- Parameters:
- !Array. diffs
- Array of diff tuples.
- Returns:
- number Number of changes.
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.
- Parameters:
- !Array. diffs
- Array of diff tuples.
- Returns:
- string HTML representation.
- Parameters:
- !Array. diffs
- Array of diff tuples.
- Returns:
- string Source text.
- Parameters:
- !Array. diffs
- Array of diff tuples.
- Returns:
- string Destination text.
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.
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.
- 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.
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.
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.
- Parameters:
- !Array. patches
- Array of patch objects.
- Returns:
- !Array. Array of patch objects.
- Parameters:
- string textline
- Text representation of patches.
- Throws:
- !Error
- If invalid input.
- Returns:
- !Array. Array of patch objects.
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.
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.
- Parameters:
- !Array. patches
- Array of patch objects.
- Returns:
- string Text representation of patches.