qmimeglobpattern: port some methods to QSV
It's private API, so it's safe Change-Id: Ibf35262117c4ce4a1e548fff814a6e7bea362309 Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
parent
8111a7d08f
commit
18367d0a11
@ -58,7 +58,7 @@ void QMimeGlobMatchResult::addMatch(const QString &mimeType, int weight, const Q
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QMimeGlobPattern::PatternType QMimeGlobPattern::detectPatternType(const QString &pattern) const
|
QMimeGlobPattern::PatternType QMimeGlobPattern::detectPatternType(QStringView pattern) const
|
||||||
{
|
{
|
||||||
const qsizetype patternLength = pattern.size();
|
const qsizetype patternLength = pattern.size();
|
||||||
if (!patternLength)
|
if (!patternLength)
|
||||||
@ -163,7 +163,7 @@ bool QMimeGlobPattern::matchFileName(const QString &inputFileName) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isSimplePattern(const QString &pattern)
|
static bool isSimplePattern(QStringView pattern)
|
||||||
{
|
{
|
||||||
// starts with "*.", has no other '*'
|
// starts with "*.", has no other '*'
|
||||||
return pattern.lastIndexOf(u'*') == 0
|
return pattern.lastIndexOf(u'*') == 0
|
||||||
@ -175,7 +175,7 @@ static bool isSimplePattern(const QString &pattern)
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isFastPattern(const QString &pattern)
|
static bool isFastPattern(QStringView pattern)
|
||||||
{
|
{
|
||||||
// starts with "*.", has no other '*' and no other '.'
|
// starts with "*.", has no other '*' and no other '.'
|
||||||
return pattern.lastIndexOf(u'*') == 0
|
return pattern.lastIndexOf(u'*') == 0
|
||||||
|
@ -22,6 +22,8 @@ QT_REQUIRE_CONFIG(mimetype);
|
|||||||
#include <QtCore/qstringlist.h>
|
#include <QtCore/qstringlist.h>
|
||||||
#include <QtCore/qhash.h>
|
#include <QtCore/qhash.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
struct QMimeGlobMatchResult
|
struct QMimeGlobMatchResult
|
||||||
@ -77,7 +79,7 @@ private:
|
|||||||
AnimPattern, // special handling for "*.anim[1-9j]" pattern
|
AnimPattern, // special handling for "*.anim[1-9j]" pattern
|
||||||
OtherPattern
|
OtherPattern
|
||||||
};
|
};
|
||||||
PatternType detectPatternType(const QString &pattern) const;
|
PatternType detectPatternType(QStringView pattern) const;
|
||||||
|
|
||||||
QString m_pattern;
|
QString m_pattern;
|
||||||
QString m_mimeType;
|
QString m_mimeType;
|
||||||
@ -92,22 +94,20 @@ using AddMatchFilterFunc = std::function<bool(const QString &)>;
|
|||||||
class QMimeGlobPatternList : public QList<QMimeGlobPattern>
|
class QMimeGlobPatternList : public QList<QMimeGlobPattern>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
bool hasPattern(const QString &mimeType, const QString &pattern) const
|
bool hasPattern(QStringView mimeType, QStringView pattern) const
|
||||||
{
|
{
|
||||||
const_iterator it = begin();
|
auto matchesMimeAndPattern = [mimeType, pattern](const QMimeGlobPattern &e) {
|
||||||
const const_iterator myend = end();
|
return e.pattern() == pattern && e.mimeType() == mimeType;
|
||||||
for (; it != myend; ++it)
|
};
|
||||||
if ((*it).pattern() == pattern && (*it).mimeType() == mimeType)
|
return std::any_of(begin(), end(), matchesMimeAndPattern);
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
"noglobs" is very rare occurrence, so it's ok if it's slow
|
"noglobs" is very rare occurrence, so it's ok if it's slow
|
||||||
*/
|
*/
|
||||||
void removeMimeType(const QString &mimeType)
|
void removeMimeType(QStringView mimeType)
|
||||||
{
|
{
|
||||||
auto isMimeTypeEqual = [&mimeType](const QMimeGlobPattern &pattern) {
|
auto isMimeTypeEqual = [mimeType](const QMimeGlobPattern &pattern) {
|
||||||
return pattern.mimeType() == mimeType;
|
return pattern.mimeType() == mimeType;
|
||||||
};
|
};
|
||||||
removeIf(isMimeTypeEqual);
|
removeIf(isMimeTypeEqual);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user