forked from qt-creator/qt-creator
Update mime database from Qt
qtbase/18367d0a1182d22f23fa1414432e52b429ae9fa8 qmimeglobpattern: port some methods to QSV Change-Id: I7e94df860c131163accad2c9848b8ba2a9a70bed Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -58,7 +58,7 @@ void MimeGlobMatchResult::addMatch(const QString &mimeType, int weight, const QS
|
||||
}
|
||||
}
|
||||
|
||||
MimeGlobPattern::PatternType MimeGlobPattern::detectPatternType(const QString &pattern) const
|
||||
MimeGlobPattern::PatternType MimeGlobPattern::detectPatternType(QStringView pattern) const
|
||||
{
|
||||
const qsizetype patternLength = pattern.size();
|
||||
if (!patternLength)
|
||||
@@ -164,7 +164,7 @@ bool MimeGlobPattern::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
|
||||
@@ -176,7 +176,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
|
||||
|
@@ -17,6 +17,8 @@
|
||||
#include <QtCore/qstringlist.h>
|
||||
#include <QtCore/qhash.h>
|
||||
|
||||
#include <algorithm.h>
|
||||
|
||||
namespace Utils {
|
||||
|
||||
struct MimeGlobMatchResult
|
||||
@@ -72,7 +74,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;
|
||||
@@ -86,22 +88,20 @@ using AddMatchFilterFunc = std::function<bool(const QString &)>;
|
||||
class MimeGlobPatternList : public QList<MimeGlobPattern>
|
||||
{
|
||||
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 MimeGlobPattern &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 MimeGlobPattern &pattern) {
|
||||
auto isMimeTypeEqual = [mimeType](const MimeGlobPattern &pattern) {
|
||||
return pattern.mimeType() == mimeType;
|
||||
};
|
||||
erase(std::remove_if(begin(), end(), isMimeTypeEqual), end());
|
||||
|
Reference in New Issue
Block a user