scaffold  1.0.0
Generates files and directories based on templates and user input
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
diff_match_patch Class Reference

#include <diff_match_patch.h>

Public Member Functions

QList< Diffdiff_main (const QString &text1, const QString &text2)
 
QList< Diffdiff_main (const QString &text1, const QString &text2, bool checklines)
 
int diff_commonPrefix (const QString &text1, const QString &text2)
 
int diff_commonSuffix (const QString &text1, const QString &text2)
 
void diff_cleanupSemantic (QList< Diff > &diffs)
 
void diff_cleanupSemanticLossless (QList< Diff > &diffs)
 
void diff_cleanupEfficiency (QList< Diff > &diffs)
 
void diff_cleanupMerge (QList< Diff > &diffs)
 
int diff_xIndex (const QList< Diff > &diffs, int loc)
 
QString diff_prettyHtml (const QList< Diff > &diffs)
 
QString diff_text1 (const QList< Diff > &diffs)
 
QString diff_text2 (const QList< Diff > &diffs)
 
int diff_levenshtein (const QList< Diff > &diffs)
 
QString diff_toDelta (const QList< Diff > &diffs)
 
QList< Diffdiff_fromDelta (const QString &text1, const QString &delta)
 
int match_main (const QString &text, const QString &pattern, int loc)
 
QList< Patchpatch_make (const QString &text1, const QString &text2)
 
QList< Patchpatch_make (const QList< Diff > &diffs)
 
QList< Patchpatch_make (const QString &text1, const QString &text2, const QList< Diff > &diffs)
 
QList< Patchpatch_make (const QString &text1, const QList< Diff > &diffs)
 
QList< Patchpatch_deepCopy (QList< Patch > &patches)
 
QPair< QString, QVector< bool > > patch_apply (QList< Patch > &patches, const QString &text)
 
QString patch_addPadding (QList< Patch > &patches)
 
void patch_splitMax (QList< Patch > &patches)
 
QString patch_toText (const QList< Patch > &patches)
 
QList< Patchpatch_fromText (const QString &textline)
 

Public Attributes

float Diff_Timeout
 
short Diff_EditCost
 
float Match_Threshold
 
int Match_Distance
 
float Patch_DeleteThreshold
 
short Patch_Margin
 
short Match_MaxBits
 

Protected Member Functions

QList< Diffdiff_bisect (const QString &text1, const QString &text2, clock_t deadline)
 
QList< QVariant > diff_linesToChars (const QString &text1, const QString &text2)
 
int diff_commonOverlap (const QString &text1, const QString &text2)
 
QStringList diff_halfMatch (const QString &text1, const QString &text2)
 
int match_bitap (const QString &text, const QString &pattern, int loc)
 
QMap< QChar, int > match_alphabet (const QString &pattern)
 
void patch_addContext (Patch &patch, const QString &text)
 

Friends

class diff_match_patch_test
 

Detailed Description

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

Member Function Documentation

QList< Diff > diff_match_patch::diff_bisect ( const QString &  text1,
const QString &  text2,
clock_t  deadline 
)
protected

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.

Parameters
text1Old string to be diffed.
text2New string to be diffed.
Returns
Linked List of Diff objects.
void diff_match_patch::diff_cleanupEfficiency ( QList< Diff > &  diffs)

Reduce the number of edits by eliminating operationally trivial equalities.

Parameters
diffsLinkedList of Diff objects.
void diff_match_patch::diff_cleanupMerge ( QList< Diff > &  diffs)

Reorder and merge like edit sections. Merge equalities. Any edit section can move as long as it doesn't cross an equality.

Parameters
diffsLinkedList of Diff objects.
void diff_match_patch::diff_cleanupSemantic ( QList< Diff > &  diffs)

Reduce the number of edits by eliminating semantically trivial equalities.

Parameters
diffsLinkedList of Diff objects.
void diff_match_patch::diff_cleanupSemanticLossless ( QList< 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.

Parameters
diffsLinkedList of Diff objects.
int diff_match_patch::diff_commonOverlap ( const QString &  text1,
const QString &  text2 
)
protected

Determine if the suffix of one string is the prefix of another.

Parameters
text1First string.
text2Second string.
Returns
The number of characters common to the end of the first string and the start of the second string.
int diff_match_patch::diff_commonPrefix ( const QString &  text1,
const QString &  text2 
)

Determine the common prefix of two strings.

Parameters
text1First string.
text2Second string.
Returns
The number of characters common to the start of each string.
int diff_match_patch::diff_commonSuffix ( const QString &  text1,
const QString &  text2 
)

Determine the common suffix of two strings.

Parameters
text1First string.
text2Second string.
Returns
The number of characters common to the end of each string.
QList< Diff > diff_match_patch::diff_fromDelta ( const QString &  text1,
const QString &  delta 
)

Given the original text1, and an encoded string which describes the operations required to transform text1 into text2, compute the full diff.

Parameters
text1Source string for the diff.
deltaDelta text.
Returns
Array of diff tuples or null if invalid.
Exceptions
QStringIf invalid input.
QStringList diff_match_patch::diff_halfMatch ( const QString &  text1,
const QString &  text2 
)
protected

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.

Parameters
text1First string.
text2Second string.
Returns
Five element String array, containing the prefix of text1, the suffix of text1, the prefix of text2, the suffix of text2 and the common middle. Or null if there was no match.
int diff_match_patch::diff_levenshtein ( const QList< Diff > &  diffs)

Compute the Levenshtein distance; the number of inserted, deleted or substituted characters.

Parameters
diffsLinkedList of Diff objects.
Returns
Number of changes.
QList< QVariant > diff_match_patch::diff_linesToChars ( const QString &  text1,
const QString &  text2 
)
protected

Split two texts into a list of strings. Reduce the texts to a string of hashes where each Unicode character represents one line.

Parameters
text1First string.
text2Second string.
Returns
Three element Object array, containing the encoded text1, the encoded text2 and the List of unique strings. The zeroth element of the List of unique strings is intentionally blank.
QList< Diff > diff_match_patch::diff_main ( const QString &  text1,
const QString &  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.

Parameters
text1Old string to be diffed.
text2New string to be diffed.
Returns
Linked List of Diff objects.
QList< Diff > diff_match_patch::diff_main ( const QString &  text1,
const QString &  text2,
bool  checklines 
)

Find the differences between two texts.

Parameters
text1Old string to be diffed.
text2New string to be diffed.
checklinesSpeedup 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.
Returns
Linked List of Diff objects.
QString diff_match_patch::diff_prettyHtml ( const QList< Diff > &  diffs)

Convert a Diff list into a pretty HTML report.

Parameters
diffsLinkedList of Diff objects.
Returns
HTML representation.
QString diff_match_patch::diff_text1 ( const QList< Diff > &  diffs)

Compute and return the source text (all equalities and deletions).

Parameters
diffsLinkedList of Diff objects.
Returns
Source text.
QString diff_match_patch::diff_text2 ( const QList< Diff > &  diffs)

Compute and return the destination text (all equalities and insertions).

Parameters
diffsLinkedList of Diff objects.
Returns
Destination text.
QString diff_match_patch::diff_toDelta ( const QList< Diff > &  diffs)

Crush the diff into an encoded string which describes the operations required to transform text1 into text2. E.g. =3-2+ing -> Keep 3 chars, delete 2 chars, insert 'ing'. Operations are tab-separated. Inserted text is escaped using xx notation.

Parameters
diffsArray of diff tuples.
Returns
Delta text.
int diff_match_patch::diff_xIndex ( const QList< 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

Parameters
diffsLinkedList of Diff objects.
locLocation within text1.
Returns
Location within text2.
QMap< QChar, int > diff_match_patch::match_alphabet ( const QString &  pattern)
protected

Initialise the alphabet for the Bitap algorithm.

Parameters
patternThe text to encode.
Returns
Hash of character locations.
int diff_match_patch::match_bitap ( const QString &  text,
const QString &  pattern,
int  loc 
)
protected

Locate the best instance of 'pattern' in 'text' near 'loc' using the Bitap algorithm. Returns -1 if no match found.

Parameters
textThe text to search.
patternThe pattern to search for.
locThe location to search around.
Returns
Best match index or -1.
int diff_match_patch::match_main ( const QString &  text,
const QString &  pattern,
int  loc 
)

Locate the best instance of 'pattern' in 'text' near 'loc'. Returns -1 if no match found.

Parameters
textThe text to search.
patternThe pattern to search for.
locThe location to search around.
Returns
Best match index or -1.
void diff_match_patch::patch_addContext ( Patch patch,
const QString &  text 
)
protected

Increase the context until it is unique, but don't let the pattern expand beyond Match_MaxBits.

Parameters
patchThe patch to grow.
textSource text.
QString diff_match_patch::patch_addPadding ( QList< Patch > &  patches)

Add some padding on text start and end so that edges can match something. Intended to be called only from within patch_apply.

Parameters
patchesArray of patch objects.
Returns
The padding string added to each side.
QPair< QString, QVector< bool > > diff_match_patch::patch_apply ( QList< Patch > &  patches,
const QString &  text 
)

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.

Parameters
patchesArray of patch objects.
textOld text.
Returns
Two element Object array, containing the new text and an array of boolean values.
QList< Patch > diff_match_patch::patch_deepCopy ( QList< Patch > &  patches)

Given an array of patches, return another array that is identical.

Parameters
patchesArray of patch objects.
Returns
Array of patch objects.
QList< Patch > diff_match_patch::patch_fromText ( const QString &  textline)

Parse a textual representation of patches and return a List of Patch objects.

Parameters
textlineText representation of patches.
Returns
List of Patch objects.
Exceptions
QStringIf invalid input.
QList< Patch > diff_match_patch::patch_make ( const QString &  text1,
const QString &  text2 
)

Compute a list of patches to turn text1 into text2. A set of diffs will be computed.

Parameters
text1Old text.
text2New text.
Returns
LinkedList of Patch objects.
QList< Patch > diff_match_patch::patch_make ( const QList< Diff > &  diffs)

Compute a list of patches to turn text1 into text2. text1 will be derived from the provided diffs.

Parameters
diffsArray of diff tuples for text1 to text2.
Returns
LinkedList of Patch objects.
QList< Patch > diff_match_patch::patch_make ( const QString &  text1,
const QString &  text2,
const QList< Diff > &  diffs 
)

Compute a list of patches to turn text1 into text2. text2 is ignored, diffs are the delta between text1 and text2.

Parameters
text1Old text.
text2Ignored.
diffsArray of diff tuples for text1 to text2.
Returns
LinkedList of Patch objects.
Deprecated:
Prefer patch_make(const QString &text1, const QList<Diff> &diffs).
QList< Patch > diff_match_patch::patch_make ( const QString &  text1,
const QList< Diff > &  diffs 
)

Compute a list of patches to turn text1 into text2. text2 is not provided, diffs are the delta between text1 and text2.

Parameters
text1Old text.
diffsArray of diff tuples for text1 to text2.
Returns
LinkedList of Patch objects.
void diff_match_patch::patch_splitMax ( QList< Patch > &  patches)

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.

Parameters
patchesLinkedList of Patch objects.
QString diff_match_patch::patch_toText ( const QList< Patch > &  patches)

Take a list of patches and return a textual representation.

Parameters
patchesList of Patch objects.
Returns
Text representation of patches.

The documentation for this class was generated from the following files: