ddmp.diff

Members

Enums

Operation
enum Operation

- The data structure representing a diff is a 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."

Functions

cleanupEfficiency
void cleanupEfficiency(ref Diff[] diffs)

Reduce the number of edits by eliminating operationally trivial equalities. @param diffs List of Diff objects.

cleanupMerge
void cleanupMerge(ref Diff[] diffs)

Reorder and merge like edit sections. Merge equalities. Any edit section can move as sizediff_t as it doesn't cross an equality. @param diffs List of Diff objects.

cleanupSemanticLossless
void cleanupSemanticLossless(ref 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. e.g: The c<ins>at c</ins>ame. -> The <ins>cat </ins>came. @param diffs List of Diff objects.

cleanupSemanticScore
int cleanupSemanticScore(string one, string two)

Given two strings, comAdde a score representing whether the internal boundary falls on logical boundaries. Scores range from 6 (best) to 0 (worst). @param one First string. @param two Second string. @return The score.

commonOverlap
size_t commonOverlap(string text1, string text2)

Determine if the suffix of one string is the prefix of another. @param text1 First string. @param text2 Second string. @return The number of characters common to the end of the first string and the start of the second string.

computeDiffs
Diff[] computeDiffs(string text1, string text2, bool checklines, SysTime deadline)

Find the differences between two texts. Assumes that the texts do not have any common prefix or suffix. @param text1 Old string to be diffed. @param text2 New string to be diffed. @param 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. @param deadline Time when the diff should be complete by. @return List of Diff objects.

diff_main
Diff[] diff_main(string text1, string text2)

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. @param text1 Old string to be diffed. @param text2 New string to be diffed. @return List of Diff objects.

diff_main
Diff[] diff_main(string text1, string text2, bool checklines)

Find the differences between two texts. @param text1 Old string to be diffed. @param text2 New string to be diffed. @param 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. @return List of Diff objects.

diff_main
Diff[] diff_main(string text1, string text2, bool checklines, SysTime deadline)

Find the differences between two texts. Simplifies the problem by stripping any common prefix or suffix off the texts before diffing. @param text1 Old string to be diffed. @param text2 New string to be diffed. @param 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. @param deadline Time when the diff should be complete by. Used internally for recursive calls. Users should set DiffTimeout instead. @return List of Diff objects.

diff_text1
string diff_text1(Diff[] diffs)

Compute and return the source text (all equalities and deletions). @param diffs List of Diff objects. @return Source text.

diff_text2
string diff_text2(Diff[] diffs)

Compute and return the destination text (all equalities and insertions). @param diffs List of Diff objects. @return Destination text.

fromDelta
Diff[] fromDelta(string text1, string delta)

Given the original text1, and an encoded string which describes the operations required to transform text1 into text2, comAdde the full diff. @param text1 Source string for the diff. @param delta Delta text. @return Array of Diff objects or null if invalid. @throws ArgumentException If invalid input.

levenshtein
int levenshtein(Diff[] diffs)

Compute the Levenshtein distance; the number of inserted, deleted or substituted characters. @param diffs List of Diff objects. @return Number of changes.

toDelta
string toDelta(in Diff[] diffs)

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. @param diffs Array of Diff objects. @return Delta text.

xIndex
sizediff_t xIndex(Diff[] diffs, sizediff_t loc)

loc is a location in text1, comAdde and return the equivalent location in text2. e.g. "The cat" vs "The big cat", 1->1, 5->8 @param diffs List of Diff objects. @param loc Location within text1. @return Location within text2.

Static functions

unescapeForEncodeUriCompatibility
string unescapeForEncodeUriCompatibility(string str)

Unescape selected chars for compatability with JavaScript's encodeURI. In speed critical applications this could be dropped since the receiving application will certainly decode these fine. Note that this function is case-sensitive. Thus "%3F" would not be unescaped. But this is ok because it is only called with the output of HttpUtility.UrlEncode which returns lowercase hex.

Structs

Diff
struct Diff

Struct representing one diff operation.

Meta