public final class DiffMatchPatch extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
DiffMatchPatch.Diff
Class representing one diff operation.
|
static class |
DiffMatchPatch.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.")} which means: delete "Hello", add "Goodbye" and
keep " world."
|
static class |
DiffMatchPatch.Patch
Class representing one patch operation.
|
| Modifier and Type | Field and Description |
|---|---|
short |
diffEditCost
Cost of an empty edit operation in terms of edit characters.
|
float |
diffTimeout
Number of seconds to map a diff before giving up (0 for infinity).
|
int |
matchDistance
How far to search for a match (0 = exact location, 1000+ = broad match).
|
float |
matchThreshold
At what point is no match declared (0.0 = perfection, 1.0 = very loose).
|
float |
patchDeleteThreshold
When deleting a large block of text (over ~64 characters), how close do the contents have to be to match the
expected contents.
|
short |
patchMargin
Chunk size for context length.
|
| Constructor and Description |
|---|
DiffMatchPatch() |
| Modifier and Type | Method and Description |
|---|---|
void |
diffCleanupEfficiency(LinkedList<DiffMatchPatch.Diff> diffs)
Reduce the number of edits by eliminating operationally trivial equalities.
|
void |
diffCleanupMerge(LinkedList<DiffMatchPatch.Diff> diffs)
Reorder and merge like edit sections.
|
void |
diffCleanupSemantic(LinkedList<DiffMatchPatch.Diff> diffs)
Reduce the number of edits by eliminating semantically trivial equalities.
|
void |
diffCleanupSemanticLossless(LinkedList<DiffMatchPatch.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.
|
int |
diffCommonPrefix(String text1,
String text2)
Determine the common prefix of two strings
|
int |
diffCommonSuffix(String text1,
String text2)
Determine the common suffix of two strings
|
LinkedList<DiffMatchPatch.Diff> |
diffFromDelta(String text1,
String delta)
Given the original text1, and an encoded string which describes the operations required to transform text1 into
text2, compute the full diff.
|
int |
diffLevenshtein(LinkedList<DiffMatchPatch.Diff> diffs)
Compute the Levenshtein distance; the number of inserted, deleted or substituted characters.
|
LinkedList<DiffMatchPatch.Diff> |
diffMain(String text1,
String text2)
Find the differences between two texts.
|
LinkedList<DiffMatchPatch.Diff> |
diffMain(String text1,
String text2,
boolean checklines)
Find the differences between two texts.
|
String |
diffPrettyHtml(LinkedList<DiffMatchPatch.Diff> diffs)
Convert a Diff list into a pretty HTML report.
|
String |
diffText1(LinkedList<DiffMatchPatch.Diff> diffs)
Compute and return the source text (all equalities and deletions).
|
String |
diffText2(LinkedList<DiffMatchPatch.Diff> diffs)
Compute and return the destination text (all equalities and insertions).
|
String |
diffToDelta(LinkedList<DiffMatchPatch.Diff> diffs)
Crush the diff into an encoded string which describes the operations required to transform text1 into text2.
|
int |
diffXIndex(LinkedList<DiffMatchPatch.Diff> diffs,
int loc)
loc is a location in text1, compute and return the equivalent location in text2. |
int |
matchMain(String text,
String pattern,
int loc)
Locate the best instance of 'pattern' in 'text' near 'loc'.
|
String |
patchAddPadding(LinkedList<DiffMatchPatch.Patch> patches)
Add some padding on text start and end so that edges can match something.
|
Object[] |
patchApply(LinkedList<DiffMatchPatch.Patch> patches,
String text)
Merge a set of patches onto the text.
|
LinkedList<DiffMatchPatch.Patch> |
patchDeepCopy(LinkedList<DiffMatchPatch.Patch> patches)
Given an array of patches, return another array that is identical.
|
List<DiffMatchPatch.Patch> |
patchFromText(String textline)
Parse a textual representation of patches and return a List of Patch objects.
|
LinkedList<DiffMatchPatch.Patch> |
patchMake(LinkedList<DiffMatchPatch.Diff> diffs)
Compute a list of patches to turn text1 into text2.
|
LinkedList<DiffMatchPatch.Patch> |
patchMake(String text1,
LinkedList<DiffMatchPatch.Diff> diffs)
Compute a list of patches to turn text1 into text2.
|
LinkedList<DiffMatchPatch.Patch> |
patchMake(String text1,
String text2)
Compute a list of patches to turn text1 into text2.
|
LinkedList<DiffMatchPatch.Patch> |
patchMake(String text1,
String text2,
LinkedList<DiffMatchPatch.Diff> diffs)
Deprecated.
|
void |
patchSplitMax(LinkedList<DiffMatchPatch.Patch> patches)
Look through the patches and break up any which are longer than the maximum limit of the match algorithm.
|
String |
patchToText(List<DiffMatchPatch.Patch> patches)
Take a list of patches and return a textual representation.
|
public float diffTimeout
public short diffEditCost
public float matchThreshold
public int matchDistance
public float patchDeleteThreshold
public short patchMargin
public LinkedList<DiffMatchPatch.Diff> diffMain(String text1, String text2)
text1 - Old string to be diffed.text2 - New string to be diffed.public LinkedList<DiffMatchPatch.Diff> diffMain(String text1, 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 int diffCommonPrefix(String text1, String text2)
text1 - First string.text2 - Second string.public int diffCommonSuffix(String text1, String text2)
text1 - First string.text2 - Second string.public void diffCleanupSemantic(LinkedList<DiffMatchPatch.Diff> diffs)
diffs - LinkedList of Diff objects.public void diffCleanupSemanticLossless(LinkedList<DiffMatchPatch.Diff> diffs)
The c<ins>at c</ins>ame. -> The <ins>cat </ins>came.
diffs - LinkedList of Diff objects.public void diffCleanupEfficiency(LinkedList<DiffMatchPatch.Diff> diffs)
diffs - LinkedList of Diff objects.public void diffCleanupMerge(LinkedList<DiffMatchPatch.Diff> diffs)
diffs - LinkedList of Diff objects.public int diffXIndex(LinkedList<DiffMatchPatch.Diff> diffs, int loc)
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 - LinkedList of Diff objects.loc - Location within text1.public String diffPrettyHtml(LinkedList<DiffMatchPatch.Diff> diffs)
diffs - LinkedList of Diff objects.public String diffText1(LinkedList<DiffMatchPatch.Diff> diffs)
diffs - LinkedList of Diff objects.public String diffText2(LinkedList<DiffMatchPatch.Diff> diffs)
diffs - LinkedList of Diff objects.public int diffLevenshtein(LinkedList<DiffMatchPatch.Diff> diffs)
diffs - LinkedList of Diff objects.public String diffToDelta(LinkedList<DiffMatchPatch.Diff> diffs)
=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 - Array of Diff objects.public LinkedList<DiffMatchPatch.Diff> diffFromDelta(String text1, String delta) throws IllegalArgumentException
text1 - Source string for the diff.delta - Delta text.IllegalArgumentException - If invalid input.public int matchMain(String text, String pattern, int loc)
text - The text to search.pattern - The pattern to search for.loc - The location to search around.public LinkedList<DiffMatchPatch.Patch> patchMake(String text1, String text2)
text1 - Old text.text2 - New text.public LinkedList<DiffMatchPatch.Patch> patchMake(LinkedList<DiffMatchPatch.Diff> diffs)
diffs - Array of Diff objects for text1 to text2.@Deprecated public LinkedList<DiffMatchPatch.Patch> patchMake(String text1, String text2, LinkedList<DiffMatchPatch.Diff> diffs)
patchMake(String text1, LinkedList diffs).text1 - Old texttext2 - Ignored.diffs - Array of Diff objects for text1 to text2.public LinkedList<DiffMatchPatch.Patch> patchMake(String text1, LinkedList<DiffMatchPatch.Diff> diffs)
text1 - Old text.diffs - Array of Diff objects for text1 to text2.public LinkedList<DiffMatchPatch.Patch> patchDeepCopy(LinkedList<DiffMatchPatch.Patch> patches)
patches - Array of Patch objects.public Object[] patchApply(LinkedList<DiffMatchPatch.Patch> patches, String text)
patches - Array of Patch objectstext - Old text.public String patchAddPadding(LinkedList<DiffMatchPatch.Patch> patches)
patches - Array of Patch objects.public void patchSplitMax(LinkedList<DiffMatchPatch.Patch> patches)
patches - LinkedList of Patch objects.public String patchToText(List<DiffMatchPatch.Patch> patches)
patches - List of Patch objects.public List<DiffMatchPatch.Patch> patchFromText(String textline) throws IllegalArgumentException
textline - Text representation of patches.IllegalArgumentException - If invalid input.Copyright © 2015. All rights reserved.