Workspace 6.21.5
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | List of all members
TextDifferencer Class Reference

#include <Tools/Widgets/textdifferencer.h>

Public Member Functions

 TextDifferencer ()
 
void cleanupEfficiency (QList< TextDifference > &diffs)
 
void cleanupMerge (QList< TextDifference > &diffs)
 
void cleanupSemantic (QList< TextDifference > &diffs)
 
void cleanupSemanticLossless (QList< TextDifference > &diffs)
 
int findCommonPrefix (const QString &text1, const QString &text2)
 
int findCommonSuffix (const QString &text1, const QString &text2)
 
QList< TextDifferencefindDifferences (const QString &text1, const QString &text2)
 
QList< TextDifferencefindDifferences (const QString &text1, const QString &text2, bool checklines)
 

Static Public Member Functions

static QMap< int, StringHighlightscompareLines (int keyA, int keyB, const QString &stringA, const QString &stringB)
 

Public Attributes

short diffEditCost_
 
float diffTimeout_
 

Protected Member Functions

QList< TextDifferencebisect (const QString &text1, const QString &text2, clock_t deadline)
 
int findCommonOverlap (const QString &text1, const QString &text2)
 
QStringList halfMatch (const QString &text1, const QString &text2)
 
QList< QVariant > linesToChars (const QString &text1, const QString &text2)
 

Constructor & Destructor Documentation

◆ TextDifferencer()

Member Function Documentation

◆ bisect()

QList< TextDifference > 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.
deadlineOperation returns if this time is reached (comparison with clock()>deadline)
Returns
List of TextDifference objects.

◆ cleanupEfficiency()

void cleanupEfficiency ( QList< TextDifference > &  diffs)

Reduce the number of edits by eliminating operationally trivial equalities.

Parameters
diffsLinkedList of Diff objects.

◆ cleanupMerge()

void cleanupMerge ( QList< TextDifference > &  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.

◆ cleanupSemantic()

void cleanupSemantic ( QList< TextDifference > &  diffs)

Reduce the number of edits by eliminating semantically trivial equalities.

Parameters
diffsList of TextDifference objects.

◆ cleanupSemanticLossless()

void cleanupSemanticLossless ( QList< TextDifference > &  diffs)

◆ compareLines()

QMap< int, StringHighlights > compareLines ( int  keyA,
int  keyB,
const QString &  stringA,
const QString &  stringB 
)
static

◆ findCommonOverlap()

int findCommonOverlap ( 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.

◆ findCommonPrefix()

int findCommonPrefix ( 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.

◆ findCommonSuffix()

int findCommonSuffix ( 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.

◆ findDifferences() [1/2]

QList< TextDifference > findDifferences ( 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
List of TextDifference objects.

◆ findDifferences() [2/2]

QList< TextDifference > findDifferences ( 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
List of TextDifference objects.

◆ halfMatch()

QStringList 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.

◆ linesToChars()

QList< QVariant > 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.

Member Data Documentation

◆ diffEditCost_

short diffEditCost_

◆ diffTimeout_

float diffTimeout_