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 "qhelp_global.h"
5
6#include <QtCore/qcoreapplication.h>
7#include <QtCore/qhash.h>
8#include <QtCore/qmutex.h>
9#include <QtGui/qtextdocument.h>
10
11QT_BEGIN_NAMESPACE
12
13using namespace Qt::StringLiterals;
14
15QString QHelpGlobal::uniquifyConnectionName(const QString &name, void *pointer)
16{
17 static QMutex mutex;
18 QMutexLocker locker(&mutex);
19 static QHash<QString, quint16> idHash;
20 return QString::asprintf(format: "%ls-%p-%d", qUtf16Printable(name), pointer, ++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: "<title>"_L1, from: 0, cs: Qt::CaseInsensitive) + 7;
28 const int end = content.indexOf(s: "</title>"_L1, 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: u'&')) {
32 QTextDocument doc;
33 doc.setHtml(title);
34 title = doc.toPlainText();
35 }
36 }
37 }
38 return title;
39}
40
41QT_END_NAMESPACE
42

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

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