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:
Anton Kudryavtsev 2023-10-16 21:23:51 +03:00 committed by Anton Kudryavtsev
parent 8111a7d08f
commit 18367d0a11
2 changed files with 13 additions and 13 deletions

View File

@ -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();
if (!patternLength)
@ -163,7 +163,7 @@ bool QMimeGlobPattern::matchFileName(const QString &inputFileName) const
return false;
}
static bool isSimplePattern(const QString &pattern)
static bool isSimplePattern(QStringView pattern)
{
// starts with "*.", has no other '*'
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 '.'
return pattern.lastIndexOf(u'*') == 0

View File

@ -22,6 +22,8 @@ QT_REQUIRE_CONFIG(mimetype);
#include <QtCore/qstringlist.h>
#include <QtCore/qhash.h>
#include <algorithm>
QT_BEGIN_NAMESPACE
struct QMimeGlobMatchResult
@ -77,7 +79,7 @@ private:
AnimPattern, // special handling for "*.anim[1-9j]" pattern
OtherPattern
};
PatternType detectPatternType(const QString &pattern) const;
PatternType detectPatternType(QStringView pattern) const;
QString m_pattern;
QString m_mimeType;
@ -92,22 +94,20 @@ using AddMatchFilterFunc = std::function<bool(const QString &)>;
class QMimeGlobPatternList : public QList<QMimeGlobPattern>
{
public:
bool hasPattern(const QString &mimeType, const QString &pattern) const
bool hasPattern(QStringView mimeType, QStringView pattern) const
{
const_iterator it = begin();
const const_iterator myend = end();
for (; it != myend; ++it)
if ((*it).pattern() == pattern && (*it).mimeType() == mimeType)
return true;
return false;
auto matchesMimeAndPattern = [mimeType, pattern](const QMimeGlobPattern &e) {
return e.pattern() == pattern && e.mimeType() == mimeType;
};
return std::any_of(begin(), end(), matchesMimeAndPattern);
}
/*!
"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;
};
removeIf(isMimeTypeEqual);