21 int length1 = string1.
length();
22 int length2 = string2.
length();
38 const QChar* s1Char = s1.constData();
39 const QChar* s2Char = s2.constData();
42 int commonPrefixLen = 0;
43 while ( length1 > 0 && length2 > 0 && *s1Char == *s2Char )
53 while ( length1 > 0 && length2 > 0 && s1.at( commonPrefixLen + length1 - 1 ) == s2.at( commonPrefixLen + length2 - 1 ) )
64 else if ( length2 == 0 )
70 if ( length1 > length2 )
73 qSwap( length1, length2 );
78 col.
fill( 0, length2 + 1 );
81 for (
int i = 0; i < length2 + 1; ++i )
85 const QChar* s2start = s2Char;
86 for (
int i = 0; i < length1; ++i )
90 for (
int j = 0; j < length2; ++j )
92 col[j + 1] = qMin( qMin( 1 + col[j], 1 + prevCol[1 + j] ), prevCol[j] + (( *s1Char == *s2Char ) ? 0 : 1 ) );
98 return prevCol[length2];
119 int* currentScores =
new int [ s2.length()];
120 int* previousScores =
new int [ s2.length()];
121 int maxCommonLength = 0;
122 int lastMaxBeginIndex = 0;
124 const QChar* s1Char = s1.constData();
125 const QChar* s2Char = s2.constData();
126 const QChar* s2Start = s2Char;
128 for (
int i = 0; i < s1.length(); ++i )
130 for (
int j = 0; j < s2.length(); ++j )
132 if ( *s1Char != *s2Char )
134 currentScores[j] = 0;
138 if ( i == 0 || j == 0 )
140 currentScores[j] = 1;
144 currentScores[j] = 1 + previousScores[j - 1];
147 if ( maxCommonLength < currentScores[j] )
149 maxCommonLength = currentScores[j];
150 lastMaxBeginIndex = i;
155 qSwap( currentScores, previousScores );
159 delete [] currentScores;
160 delete [] previousScores;
161 return string1.
mid( lastMaxBeginIndex - maxCommonLength + 1, maxCommonLength );
189 const QChar* s1Char = s1.constData();
190 const QChar* s2Char = s2.constData();
192 for (
int i = 0; i < string1.
length(); ++i )
194 if ( *s1Char != *s2Char )
205 if (
string.isEmpty() )
214 for (
int i = 0; i < tmp.
length(); ++i, ++char2 )
216 if (( *char2 ).unicode() >= 0x41 && ( *char2 ).unicode() <= 0x5A && ( i == 0 || (( *char2 ).unicode() != 0x41 && ( *char2 ).unicode() != 0x45
217 && ( *char2 ).unicode() != 0x48 && ( *char2 ).unicode() != 0x49
218 && ( *char2 ).unicode() != 0x4F && ( *char2 ).unicode() != 0x55
219 && ( *char2 ).unicode() != 0x57 && ( *char2 ).unicode() != 0x59 ) ) )
230 for (
int i = 1; i < tmp.
length(); ++i, ++tmpChar )
232 switch (( *tmpChar ).unicode() )
277 for (
int i = 1; i < tmp.
length(); ++i, ++char2 )
279 if ( *char2 != *char1 )
static QString longestCommonSubstring(const QString &string1, const QString &string2, bool caseSensitive=false)
Returns the longest common substring between two strings.
QString & append(QChar ch)
void truncate(int position)
QVector< T > & fill(const T &value, int size)
static QString soundex(const QString &string)
Returns the Soundex representation of a string.
static int levenshteinDistance(const QString &string1, const QString &string2, bool caseSensitive=false)
Returns the Levenshtein edit distance between two strings.
QString & replace(int position, int n, QChar after)
QString mid(int position, int n) const
void swap(QVector< T > &other)
static int hammingDistance(const QString &string1, const QString &string2, bool caseSensitive=false)
Returns the Hamming distance between two strings.