summaryrefslogtreecommitdiff
path: root/src/qdoc/qdoc/editdistance.cpp
diff options
context:
space:
mode:
authorLuca Di Sera <luca.disera@qt.io>2023-04-11 14:38:38 +0200
committerLuca Di Sera <luca.disera@qt.io>2023-04-12 15:06:56 +0200
commit846c860b89ee5fbef4f1db583bd951f8a33e196a (patch)
treef29b0f8ae9c1ab4d796e11e7b72cc56347e8a5e5 /src/qdoc/qdoc/editdistance.cpp
parent2ba87cd00e6527dbd64f5884f29081bd535605bb (diff)
downloadqttools-846c860b89ee5fbef4f1db583bd951f8a33e196a.tar.gz
QDoc: Move QDoc source files under a further "qdoc" directory
QDoc development under the "qttools" repository is currently performed under the "src/qdoc" directory, which contains all source files and directories relevant to QDoc as direct children. Due to a slow restructuring of how QDoc works, what its dependencies are and certain possible architectural changes, the infrastructure that is expected to be required for the development of QDoc might increase. Some of that infrastructure, which might require some custom effort, is expected to be developed as "independent" "library-like" sub-projects, which QDoc depends on. Albeit developed "independently", such infrastructure would be developed specifically for QDoc and thus should live "adjacent" to it. To allow such a structure a new "qdoc" directory was added under the "src/qdoc" directory. All source files and directory that were previously children of the "src/qdoc" directory were moved under the new "qdoc" directory. This preserves the space for QDoc-related elements and the relative project structure while allowing some space for "adjacent" projects that are intended for QDoc specifically. To support the change, a new "CMakeLists.txt" file was introduced under "src/qdoc", which dispatches to the "CMakeLists.txt" file in the new "src/qdoc/qdoc" directory. QDoc is only built when certain dependencies are found. This is supported through the use of Qt features at the CMake level. The "CMakeLists.txt" file in "src", thus dispatched to the "src/qdoc" directory only when the required features were found. As "independent", "library-like", entities might not have the same requirements as QDoc, the "CMakeLists.txt" file in "src" was modified to always dispatch to the "src/qdoc" directory while the features-check was moved to the new "CMakeLists.txt" files in "src/qdoc", so as to allow non-QDoc but QDoc-specific project to have an independent configuration for building. Certain test projects in "test/auto/qdoc/" depends on QDoc-specific source-files to generate their CMake targets. Those dependencies were generally specified as relative paths. The additional level in the directory structure invalidated the paths and, hence, the relevant "CMakeLists.txt" files for those projects were modified to correctly refer to the new directory structure. Change-Id: I50c7106614428753544eaba5091e1e44d48fd31d Reviewed-by: Topi Reiniƶ <topi.reinio@qt.io>
Diffstat (limited to 'src/qdoc/qdoc/editdistance.cpp')
-rw-r--r--src/qdoc/qdoc/editdistance.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/qdoc/qdoc/editdistance.cpp b/src/qdoc/qdoc/editdistance.cpp
new file mode 100644
index 000000000..303979ec3
--- /dev/null
+++ b/src/qdoc/qdoc/editdistance.cpp
@@ -0,0 +1,68 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+#include "editdistance.h"
+
+QT_BEGIN_NAMESPACE
+
+int editDistance(const QString &s, const QString &t)
+{
+#define D(i, j) d[(i)*n + (j)]
+ int i;
+ int j;
+ qsizetype m = s.size() + 1;
+ qsizetype n = t.size() + 1;
+ 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);
+ } 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);
+ }
+ }
+ }
+ result = D(m - 1, n - 1);
+ delete[] d;
+ return result;
+#undef D
+}
+
+QString nearestName(const QString &actual, const QSet<QString> &candidates)
+{
+ if (actual.isEmpty())
+ return QString();
+
+ int deltaBest = 10000;
+ int numBest = 0;
+ QString best;
+
+ for (const auto &candidate : candidates) {
+ if (candidate[0] == actual[0]) {
+ int delta = editDistance(actual, candidate);
+ if (delta < deltaBest) {
+ deltaBest = delta;
+ numBest = 1;
+ best = candidate;
+ } else if (delta == deltaBest) {
+ ++numBest;
+ }
+ }
+ }
+
+ if (numBest == 1 && deltaBest <= 2 && actual.size() + best.size() >= 5)
+ return best;
+
+ return QString();
+}
+
+QT_END_NAMESPACE