19 #include <QStringList> 20 #include <QTextBoundaryFinder> 24 if (
string.isEmpty() )
27 switch ( capitalization )
33 return string.toUpper();
36 return string.toLower();
42 QTextBoundaryFinder wordSplitter( QTextBoundaryFinder::Word,
string.constData(),
string.length(), 0, 0 );
43 QTextBoundaryFinder letterSplitter( QTextBoundaryFinder::Grapheme,
string.constData(),
string.length(), 0, 0 );
47 #if QT_VERSION >= 0x050000 48 while (( first && wordSplitter.
boundaryReasons() & QTextBoundaryFinder::StartOfItem )
51 while (( first && wordSplitter.
boundaryReasons() & QTextBoundaryFinder::StartWord )
71 int length1 = string1.
length();
72 int length2 = string2.
length();
88 const QChar* s1Char = s1.constData();
89 const QChar* s2Char = s2.constData();
92 int commonPrefixLen = 0;
93 while ( length1 > 0 && length2 > 0 && *s1Char == *s2Char )
103 while ( length1 > 0 && length2 > 0 && s1.at( commonPrefixLen + length1 - 1 ) == s2.at( commonPrefixLen + length2 - 1 ) )
114 else if ( length2 == 0 )
120 if ( length1 > length2 )
123 qSwap( length1, length2 );
128 col.
fill( 0, length2 + 1 );
130 prevCol.
reserve( length2 + 1 );
131 for (
int i = 0; i < length2 + 1; ++i )
135 const QChar* s2start = s2Char;
136 for (
int i = 0; i < length1; ++i )
140 for (
int j = 0; j < length2; ++j )
142 col[j + 1] = qMin( qMin( 1 + col[j], 1 + prevCol[1 + j] ), prevCol[j] + (( *s1Char == *s2Char ) ? 0 : 1 ) );
148 return prevCol[length2];
169 int* currentScores =
new int [ s2.length()];
170 int* previousScores =
new int [ s2.length()];
171 int maxCommonLength = 0;
172 int lastMaxBeginIndex = 0;
174 const QChar* s1Char = s1.constData();
175 const QChar* s2Char = s2.constData();
176 const QChar* s2Start = s2Char;
178 for (
int i = 0; i < s1.length(); ++i )
180 for (
int j = 0; j < s2.length(); ++j )
182 if ( *s1Char != *s2Char )
184 currentScores[j] = 0;
188 if ( i == 0 || j == 0 )
190 currentScores[j] = 1;
194 currentScores[j] = 1 + previousScores[j - 1];
197 if ( maxCommonLength < currentScores[j] )
199 maxCommonLength = currentScores[j];
200 lastMaxBeginIndex = i;
205 qSwap( currentScores, previousScores );
209 delete [] currentScores;
210 delete [] previousScores;
211 return string1.
mid( lastMaxBeginIndex - maxCommonLength + 1, maxCommonLength );
239 const QChar* s1Char = s1.constData();
240 const QChar* s2Char = s2.constData();
242 for (
int i = 0; i < string1.
length(); ++i )
244 if ( *s1Char != *s2Char )
255 if (
string.isEmpty() )
264 for (
int i = 0; i < tmp.
length(); ++i, ++char2 )
266 if (( *char2 ).unicode() >= 0x41 && ( *char2 ).unicode() <= 0x5A && ( i == 0 || (( *char2 ).unicode() != 0x41 && ( *char2 ).unicode() != 0x45
267 && ( *char2 ).unicode() != 0x48 && ( *char2 ).unicode() != 0x49
268 && ( *char2 ).unicode() != 0x4F && ( *char2 ).unicode() != 0x55
269 && ( *char2 ).unicode() != 0x57 && ( *char2 ).unicode() != 0x59 ) ) )
280 for (
int i = 1; i < tmp.
length(); ++i, ++tmpChar )
282 switch (( *tmpChar ).unicode() )
327 for (
int i = 1; i < tmp.
length(); ++i, ++char2 )
329 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 QString capitalize(const QString &string, Capitalization capitalization)
Converts a string by applying capitalization rules to the string.
void setPosition(int position)
static int levenshteinDistance(const QString &string1, const QString &string2, bool caseSensitive=false)
Returns the Levenshtein edit distance between two strings.
Convert just the first letter of each word to uppercase, leave the rest untouched.
Convert all characters to uppercase.
Capitalization
Capitalization options.
QString & replace(int position, int n, QChar after)
QString mid(int position, int n) const
Mixed case, ie no change.
void swap(QVector< T > &other)
Convert all characters to lowercase.
BoundaryReasons boundaryReasons() const
static int hammingDistance(const QString &string1, const QString &string2, bool caseSensitive=false)
Returns the Hamming distance between two strings.