summaryrefslogtreecommitdiff
path: root/src/qdoc/editdistance.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/qdoc/editdistance.cpp')
-rw-r--r--src/qdoc/editdistance.cpp40
1 files changed, 19 insertions, 21 deletions
diff --git a/src/qdoc/editdistance.cpp b/src/qdoc/editdistance.cpp
index c96071bf0..841f5f48d 100644
--- a/src/qdoc/editdistance.cpp
+++ b/src/qdoc/editdistance.cpp
@@ -36,7 +36,7 @@ QT_BEGIN_NAMESPACE
int editDistance(const QString &s, const QString &t)
{
-#define D( i, j ) d[(i) * n + (j)]
+#define D(i, j) d[(i)*n + (j)]
int i;
int j;
int m = s.length() + 1;
@@ -44,23 +44,23 @@ int editDistance(const QString &s, const QString &t)
int *d = new int[m * n];
int result;
- for ( i = 0; i < m; i++ )
- D( i, 0 ) = i;
- for ( j = 0; j < n; j++ )
- D( 0, j ) = j;
- for ( i = 1; i < m; i++ ) {
- for ( j = 1; j < n; j++ ) {
- if ( s[i - 1] == t[j - 1] ) {
- D( i, j ) = D( i - 1, j - 1 );
+ for (i = 0; i < m; ++i)
+ D(i, 0) = i;
+ for (j = 0; j < n; ++j)
+ D(0, j) = j;
+ for (i = 1; i < m; ++i) {
+ for (j = 1; j < n; ++j) {
+ if (s[i - 1] == t[j - 1]) {
+ D(i, j) = D(i - 1, j - 1);
} else {
- int x = D( i - 1, j );
- int y = D( i - 1, j - 1 );
- int z = D( i, j - 1 );
- D( i, j ) = 1 + qMin( qMin(x, y), z );
+ int x = D(i - 1, j);
+ int y = D(i - 1, j - 1);
+ int z = D(i, j - 1);
+ D(i, j) = 1 + qMin(qMin(x, y), z);
}
}
}
- result = D( m - 1, n - 1 );
+ result = D(m - 1, n - 1);
delete[] d;
return result;
#undef D
@@ -75,19 +75,17 @@ QString nearestName(const QString &actual, const QSet<QString> &candidates)
int numBest = 0;
QString best;
- QSet<QString>::ConstIterator c = candidates.constBegin();
- while (c != candidates.constEnd()) {
- if ((*c)[0] == actual[0]) {
- int delta = editDistance(actual, *c);
+ for (const auto &candidate : candidates) {
+ if (candidate[0] == actual[0]) {
+ int delta = editDistance(actual, candidate);
if (delta < deltaBest) {
deltaBest = delta;
numBest = 1;
- best = *c;
+ best = candidate;
} else if (delta == deltaBest) {
- numBest++;
+ ++numBest;
}
}
- ++c;
}
if (numBest == 1 && deltaBest <= 2 && actual.length() + best.length() >= 5)