summaryrefslogtreecommitdiffstats
path: root/src/corelib/mimetypes
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/mimetypes')
-rw-r--r--src/corelib/mimetypes/qmimedatabase.cpp63
-rw-r--r--src/corelib/mimetypes/qmimedatabase.h34
-rw-r--r--src/corelib/mimetypes/qmimedatabase_p.h34
-rw-r--r--src/corelib/mimetypes/qmimeglobpattern.cpp46
-rw-r--r--src/corelib/mimetypes/qmimeglobpattern_p.h53
-rw-r--r--src/corelib/mimetypes/qmimemagicrule.cpp259
-rw-r--r--src/corelib/mimetypes/qmimemagicrule_p.h81
-rw-r--r--src/corelib/mimetypes/qmimemagicrulematcher.cpp36
-rw-r--r--src/corelib/mimetypes/qmimemagicrulematcher_p.h42
-rw-r--r--src/corelib/mimetypes/qmimeprovider.cpp68
-rw-r--r--src/corelib/mimetypes/qmimeprovider_p.h34
-rw-r--r--src/corelib/mimetypes/qmimetype.cpp47
-rw-r--r--src/corelib/mimetypes/qmimetype.h34
-rw-r--r--src/corelib/mimetypes/qmimetype_p.h34
-rw-r--r--src/corelib/mimetypes/qmimetypeparser.cpp101
-rw-r--r--src/corelib/mimetypes/qmimetypeparser_p.h36
16 files changed, 537 insertions, 465 deletions
diff --git a/src/corelib/mimetypes/qmimedatabase.cpp b/src/corelib/mimetypes/qmimedatabase.cpp
index 5c272d420b..f786b2ae03 100644
--- a/src/corelib/mimetypes/qmimedatabase.cpp
+++ b/src/corelib/mimetypes/qmimedatabase.cpp
@@ -1,32 +1,38 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
+** Copyright (C) 2016 The Qt Company Ltd.
** Copyright (C) 2015 Klaralvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author David Faure <david.faure@kdab.com>
-** Contact: http://www.qt.io/licensing/
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
@@ -47,11 +53,11 @@
#include <QtCore/QSet>
#include <QtCore/QBuffer>
#include <QtCore/QUrl>
-#include <QtCore/QStack>
#include <QtCore/QDebug>
#include <algorithm>
#include <functional>
+#include <stack>
QT_BEGIN_NAMESPACE
@@ -107,7 +113,8 @@ QStringList QMimeDatabasePrivate::mimeTypeForFileName(const QString &fileName, Q
if (fileName.endsWith(QLatin1Char('/')))
return QStringList() << QLatin1String("inode/directory");
- const QStringList matchingMimeTypes = provider()->findByFileName(QFileInfo(fileName).fileName(), foundSuffix);
+ QStringList matchingMimeTypes = provider()->findByFileName(QFileInfo(fileName).fileName(), foundSuffix);
+ matchingMimeTypes.sort(); // make it deterministic
return matchingMimeTypes;
}
@@ -186,7 +193,7 @@ QMimeType QMimeDatabasePrivate::mimeTypeForFileNameAndData(const QString &fileNa
// "for glob_match in glob_matches:"
// "if glob_match is subclass or equal to sniffed_type, use glob_match"
const QString sniffedMime = candidateByData.name();
- foreach (const QString &m, candidatesByName) {
+ for (const QString &m : qAsConst(candidatesByName)) {
if (inherits(m, sniffedMime)) {
// We have magic + pattern pointing to this, so it's a pretty good match
*accuracyPtr = 100;
@@ -200,7 +207,6 @@ QMimeType QMimeDatabasePrivate::mimeTypeForFileNameAndData(const QString &fileNa
if (candidatesByName.count() > 1) {
*accuracyPtr = 20;
- candidatesByName.sort(); // to make it deterministic
const QMimeType mime = mimeTypeForName(candidatesByName.at(0));
if (mime.isValid())
return mime;
@@ -218,13 +224,14 @@ bool QMimeDatabasePrivate::inherits(const QString &mime, const QString &parent)
{
const QString resolvedParent = provider()->resolveAlias(parent);
//Q_ASSERT(provider()->resolveAlias(mime) == mime);
- QStack<QString> toCheck;
+ std::stack<QString, QStringList> toCheck;
toCheck.push(mime);
- while (!toCheck.isEmpty()) {
- const QString current = toCheck.pop();
- if (current == resolvedParent)
+ while (!toCheck.empty()) {
+ if (toCheck.top() == resolvedParent)
return true;
- foreach (const QString &par, provider()->parents(current))
+ const auto parents = provider()->parents(toCheck.top());
+ toCheck.pop();
+ for (const QString &par : parents)
toCheck.push(par);
}
return false;
@@ -278,7 +285,7 @@ bool QMimeDatabasePrivate::inherits(const QString &mime, const QString &parent)
\snippet code/src_corelib_mimetype_qmimedatabase.cpp 0
- \sa QMimeType
+ \sa QMimeType, {MIME Type Browser Example}
*/
/*!
@@ -399,7 +406,7 @@ QMimeType QMimeDatabase::mimeTypeForFile(const QString &fileName, MatchMode mode
{
if (mode == MatchExtension) {
QMutexLocker locker(&d->mutex);
- QStringList matches = d->mimeTypeForFileName(fileName);
+ const QStringList matches = d->mimeTypeForFileName(fileName);
const int matchCount = matches.count();
if (matchCount == 0) {
return d->mimeTypeForName(d->defaultMimeType());
@@ -407,7 +414,6 @@ QMimeType QMimeDatabase::mimeTypeForFile(const QString &fileName, MatchMode mode
return d->mimeTypeForName(matches.first());
} else {
// We have to pick one.
- matches.sort(); // Make it deterministic
return d->mimeTypeForName(matches.first());
}
} else {
@@ -433,11 +439,10 @@ QList<QMimeType> QMimeDatabase::mimeTypesForFileName(const QString &fileName) co
{
QMutexLocker locker(&d->mutex);
- QStringList matches = d->mimeTypeForFileName(fileName);
+ const QStringList matches = d->mimeTypeForFileName(fileName);
QList<QMimeType> mimes;
- matches.sort(); // Make it deterministic
mimes.reserve(matches.count());
- foreach (const QString &mime, matches)
+ for (const QString &mime : matches)
mimes.append(d->mimeTypeForName(mime));
return mimes;
}
diff --git a/src/corelib/mimetypes/qmimedatabase.h b/src/corelib/mimetypes/qmimedatabase.h
index fd19636e27..358f0ab779 100644
--- a/src/corelib/mimetypes/qmimedatabase.h
+++ b/src/corelib/mimetypes/qmimedatabase.h
@@ -1,32 +1,38 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
+** Copyright (C) 2016 The Qt Company Ltd.
** Copyright (C) 2015 Klaralvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author David Faure <david.faure@kdab.com>
-** Contact: http://www.qt.io/licensing/
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
diff --git a/src/corelib/mimetypes/qmimedatabase_p.h b/src/corelib/mimetypes/qmimedatabase_p.h
index 1ac7264a9e..4ff5110a5b 100644
--- a/src/corelib/mimetypes/qmimedatabase_p.h
+++ b/src/corelib/mimetypes/qmimedatabase_p.h
@@ -1,32 +1,38 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
+** Copyright (C) 2016 The Qt Company Ltd.
** Copyright (C) 2015 Klaralvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author David Faure <david.faure@kdab.com>
-** Contact: http://www.qt.io/licensing/
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
diff --git a/src/corelib/mimetypes/qmimeglobpattern.cpp b/src/corelib/mimetypes/qmimeglobpattern.cpp
index 57d834ac78..94be5385f3 100644
--- a/src/corelib/mimetypes/qmimeglobpattern.cpp
+++ b/src/corelib/mimetypes/qmimeglobpattern.cpp
@@ -1,31 +1,37 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
@@ -176,10 +182,8 @@ void QMimeAllGlobPatterns::addGlob(const QMimeGlobPattern &glob)
void QMimeAllGlobPatterns::removeMimeType(const QString &mimeType)
{
- QMutableHashIterator<QString, QStringList> it(m_fastPatterns);
- while (it.hasNext()) {
- it.next().value().removeAll(mimeType);
- }
+ for (auto &x : m_fastPatterns)
+ x.removeAll(mimeType);
m_highWeightGlobs.removeMimeType(mimeType);
m_lowWeightGlobs.removeMimeType(mimeType);
}
@@ -213,9 +217,9 @@ QStringList QMimeAllGlobPatterns::matchingGlobs(const QString &fileName, QString
// (toLower because fast patterns are always case-insensitive and saved as lowercase)
const QStringList matchingMimeTypes = m_fastPatterns.value(simpleExtension);
- foreach (const QString &mime, matchingMimeTypes) {
- result.addMatch(mime, 50, QLatin1String("*.") + simpleExtension);
- }
+ const QString simplePattern = QLatin1String("*.") + simpleExtension;
+ for (const QString &mime : matchingMimeTypes)
+ result.addMatch(mime, 50, simplePattern);
// Can't return yet; *.tar.bz2 has to win over *.bz2, so we need the low-weight mimetypes anyway,
// at least those with weight 50.
}
diff --git a/src/corelib/mimetypes/qmimeglobpattern_p.h b/src/corelib/mimetypes/qmimeglobpattern_p.h
index 9ee3eb61cf..e4c74ff7fa 100644
--- a/src/corelib/mimetypes/qmimeglobpattern_p.h
+++ b/src/corelib/mimetypes/qmimeglobpattern_p.h
@@ -1,31 +1,37 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
@@ -82,7 +88,14 @@ public:
m_pattern = m_pattern.toLower();
}
}
- ~QMimeGlobPattern() {}
+
+ void swap(QMimeGlobPattern &other) Q_DECL_NOTHROW
+ {
+ qSwap(m_pattern, other.m_pattern);
+ qSwap(m_mimeType, other.m_mimeType);
+ qSwap(m_weight, other.m_weight);
+ qSwap(m_caseSensitivity, other.m_caseSensitivity);
+ }
bool matchFileName(const QString &filename) const;
@@ -97,6 +110,7 @@ private:
int m_weight;
Qt::CaseSensitivity m_caseSensitivity;
};
+Q_DECLARE_SHARED(QMimeGlobPattern)
class QMimeGlobPatternList : public QList<QMimeGlobPattern>
{
@@ -116,11 +130,10 @@ public:
*/
void removeMimeType(const QString &mimeType)
{
- QMutableListIterator<QMimeGlobPattern> it(*this);
- while (it.hasNext()) {
- if (it.next().mimeType() == mimeType)
- it.remove();
- }
+ auto isMimeTypeEqual = [&mimeType](const QMimeGlobPattern &pattern) {
+ return pattern.mimeType() == mimeType;
+ };
+ erase(std::remove_if(begin(), end(), isMimeTypeEqual), end());
}
void match(QMimeGlobMatchResult &result, const QString &fileName) const;
diff --git a/src/corelib/mimetypes/qmimemagicrule.cpp b/src/corelib/mimetypes/qmimemagicrule.cpp
index 398a670544..7e07f8acb9 100644
--- a/src/corelib/mimetypes/qmimemagicrule.cpp
+++ b/src/corelib/mimetypes/qmimemagicrule.cpp
@@ -1,31 +1,37 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
@@ -76,36 +82,17 @@ QByteArray QMimeMagicRule::typeName(QMimeMagicRule::Type theType)
return magicRuleTypes_string + magicRuleTypes_indices[theType];
}
-class QMimeMagicRulePrivate
-{
-public:
- bool operator==(const QMimeMagicRulePrivate &other) const;
-
- QMimeMagicRule::Type type;
- QByteArray value;
- int startPos;
- int endPos;
- QByteArray mask;
-
- QByteArray pattern;
- quint32 number;
- quint32 numberMask;
-
- typedef bool (*MatchFunction)(const QMimeMagicRulePrivate *d, const QByteArray &data);
- MatchFunction matchFunction;
-};
-
-bool QMimeMagicRulePrivate::operator==(const QMimeMagicRulePrivate &other) const
+bool QMimeMagicRule::operator==(const QMimeMagicRule &other) const
{
- return type == other.type &&
- value == other.value &&
- startPos == other.startPos &&
- endPos == other.endPos &&
- mask == other.mask &&
- pattern == other.pattern &&
- number == other.number &&
- numberMask == other.numberMask &&
- matchFunction == other.matchFunction;
+ return m_type == other.m_type &&
+ m_value == other.m_value &&
+ m_startPos == other.m_startPos &&
+ m_endPos == other.m_endPos &&
+ m_mask == other.m_mask &&
+ m_pattern == other.m_pattern &&
+ m_number == other.m_number &&
+ m_numberMask == other.m_numberMask &&
+ m_matchFunction == other.m_matchFunction;
}
// Used by both providers
@@ -158,25 +145,25 @@ bool QMimeMagicRule::matchSubstring(const char *dataPtr, int dataSize, int range
return true;
}
-static bool matchString(const QMimeMagicRulePrivate *d, const QByteArray &data)
+bool QMimeMagicRule::matchString(const QByteArray &data) const
{
- const int rangeLength = d->endPos - d->startPos + 1;
- return QMimeMagicRule::matchSubstring(data.constData(), data.size(), d->startPos, rangeLength, d->pattern.size(), d->pattern.constData(), d->mask.constData());
+ const int rangeLength = m_endPos - m_startPos + 1;
+ return QMimeMagicRule::matchSubstring(data.constData(), data.size(), m_startPos, rangeLength, m_pattern.size(), m_pattern.constData(), m_mask.constData());
}
template <typename T>
-static bool matchNumber(const QMimeMagicRulePrivate *d, const QByteArray &data)
+bool QMimeMagicRule::matchNumber(const QByteArray &data) const
{
- const T value(d->number);
- const T mask(d->numberMask);
+ const T value(m_number);
+ const T mask(m_numberMask);
- //qDebug() << "matchNumber" << "0x" << QString::number(d->number, 16) << "size" << sizeof(T);
- //qDebug() << "mask" << QString::number(d->numberMask, 16);
+ //qDebug() << "matchNumber" << "0x" << QString::number(m_number, 16) << "size" << sizeof(T);
+ //qDebug() << "mask" << QString::number(m_numberMask, 16);
- const char *p = data.constData() + d->startPos;
- const char *e = data.constData() + qMin(data.size() - int(sizeof(T)), d->endPos + 1);
+ const char *p = data.constData() + m_startPos;
+ const char *e = data.constData() + qMin(data.size() - int(sizeof(T)), m_endPos + 1);
for ( ; p <= e; ++p) {
- if ((qFromUnaligned<T>(reinterpret_cast<const uchar *>(p)) & mask) == (value & mask))
+ if ((qFromUnaligned<T>(p) & mask) == (value & mask))
return true;
}
@@ -236,105 +223,99 @@ static inline QByteArray makePattern(const QByteArray &value)
// <match value="must be converted with BinHex" type="string" offset="11"/>
// <match value="0x9501" type="big16" offset="0:64"/>
-QMimeMagicRule::QMimeMagicRule(const QString &typeStr,
- const QByteArray &theValue,
+QMimeMagicRule::QMimeMagicRule(const QString &type,
+ const QByteArray &value,
const QString &offsets,
- const QByteArray &theMask,
- QString *errorString) :
- d(new QMimeMagicRulePrivate)
+ const QByteArray &mask,
+ QString *errorString)
+ : m_type(QMimeMagicRule::type(type.toLatin1())),
+ m_value(value),
+ m_mask(mask),
+ m_matchFunction(nullptr)
{
- d->value = theValue;
- d->mask = theMask;
- d->matchFunction = 0;
-
- d->type = QMimeMagicRule::type(typeStr.toLatin1());
- if (d->type == Invalid) {
- *errorString = QStringLiteral("Type %s is not supported").arg(typeStr);
- }
+ if (Q_UNLIKELY(m_type == Invalid))
+ *errorString = QLatin1String("Type ") + type + QLatin1String(" is not supported");
// Parse for offset as "1" or "1:10"
const int colonIndex = offsets.indexOf(QLatin1Char(':'));
- const QString startPosStr = colonIndex == -1 ? offsets : offsets.mid(0, colonIndex);
- const QString endPosStr = colonIndex == -1 ? offsets : offsets.mid(colonIndex + 1);
- if (!QMimeTypeParserBase::parseNumber(startPosStr, &d->startPos, errorString) ||
- !QMimeTypeParserBase::parseNumber(endPosStr, &d->endPos, errorString)) {
- d->type = Invalid;
+ const QStringRef startPosStr = offsets.midRef(0, colonIndex); // \ These decay to returning 'offsets'
+ const QStringRef endPosStr = offsets.midRef(colonIndex + 1);// / unchanged when colonIndex == -1
+ if (Q_UNLIKELY(!QMimeTypeParserBase::parseNumber(startPosStr, &m_startPos, errorString)) ||
+ Q_UNLIKELY(!QMimeTypeParserBase::parseNumber(endPosStr, &m_endPos, errorString))) {
+ m_type = Invalid;
return;
}
- if (d->value.isEmpty()) {
- d->type = Invalid;
+ if (Q_UNLIKELY(m_value.isEmpty())) {
+ m_type = Invalid;
if (errorString)
- *errorString = QLatin1String("Invalid empty magic rule value");
+ *errorString = QStringLiteral("Invalid empty magic rule value");
return;
}
- if (d->type >= Host16 && d->type <= Byte) {
+ if (m_type >= Host16 && m_type <= Byte) {
bool ok;
- d->number = d->value.toUInt(&ok, 0); // autodetect
- if (!ok) {
- d->type = Invalid;
+ m_number = m_value.toUInt(&ok, 0); // autodetect base
+ if (Q_UNLIKELY(!ok)) {
+ m_type = Invalid;
if (errorString)
- *errorString = QString::fromLatin1("Invalid magic rule value \"%1\"").arg(
- QString::fromLatin1(d->value));
+ *errorString = QLatin1String("Invalid magic rule value \"") + QLatin1String(m_value) + QLatin1Char('"');
return;
}
- d->numberMask = !d->mask.isEmpty() ? d->mask.toUInt(&ok, 0) : 0; // autodetect
+ m_numberMask = !m_mask.isEmpty() ? m_mask.toUInt(&ok, 0) : 0; // autodetect base
}
- switch (d->type) {
+ switch (m_type) {
case String:
- d->pattern = makePattern(d->value);
- d->pattern.squeeze();
- if (!d->mask.isEmpty()) {
- if (d->mask.size() < 4 || !d->mask.startsWith("0x")) {
- d->type = Invalid;
+ m_pattern = makePattern(m_value);
+ m_pattern.squeeze();
+ if (!m_mask.isEmpty()) {
+ if (Q_UNLIKELY(m_mask.size() < 4 || !m_mask.startsWith("0x"))) {
+ m_type = Invalid;
if (errorString)
- *errorString = QString::fromLatin1("Invalid magic rule mask \"%1\"").arg(
- QString::fromLatin1(d->mask));
+ *errorString = QLatin1String("Invalid magic rule mask \"") + QLatin1String(m_mask) + QLatin1Char('"');
return;
}
const QByteArray &tempMask = QByteArray::fromHex(QByteArray::fromRawData(
- d->mask.constData() + 2, d->mask.size() - 2));
- if (tempMask.size() != d->pattern.size()) {
- d->type = Invalid;
+ m_mask.constData() + 2, m_mask.size() - 2));
+ if (Q_UNLIKELY(tempMask.size() != m_pattern.size())) {
+ m_type = Invalid;
if (errorString)
- *errorString = QString::fromLatin1("Invalid magic rule mask size \"%1\"").arg(
- QString::fromLatin1(d->mask));
+ *errorString = QLatin1String("Invalid magic rule mask size \"") + QLatin1String(m_mask) + QLatin1Char('"');
return;
}
- d->mask = tempMask;
+ m_mask = tempMask;
} else {
- d->mask.fill(char(-1), d->pattern.size());
+ m_mask.fill(char(-1), m_pattern.size());
}
- d->mask.squeeze();
- d->matchFunction = matchString;
+ m_mask.squeeze();
+ m_matchFunction = &QMimeMagicRule::matchString;
break;
case Byte:
- if (d->number <= quint8(-1)) {
- if (d->numberMask == 0)
- d->numberMask = quint8(-1);
- d->matchFunction = matchNumber<quint8>;
+ if (m_number <= quint8(-1)) {
+ if (m_numberMask == 0)
+ m_numberMask = quint8(-1);
+ m_matchFunction = &QMimeMagicRule::matchNumber<quint8>;
}
break;
case Big16:
case Host16:
case Little16:
- if (d->number <= quint16(-1)) {
- d->number = d->type == Little16 ? qFromLittleEndian<quint16>(d->number) : qFromBigEndian<quint16>(d->number);
- if (d->numberMask == 0)
- d->numberMask = quint16(-1);
- d->matchFunction = matchNumber<quint16>;
+ if (m_number <= quint16(-1)) {
+ m_number = m_type == Little16 ? qFromLittleEndian<quint16>(m_number) : qFromBigEndian<quint16>(m_number);
+ if (m_numberMask == 0)
+ m_numberMask = quint16(-1);
+ m_matchFunction = &QMimeMagicRule::matchNumber<quint16>;
}
break;
case Big32:
case Host32:
case Little32:
- if (d->number <= quint32(-1)) {
- d->number = d->type == Little32 ? qFromLittleEndian<quint32>(d->number) : qFromBigEndian<quint32>(d->number);
- if (d->numberMask == 0)
- d->numberMask = quint32(-1);
- d->matchFunction = matchNumber<quint32>;
+ if (m_number <= quint32(-1)) {
+ m_number = m_type == Little32 ? qFromLittleEndian<quint32>(m_number) : qFromBigEndian<quint32>(m_number);
+ if (m_numberMask == 0)
+ m_numberMask = quint32(-1);
+ m_matchFunction = &QMimeMagicRule::matchNumber<quint32>;
}
break;
default:
@@ -342,65 +323,19 @@ QMimeMagicRule::QMimeMagicRule(const QString &typeStr,
}
}
-QMimeMagicRule::QMimeMagicRule(const QMimeMagicRule &other) :
- d(new QMimeMagicRulePrivate(*other.d))
-{
-}
-
-QMimeMagicRule::~QMimeMagicRule()
-{
-}
-
-QMimeMagicRule &QMimeMagicRule::operator=(const QMimeMagicRule &other)
-{
- *d = *other.d;
- return *this;
-}
-
-bool QMimeMagicRule::operator==(const QMimeMagicRule &other) const
-{
- return d == other.d ||
- *d == *other.d;
-}
-
-QMimeMagicRule::Type QMimeMagicRule::type() const
-{
- return d->type;
-}
-
-QByteArray QMimeMagicRule::value() const
-{
- return d->value;
-}
-
-int QMimeMagicRule::startPos() const
-{
- return d->startPos;
-}
-
-int QMimeMagicRule::endPos() const
-{
- return d->endPos;
-}
-
QByteArray QMimeMagicRule::mask() const
{
- QByteArray result = d->mask;
- if (d->type == String) {
+ QByteArray result = m_mask;
+ if (m_type == String) {
// restore '0x'
result = "0x" + result.toHex();
}
return result;
}
-bool QMimeMagicRule::isValid() const
-{
- return d->matchFunction;
-}
-
bool QMimeMagicRule::matches(const QByteArray &data) const
{
- const bool ok = d->matchFunction && d->matchFunction(d.data(), data);
+ const bool ok = m_matchFunction && (this->*m_matchFunction)(data);
if (!ok)
return false;
diff --git a/src/corelib/mimetypes/qmimemagicrule_p.h b/src/corelib/mimetypes/qmimemagicrule_p.h
index 6b64bfcc10..26f93d96cc 100644
--- a/src/corelib/mimetypes/qmimemagicrule_p.h
+++ b/src/corelib/mimetypes/qmimemagicrule_p.h
@@ -1,31 +1,37 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
@@ -55,7 +61,6 @@
QT_BEGIN_NAMESPACE
-class QMimeMagicRulePrivate;
class QMimeMagicRule
{
public:
@@ -63,20 +68,29 @@ public:
QMimeMagicRule(const QString &typeStr, const QByteArray &value, const QString &offsets,
const QByteArray &mask, QString *errorString);
- QMimeMagicRule(const QMimeMagicRule &other);
- ~QMimeMagicRule();
- QMimeMagicRule &operator=(const QMimeMagicRule &other);
+ void swap(QMimeMagicRule &other) Q_DECL_NOTHROW
+ {
+ qSwap(m_type, other.m_type);
+ qSwap(m_value, other.m_value);
+ qSwap(m_startPos, other.m_startPos);
+ qSwap(m_endPos, other.m_endPos);
+ qSwap(m_mask, other.m_mask);
+ qSwap(m_pattern, other.m_pattern);
+ qSwap(m_number, other.m_number);
+ qSwap(m_numberMask, other.m_numberMask);
+ qSwap(m_matchFunction, other.m_matchFunction);
+ }
bool operator==(const QMimeMagicRule &other) const;
- Type type() const;
- QByteArray value() const;
- int startPos() const;
- int endPos() const;
+ Type type() const { return m_type; }
+ QByteArray value() const { return m_value; }
+ int startPos() const { return m_startPos; }
+ int endPos() const { return m_endPos; }
QByteArray mask() const;
- bool isValid() const;
+ bool isValid() const { return m_matchFunction != Q_NULLPTR; }
bool matches(const QByteArray &data) const;
@@ -88,9 +102,26 @@ public:
static bool matchSubstring(const char *dataPtr, int dataSize, int rangeStart, int rangeLength, int valueLength, const char *valueData, const char *mask);
private:
- const QScopedPointer<QMimeMagicRulePrivate> d;
+ Type m_type;
+ QByteArray m_value;
+ int m_startPos;
+ int m_endPos;
+ QByteArray m_mask;
+
+ QByteArray m_pattern;
+ quint32 m_number;
+ quint32 m_numberMask;
+
+ typedef bool (QMimeMagicRule::*MatchFunction)(const QByteArray &data) const;
+ MatchFunction m_matchFunction;
+
+private:
+ // match functions
+ bool matchString(const QByteArray &data) const;
+ template <typename T>
+ bool matchNumber(const QByteArray &data) const;
};
-Q_DECLARE_TYPEINFO(QMimeMagicRule, Q_MOVABLE_TYPE);
+Q_DECLARE_SHARED(QMimeMagicRule)
QT_END_NAMESPACE
diff --git a/src/corelib/mimetypes/qmimemagicrulematcher.cpp b/src/corelib/mimetypes/qmimemagicrulematcher.cpp
index 629e8d9d2f..b5194d3543 100644
--- a/src/corelib/mimetypes/qmimemagicrulematcher.cpp
+++ b/src/corelib/mimetypes/qmimemagicrulematcher.cpp
@@ -1,31 +1,37 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
@@ -85,7 +91,7 @@ QList<QMimeMagicRule> QMimeMagicRuleMatcher::magicRules() const
// Check for a match on contents of a file
bool QMimeMagicRuleMatcher::matches(const QByteArray &data) const
{
- foreach (const QMimeMagicRule &magicRule, m_list) {
+ for (const QMimeMagicRule &magicRule : m_list) {
if (magicRule.matches(data))
return true;
}
diff --git a/src/corelib/mimetypes/qmimemagicrulematcher_p.h b/src/corelib/mimetypes/qmimemagicrulematcher_p.h
index 1ea6227378..5e3d5306c0 100644
--- a/src/corelib/mimetypes/qmimemagicrulematcher_p.h
+++ b/src/corelib/mimetypes/qmimemagicrulematcher_p.h
@@ -1,31 +1,37 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
@@ -60,6 +66,13 @@ class QMimeMagicRuleMatcher
public:
explicit QMimeMagicRuleMatcher(const QString &mime, unsigned priority = 65535);
+ void swap(QMimeMagicRuleMatcher &other) Q_DECL_NOTHROW
+ {
+ qSwap(m_list, other.m_list);
+ qSwap(m_priority, other.m_priority);
+ qSwap(m_mimetype, other.m_mimetype);
+ }
+
bool operator==(const QMimeMagicRuleMatcher &other) const;
void addRule(const QMimeMagicRule &rule);
@@ -77,6 +90,7 @@ private:
unsigned m_priority;
QString m_mimetype;
};
+Q_DECLARE_SHARED(QMimeMagicRuleMatcher)
QT_END_NAMESPACE
diff --git a/src/corelib/mimetypes/qmimeprovider.cpp b/src/corelib/mimetypes/qmimeprovider.cpp
index aa8d8c9b08..aae5cc411b 100644
--- a/src/corelib/mimetypes/qmimeprovider.cpp
+++ b/src/corelib/mimetypes/qmimeprovider.cpp
@@ -1,32 +1,38 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
+** Copyright (C) 2016 The Qt Company Ltd.
** Copyright (C) 2015 Klaralvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author David Faure <david.faure@kdab.com>
-** Contact: http://www.qt.io/licensing/
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
@@ -199,7 +205,7 @@ bool QMimeBinaryProvider::isValid()
return false;
// We found exactly one file; is it the user-modified mimes, or a system file?
- const QString foundFile = m_cacheFiles.first()->file.fileName();
+ const QString foundFile = m_cacheFiles.constFirst()->file.fileName();
const QString localCacheFile = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/mime/mime.cache");
return foundFile != localCacheFile;
@@ -242,7 +248,7 @@ void QMimeBinaryProvider::checkCache()
// Then check if new cache files appeared
const QStringList cacheFileNames = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QLatin1String("mime/mime.cache"));
if (cacheFileNames != m_cacheFileNames) {
- foreach (const QString &cacheFileName, cacheFileNames) {
+ for (const QString &cacheFileName : cacheFileNames) {
CacheFile *cacheFile = m_cacheFiles.findCacheFile(cacheFileName);
if (!cacheFile) {
//qDebug() << "new file:" << cacheFileName;
@@ -287,7 +293,7 @@ QStringList QMimeBinaryProvider::findByFileName(const QString &fileName, QString
const QString lowerFileName = fileName.toLower();
QMimeGlobMatchResult result;
// TODO this parses in the order (local, global). Check that it handles "NOGLOBS" correctly.
- foreach (CacheFile *cacheFile, m_cacheFiles) {
+ for (CacheFile *cacheFile : qAsConst(m_cacheFiles)) {
matchGlobList(result, cacheFile, cacheFile->getUint32(PosLiteralListOffset), fileName);
matchGlobList(result, cacheFile, cacheFile->getUint32(PosGlobListOffset), fileName);
const int reverseSuffixTreeOffset = cacheFile->getUint32(PosReverseSuffixTreeOffset);
@@ -399,7 +405,7 @@ bool QMimeBinaryProvider::matchMagicRule(QMimeBinaryProvider::CacheFile *cacheFi
QMimeType QMimeBinaryProvider::findByMagic(const QByteArray &data, int *accuracyPtr)
{
checkCache();
- foreach (CacheFile *cacheFile, m_cacheFiles) {
+ for (CacheFile *cacheFile : qAsConst(m_cacheFiles)) {
const int magicListOffset = cacheFile->getUint32(PosMagicListOffset);
const int numMatches = cacheFile->getUint32(magicListOffset);
//const int maxExtent = cacheFile->getUint32(magicListOffset + 4);
@@ -427,7 +433,7 @@ QStringList QMimeBinaryProvider::parents(const QString &mime)
checkCache();
const QByteArray mimeStr = mime.toLatin1();
QStringList result;
- foreach (CacheFile *cacheFile, m_cacheFiles) {
+ for (CacheFile *cacheFile : qAsConst(m_cacheFiles)) {
const int parentListOffset = cacheFile->getUint32(PosParentListOffset);
const int numEntries = cacheFile->getUint32(parentListOffset);
@@ -467,7 +473,7 @@ QString QMimeBinaryProvider::resolveAlias(const QString &name)
{
checkCache();
const QByteArray input = name.toLatin1();
- foreach (CacheFile *cacheFile, m_cacheFiles) {
+ for (CacheFile *cacheFile : qAsConst(m_cacheFiles)) {
const int aliasListOffset = cacheFile->getUint32(PosAliasListOffset);
const int numEntries = cacheFile->getUint32(aliasListOffset);
int begin = 0;
@@ -498,7 +504,7 @@ QStringList QMimeBinaryProvider::listAliases(const QString &name)
checkCache();
QStringList result;
const QByteArray input = name.toLatin1();
- foreach (CacheFile *cacheFile, m_cacheFiles) {
+ for (CacheFile *cacheFile : qAsConst(m_cacheFiles)) {
const int aliasListOffset = cacheFile->getUint32(PosAliasListOffset);
const int numEntries = cacheFile->getUint32(aliasListOffset);
for (int pos = 0; pos < numEntries; ++pos) {
@@ -524,7 +530,7 @@ void QMimeBinaryProvider::loadMimeTypeList()
// Unfortunately mime.cache doesn't have a full list of all mimetypes.
// So we have to parse the plain-text files called "types".
const QStringList typesFilenames = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QLatin1String("mime/types"));
- foreach (const QString &typeFilename, typesFilenames) {
+ for (const QString &typeFilename : typesFilenames) {
QFile file(typeFilename);
if (file.open(QIODevice::ReadOnly)) {
while (!file.atEnd()) {
@@ -553,7 +559,7 @@ QList<QMimeType> QMimeBinaryProvider::allMimeTypes()
void QMimeBinaryProvider::loadMimeTypePrivate(QMimeTypePrivate &data)
{
#ifdef QT_NO_XMLSTREAMREADER
- qWarning() << "Cannot load mime type since QXmlStreamReader is not available.";
+ qWarning("Cannot load mime type since QXmlStreamReader is not available.");
return;
#else
if (data.loaded)
@@ -574,9 +580,7 @@ void QMimeBinaryProvider::loadMimeTypePrivate(QMimeTypePrivate &data)
return;
}
- QString comment;
QString mainPattern;
- const QString preferredLanguage = QLocale().name();
for (QStringList::const_reverse_iterator it = mimeFiles.crbegin(), end = mimeFiles.crend(); it != end; ++it) { // global first, then local.
QFile qfile(*it);
@@ -625,7 +629,7 @@ void QMimeBinaryProvider::loadMimeTypePrivate(QMimeTypePrivate &data)
// Let's assume that shared-mime-info is at least version 0.70
// Otherwise we would need 1) a version check, and 2) code for parsing patterns from the globs file.
#if 1
- if (!mainPattern.isEmpty() && (data.globPatterns.isEmpty() || data.globPatterns.first() != mainPattern)) {
+ if (!mainPattern.isEmpty() && (data.globPatterns.isEmpty() || data.globPatterns.constFirst() != mainPattern)) {
// ensure it's first in the list of patterns
data.globPatterns.removeAll(mainPattern);
data.globPatterns.prepend(mainPattern);
@@ -633,7 +637,7 @@ void QMimeBinaryProvider::loadMimeTypePrivate(QMimeTypePrivate &data)
#else
const bool globsInXml = sharedMimeInfoVersion() >= QT_VERSION_CHECK(0, 70, 0);
if (globsInXml) {
- if (!mainPattern.isEmpty() && data.globPatterns.first() != mainPattern) {
+ if (!mainPattern.isEmpty() && data.globPatterns.constFirst() != mainPattern) {
// ensure it's first in the list of patterns
data.globPatterns.removeAll(mainPattern);
data.globPatterns.prepend(mainPattern);
@@ -676,7 +680,7 @@ void QMimeBinaryProvider::loadIcon(QMimeTypePrivate &data)
{
checkCache();
const QByteArray inputMime = data.name.toLatin1();
- foreach (CacheFile *cacheFile, m_cacheFiles) {
+ for (CacheFile *cacheFile : qAsConst(m_cacheFiles)) {
const QString icon = iconForMime(cacheFile, PosIconsListOffset, inputMime);
if (!icon.isEmpty()) {
data.iconName = icon;
@@ -689,7 +693,7 @@ void QMimeBinaryProvider::loadGenericIcon(QMimeTypePrivate &data)
{
checkCache();
const QByteArray inputMime = data.name.toLatin1();
- foreach (CacheFile *cacheFile, m_cacheFiles) {
+ for (CacheFile *cacheFile : qAsConst(m_cacheFiles)) {
const QString icon = iconForMime(cacheFile, PosGenericIconsListOffset, inputMime);
if (!icon.isEmpty()) {
data.genericIconName = icon;
@@ -736,7 +740,7 @@ QMimeType QMimeXMLProvider::findByMagic(const QByteArray &data, int *accuracyPtr
QString candidate;
- foreach (const QMimeMagicRuleMatcher &matcher, m_magicMatchers) {
+ for (const QMimeMagicRuleMatcher &matcher : qAsConst(m_magicMatchers)) {
if (matcher.matches(data)) {
const int priority = matcher.priority();
if (priority > *accuracyPtr) {
@@ -756,7 +760,7 @@ void QMimeXMLProvider::ensureLoaded()
const QStringList packageDirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QLatin1String("mime/packages"), QStandardPaths::LocateDirectory);
//qDebug() << "packageDirs=" << packageDirs;
- foreach (const QString &packageDir, packageDirs) {
+ for (const QString &packageDir : packageDirs) {
QDir dir(packageDir);
const QStringList files = dir.entryList(QDir::Files | QDir::NoDotAndDotDot);
//qDebug() << static_cast<const void *>(this) << packageDir << files;
@@ -785,7 +789,7 @@ void QMimeXMLProvider::ensureLoaded()
//qDebug() << "Loading" << m_allFiles;
- foreach (const QString &file, allFiles)
+ for (const QString &file : qAsConst(allFiles))
load(file);
}
}
diff --git a/src/corelib/mimetypes/qmimeprovider_p.h b/src/corelib/mimetypes/qmimeprovider_p.h
index 8eba71eddd..e6fc47bf80 100644
--- a/src/corelib/mimetypes/qmimeprovider_p.h
+++ b/src/corelib/mimetypes/qmimeprovider_p.h
@@ -1,32 +1,38 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
+** Copyright (C) 2016 The Qt Company Ltd.
** Copyright (C) 2015 Klaralvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author David Faure <david.faure@kdab.com>
-** Contact: http://www.qt.io/licensing/
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
diff --git a/src/corelib/mimetypes/qmimetype.cpp b/src/corelib/mimetypes/qmimetype.cpp
index 980e8c1e5e..b259b42ac8 100644
--- a/src/corelib/mimetypes/qmimetype.cpp
+++ b/src/corelib/mimetypes/qmimetype.cpp
@@ -1,32 +1,38 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
+** Copyright (C) 2016 The Qt Company Ltd.
** Copyright (C) 2015 Klaralvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author David Faure <david.faure@kdab.com>
-** Contact: http://www.qt.io/licensing/
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
@@ -101,7 +107,7 @@ void QMimeTypePrivate::addGlobPattern(const QString &pattern)
MIME types can inherit from each other: for instance a C source file is
a specific type of plain text file, so text/x-csrc inherits text/plain.
- \sa QMimeDatabase
+ \sa QMimeDatabase, {MIME Type Browser Example}
*/
/*!
@@ -241,7 +247,7 @@ QString QMimeType::comment() const
QStringList languageList;
languageList << QLocale().name();
languageList << QLocale().uiLanguages();
- Q_FOREACH (const QString &language, languageList) {
+ for (const QString &language : qAsConst(languageList)) {
const QString lang = language == QLatin1String("C") ? QLatin1String("en_US") : language;
const QString comm = d->localeComments.value(lang);
if (!comm.isEmpty())
@@ -337,17 +343,16 @@ QStringList QMimeType::parentMimeTypes() const
static void collectParentMimeTypes(const QString &mime, QStringList &allParents)
{
- QStringList parents = QMimeDatabasePrivate::instance()->provider()->parents(mime);
- foreach (const QString &parent, parents) {
+ const QStringList parents = QMimeDatabasePrivate::instance()->provider()->parents(mime);
+ for (const QString &parent : parents) {
// I would use QSet, but since order matters I better not
if (!allParents.contains(parent))
allParents.append(parent);
}
// We want a breadth-first search, so that the least-specific parent (octet-stream) is last
// This means iterating twice, unfortunately.
- foreach (const QString &parent, parents) {
+ for (const QString &parent : parents)
collectParentMimeTypes(parent, allParents);
- }
}
/*!
@@ -392,7 +397,7 @@ QStringList QMimeType::suffixes() const
QMimeDatabasePrivate::instance()->provider()->loadMimeTypePrivate(*d);
QStringList result;
- foreach (const QString &pattern, d->globPatterns) {
+ for (const QString &pattern : qAsConst(d->globPatterns)) {
// Not a simple suffix if it looks like: README or *. or *.* or *.JP*G or *.JP?
if (pattern.startsWith(QLatin1String("*.")) &&
pattern.length() > 2 &&
diff --git a/src/corelib/mimetypes/qmimetype.h b/src/corelib/mimetypes/qmimetype.h
index 6a00541ebc..e9ff9ace84 100644
--- a/src/corelib/mimetypes/qmimetype.h
+++ b/src/corelib/mimetypes/qmimetype.h
@@ -1,32 +1,38 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
+** Copyright (C) 2016 The Qt Company Ltd.
** Copyright (C) 2015 Klaralvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author David Faure <david.faure@kdab.com>
-** Contact: http://www.qt.io/licensing/
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
diff --git a/src/corelib/mimetypes/qmimetype_p.h b/src/corelib/mimetypes/qmimetype_p.h
index 2161dd8901..c89ffbefa3 100644
--- a/src/corelib/mimetypes/qmimetype_p.h
+++ b/src/corelib/mimetypes/qmimetype_p.h
@@ -1,31 +1,37 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
diff --git a/src/corelib/mimetypes/qmimetypeparser.cpp b/src/corelib/mimetypes/qmimetypeparser.cpp
index 8a8b97655a..535fa51c92 100644
--- a/src/corelib/mimetypes/qmimetypeparser.cpp
+++ b/src/corelib/mimetypes/qmimetypeparser.cpp
@@ -1,31 +1,37 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
@@ -154,25 +160,36 @@ QMimeTypeParserBase::ParseState QMimeTypeParserBase::nextState(ParseState curren
}
// Parse int number from an (attribute) string
-bool QMimeTypeParserBase::parseNumber(const QString &n, int *target, QString *errorMessage)
+bool QMimeTypeParserBase::parseNumber(const QStringRef &n, int *target, QString *errorMessage)
{
bool ok;
*target = n.toInt(&ok);
- if (!ok) {
- *errorMessage = QString::fromLatin1("Not a number '%1'.").arg(n);
+ if (Q_UNLIKELY(!ok)) {
+ *errorMessage = QLatin1String("Not a number '") + n + QLatin1String("'.");
return false;
}
return true;
}
#ifndef QT_NO_XMLSTREAMREADER
-static QMimeMagicRule *createMagicMatchRule(const QXmlStreamAttributes &atts, QString *errorMessage)
+struct CreateMagicMatchRuleResult {
+ QString errorMessage; // must be first
+ QMimeMagicRule rule;
+
+ CreateMagicMatchRuleResult(const QStringRef &type, const QStringRef &value, const QStringRef &offsets, const QStringRef &mask)
+ : errorMessage(), rule(type.toString(), value.toUtf8(), offsets.toString(), mask.toLatin1(), &errorMessage)
+ {
+
+ }
+};
+
+static CreateMagicMatchRuleResult createMagicMatchRule(const QXmlStreamAttributes &atts)
{
- const QString type = atts.value(QLatin1String(matchTypeAttributeC)).toString();
- const QString value = atts.value(QLatin1String(matchValueAttributeC)).toString();
- const QString offsets = atts.value(QLatin1String(matchOffsetAttributeC)).toString();
- const QString mask = atts.value(QLatin1String(matchMaskAttributeC)).toString();
- return new QMimeMagicRule(type, value.toUtf8(), offsets, mask.toLatin1(), errorMessage);
+ const QStringRef type = atts.value(QLatin1String(matchTypeAttributeC));
+ const QStringRef value = atts.value(QLatin1String(matchValueAttributeC));
+ const QStringRef offsets = atts.value(QLatin1String(matchOffsetAttributeC));
+ const QStringRef mask = atts.value(QLatin1String(matchMaskAttributeC));
+ return CreateMagicMatchRuleResult(type, value, offsets, mask);
}
#endif
@@ -189,17 +206,16 @@ bool QMimeTypeParserBase::parse(QIODevice *dev, const QString &fileName, QString
QList<QMimeMagicRule> rules; // toplevel rules
QXmlStreamReader reader(dev);
ParseState ps = ParseBeginning;
- QXmlStreamAttributes atts;
while (!reader.atEnd()) {
switch (reader.readNext()) {
- case QXmlStreamReader::StartElement:
+ case QXmlStreamReader::StartElement: {
ps = nextState(ps, reader.name());
- atts = reader.attributes();
+ const QXmlStreamAttributes atts = reader.attributes();
switch (ps) {
case ParseMimeType: { // start parsing a MIME type name
const QString name = atts.value(QLatin1String(mimeTypeAttributeC)).toString();
if (name.isEmpty()) {
- reader.raiseError(QString::fromLatin1("Missing '%1'-attribute").arg(QString::fromLatin1(mimeTypeAttributeC)));
+ reader.raiseError(QStringLiteral("Missing 'type'-attribute"));
} else {
data.name = name;
}
@@ -213,8 +229,8 @@ bool QMimeTypeParserBase::parse(QIODevice *dev, const QString &fileName, QString
break;
case ParseGlobPattern: {
const QString pattern = atts.value(QLatin1String(patternAttributeC)).toString();
- unsigned weight = atts.value(QLatin1String(weightAttributeC)).toString().toInt();
- const bool caseSensitive = atts.value(QLatin1String(caseSensitiveAttributeC)).toString() == QLatin1String("true");
+ unsigned weight = atts.value(QLatin1String(weightAttributeC)).toInt();
+ const bool caseSensitive = atts.value(QLatin1String(caseSensitiveAttributeC)) == QLatin1String("true");
if (weight == 0)
weight = QMimeGlobPattern::DefaultWeight;
@@ -249,7 +265,7 @@ bool QMimeTypeParserBase::parse(QIODevice *dev, const QString &fileName, QString
break;
case ParseMagic: {
priority = 50;
- const QString priorityS = atts.value(QLatin1String(priorityAttributeC)).toString();
+ const QStringRef priorityS = atts.value(QLatin1String(priorityAttributeC));
if (!priorityS.isEmpty()) {
if (!parseNumber(priorityS, &priority, errorMessage))
return false;
@@ -260,28 +276,27 @@ bool QMimeTypeParserBase::parse(QIODevice *dev, const QString &fileName, QString
}
break;
case ParseMagicMatchRule: {
- QString magicErrorMessage;
- QMimeMagicRule *rule = createMagicMatchRule(atts, &magicErrorMessage);
- if (!rule->isValid())
- qWarning("QMimeDatabase: Error parsing %s\n%s", qPrintable(fileName), qPrintable(magicErrorMessage));
+ auto result = createMagicMatchRule(atts);
+ if (Q_UNLIKELY(!result.rule.isValid()))
+ qWarning("QMimeDatabase: Error parsing %ls\n%ls",
+ qUtf16Printable(fileName), qUtf16Printable(result.errorMessage));
QList<QMimeMagicRule> *ruleList;
if (currentRules.isEmpty())
ruleList = &rules;
else // nest this rule into the proper parent
ruleList = &currentRules.top()->m_subMatches;
- ruleList->append(*rule);
+ ruleList->append(std::move(result.rule));
//qDebug() << " MATCH added. Stack size was" << currentRules.size();
currentRules.push(&ruleList->last());
- delete rule;
break;
}
case ParseError:
- reader.raiseError(QString::fromLatin1("Unexpected element <%1>").
- arg(reader.name().toString()));
+ reader.raiseError(QLatin1String("Unexpected element <") + reader.name() + QLatin1Char('>'));
break;
default:
break;
}
+ }
break;
// continue switch QXmlStreamReader::Token...
case QXmlStreamReader::EndElement: // Finished element
@@ -310,9 +325,13 @@ bool QMimeTypeParserBase::parse(QIODevice *dev, const QString &fileName, QString
}
}
- if (reader.hasError()) {
- if (errorMessage)
- *errorMessage = QString::fromLatin1("An error has been encountered at line %1 of %2: %3:").arg(reader.lineNumber()).arg(fileName, reader.errorString());
+ if (Q_UNLIKELY(reader.hasError())) {
+ if (errorMessage) {
+ *errorMessage = QString::asprintf("An error has been encountered at line %lld of %ls: %ls:",
+ reader.lineNumber(),
+ qUtf16Printable(fileName),
+ qUtf16Printable(reader.errorString()));
+ }
return false;
}
diff --git a/src/corelib/mimetypes/qmimetypeparser_p.h b/src/corelib/mimetypes/qmimetypeparser_p.h
index 3a2e6b8a14..a502439419 100644
--- a/src/corelib/mimetypes/qmimetypeparser_p.h
+++ b/src/corelib/mimetypes/qmimetypeparser_p.h
@@ -1,31 +1,37 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
@@ -66,7 +72,7 @@ public:
bool parse(QIODevice *dev, const QString &fileName, QString *errorMessage);
- static bool parseNumber(const QString &n, int *target, QString *errorMessage);
+ static bool parseNumber(const QStringRef &n, int *target, QString *errorMessage);
protected:
virtual bool process(const QMimeType &t, QString *errorMessage) = 0;