summaryrefslogtreecommitdiff
path: root/src/qdoc/qdoc/htmlgenerator.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/htmlgenerator.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/htmlgenerator.cpp')
-rw-r--r--src/qdoc/qdoc/htmlgenerator.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/qdoc/qdoc/htmlgenerator.cpp b/src/qdoc/qdoc/htmlgenerator.cpp
index 545541aad..c7faf7276 100644
--- a/src/qdoc/qdoc/htmlgenerator.cpp
+++ b/src/qdoc/qdoc/htmlgenerator.cpp
@@ -528,7 +528,7 @@ qsizetype HtmlGenerator::generateAtom(const Atom *atom, const Node *relative, Co
for (const auto &section : sinceSections) {
if (!section.members().isEmpty()) {
out() << "<li>"
- << "<a href=\"#" << Doc::canonicalTitle(section.title()) << "\">"
+ << "<a href=\"#" << Utilities::asAsciiPrintable(section.title()) << "\">"
<< section.title() << "</a></li>\n";
}
}
@@ -537,7 +537,7 @@ qsizetype HtmlGenerator::generateAtom(const Atom *atom, const Node *relative, Co
int index = 0;
for (const auto &section : sinceSections) {
if (!section.members().isEmpty()) {
- out() << "<h3 id=\"" << Doc::canonicalTitle(section.title()) << "\">"
+ out() << "<h3 id=\"" << Utilities::asAsciiPrintable(section.title()) << "\">"
<< protectEnc(section.title()) << "</h3>\n";
if (index == Sections::SinceClasses)
generateCompactList(Generic, relative, ncmap, false, QStringLiteral("Q"));
@@ -867,7 +867,7 @@ qsizetype HtmlGenerator::generateAtom(const Atom *atom, const Node *relative, Co
case Atom::SectionHeadingLeft: {
int unit = atom->string().toInt() + hOffset(relative);
out() << "<h" + QString::number(unit) + QLatin1Char(' ') << "id=\""
- << Doc::canonicalTitle(Text::sectionHeading(atom).toString()) << "\">";
+ << Utilities::asAsciiPrintable(Text::sectionHeading(atom).toString()) << "\">";
m_inSectionHeading = true;
break;
}
@@ -970,7 +970,7 @@ qsizetype HtmlGenerator::generateAtom(const Atom *atom, const Node *relative, Co
case Atom::Keyword:
break;
case Atom::Target:
- out() << "<span id=\"" << Doc::canonicalTitle(atom->string()) << "\"></span>";
+ out() << "<span id=\"" << Utilities::asAsciiPrintable(atom->string()) << "\"></span>";
break;
case Atom::UnhandledFormat:
out() << "<b class=\"redFont\">&lt;Missing HTML&gt;</b>";
@@ -2123,7 +2123,7 @@ void HtmlGenerator::addStatusToMap(const Aggregate *aggregate, QMap<QString, Tex
if (aggregate->status() == Node::Deprecated)
spanClass = u"deprecated"_s; // Disregard any version info
else
- spanClass = Utilities::canonicalizeFileName(status.value());
+ spanClass = Utilities::asAsciiPrintable(status.value());
text.clear();
text << Atom(Atom::String, status.value())
@@ -2367,7 +2367,7 @@ void HtmlGenerator::generateTableOfContents(const Node *node, CodeMarker *marker
Text headingText = Text::sectionHeading(atom);
QString s = headingText.toString();
out() << "<li class=\"level" << sectionNumber << "\">";
- out() << "<a href=\"" << '#' << Doc::canonicalTitle(s) << "\">";
+ out() << "<a href=\"" << '#' << Utilities::asAsciiPrintable(s) << "\">";
generateAtomList(headingText.firstAtom(), node, marker, true, numAtoms);
out() << "</a></li>\n";
}