Changeset View
Changeset View
Standalone View
Standalone View
src/file/regexpcache.cpp
Show All 30 Lines | |||||
31 | 31 | | |||
32 | RegExpCache::~RegExpCache() | 32 | RegExpCache::~RegExpCache() | ||
33 | { | 33 | { | ||
34 | } | 34 | } | ||
35 | 35 | | |||
36 | 36 | | |||
37 | bool RegExpCache::exactMatch(const QString& s) const | 37 | bool RegExpCache::exactMatch(const QString& s) const | ||
38 | { | 38 | { | ||
39 | if (m_exactMatches.contains(s)) { | ||||
40 | return true; | ||||
41 | } | ||||
39 | for (const QRegularExpression& filter : qAsConst(m_regexpCache)) { | 42 | for (const QRegularExpression& filter : qAsConst(m_regexpCache)) { | ||
40 | if (filter.match(s).hasMatch()) { | 43 | if (filter.match(s).hasMatch()) { | ||
41 | return true; | 44 | return true; | ||
42 | } | 45 | } | ||
43 | } | 46 | } | ||
44 | return false; | 47 | return false; | ||
45 | } | 48 | } | ||
46 | 49 | | |||
47 | void RegExpCache::rebuildCacheFromFilterList(const QStringList& filters) | 50 | void RegExpCache::rebuildCacheFromFilterList(const QStringList& filters) | ||
48 | { | 51 | { | ||
49 | m_regexpCache.clear(); | 52 | m_regexpCache.clear(); | ||
53 | m_exactMatches.clear(); | ||||
50 | for (const QString& filter : filters) { | 54 | for (const QString& filter : filters) { | ||
51 | QString f = filter; | 55 | QString f = filter; | ||
56 | if (!f.contains(QLatin1Char('*')) && !f.contains(QLatin1Char('?'))) { | ||||
57 | m_exactMatches += f; | ||||
58 | continue; | ||||
59 | } | ||||
52 | f.replace(QLatin1Char('.'), QStringLiteral("\\.")); | 60 | f.replace(QLatin1Char('.'), QStringLiteral("\\.")); | ||
poboiko: A quick note for future. There is `QRegularExpression::wildcardToRegularExpression()`, which… | |||||
53 | f.replace(QLatin1Char('?'), QLatin1Char('.')); | 61 | f.replace(QLatin1Char('?'), QLatin1Char('.')); | ||
54 | f.replace(QStringLiteral("*"), QStringLiteral(".*")); | 62 | f.replace(QStringLiteral("*"), QStringLiteral(".*")); | ||
55 | f = QLatin1String("^") + f + QLatin1String("$"); | 63 | f = QLatin1String("^") + f + QLatin1String("$"); | ||
56 | 64 | | |||
57 | m_regexpCache.append(QRegularExpression(f)); | 65 | m_regexpCache.append(QRegularExpression(f)); | ||
58 | } | 66 | } | ||
59 | } | 67 | } |
A quick note for future. There is QRegularExpression::wildcardToRegularExpression(), which apparently does precicely this.
It is there since Qt 5.12 though, while we depend on Qt 5.10. But Plasma already bumped dependency to 5.12, so so we can change it when Frameworks will follow this bump.