DiffMatchPatch class

Class containing the diff, match and patch methods. Also contains the behaviour settings.

Constructors

DiffMatchPatch()

Properties

blanklineEndRegex_ RegExp
final
blanklineStartRegex_ RegExp
final
Diff_EditCost int
Cost of an empty edit operation in terms of edit characters.
getter/setter pair
Diff_Timeout double
Number of seconds to map a diff before giving up (0 for infinity).
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
linebreakRegex_ RegExp
final
Match_Distance int
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).
getter/setter pair
Match_MaxBits int
The number of bits in an int.
getter/setter pair
Match_Threshold double
At what point is no match declared (0.0 = perfection, 1.0 = very loose).
getter/setter pair
nonAlphaNumericRegex_ RegExp
final
Patch_DeleteThreshold double
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.
getter/setter pair
Patch_Margin int
Chunk size for context length.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
whitespaceRegex_ RegExp
final

Methods

diff_cleanupEfficiency(List<Diff> diffs) → void
Reduce the number of edits by eliminating operationally trivial equalities. diffs is a List of Diff objects.
diff_cleanupMerge(List<Diff> diffs) → void
Reorder and merge like edit sections. Merge equalities. Any edit section can move as long as it doesn't cross an equality. diffs is a List of Diff objects.
diff_cleanupSemantic(List<Diff> diffs) → void
Reduce the number of edits by eliminating semantically trivial equalities. diffs is a List of Diff objects.
diff_commonPrefix(String text1, String text2) int
Determine the common prefix of two strings text1 is the first string. text2 is the second string. Returns the number of characters common to the start of each string.
diff_commonSuffix(String text1, String text2) int
Determine the common suffix of two strings text1 is the first string. text2 is the second string. Returns the number of characters common to the end of each string.
diff_fromDelta(String text1, String delta) List<Diff>
Given the original text1, and an encoded string which describes the operations required to transform text1 into text2, compute the full diff. text1 is the source string for the diff. delta is the delta text. Returns a List of Diff objects or null if invalid. Throws ArgumentError if invalid input.
diff_levenshtein(List<Diff> diffs) int
Compute the Levenshtein distance; the number of inserted, deleted or substituted characters. diffs is a List of Diff objects. Returns the number of changes.
diff_main(String text1, String text2, [bool checklines = true, DateTime? deadline]) List<Diff>
Find the differences between two texts. Simplifies the problem by stripping any common prefix or suffix off the texts before diffing. text1 is the old string to be diffed. text2 is the new string to be diffed. checklines is an 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. deadline is an optional time when the diff should be complete by. Used internally for recursive calls. Users should set DiffTimeout instead. Returns a List of Diff objects.
diff_prettyHtml(List<Diff> diffs) String
Convert a Diff list into a pretty HTML report. diffs is a List of Diff objects. Returns an HTML representation.
diff_text1(List<Diff> diffs) String
Compute and return the source text (all equalities and deletions). diffs is a List of Diff objects. Returns the source text.
diff_text2(List<Diff> diffs) String
Compute and return the destination text (all equalities and insertions). diffs is a List of Diff objects. Returns the destination text.
diff_toDelta(List<Diff> diffs) String
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 is a List of Diff objects. Returns the delta text.
diff_xIndex(List<Diff> diffs, int loc) int
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 is a List of Diff objects. loc is the location within text1. Returns the location within text2.
match_main(String? text, String? pattern, int loc) int
Locate the best instance of 'pattern' in 'text' near 'loc'. Returns -1 if no match found. text is the text to search. pattern is the pattern to search for. loc is the location to search around. Returns the best match index or -1.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
patch_addPadding(List<Patch> patches) String
Add some padding on text start and end so that edges can match something. Intended to be called only from within patch_apply. patches is a List of Patch objects. Returns the padding string added to each side.
patch_apply(List<Patch> patches, String text) → Pair<String, Map<int, bool>>
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 is a List of Patch objects text is the old text.
patch_deepCopy(List<Patch> patches) List<Patch>
Given an array of patches, return another array that is identical. patches is a List of Patch objects. Returns a List of Patch objects.
patch_diffs(List<Diff> diffs) List<Patch>
Compute a list of patches to turn text1 into text2.
patch_fromText(String textline) List<Patch>
Parse a textual representation of patches and return a List of Patch objects. textline is a text representation of patches. Returns a List of Patch objects. Throws ArgumentError if invalid input.
patch_main(String text1, String text2) List<Patch>
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:
patch_make(String text1, List<Diff> diffs) List<Patch>
Compute a list of patches to turn text1 into text2.
patch_splitMax(List<Patch> patches) → dynamic
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 is a List of Patch objects.
patch_toText(List<Patch> patches) String
Take a list of patches and return a textual representation. patches is a List of Patch objects. Returns a text representation of patches.
test_diff_bisect(String text1, String text2, DateTime deadline) List<Diff>
Hack to allow unit tests to call private method. Do not use.
test_diff_charsToLines(List<Diff> diffs, List<String> lineArray) → void
Hack to allow unit tests to call private method. Do not use.
test_diff_cleanupSemanticLossless(List<Diff> diffs) → void
Hack to allow unit tests to call private method. Do not use.
test_diff_commonOverlap(String text1, String text2) int
Hack to allow unit tests to call private method. Do not use.
test_diff_halfMatch(String text1, String text2) List<String>?
Hack to allow unit tests to call private method. Do not use.
test_diff_linesToChars(String text1, String text2) Map<String, dynamic>
Hack to allow unit tests to call private method. Do not use.
test_match_alphabet(String pattern) Map<String, int>
Hack to allow unit tests to call private method. Do not use.
test_match_bitap(String text, String pattern, int loc) int
Hack to allow unit tests to call private method. Do not use.
test_patch_addContext(Patch patch, String text) → void
Hack to allow unit tests to call private method. Do not use.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited