aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2020-10-26 21:18:54 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2020-10-26 21:18:54 +0000
commit81170fffef768feee0c91ae953f2c05d1fed6a75 (patch)
tree5f281b5ba6355f021d61cf1a04d9c7c730f4a620
parent4b8d091b06ce56c9797138e62cabfe791b0e60a0 (diff)
downloadqmmp-81170fffef768feee0c91ae953f2c05d1fed6a75.tar.gz
qmmp-81170fffef768feee0c91ae953f2c05d1fed6a75.tar.bz2
qmmp-81170fffef768feee0c91ae953f2c05d1fed6a75.zip
ported some code to QRegularExpression and QDir::match
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@9531 90c681e8-e032-0410-971d-27865f9a5e38
-rw-r--r--src/qmmp/decoder.cpp11
-rw-r--r--src/qmmp/metadatamanager.cpp20
-rw-r--r--src/qmmp/metadatamanager.h4
-rw-r--r--src/qmmpui/fileloader.cpp26
-rw-r--r--src/qmmpui/playlistparser.cpp17
5 files changed, 14 insertions, 64 deletions
diff --git a/src/qmmp/decoder.cpp b/src/qmmp/decoder.cpp
index fbd93f85b..f7938c71c 100644
--- a/src/qmmp/decoder.cpp
+++ b/src/qmmp/decoder.cpp
@@ -288,15 +288,8 @@ QList<DecoderFactory *> Decoder::findByFileExtension(const QString &path)
if(!(fact = item->decoderFactory()))
continue;
- for(const QString &filter : fact->properties().filters)
- {
- QRegExp regexp(filter, Qt::CaseInsensitive, QRegExp::Wildcard);
- if (regexp.exactMatch(path))
- {
- filtered.append(fact);
- break;
- }
- }
+ if(QDir::match(fact->properties().filters, path.section(QChar('/'), -1)))
+ filtered.append(fact);
}
return filtered;
diff --git a/src/qmmp/metadatamanager.cpp b/src/qmmp/metadatamanager.cpp
index e39abb16f..b5b6e95f5 100644
--- a/src/qmmp/metadatamanager.cpp
+++ b/src/qmmp/metadatamanager.cpp
@@ -255,14 +255,8 @@ QFileInfoList MetaDataManager::findCoverFiles(QDir dir, int depth) const
const auto fileListCopy = file_list; //avoid container modification
for(const QFileInfo &i : qAsConst(fileListCopy))
{
- for(const QString &pattern : m_settings->coverNameFilters(false))
- {
- if(QRegExp (pattern, Qt::CaseInsensitive, QRegExp::Wildcard).exactMatch(i.fileName()))
- {
- file_list.removeAll(i);
- break;
- }
- }
+ if(QDir::match(m_settings->coverNameFilters(false), i.fileName()))
+ file_list.removeAll(i);
if(QImageReader::imageFormat(i.fileName()).isEmpty()) //remove unsupported image formats
file_list.removeAll(i.fileName());
@@ -328,16 +322,6 @@ bool MetaDataManager::hasMatch(const QList<QRegularExpression> &regExps, const Q
return false;
}
-bool MetaDataManager::hasMatch(const QList<QRegExp> &regExps, const QString &path)
-{
- for(const QRegExp &re : qAsConst(regExps))
- {
- if(re.exactMatch(path))
- return true;
- }
- return false;
-}
-
MetaDataManager *MetaDataManager::instance()
{
if(!m_instance)
diff --git a/src/qmmp/metadatamanager.h b/src/qmmp/metadatamanager.h
index b642c6775..cdaa4d039 100644
--- a/src/qmmp/metadatamanager.h
+++ b/src/qmmp/metadatamanager.h
@@ -112,10 +112,6 @@ public:
*/
static bool hasMatch(const QList<QRegularExpression> &regExps, const QString &path);
/*!
- * Returns \b true if the one regular expression in the list \b regExps matched against the \b path or \b false otherwise.
- */
- static bool hasMatch(const QList<QRegExp> &regExps, const QString &path);
- /*!
* Returns a pointer to the MetaDataManager instance.
*/
static MetaDataManager* instance();
diff --git a/src/qmmpui/fileloader.cpp b/src/qmmpui/fileloader.cpp
index 55d3ee3c5..11f682b83 100644
--- a/src/qmmpui/fileloader.cpp
+++ b/src/qmmpui/fileloader.cpp
@@ -18,11 +18,11 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
-#include <qmmp/metadatamanager.h>
-#include <QRegExp>
+#include <QRegularExpression>
#include <QMetaType>
#include <QDir>
#include <QApplication>
+#include <qmmp/metadatamanager.h>
#include "fileloader_p.h"
#include "qmmpuisettings.h"
#include "playlistitem.h"
@@ -128,9 +128,9 @@ void FileLoader::insertPlayList(const QString &path, PlayListItem *before)
{
QStringList protocols = MetaDataManager::instance()->protocols();
QList<QRegularExpression> regExps = MetaDataManager::instance()->regExps();
- QList<QRegExp> filters;
+ QList<QRegularExpression> filters;
for(const QString &pattern : MetaDataManager::instance()->nameFilters())
- filters << QRegExp(pattern, Qt::CaseInsensitive, QRegExp::Wildcard);
+ filters << QRegularExpression(QRegularExpression::wildcardToRegularExpression(pattern), QRegularExpression::CaseInsensitiveOption);
QList<PlayListTrack *>::iterator it = tracks.begin();
@@ -146,7 +146,7 @@ void FileLoader::insertPlayList(const QString &path, PlayListItem *before)
continue;
}
}
- else if(!QFile::exists((*it)->path()) || !MetaDataManager::hasMatch(filters, (*it)->path()))
+ else if(!QFile::exists((*it)->path()) || !MetaDataManager::hasMatch(filters, (*it)->path().section(QChar('/'), -1)))
{
delete (*it);
it = tracks.erase(it);
@@ -346,13 +346,7 @@ bool FileLoader::checkRestrictFilters(const QFileInfo &info)
if(m_settings->restrictFilters().isEmpty())
return true;
- for(const QString &filter : m_settings->restrictFilters())
- {
- QRegExp regexp (filter, Qt::CaseInsensitive, QRegExp::Wildcard);
- if(regexp.exactMatch(info.absoluteFilePath()))
- return true;
- }
- return false;
+ return QDir::match(m_settings->restrictFilters(), info.fileName());
}
bool FileLoader::checkExcludeFilters(const QFileInfo &info)
@@ -360,13 +354,7 @@ bool FileLoader::checkExcludeFilters(const QFileInfo &info)
if(m_settings->excludeFilters().isEmpty())
return true;
- for(const QString &filter : m_settings->excludeFilters())
- {
- QRegExp regexp (filter, Qt::CaseInsensitive, QRegExp::Wildcard);
- if(regexp.exactMatch(info.absoluteFilePath()))
- return false;
- }
- return true;
+ return !QDir::match(m_settings->excludeFilters() , info.fileName());
}
void FileLoader::removeIgnoredTracks(QList<PlayListTrack *> *tracks, const QStringList &ignoredPaths)
diff --git a/src/qmmpui/playlistparser.cpp b/src/qmmpui/playlistparser.cpp
index 2aac76bda..e1fdc1756 100644
--- a/src/qmmpui/playlistparser.cpp
+++ b/src/qmmpui/playlistparser.cpp
@@ -19,7 +19,6 @@
***************************************************************************/
#include <QPluginLoader>
-#include <QRegExp>
#include <QList>
#include <QDir>
#include <QApplication>
@@ -61,13 +60,7 @@ QStringList PlayListParser::filters()
bool PlayListParser::isPlayList(const QString &url)
{
- for(const QString &filter : nameFilters())
- {
- QRegExp r(filter, Qt::CaseInsensitive, QRegExp::Wildcard);
- if(r.exactMatch(url))
- return true;
- }
- return false;
+ return QDir::match(nameFilters(), url.section(QChar('/'), -1));
}
PlayListFormat *PlayListParser::findByMime(const QString &mime)
@@ -83,12 +76,8 @@ PlayListFormat *PlayListParser::findByPath(const QString &filePath)
loadFormats();
for(PlayListFormat *format : qAsConst(*m_formats))
{
- for(const QString &filter : format->properties().filters)
- {
- QRegExp r(filter, Qt::CaseInsensitive, QRegExp::Wildcard);
- if(r.exactMatch(filePath))
- return format;
- }
+ if(QDir::match(format->properties().filters, filePath.section(QChar('/'), -1)))
+ return format;
}
return nullptr;
}