summaryrefslogtreecommitdiff
path: root/src/qdoc/qdoc/doc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/qdoc/qdoc/doc.cpp')
-rw-r--r--src/qdoc/qdoc/doc.cpp79
1 files changed, 1 insertions, 78 deletions
diff --git a/src/qdoc/qdoc/doc.cpp b/src/qdoc/qdoc/doc.cpp
index a4d196e36..1f4e517d3 100644
--- a/src/qdoc/qdoc/doc.cpp
+++ b/src/qdoc/qdoc/doc.cpp
@@ -12,6 +12,7 @@
#include "qmltypenode.h"
#include "quoter.h"
#include "text.h"
+#include "utilities.h"
#include <qcryptographichash.h>
@@ -409,84 +410,6 @@ CodeMarker *Doc::quoteFromFile(const Location &location, Quoter &quoter, Resolve
return marker;
}
-/*!
- \brief Generates a url-friendly string representation from \a title.
-
- "Url-friendly" in this context is a string that contains only a subset of
- printable ascii characters.
-
- The subset includes alphanumeric (alnum) characters ([a-zA-Z0-9]), printable
- ascii characters, space, punctuation characters, and common symbols.
- Non-alnum characters in this subset are replaced by a single dash. Leading
- and trailing dashes are removed, such that the resulting string does not
- start or end with a dash. Any capital character is replaced by its lowercase
- counterpart.
-
- If any character in \a title is non-latin, or latin and not found in the
- aforementioned subset (e.g. 'ß', 'å', or 'ö'), a hash of \a title is
- appended to the final string.
-
- Returns a string that is normalized for the purpose of generating fragment
- identifiers for \a title in URLs.
- */
-QString Doc::canonicalTitle(const QString &title)
-{
- auto legal_ascii = [](const uint value) {
- const uint start_ascii_subset{ 32 };
- const uint end_ascii_subset{ 126 };
-
- return value >= start_ascii_subset && value <= end_ascii_subset;
- };
-
- // The code below is equivalent to the following chunk, but
- // has been measured to be approximately 4 times faster.
- //
- // QRegularExpression attributeExpr("[^A-Za-z0-9]+");
- // QString result = title.toLower();
- // result.replace(attributeExpr, " ");
- // result = result.simplified();
- // result.replace(QLatin1Char(' '), QLatin1Char('-'));
-
- QString result;
- result.reserve(title.size());
-
- bool dashAppended{false};
- bool begun{false};
- qsizetype lastAlnum{0};
- bool has_non_alnum_content{false};
-
- for (const auto &i : title) {
- uint c = i.unicode();
-
- if (!legal_ascii(c))
- has_non_alnum_content = true;
- if (c >= 'A' && c <= 'Z')
- c += 'a' - 'A';
- bool alnum = (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9');
- if (alnum) {
- result += QLatin1Char(c);
- begun = true;
- dashAppended = false;
- lastAlnum = result.size();
- } else if (!dashAppended) {
- if (begun)
- result += QLatin1Char('-');
- dashAppended = true;
- }
- }
- result.truncate(lastAlnum);
-
- if (has_non_alnum_content) {
- auto title_hash = QString::fromLocal8Bit(
- QCryptographicHash::hash(title.toUtf8(), QCryptographicHash::Md5).toHex());
- title_hash.truncate(8);
- if (!result.isEmpty())
- result.append(QLatin1Char('-'));
- result.append(title_hash);
- }
- return result;
-}
-
void Doc::detach()
{
if (m_priv == nullptr) {