diff options
author | Paul Wicking <paul.wicking@qt.io> | 2023-05-15 11:10:23 +0200 |
---|---|---|
committer | Paul Wicking <paul.wicking@qt.io> | 2023-05-15 14:56:54 +0200 |
commit | 24085ee19751fa39db5f70d2d850ff5b82a7e400 (patch) | |
tree | 94dff7645e21cab80126abd6cef6c8c86b992c86 /src/qdoc/qdoc/docbookgenerator.cpp | |
parent | 52c8f1dbdd52f6c6e5e5419a55c456c832d8cdf4 (diff) | |
download | qttools-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/docbookgenerator.cpp')
-rw-r--r-- | src/qdoc/qdoc/docbookgenerator.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/qdoc/qdoc/docbookgenerator.cpp b/src/qdoc/qdoc/docbookgenerator.cpp index 115a9a6e1..d6e72b3b4 100644 --- a/src/qdoc/qdoc/docbookgenerator.cpp +++ b/src/qdoc/qdoc/docbookgenerator.cpp @@ -1052,7 +1052,8 @@ qsizetype DocBookGenerator::generateAtom(const Atom *atom, const Node *relative) } // If there is an anchor just after with the same ID, skip it. - if (matchAhead(atom, Atom::Target) && Doc::canonicalTitle(atom->next()->string()) == id) { + if (matchAhead(atom, Atom::Target) + && Utilities::asAsciiPrintable(atom->next()->string()) == id) { ++skipAhead; } } else { @@ -1514,7 +1515,7 @@ qsizetype DocBookGenerator::generateAtom(const Atom *atom, const Node *relative) sectionLevels.push(currentSectionLevel); m_writer->writeStartElement(dbNamespace, "section"); - writeXmlId(Doc::canonicalTitle(Text::sectionHeading(atom).toString())); + writeXmlId(Utilities::asAsciiPrintable(Text::sectionHeading(atom).toString())); newLine(); // Unlike startSectionBegin, don't start a title here. } @@ -1624,7 +1625,7 @@ qsizetype DocBookGenerator::generateAtom(const Atom *atom, const Node *relative) const Atom *next = atom->next(); QString id{""}; if (matchAhead(atom, Atom::Target)) { - id = Doc::canonicalTitle(next->string()); + id = Utilities::asAsciiPrintable(next->string()); next = next->next(); ++skipAhead; } @@ -1671,7 +1672,7 @@ qsizetype DocBookGenerator::generateAtom(const Atom *atom, const Node *relative) QString id{""}; bool hasTarget {false}; if (matchAhead(atom, Atom::Target)) { - id = Doc::canonicalTitle(atom->next()->string()); + id = Utilities::asAsciiPrintable(atom->next()->string()); ++skipAhead; hasTarget = true; } @@ -1768,13 +1769,14 @@ qsizetype DocBookGenerator::generateAtom(const Atom *atom, const Node *relative) case Atom::Target: // Sometimes, there is a \target just before a section title with the same ID. Only outut one xml:id. if (matchAhead(atom, Atom::SectionRight) && matchAhead(atom->next(), Atom::SectionLeft)) { - QString nextId = Doc::canonicalTitle(Text::sectionHeading(atom->next()->next()).toString()); - QString ownId = Doc::canonicalTitle(atom->string()); + QString nextId = Utilities::asAsciiPrintable( + Text::sectionHeading(atom->next()->next()).toString()); + QString ownId = Utilities::asAsciiPrintable(atom->string()); if (nextId == ownId) break; } - writeAnchor(Doc::canonicalTitle(atom->string())); + writeAnchor(Utilities::asAsciiPrintable(atom->string())); break; case Atom::UnhandledFormat: m_writer->writeStartElement(dbNamespace, "emphasis"); |