public class DiffMatchPatch
extends java.lang.Object
| Modifier and Type | Field and 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 dmp (over ~64 characters), how close do
the contents have to be to match the expected contents.
|
short |
Patch_Margin
Chunk size for context length.
|
| Constructor and Description |
|---|
DiffMatchPatch() |
| Modifier and Type | Method 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.LinkedList<Diff> diffs,
java.util.List<java.lang.String> lineArray)
Rehydrate the dmp in a diff from a string of line hashes to real lines of
dmp.
|
void |
diff_cleanupEfficiency(java.util.LinkedList<Diff> diffs)
Reduce the number of edits by eliminating operationally trivial equalities.
|
void |
diff_cleanupMerge(java.util.LinkedList<Diff> diffs)
Reorder and merge like edit sections.
|
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.
|
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 dmp?
This speedup can produce non-minimal diffs.
|
int |
diff_levenshtein(java.util.LinkedList<Diff> diffs)
Compute the Levenshtein distance; the number of inserted, deleted or
substituted characters.
|
java.util.LinkedList<Diff> |
diff_lineMode(java.lang.String text1,
java.lang.String text2,
long deadline)
Do a quick line-level diff on both strings, then rediff the parts for
greater accuracy.
|
LinesToCharsResult |
diff_linesToChars(java.lang.String text1,
java.lang.String text2)
Split two texts into a list of strings.
|
java.util.LinkedList<Diff> |
diff_main(java.lang.String text1,
java.lang.String text2)
Find the differences between two texts.
|
java.util.LinkedList<Diff> |
diff_main(java.lang.String text1,
java.lang.String text2,
boolean checklines)
Find the differences between two texts.
|
java.lang.String |
diff_text1(java.util.LinkedList<Diff> diffs)
Compute and return the source dmp (all equalities and deletions).
|
java.lang.String |
diff_text2(java.util.LinkedList<Diff> diffs)
Compute and return the destination dmp (all equalities and insertions).
|
java.lang.String |
diff_toDelta(java.util.LinkedList<Diff> diffs)
Crush the diff into an encoded string which describes the operations
required to transform text1 into text2.
|
int |
diff_xIndex(java.util.LinkedList<Diff> diffs,
int loc)
loc is a location in text1, compute and return the equivalent location in
text2.
|
void |
diffCleanupSemantic(java.util.LinkedList<Diff> diffs)
Reduce the number of edits by eliminating semantically trivial equalities.
|
int |
diffCommonPrefix(java.lang.String text1,
java.lang.String text2)
Determine the common prefix of two strings
|
int |
diffCommonSuffix(java.lang.String text1,
java.lang.String text2)
Determine the common suffix of two strings
|
java.util.LinkedList<Diff> |
diffFromDelta(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.
|
java.lang.String |
diffPrettyHtml(java.util.LinkedList<Diff> diffs)
Convert a Diff list into a pretty HTML report.
|
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 'dmp' near 'loc' using the
Bitap algorithm.
|
int |
match_main(java.lang.String text,
java.lang.String pattern,
int loc)
Locate the best instance of 'pattern' in 'dmp' near 'loc'.
|
protected void |
patch_addContext(Patch patch,
java.lang.String text)
Increase the context until it is unique,
but don't let the pattern expand beyond Match_MaxBits.
|
java.lang.String |
patch_addPadding(java.util.LinkedList<Patch> patches)
Add some padding on dmp start and end so that edges can match something.
|
java.lang.Object[] |
patch_apply(java.util.LinkedList<Patch> patches,
java.lang.String text)
Merge a set of patches onto the dmp.
|
java.util.LinkedList<Patch> |
patch_deepCopy(java.util.LinkedList<Patch> patches)
Given an array of patches, return another array that is identical.
|
java.util.List<Patch> |
patch_fromText(java.lang.String textline)
Parse a textual representation of patches and return a List of Patch
objects.
|
java.util.LinkedList<Patch> |
patch_make(java.util.LinkedList<Diff> diffs)
Compute a list of patches to turn text1 into text2.
|
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.
|
java.util.LinkedList<Patch> |
patch_make(java.lang.String text1,
java.lang.String text2)
Compute a list of patches to turn text1 into text2.
|
java.util.LinkedList<Patch> |
patch_make(java.lang.String text1,
java.lang.String text2,
java.util.LinkedList<Diff> diffs)
Deprecated.
Prefer patch_make(String text1, LinkedList<Diff> diffs).
|
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.
|
java.lang.String |
patch_toText(java.util.List<Patch> patches)
Take a list of patches and return a textual representation.
|
public float Diff_Timeout
public short Diff_EditCost
public float Match_Threshold
public int Match_Distance
public float Patch_DeleteThreshold
public short Patch_Margin
public java.util.LinkedList<Diff> diff_main(java.lang.String text1, java.lang.String text2)
text1 - Old string to be diffed.text2 - New string to be diffed.public java.util.LinkedList<Diff> diff_main(java.lang.String text1, java.lang.String text2, boolean checklines)
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.public java.util.LinkedList<Diff> diff_lineMode(java.lang.String text1, java.lang.String text2, long deadline)
text1 - Old string to be diffed.text2 - New string to be diffed.deadline - Time when the diff should be complete by.protected java.util.LinkedList<Diff> diff_bisect(java.lang.String text1, java.lang.String text2, long deadline)
text1 - Old string to be diffed.text2 - New string to be diffed.deadline - Time at which to bail if not yet complete.public LinesToCharsResult diff_linesToChars(java.lang.String text1, java.lang.String text2)
text1 - First string.text2 - Second string.protected void diff_charsToLines(java.util.LinkedList<Diff> diffs, java.util.List<java.lang.String> lineArray)
diffs - LinkedList of Diff objects.lineArray - List of unique strings.public int diffCommonPrefix(java.lang.String text1,
java.lang.String text2)
text1 - First string.text2 - Second string.public int diffCommonSuffix(java.lang.String text1,
java.lang.String text2)
text1 - First string.text2 - Second string.protected int diff_commonOverlap(java.lang.String text1,
java.lang.String text2)
text1 - First string.text2 - Second string.protected java.lang.String[] diff_halfMatch(java.lang.String text1,
java.lang.String text2)
text1 - First string.text2 - Second string.public void diffCleanupSemantic(java.util.LinkedList<Diff> diffs)
diffs - LinkedList of Diff objects.public void diff_cleanupSemanticLossless(java.util.LinkedList<Diff> diffs)
diffs - LinkedList of Diff objects.public void diff_cleanupEfficiency(java.util.LinkedList<Diff> diffs)
diffs - LinkedList of Diff objects.public void diff_cleanupMerge(java.util.LinkedList<Diff> diffs)
diffs - LinkedList of Diff objects.public int diff_xIndex(java.util.LinkedList<Diff> diffs, int loc)
diffs - LinkedList of Diff objects.loc - Location within text1.public java.lang.String diffPrettyHtml(java.util.LinkedList<Diff> diffs)
diffs - LinkedList of Diff objects.public java.lang.String diff_text1(java.util.LinkedList<Diff> diffs)
diffs - LinkedList of Diff objects.public java.lang.String diff_text2(java.util.LinkedList<Diff> diffs)
diffs - LinkedList of Diff objects.public int diff_levenshtein(java.util.LinkedList<Diff> diffs)
diffs - LinkedList of Diff objects.public java.lang.String diff_toDelta(java.util.LinkedList<Diff> diffs)
diffs - Array of Diff objects.public java.util.LinkedList<Diff> diffFromDelta(java.lang.String text1, java.lang.String delta) throws java.lang.IllegalArgumentException
text1 - Source string for the diff.delta - Delta dmp.java.lang.IllegalArgumentException - If invalid input.public int match_main(java.lang.String text,
java.lang.String pattern,
int loc)
text - The dmp to search.pattern - The pattern to search for.loc - The location to search around.protected int match_bitap(java.lang.String text,
java.lang.String pattern,
int loc)
text - The dmp to search.pattern - The pattern to search for.loc - The location to search around.protected java.util.Map<java.lang.Character,java.lang.Integer> match_alphabet(java.lang.String pattern)
pattern - The dmp to encode.protected void patch_addContext(Patch patch, java.lang.String text)
patch - The patch to grow.text - Source dmp.public java.util.LinkedList<Patch> patch_make(java.lang.String text1, java.lang.String text2)
text1 - Old dmp.text2 - New dmp.public java.util.LinkedList<Patch> patch_make(java.util.LinkedList<Diff> diffs)
diffs - Array of Diff objects for text1 to text2.public java.util.LinkedList<Patch> patch_make(java.lang.String text1, java.lang.String text2, java.util.LinkedList<Diff> diffs)
text1 - Old dmptext2 - Ignored.diffs - Array of Diff objects for text1 to text2.public java.util.LinkedList<Patch> patch_make(java.lang.String text1, java.util.LinkedList<Diff> diffs)
text1 - Old dmp.diffs - Array of Diff objects for text1 to text2.public java.util.LinkedList<Patch> patch_deepCopy(java.util.LinkedList<Patch> patches)
patches - Array of Patch objects.public java.lang.Object[] patch_apply(java.util.LinkedList<Patch> patches, java.lang.String text)
patches - Array of Patch objectstext - Old dmp.public java.lang.String patch_addPadding(java.util.LinkedList<Patch> patches)
patches - Array of Patch objects.public void patch_splitMax(java.util.LinkedList<Patch> patches)
patches - LinkedList of Patch objects.public java.lang.String patch_toText(java.util.List<Patch> patches)
patches - List of Patch objects.public java.util.List<Patch> patch_fromText(java.lang.String textline) throws java.lang.IllegalArgumentException
textline - Text representation of patches.java.lang.IllegalArgumentException - If invalid input.Copyright © 2018. All Rights Reserved.