1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include <QtCore/QCoreApplication>
5#include <QtCore/QHash>
6#include <QtCore/QRegularExpression>
7#include <QtCore/QMutexLocker>
8#include <QtGui/QTextDocument>
9
10#include "qhelp_global.h"
11
12QString QHelpGlobal::uniquifyConnectionName(const QString &name, void *pointer)
13{
14 static QMutex mutex;
15 QMutexLocker locker(&mutex);
16
17 static QHash<QString,quint16> idHash;
18
19 return QString::fromLatin1(ba: "%1-%2-%3").
20 arg(a: name).arg(a: quintptr(pointer)).arg(a: ++idHash[name]);
21}
22
23QString QHelpGlobal::documentTitle(const QString &content)
24{
25 QString title = QCoreApplication::translate(context: "QHelp", key: "Untitled");
26 if (!content.isEmpty()) {
27 const int start = content.indexOf(s: QLatin1String("<title>"), from: 0, cs: Qt::CaseInsensitive) + 7;
28 const int end = content.indexOf(s: QLatin1String("</title>"), from: 0, cs: Qt::CaseInsensitive);
29 if ((end - start) > 0) {
30 title = content.mid(position: start, n: end - start);
31 if (Qt::mightBeRichText(title) || title.contains(c: QLatin1Char('&'))) {
32 QTextDocument doc;
33 doc.setHtml(title);
34 title = doc.toPlainText();
35 }
36 }
37 }
38 return title;
39}
40

source code of qttools/src/assistant/help/qhelp_global.cpp