Home | Trees | Indices | Help |
|
---|
|
Class containing the diff, match and patch methods.
Also contains the behaviour settings.
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|
|||
DIFF_DELETE = -1
|
|||
DIFF_INSERT = 1
|
|||
DIFF_EQUAL = 0
|
|
Inits a diff_match_patch object with default settings. Redefine these in your program to override the defaults. |
Find the differences between two texts. Simplifies the problem by stripping any common prefix or suffix off the texts before diffing. Args: text1: Old string to be diffed. text2: New string to be diffed. 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. Returns: Array of changes. |
Find the differences between two texts. Assumes that the texts do not have any common prefix or suffix. Args: text1: Old string to be diffed. text2: New string to be diffed. checklines: 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. Returns: Array of changes. |
Split two texts into an array of strings. Reduce the texts to a string of hashes where each Unicode character represents one line. Args: text1: First string. text2: Second string. Returns: Three element tuple, containing the encoded text1, the encoded text2 and the array of unique strings. The zeroth element of the array of unique strings is intentionally blank. |
Rehydrate the text in a diff from a string of line hashes to real lines of text. Args: diffs: Array of diff tuples. lineArray: Array of unique strings. |
Explore the intersection points between the two texts. Args: text1: Old string to be diffed. text2: New string to be diffed. Returns: Array of diff tuples or None if no diff available. |
Work from the middle back to the start to determine the path. Args: v_map: Array of paths. text1: Old string fragment to be diffed. text2: New string fragment to be diffed. Returns: Array of diff tuples. |
Work from the middle back to the end to determine the path. Args: v_map: Array of paths. text1: Old string fragment to be diffed. text2: New string fragment to be diffed. Returns: Array of diff tuples. |
Determine the common prefix of two strings. Args: text1: First string. text2: Second string. Returns: The number of characters common to the start of each string. |
Determine the common suffix of two strings. Args: text1: First string. text2: Second string. Returns: The number of characters common to the end of each string. |
Do the two texts share a substring which is at least half the length of the longer text? Args: text1: First string. text2: Second string. Returns: Five element Array, containing the prefix of text1, the suffix of text1, the prefix of text2, the suffix of text2 and the common middle. Or None if there was no match. |
Reduce the number of edits by eliminating semantically trivial equalities. Args: 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 c<ins>at c</ins>ame. -> The <ins>cat </ins>came. Args: diffs: Array of diff tuples. |
Reduce the number of edits by eliminating operationally trivial equalities. Args: 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. Args: diffs: Array of diff tuples. |
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 Args: diffs: Array of diff tuples. loc: Location within text1. Returns: Location within text2. |
Convert a diff array into a pretty HTML report. Args: diffs: Array of diff tuples. Returns: HTML representation. |
Compute and return the source text (all equalities and deletions). Args: diffs: Array of diff tuples. Returns: Source text. |
Compute and return the destination text (all equalities and insertions). Args: diffs: Array of diff tuples. Returns: Destination text. |
Compute the Levenshtein distance; the number of inserted, deleted or substituted characters. Args: diffs: Array of diff tuples. Returns: Number of changes. |
Crush the diff into an encoded string which describes the operations required to transform text1 into text2. E.g. =3 -2 +ing -> Keep 3 chars, delete 2 chars, insert 'ing'. Operations are tab-separated. Inserted text is escaped using %xx notation. Args: diffs: Array of diff tuples. Returns: Delta text. |
Given the original text1, and an encoded string which describes the operations required to transform text1 into text2, compute the full diff. Args: text1: Source string for the diff. delta: Delta text. Returns: Array of diff tuples. Raises: ValueError: If invalid input. |
Locate the best instance of 'pattern' in 'text' near 'loc'. Args: text: The text to search. pattern: The pattern to search for. loc: The location to search around. Returns: Best match index or -1. |
Locate the best instance of 'pattern' in 'text' near 'loc' using the Bitap algorithm. Args: text: The text to search. pattern: The pattern to search for. loc: The location to search around. Returns: Best match index or -1. |
Initialise the alphabet for the Bitap algorithm. Args: pattern: The text to encode. Returns: Hash of character locations. |
Increase the context until it is unique, but don't let the pattern expand beyond Match_MaxBits. Args: patch: The patch to grow. text: Source text. |
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 Args: a: text1 (methods 1,3,4) or Array of diff tuples for text1 to text2 (method 2). b: text2 (methods 1,4) or Array of diff tuples for text1 to text2 (method 3) or undefined (method 2). c: Array of diff tuples for text1 to text2 (method 4) or undefined (methods 1,2,3). Returns: Array of patch objects. |
Given an array of patches, return another array that is identical. Args: patches: Array of patch objects. Returns: Array of patch objects. |
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. Args: patches: Array of patch objects. text: Old text. Returns: Two element Array, containing the new text and an array of boolean values. |
Add some padding on text start and end so that edges can match something. Intended to be called only from within patch_apply. Args: patches: Array of patch objects. Returns: The padding string added to each side. |
Look through the patches and break up any which are longer than the maximum limit of the match algorithm. Args: patches: Array of patch objects. |
Take a list of patches and return a textual representation. Args: patches: Array of patch objects. Returns: Text representation of patches. |
Parse a textual representation of patches and return a list of patch objects. Args: textline: Text representation of patches. Returns: Array of patch objects. Raises: ValueError: If invalid input. |
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Tue Apr 12 18:11:56 2011 | http://epydoc.sourceforge.net |