summaryrefslogtreecommitdiffstats
path: root/src/corelib/mimetypes/qmimeglobpattern.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/mimetypes/qmimeglobpattern.cpp')
-rw-r--r--src/corelib/mimetypes/qmimeglobpattern.cpp50
1 files changed, 26 insertions, 24 deletions
diff --git a/src/corelib/mimetypes/qmimeglobpattern.cpp b/src/corelib/mimetypes/qmimeglobpattern.cpp
index 568f9bf4de..a4d2b046fa 100644
--- a/src/corelib/mimetypes/qmimeglobpattern.cpp
+++ b/src/corelib/mimetypes/qmimeglobpattern.cpp
@@ -58,9 +58,13 @@ QT_BEGIN_NAMESPACE
void QMimeGlobMatchResult::addMatch(const QString &mimeType, int weight, const QString &pattern)
{
+ if (m_allMatchingMimeTypes.contains(mimeType))
+ return;
// Is this a lower-weight pattern than the last match? Skip this match then.
- if (weight < m_weight)
+ if (weight < m_weight) {
+ m_allMatchingMimeTypes.append(mimeType);
return;
+ }
bool replace = weight > m_weight;
if (!replace) {
// Compare the length of the match
@@ -79,6 +83,7 @@ void QMimeGlobMatchResult::addMatch(const QString &mimeType, int weight, const Q
}
if (!m_matchingMimeTypes.contains(mimeType)) {
m_matchingMimeTypes.append(mimeType);
+ m_allMatchingMimeTypes.append(mimeType);
if (pattern.startsWith(QLatin1String("*.")))
m_foundSuffix = pattern.mid(2);
}
@@ -201,35 +206,32 @@ void QMimeGlobPatternList::match(QMimeGlobMatchResult &result,
}
}
-QStringList QMimeAllGlobPatterns::matchingGlobs(const QString &fileName, QString *foundSuffix) const
+QMimeGlobMatchResult QMimeAllGlobPatterns::matchingGlobs(const QString &fileName) const
{
// First try the high weight matches (>50), if any.
QMimeGlobMatchResult result;
m_highWeightGlobs.match(result, fileName);
- if (result.m_matchingMimeTypes.isEmpty()) {
-
- // Now use the "fast patterns" dict, for simple *.foo patterns with weight 50
- // (which is most of them, so this optimization is definitely worth it)
- const int lastDot = fileName.lastIndexOf(QLatin1Char('.'));
- if (lastDot != -1) { // if no '.', skip the extension lookup
- const int ext_len = fileName.length() - lastDot - 1;
- const QString simpleExtension = fileName.right(ext_len).toLower();
- // (toLower because fast patterns are always case-insensitive and saved as lowercase)
-
- const QStringList matchingMimeTypes = m_fastPatterns.value(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.
- }
- // Finally, try the low weight matches (<=50)
- m_lowWeightGlobs.match(result, fileName);
+ // Now use the "fast patterns" dict, for simple *.foo patterns with weight 50
+ // (which is most of them, so this optimization is definitely worth it)
+ const int lastDot = fileName.lastIndexOf(QLatin1Char('.'));
+ if (lastDot != -1) { // if no '.', skip the extension lookup
+ const int ext_len = fileName.length() - lastDot - 1;
+ const QString simpleExtension = fileName.right(ext_len).toLower();
+ // (toLower because fast patterns are always case-insensitive and saved as lowercase)
+
+ const QStringList matchingMimeTypes = m_fastPatterns.value(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.
}
- if (foundSuffix)
- *foundSuffix = result.m_foundSuffix;
- return result.m_matchingMimeTypes;
+
+ // Finally, try the low weight matches (<=50)
+ m_lowWeightGlobs.match(result, fileName);
+
+ return result;
}
void QMimeAllGlobPatterns::clear()