6#if QT_CONFIG(regularexpression)
7#include <QRegularExpression>
61QMimeGlobPattern::PatternType QMimeGlobPattern::detectPatternType(
QStringView pattern)
const
68 const bool hasSquareBracket =
pattern.indexOf(u
'[') != -1;
69 const bool hasQuestionMark =
pattern.indexOf(u
'?') != -1;
71 if (!hasSquareBracket && !hasQuestionMark) {
77 if (
pattern.at(patternLength - 1) == u
'*')
79 }
else if (starCount == 0) {
81 return LiteralPattern;
85 if (
pattern ==
"[0-9][0-9][0-9].vdr"_L1)
88 if (
pattern ==
"*.anim[1-9j]"_L1)
110 ? inputFileName.
toLower() : inputFileName;
117 switch (m_patternType) {
118 case SuffixPattern: {
119 if (fileNameLength + 1 < patternLength)
122 const QChar *c1 = m_pattern.
unicode() + patternLength - 1;
125 while (cnt < patternLength && *c1-- == *
c2--)
127 return cnt == patternLength;
129 case PrefixPattern: {
130 if (fileNameLength + 1 < patternLength)
136 while (cnt < patternLength && *c1++ == *
c2++)
138 return cnt == patternLength;
143 return fileNameLength == 7
147 if (fileNameLength < 6)
150 const bool lastCharOK = (lastChar.isDigit() && lastChar != u
'0')
156#if QT_CONFIG(regularexpression)
169 return pattern.lastIndexOf(u
'*') == 0
181 return pattern.lastIndexOf(u
'*') == 0
182 &&
pattern.lastIndexOf(u
'.') == 1
202 if (!patterns.contains(glob.mimeType()))
203 patterns.append(glob.mimeType());
205 if (glob.weight() > 50) {
227 if (glob.matchFileName(
fileName) && filterFunc(glob.mimeType())) {
230 result.addMatch(glob.mimeType(), glob.weight(),
pattern, suffixLen);
250 const QString simplePattern =
"*."_L1 + simpleExtension;
252 if (filterFunc(
mime)) {
253 result.addMatch(
mime, 50, simplePattern, simpleExtension.size());
T value(const Key &key) const noexcept
void clear() noexcept(std::is_nothrow_destructible< Node >::value)
Removes all items from the hash and frees up all memory used by it.
void append(parameter_type t)
void addGlob(const QMimeGlobPattern &glob)
void matchingGlobs(const QString &fileName, QMimeGlobMatchResult &result, const AddMatchFilterFunc &filterFunc) const
PatternsMap m_fastPatterns
void removeMimeType(const QString &mimeType)
QMimeGlobPatternList m_highWeightGlobs
QMimeGlobPatternList m_lowWeightGlobs
bool hasPattern(QStringView mimeType, QStringView pattern) const
void removeMimeType(QStringView mimeType)
"noglobs" is very rare occurrence, so it's ok if it's slow
void match(QMimeGlobMatchResult &result, const QString &fileName, const AddMatchFilterFunc &filterFunc) const
The QMimeGlobPattern class contains the glob pattern for file names for MIME type matching.
bool matchFileName(const QString &inputFileName) const
static QRegularExpression fromWildcard(QStringView pattern, Qt::CaseSensitivity cs=Qt::CaseInsensitive, WildcardConversionOptions options=DefaultWildcardConversion)
constexpr QStringView mid(qsizetype pos, qsizetype n=-1) const noexcept
Returns the substring of length length starting at position start in this object.
\macro QT_RESTRICTED_CAST_FROM_ASCII
QString mid(qsizetype position, qsizetype n=-1) const &
qsizetype size() const noexcept
Returns the number of characters in this string.
QString right(qsizetype n) const &
QString toLower() const &
const QChar * unicode() const
Returns a Unicode representation of the string.
Combined button and popup list for selecting options.
static bool isSimplePattern(QStringView pattern)
static bool isFastPattern(QStringView pattern)
std::function< bool(const QString &)> AddMatchFilterFunc
GLint GLint GLint GLint GLint x
[0]
GLuint GLuint GLfloat weight
application x qt windows mime
[2]
The QMimeGlobMatchResult class accumulates results from glob matching.
void addMatch(const QString &mimeType, int weight, const QString &pattern, qsizetype knownSuffixLength=0)
qsizetype m_matchingPatternLength
QStringList m_allMatchingMimeTypes
qsizetype m_knownSuffixLength
QStringList m_matchingMimeTypes