summaryrefslogtreecommitdiff
path: root/src/qdoc/qdoc/tree.cpp
diff options
context:
space:
mode:
authorPaul Wicking <paul.wicking@qt.io>2023-05-15 11:10:23 +0200
committerPaul Wicking <paul.wicking@qt.io>2023-05-15 14:56:54 +0200
commit24085ee19751fa39db5f70d2d850ff5b82a7e400 (patch)
tree94dff7645e21cab80126abd6cef6c8c86b992c86 /src/qdoc/qdoc/tree.cpp
parent52c8f1dbdd52f6c6e5e5419a55c456c832d8cdf4 (diff)
downloadqttools-24085ee19751fa39db5f70d2d850ff5b82a7e400.tar.gz
QDoc: Merge Doc::canonicalTitle and Utilities::canonicalizeFileName
Following recent bug fixes in QDoc, it has become apparent that the implementations of `Utilities::canonicalizeFileName` and `Doc::canonicalTitle` are mostly identical. This violates the DRY principle. The use of the former method to normalize generate values for HTML class attributes, shows that the problem the method solves is also closely related to generating HTML. The latter method specifically generates "URL friendly" strings for fragment identifiers in URLs. This indicates that both methods are poorly named, and that they both see use relating to the same problem domain. This patch merges the two implementations to reduce code duplication. `Doc::canonicalTitle` is removed, and `Utilities::canonicalizeFileName` is renamed to `asAsciiPrintable` to better represent its purpose. The documentation is updated. All call sites are updated to use the new method. As there is no unit test for either method, no tests are modified. Fixes: QTBUG-113606 Change-Id: I1fd6a654075fdf8e719bf504b1d702737dd1e42e Reviewed-by: Topi Reiniƶ <topi.reinio@qt.io>
Diffstat (limited to 'src/qdoc/qdoc/tree.cpp')
-rw-r--r--src/qdoc/qdoc/tree.cpp18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/qdoc/qdoc/tree.cpp b/src/qdoc/qdoc/tree.cpp
index 02f422061..900b299c3 100644
--- a/src/qdoc/qdoc/tree.cpp
+++ b/src/qdoc/qdoc/tree.cpp
@@ -722,7 +722,7 @@ QString Tree::getRef(const QString &target, const Node *node) const
++it;
} while (it != m_nodesByTargetTitle.constEnd() && it.key() == target);
}
- QString key = Doc::canonicalTitle(target);
+ QString key = Utilities::asAsciiPrintable(target);
it = m_nodesByTargetRef.constFind(key);
if (it != m_nodesByTargetRef.constEnd()) {
do {
@@ -758,7 +758,7 @@ void Tree::resolveTargets(Aggregate *root)
QString key = node->title();
if (!key.isEmpty()) {
if (key.contains(QChar(' ')))
- key = Doc::canonicalTitle(key);
+ key = Utilities::asAsciiPrintable(key);
QList<PageNode *> nodes = m_pageNodesByTitle.values(key);
bool alreadyThere = false;
if (!nodes.empty()) {
@@ -782,7 +782,7 @@ void Tree::resolveTargets(Aggregate *root)
QString ref = refForAtom(i);
QString title = Text::sectionHeading(i).toString();
if (!ref.isEmpty() && !title.isEmpty()) {
- QString key = Doc::canonicalTitle(title);
+ QString key = Utilities::asAsciiPrintable(title);
auto *target = new TargetRec(ref, TargetRec::Contents, child, 3);
m_nodesByTargetRef.insert(key, target);
m_nodesByTargetTitle.insert(title, target);
@@ -796,7 +796,7 @@ void Tree::resolveTargets(Aggregate *root)
QString title = i->string();
if (!ref.isEmpty() && !title.isEmpty()) {
auto *target = new TargetRec(ref, TargetRec::Keyword, child, 1);
- m_nodesByTargetRef.insert(Doc::canonicalTitle(title), target);
+ m_nodesByTargetRef.insert(Utilities::asAsciiPrintable(title), target);
m_nodesByTargetTitle.insert(title, target);
}
}
@@ -807,7 +807,7 @@ void Tree::resolveTargets(Aggregate *root)
QString ref = refForAtom(i);
QString title = i->string();
if (!ref.isEmpty() && !title.isEmpty()) {
- QString key = Doc::canonicalTitle(title);
+ QString key = Utilities::asAsciiPrintable(title);
auto *target = new TargetRec(ref, TargetRec::Target, child, 2);
m_nodesByTargetRef.insert(key, target);
m_nodesByTargetTitle.insert(title, target);
@@ -841,7 +841,7 @@ const TargetRec *Tree::findUnambiguousTarget(const QString &target, Node::Genus
TargetRec *bestTarget = findBestCandidate(m_nodesByTargetTitle, target);
if (!bestTarget)
- bestTarget = findBestCandidate(m_nodesByTargetRef, Doc::canonicalTitle(target));
+ bestTarget = findBestCandidate(m_nodesByTargetRef, Utilities::asAsciiPrintable(target));
return bestTarget;
}
@@ -853,7 +853,7 @@ const PageNode *Tree::findPageNodeByTitle(const QString &title) const
{
PageNodeMultiMap::const_iterator it;
if (title.contains(QChar(' ')))
- it = m_pageNodesByTitle.constFind(Doc::canonicalTitle(title));
+ it = m_pageNodesByTitle.constFind(Utilities::asAsciiPrintable(title));
else
it = m_pageNodesByTitle.constFind(title);
if (it != m_pageNodesByTitle.constEnd()) {
@@ -890,9 +890,9 @@ QString Tree::refForAtom(const Atom *atom)
{
if (atom) {
if (atom->type() == Atom::SectionLeft)
- return Doc::canonicalTitle(Text::sectionHeading(atom).toString());
+ return Utilities::asAsciiPrintable(Text::sectionHeading(atom).toString());
if ((atom->type() == Atom::Target) || (atom->type() == Atom::Keyword))
- return Doc::canonicalTitle(atom->string());
+ return Utilities::asAsciiPrintable(atom->string());
}
return QString();
}