summaryrefslogtreecommitdiffstats
path: root/tools/assistant/lib/qhelp_global.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/assistant/lib/qhelp_global.cpp')
-rw-r--r--tools/assistant/lib/qhelp_global.cpp22
1 files changed, 12 insertions, 10 deletions
diff --git a/tools/assistant/lib/qhelp_global.cpp b/tools/assistant/lib/qhelp_global.cpp
index 539b504..c2c916b 100644
--- a/tools/assistant/lib/qhelp_global.cpp
+++ b/tools/assistant/lib/qhelp_global.cpp
@@ -39,6 +39,7 @@
**
****************************************************************************/
+#include <QtCore/QCoreApplication>
#include <QtCore/QRegExp>
#include <QtCore/QMutexLocker>
#include <QtGui/QTextDocument>
@@ -55,12 +56,12 @@ QString QHelpGlobal::uniquifyConnectionName(const QString &name, void *pointer)
counter = 0;
return QString::fromLatin1("%1-%2-%3").
- arg(name).arg(long(pointer)).arg(counter);
+ arg(name).arg(quintptr(pointer)).arg(counter);
}
QString QHelpGlobal::documentTitle(const QString &content)
{
- QString title = QObject::tr("Untitled");
+ QString title = QCoreApplication::translate("QHelp", "Untitled");
if (!content.isEmpty()) {
int start = content.indexOf(QLatin1String("<title>"), 0, Qt::CaseInsensitive) + 7;
int end = content.indexOf(QLatin1String("</title>"), 0, Qt::CaseInsensitive);
@@ -86,17 +87,18 @@ QString QHelpGlobal::codecFromData(const QByteArray &data)
QString QHelpGlobal::codecFromHtmlData(const QByteArray &data)
{
- QString content = QString::fromUtf8(data.constData(), data.size());
- int start = content.indexOf(QLatin1String("<meta"), 0, Qt::CaseInsensitive);
+ QString head = QString::fromUtf8(data.constData(), qMin(1000, data.size()));
+ int start = head.indexOf(QLatin1String("<meta"), 0, Qt::CaseInsensitive);
if (start > 0) {
- int end;
QRegExp r(QLatin1String("charset=([^\"\\s]+)"));
while (start != -1) {
- end = content.indexOf(QLatin1Char('>'), start) + 1;
- const QString &meta = content.mid(start, end - start).toLower();
+ const int end = head.indexOf(QLatin1Char('>'), start) + 1;
+ if (end <= start)
+ break;
+ const QString &meta = head.mid(start, end - start).toLower();
if (r.indexIn(meta) != -1)
return r.cap(1);
- start = content.indexOf(QLatin1String("<meta"), end,
+ start = head.indexOf(QLatin1String("<meta"), end,
Qt::CaseInsensitive);
}
}
@@ -105,8 +107,8 @@ QString QHelpGlobal::codecFromHtmlData(const QByteArray &data)
QString QHelpGlobal::codecFromXmlData(const QByteArray &data)
{
- QString content = QString::fromUtf8(data.constData(), data.size());
+ QString head = QString::fromUtf8(data.constData(), qMin(1000, data.size()));
const QRegExp encodingExp(QLatin1String("^\\s*<\\?xml version="
"\"\\d\\.\\d\" encoding=\"([^\"]+)\"\\?>.*"));
- return encodingExp.exactMatch(content) ? encodingExp.cap(1) : QString();
+ return encodingExp.exactMatch(head) ? encodingExp.cap(1) : QString();
}