diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/plugins/FileDialogs/QmmpFileDialog/qmmpfiledialogimpl.cpp | 4 | ||||
| -rw-r--r-- | src/plugins/FileDialogs/TwoPanelFileDialog/twopanelfiledialogimpl.cpp | 4 | ||||
| -rw-r--r-- | src/qmmp/qmmp.cpp | 91 | ||||
| -rw-r--r-- | src/qmmp/qmmp.h | 5 | ||||
| -rw-r--r-- | src/qmmpui/fileloader.cpp | 4 |
5 files changed, 108 insertions, 0 deletions
diff --git a/src/plugins/FileDialogs/QmmpFileDialog/qmmpfiledialogimpl.cpp b/src/plugins/FileDialogs/QmmpFileDialog/qmmpfiledialogimpl.cpp index e54e35968..6f77459e0 100644 --- a/src/plugins/FileDialogs/QmmpFileDialog/qmmpfiledialogimpl.cpp +++ b/src/plugins/FileDialogs/QmmpFileDialog/qmmpfiledialogimpl.cpp @@ -448,7 +448,11 @@ void QmmpFileDialogImpl::addFiles(const QStringList &list) bool contains = false; for(const QString &str : qt_clean_filter_list(fileTypeComboBox->currentText())) { +#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0) QRegularExpression regExp(QRegularExpression::wildcardToRegularExpression(str)); +#else + QRegularExpression regExp(Qmmp::wildcardToRegularExpression(str)); +#endif if (f_name.contains(regExp)) { contains = true; diff --git a/src/plugins/FileDialogs/TwoPanelFileDialog/twopanelfiledialogimpl.cpp b/src/plugins/FileDialogs/TwoPanelFileDialog/twopanelfiledialogimpl.cpp index 7d7b6c0cd..063f7bd21 100644 --- a/src/plugins/FileDialogs/TwoPanelFileDialog/twopanelfiledialogimpl.cpp +++ b/src/plugins/FileDialogs/TwoPanelFileDialog/twopanelfiledialogimpl.cpp @@ -431,7 +431,11 @@ void TwoPanelFileDialogImpl::addFiles(const QStringList &list, bool play) bool contains = false; for(const QString &str : qt_clean_filter_list(m_ui.fileTypeComboBox->currentText())) { +#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0) QRegularExpression regExp(QRegularExpression::wildcardToRegularExpression(str)); +#else + QRegularExpression regExp(Qmmp::wildcardToRegularExpression(str)); +#endif if (f_name.contains(regExp)) { contains = true; diff --git a/src/qmmp/qmmp.cpp b/src/qmmp/qmmp.cpp index e6c1f9fa7..cc752bbf4 100644 --- a/src/qmmp/qmmp.cpp +++ b/src/qmmp/qmmp.cpp @@ -162,3 +162,94 @@ bool Qmmp::isPortable() return QFile::exists(m_appDir + "/qmmp_portable.txt"); } #endif + +#if QT_VERSION < QT_VERSION_CHECK(5, 12, 0) +QString Qmmp::wildcardToRegularExpression(const QString &pattern) +{ + const int wclen = pattern.length(); + QString rx; + rx.reserve(wclen + wclen / 16); + int i = 0; + const QChar *wc = pattern.data(); + +#ifdef Q_OS_WIN + const QLatin1Char nativePathSeparator('\\'); + const QLatin1String starEscape("[^/\\\\]*"); + const QLatin1String questionMarkEscape("[^/\\\\]"); +#else + const QLatin1Char nativePathSeparator('/'); + const QLatin1String starEscape("[^/]*"); + const QLatin1String questionMarkEscape("[^/]"); +#endif + + while (i < wclen) { + const QChar c = wc[i++]; + switch (c.unicode()) + { + case '*': + rx += starEscape; + break; + case '?': + rx += questionMarkEscape; + break; + case '\\': +#ifdef Q_OS_WIN + case '/': + rx += QLatin1String("[/\\\\]"); + break; +#endif + case '$': + case '(': + case ')': + case '+': + case '.': + case '^': + case '{': + case '|': + case '}': + rx += QLatin1Char('\\'); + rx += c; + break; + case '[': + rx += c; + // Support for the [!abc] or [!a-c] syntax + if (i < wclen) { + if (wc[i] == QLatin1Char('!')) + { + rx += QLatin1Char('^'); + ++i; + } + + if (i < wclen && wc[i] == QLatin1Char(']')) + rx += wc[i++]; + + while (i < wclen && wc[i] != QLatin1Char(']')) + { + // The '/' appearing in a character class invalidates the + // regular expression parsing. It also concerns '\\' on + // Windows OS types. + if (wc[i] == QLatin1Char('/') || wc[i] == nativePathSeparator) + return rx; + if (wc[i] == QLatin1Char('\\')) + rx += QLatin1Char('\\'); + rx += wc[i++]; + } + } + break; + default: + rx += c; + break; + } + } + + return anchoredPattern(rx); +} + +QString Qmmp::anchoredPattern(const QString &expression) +{ + return QString() + + QLatin1String("\\A(?:") + + expression + + QLatin1String(")\\z"); +} +#endif diff --git a/src/qmmp/qmmp.h b/src/qmmp/qmmp.h index 5c556c1ad..d6530796d 100644 --- a/src/qmmp/qmmp.h +++ b/src/qmmp/qmmp.h @@ -197,6 +197,11 @@ public: static bool isPortable(); #endif +#if QT_VERSION < QT_VERSION_CHECK(5, 12, 0) + QString wildcardToRegularExpression(const QString &pattern); + QString anchoredPattern(const QString &expression); +#endif + private: static QString m_configDir; static QString m_langID; diff --git a/src/qmmpui/fileloader.cpp b/src/qmmpui/fileloader.cpp index 594479df9..fc7ca4971 100644 --- a/src/qmmpui/fileloader.cpp +++ b/src/qmmpui/fileloader.cpp @@ -127,7 +127,11 @@ void FileLoader::insertPlayList(const QString &path, PlayListItem *before) QList<QRegularExpression> regExps = MetaDataManager::instance()->regExps(); QList<QRegularExpression> filters; for(const QString &pattern : MetaDataManager::instance()->nameFilters()) +#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0) filters << QRegularExpression(QRegularExpression::wildcardToRegularExpression(pattern), QRegularExpression::CaseInsensitiveOption); +#else + filters << QRegularExpression(Qmmp::wildcardToRegularExpression(pattern), QRegularExpression::CaseInsensitiveOption); +#endif QList<PlayListTrack *>::iterator it = tracks.begin(); |
