summaryrefslogtreecommitdiffstats
path: root/tools/assistant
diff options
context:
space:
mode:
authorck <qt-info@nokia.com>2009-11-05 12:42:45 (GMT)
committerck <qt-info@nokia.com>2009-11-05 12:42:45 (GMT)
commit47cb39013d546024a34e4bf80c76cdbd39c462b8 (patch)
tree5c21f5ca117bf68120cb2fcbcf79da05d49da691 /tools/assistant
parent8d989dc8984161d93dd03bdc370c5b59df3d39db (diff)
downloadQt-47cb39013d546024a34e4bf80c76cdbd39c462b8.zip
Qt-47cb39013d546024a34e4bf80c76cdbd39c462b8.tar.gz
Qt-47cb39013d546024a34e4bf80c76cdbd39c462b8.tar.bz2
Assistant: Speed up document encoding detection.
We now only take the head of the file into account for XML and HTML documents. Reviewed-by: kh1
Diffstat (limited to 'tools/assistant')
-rw-r--r--tools/assistant/lib/qhelp_global.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/tools/assistant/lib/qhelp_global.cpp b/tools/assistant/lib/qhelp_global.cpp
index 980de27..aa9f0dd 100644
--- a/tools/assistant/lib/qhelp_global.cpp
+++ b/tools/assistant/lib/qhelp_global.cpp
@@ -86,17 +86,17 @@ 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();
+ end = head.indexOf(QLatin1Char('>'), start) + 1;
+ 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 +105,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();
}