public class diff_match_patch extends java.lang.Object
Class containing the diff, match and patch methods. Also contains the behaviour settings.
Modifiers | Name | Description |
---|---|---|
static class |
diff_match_patch.Diff |
Class representing one diff operation. |
protected static class |
diff_match_patch.LinesToCharsResult |
Internal class for returning results from diff_linesToChars(). |
enum |
diff_match_patch.Operation |
The data structure representing a diff is a Linked list of Diff objects: {Diff(Operation.DELETE, "Hello"), Diff(Operation.INSERT, "Goodbye"), Diff(Operation.EQUAL, " world.")} |
static class |
diff_match_patch.Patch |
Class representing one patch operation. |
Modifiers | Name | Description |
---|---|---|
short |
Diff_EditCost |
Cost of an empty edit operation in terms of edit characters. |
float |
Diff_Timeout |
Number of seconds to map a diff before giving up (0 for infinity). |
int |
Match_Distance |
How far to search for a match (0 = exact location, 1000+ = broad match). |
float |
Match_Threshold |
At what point is no match declared (0.0 = perfection, 1.0 = very loose). |
float |
Patch_DeleteThreshold |
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). |
short |
Patch_Margin |
Chunk size for context length. |
Type Params | Return Type | Name and description |
---|---|---|
|
protected java.util.LinkedList<Diff> |
diff_bisect(java.lang.String text1, java.lang.String text2, long deadline) Find the 'middle snake' of a diff, split the problem in two and return the recursively constructed diff. |
|
protected void |
diff_charsToLines(java.util.List<Diff> diffs, java.util.List<java.lang.String> lineArray) Rehydrate the text in a diff from a string of line hashes to real lines of text. |
|
public void |
diff_cleanupEfficiency(java.util.LinkedList<Diff> diffs) Reduce the number of edits by eliminating operationally trivial equalities. |
|
public void |
diff_cleanupMerge(java.util.LinkedList<Diff> diffs) Reorder and merge like edit sections. |
|
public void |
diff_cleanupSemantic(java.util.LinkedList<Diff> diffs) Reduce the number of edits by eliminating semantically trivial equalities. |
|
public void |
diff_cleanupSemanticLossless(java.util.LinkedList<Diff> diffs) Look for single edits surrounded on both sides by equalities which can be shifted sideways to align the edit to a word boundary. |
|
protected int |
diff_commonOverlap(java.lang.String text1, java.lang.String text2) Determine if the suffix of one string is the prefix of another. |
|
public int |
diff_commonPrefix(java.lang.String text1, java.lang.String text2) Determine the common prefix of two strings |
|
public int |
diff_commonSuffix(java.lang.String text1, java.lang.String text2) Determine the common suffix of two strings |
|
public java.util.LinkedList<Diff> |
diff_fromDelta(java.lang.String text1, java.lang.String delta) Given the original text1, and an encoded string which describes the operations required to transform text1 into text2, compute the full diff. |
|
protected java.lang.String[] |
diff_halfMatch(java.lang.String text1, java.lang.String text2) Do the two texts share a substring which is at least half the length of the longer text? |
|
public int |
diff_levenshtein(java.util.List<Diff> diffs) Compute the Levenshtein distance; the number of inserted, deleted or substituted characters. |
|
protected diff_match_patch.LinesToCharsResult |
diff_linesToChars(java.lang.String text1, java.lang.String text2) Split two texts into a list of strings. |
|
public java.util.LinkedList<Diff> |
diff_main(java.lang.String text1, java.lang.String text2) Find the differences between two texts. |
|
public java.util.LinkedList<Diff> |
diff_main(java.lang.String text1, java.lang.String text2, boolean checklines) Find the differences between two texts. |
|
public java.lang.String |
diff_prettyHtml(java.util.List<Diff> diffs) Convert a Diff list into a pretty HTML report. |
|
public java.lang.String |
diff_text1(java.util.List<Diff> diffs) Compute and return the source text (all equalities and deletions). |
|
public java.lang.String |
diff_text2(java.util.List<Diff> diffs) Compute and return the destination text (all equalities and insertions). |
|
public java.lang.String |
diff_toDelta(java.util.List<Diff> diffs) Crush the diff into an encoded string which describes the operations required to transform text1 into text2. |
|
public int |
diff_xIndex(java.util.List<Diff> diffs, int loc) loc is a location in text1, compute and return the equivalent location in text2. |
|
protected java.util.Map<java.lang.Character, java.lang.Integer> |
match_alphabet(java.lang.String pattern) Initialise the alphabet for the Bitap algorithm. |
|
protected int |
match_bitap(java.lang.String text, java.lang.String pattern, int loc) Locate the best instance of 'pattern' in 'text' near 'loc' using the Bitap algorithm. |
|
public int |
match_main(java.lang.String text, java.lang.String pattern, int loc) Locate the best instance of 'pattern' in 'text' near 'loc'. |
|
protected void |
patch_addContext(diff_match_patch.Patch patch, java.lang.String text) Increase the context until it is unique, but don't let the pattern expand beyond Match_MaxBits. |
|
public java.lang.String |
patch_addPadding(java.util.LinkedList<Patch> patches) Add some padding on text start and end so that edges can match something. |
|
public java.lang.Object[] |
patch_apply(java.util.LinkedList<Patch> patches, java.lang.String text) Merge a set of patches onto the text. |
|
public java.util.LinkedList<Patch> |
patch_deepCopy(java.util.LinkedList<Patch> patches) Given an array of patches, return another array that is identical. |
|
public java.util.List<Patch> |
patch_fromText(java.lang.String textline) Parse a textual representation of patches and return a List of Patch objects. |
|
public java.util.LinkedList<Patch> |
patch_make(java.lang.String text1, java.lang.String text2) Compute a list of patches to turn text1 into text2. |
|
public java.util.LinkedList<Patch> |
patch_make(java.util.LinkedList<Diff> diffs) Compute a list of patches to turn text1 into text2. |
|
public java.util.LinkedList<Patch> |
patch_make(java.lang.String text1, java.lang.String text2, java.util.LinkedList<Diff> diffs) Compute a list of patches to turn text1 into text2. |
|
public java.util.LinkedList<Patch> |
patch_make(java.lang.String text1, java.util.LinkedList<Diff> diffs) Compute a list of patches to turn text1 into text2. |
|
public void |
patch_splitMax(java.util.LinkedList<Patch> patches) Look through the patches and break up any which are longer than the maximum limit of the match algorithm. |
|
public java.lang.String |
patch_toText(java.util.List<Patch> patches) Take a list of patches and return a textual representation. |
Methods inherited from class | Name |
---|---|
class java.lang.Object |
java.lang.Object#getClass(), java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#hashCode(), java.lang.Object#equals(java.lang.Object), java.lang.Object#notifyAll(), java.lang.Object#toString(), java.lang.Object#notify() |
Cost of an empty edit operation in terms of edit characters.
Number of seconds to map a diff before giving up (0 for infinity).
How far to search for a match (0 = exact location, 1000+ = broad match). A match this many characters away from the expected location will add 1.0 to the score (0.0 is a perfect match).
At what point is no match declared (0.0 = perfection, 1.0 = very loose).
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.
Chunk size for context length.
Find the 'middle snake' of a diff, split the problem in two and return the recursively constructed diff. See Myers 1986 paper: An O(ND) Difference Algorithm and Its Variations.
text1
- Old string to be diffed.text2
- New string to be diffed.deadline
- Time at which to bail if not yet complete.Rehydrate the text in a diff from a string of line hashes to real lines of text.
diffs
- List of Diff objects.lineArray
- List of unique strings.Reduce the number of edits by eliminating operationally trivial equalities.
diffs
- LinkedList of Diff objects.Reorder and merge like edit sections. Merge equalities. Any edit section can move as long as it doesn't cross an equality.
diffs
- LinkedList of Diff objects.Reduce the number of edits by eliminating semantically trivial equalities.
diffs
- LinkedList of Diff objects.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.
diffs
- LinkedList of Diff objects.Determine if the suffix of one string is the prefix of another.
text1
- First string.text2
- Second string.Determine the common prefix of two strings
text1
- First string.text2
- Second string.Determine the common suffix of two strings
text1
- First string.text2
- Second string.Given the original text1, and an encoded string which describes the operations required to transform text1 into text2, compute the full diff.
text1
- Source string for the diff.delta
- Delta text.Do the two texts share a substring which is at least half the length of the longer text? This speedup can produce non-minimal diffs.
text1
- First string.text2
- Second string.Compute the Levenshtein distance; the number of inserted, deleted or substituted characters.
diffs
- List of Diff objects.Split two texts into a list of strings. Reduce the texts to a string of hashes where each Unicode character represents one line.
text1
- First string.text2
- Second string.Find the differences between two texts. Run a faster, slightly less optimal diff. This method allows the 'checklines' of diff_main() to be optional. Most of the time checklines is wanted, so default to true.
text1
- Old string to be diffed.text2
- New string to be diffed.Find the differences between two texts.
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.Convert a Diff list into a pretty HTML report.
diffs
- List of Diff objects.Compute and return the source text (all equalities and deletions).
diffs
- List of Diff objects.Compute and return the destination text (all equalities and insertions).
diffs
- List of Diff objects.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.
diffs
- List of Diff objects.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
diffs
- List of Diff objects.loc
- Location within text1.Initialise the alphabet for the Bitap algorithm.
pattern
- The text to encode.Locate the best instance of 'pattern' in 'text' near 'loc' using the Bitap algorithm. Returns -1 if no match found.
text
- The text to search.pattern
- The pattern to search for.loc
- The location to search around.Locate the best instance of 'pattern' in 'text' near 'loc'. Returns -1 if no match found.
text
- The text to search.pattern
- The pattern to search for.loc
- The location to search around.Increase the context until it is unique, but don't let the pattern expand beyond Match_MaxBits.
patch
- The patch to grow.text
- Source text.Add some padding on text start and end so that edges can match something. Intended to be called only from within patch_apply.
patches
- Array of Patch objects.Merge a set of patches onto the text. Return a patched text, as well as an array of true/false values indicating which patches were applied.
patches
- Array of Patch objectstext
- Old text.Given an array of patches, return another array that is identical.
patches
- Array of Patch objects.Parse a textual representation of patches and return a List of Patch objects.
textline
- Text representation of patches.Compute a list of patches to turn text1 into text2. A set of diffs will be computed.
text1
- Old text.text2
- New text.Compute a list of patches to turn text1 into text2. text1 will be derived from the provided diffs.
diffs
- Array of Diff objects for text1 to text2.Compute a list of patches to turn text1 into text2. text2 is ignored, diffs are the delta between text1 and text2.
text1
- Old texttext2
- Ignored.diffs
- Array of Diff objects for text1 to text2.Compute a list of patches to turn text1 into text2. text2 is not provided, diffs are the delta between text1 and text2.
text1
- Old text.diffs
- Array of Diff objects for text1 to text2.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.
patches
- LinkedList of Patch objects.Take a list of patches and return a textual representation.
patches
- List of Patch objects.