diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2020-10-27 18:39:24 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2020-10-27 18:39:24 +0000 |
| commit | 89f38b68c3a0c4a85b755006bf602d76fdc37875 (patch) | |
| tree | 674619678c1136c4b4503ff356f6d8a150a3758b /src | |
| parent | 81170fffef768feee0c91ae953f2c05d1fed6a75 (diff) | |
| download | qmmp-89f38b68c3a0c4a85b755006bf602d76fdc37875.tar.gz qmmp-89f38b68c3a0c4a85b755006bf602d76fdc37875.tar.bz2 qmmp-89f38b68c3a0c4a85b755006bf602d76fdc37875.zip | |
ported all remaining code to QRegularExpression
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@9532 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src')
5 files changed, 47 insertions, 41 deletions
diff --git a/src/plugins/FileDialogs/QmmpFileDialog/qmmpfiledialogimpl.cpp b/src/plugins/FileDialogs/QmmpFileDialog/qmmpfiledialogimpl.cpp index 6e4cd08d9..e54e35968 100644 --- a/src/plugins/FileDialogs/QmmpFileDialog/qmmpfiledialogimpl.cpp +++ b/src/plugins/FileDialogs/QmmpFileDialog/qmmpfiledialogimpl.cpp @@ -29,6 +29,7 @@ #include <QHeaderView> #include <QStorageInfo> #include <QStyle> +#include <QRegularExpression> #include <qmmp/qmmp.h> #define HISTORY_SIZE 8 @@ -48,11 +49,11 @@ const char *qt_file_dialog_filter_reg_exp = // Makes a list of filters from a normal filter string "Image Files (*.png *.jpg)" static QStringList qt_clean_filter_list(const QString &filter) { - QRegExp regexp(QString::fromLatin1(qt_file_dialog_filter_reg_exp)); + QRegularExpression regexp(QString::fromLatin1(qt_file_dialog_filter_reg_exp)); QString f = filter; - int i = regexp.indexIn(f); - if (i >= 0) - f = regexp.cap(2); + QRegularExpressionMatch match = regexp.match(f); + if (match.hasMatch()) + f = match.captured(2); return f.split(QLatin1Char(' '), QString::SkipEmptyParts); } @@ -447,8 +448,7 @@ void QmmpFileDialogImpl::addFiles(const QStringList &list) bool contains = false; for(const QString &str : qt_clean_filter_list(fileTypeComboBox->currentText())) { - QRegExp regExp(str); - regExp.setPatternSyntax(QRegExp::Wildcard); + QRegularExpression regExp(QRegularExpression::wildcardToRegularExpression(str)); if (f_name.contains(regExp)) { contains = true; diff --git a/src/plugins/FileDialogs/TwoPanelFileDialog/twopanelfiledialogimpl.cpp b/src/plugins/FileDialogs/TwoPanelFileDialog/twopanelfiledialogimpl.cpp index 9acb4a43b..7d7b6c0cd 100644 --- a/src/plugins/FileDialogs/TwoPanelFileDialog/twopanelfiledialogimpl.cpp +++ b/src/plugins/FileDialogs/TwoPanelFileDialog/twopanelfiledialogimpl.cpp @@ -25,6 +25,7 @@ #include <QSettings> #include <QMessageBox> #include <QHeaderView> +#include <QRegularExpression> #include <qmmp/qmmp.h> #include "twopanelfiledialogimpl.h" @@ -45,11 +46,11 @@ const char *qt_file_dialog_filter_reg_exp = // Makes a list of filters from a normal filter string "Image Files (*.png *.jpg)" static QStringList qt_clean_filter_list(const QString &filter) { - QRegExp regexp(QString::fromLatin1(qt_file_dialog_filter_reg_exp)); + QRegularExpression regexp(QString::fromLatin1(qt_file_dialog_filter_reg_exp)); QString f = filter; - int i = regexp.indexIn(f); - if (i >= 0) - f = regexp.cap(2); + QRegularExpressionMatch match = regexp.match(f); + if (match.hasMatch()) + f = match.captured(2); return f.split(QLatin1Char(' '), QString::SkipEmptyParts); } @@ -430,8 +431,7 @@ void TwoPanelFileDialogImpl::addFiles(const QStringList &list, bool play) bool contains = false; for(const QString &str : qt_clean_filter_list(m_ui.fileTypeComboBox->currentText())) { - QRegExp regExp(str); - regExp.setPatternSyntax(QRegExp::Wildcard); + QRegularExpression regExp(QRegularExpression::wildcardToRegularExpression(str)); if (f_name.contains(regExp)) { contains = true; diff --git a/src/plugins/Input/cue/cuefile.cpp b/src/plugins/Input/cue/cuefile.cpp index d0979e24a..806f5e4c5 100644 --- a/src/plugins/Input/cue/cuefile.cpp +++ b/src/plugins/Input/cue/cuefile.cpp @@ -24,6 +24,7 @@ #include <QSettings> #include <QTextStream> #include <QTextCodec> +#include <QRegularExpression> #include <qmmp/decoder.h> #include <qmmp/metadatamanager.h> #ifdef WITH_ENCA @@ -182,7 +183,7 @@ QString CueFile::getDirtyPath(const QString &cue_path, const QString &path) int dot = cue_path.lastIndexOf('.'); if (dot != -1) { - QRegExp r(QRegExp::escape(cue_path.left(dot)) + "\\.[^\\.]+$"); + QRegularExpression r(QRegularExpression::escape(cue_path.left(dot)) + "\\.[^\\.]+$"); int index = candidates.indexOf(r); int rindex = candidates.lastIndexOf(r); @@ -193,7 +194,7 @@ QString CueFile::getDirtyPath(const QString &cue_path, const QString &path) dot = path.lastIndexOf('.'); if (dot != -1) { - QRegExp r(QRegExp::escape(path.left(dot)) + "\\.[^\\.]+$"); + QRegularExpression r(QRegularExpression::escape(path.left(dot)) + "\\.[^\\.]+$"); int index = candidates.indexOf(r); int rindex = candidates.lastIndexOf(r); diff --git a/src/plugins/PlayListFormats/m3u/m3uplaylistformat.cpp b/src/plugins/PlayListFormats/m3u/m3uplaylistformat.cpp index 95e2bae91..29eb042e0 100644 --- a/src/plugins/PlayListFormats/m3u/m3uplaylistformat.cpp +++ b/src/plugins/PlayListFormats/m3u/m3uplaylistformat.cpp @@ -20,6 +20,7 @@ #include <QFileInfo> #include <QtPlugin> +#include <QRegularExpression> #include <qmmpui/metadataformatter.h> #include "m3uplaylistformat.h" @@ -39,8 +40,8 @@ QList<PlayListTrack *> M3UPlaylistFormat::decode(const QByteArray &contents) if(splitted.isEmpty()) return out; - QRegExp extInfRegExp("#EXTINF:(-{0,1}\\d+),(.*) - (.*)"); - QRegExp extInfRegExp2("#EXTINF:(-{0,1}\\d+),(.*)"); + QRegularExpression extInfRegExp("#EXTINF:(-{0,1}\\d+),(.*) - (.*)"); + QRegularExpression extInfRegExp2("#EXTINF:(-{0,1}\\d+),(.*)"); int length = 0; QString artist, title; bool hasExtInf = false; @@ -51,17 +52,19 @@ QList<PlayListTrack *> M3UPlaylistFormat::decode(const QByteArray &contents) if(str.startsWith("#EXTM3U") || str.isEmpty()) continue; - if(extInfRegExp.indexIn(str) > -1) + QRegularExpressionMatch match; + + if((match = extInfRegExp.match(str)).hasMatch()) { - length = extInfRegExp.cap(1).toInt(); - artist = extInfRegExp.cap(2); - title = extInfRegExp.cap(3); + length = match.captured(1).toInt(); + artist = match.captured(2); + title = match.captured(3); hasExtInf = true; } - else if(extInfRegExp2.indexIn(str) > -1) + else if((match = extInfRegExp2.match(str)).hasMatch()) { - length = extInfRegExp.cap(1).toInt(); - title = extInfRegExp.cap(2); + length = match.captured(1).toInt(); + title = match.captured(2); hasExtInf = true; } diff --git a/src/plugins/PlayListFormats/pls/plsplaylistformat.cpp b/src/plugins/PlayListFormats/pls/plsplaylistformat.cpp index 989173aaa..532acb2f1 100644 --- a/src/plugins/PlayListFormats/pls/plsplaylistformat.cpp +++ b/src/plugins/PlayListFormats/pls/plsplaylistformat.cpp @@ -19,7 +19,7 @@ ***************************************************************************/ #include <QtPlugin> -#include <QRegExp> +#include <QRegularExpression> #include <qmmpui/metadataformatter.h> #include "plsplaylistformat.h" @@ -49,57 +49,59 @@ QList<PlayListTrack *> PLSPlaylistFormat::decode(const QByteArray &contents) return out; } - QRegExp fileRegExp("^File(\\d+)=(.+)"); - QRegExp fullTitleRegExp("^Title(\\d+)=(.+) - (.+)"); - QRegExp titleRegExp("^Title(\\d+)=(.+)"); - QRegExp lengthRegExp("^Length(\\d+)=(-{0,1}\\d+)"); + const QRegularExpression fileRegExp("^File(\\d+)=(.+)"); + const QRegularExpression fullTitleRegExp("^Title(\\d+)=(.+) - (.+)"); + const QRegularExpression titleRegExp("^Title(\\d+)=(.+)"); + const QRegularExpression lengthRegExp("^Length(\\d+)=(-{0,1}\\d+)"); int number = 0; bool error = false; for(const QString &line : qAsConst(splitted)) { - if(fileRegExp.indexIn(line) > -1) + QRegularExpressionMatch match; + + if((match = fileRegExp.match(line)).hasMatch()) { - if((number = fileRegExp.cap(1).toInt()) > 0) + if((number = match.captured(1).toInt()) > 0) { while(number > out.count()) out << new PlayListTrack(); - out[number - 1]->setPath(fileRegExp.cap(2)); + out[number - 1]->setPath(match.captured(2)); } else error = true; } - else if(fullTitleRegExp.indexIn(line) > -1) + else if((match = fullTitleRegExp.match(line)).hasMatch()) { - if((number = fullTitleRegExp.cap(1).toInt()) > 0) + if((number = match.captured(1).toInt()) > 0) { while(number > out.count()) out << new PlayListTrack(); - out[number - 1]->setValue(Qmmp::ARTIST, fullTitleRegExp.cap(2)); - out[number - 1]->setValue(Qmmp::TITLE, fullTitleRegExp.cap(3)); + out[number - 1]->setValue(Qmmp::ARTIST, match.captured(2)); + out[number - 1]->setValue(Qmmp::TITLE, match.captured(3)); } else error = true; } - else if(titleRegExp.indexIn(line) > -1) + else if((match = titleRegExp.match(line)).hasMatch()) { - if((number = titleRegExp.cap(1).toInt()) > 0) + if((number = match.captured(1).toInt()) > 0) { while(number > out.count()) out << new PlayListTrack(); - out[number - 1]->setValue(Qmmp::TITLE, titleRegExp.cap(2)); + out[number - 1]->setValue(Qmmp::TITLE, match.captured(2)); } else error = true; } - else if(lengthRegExp.indexIn(line) > -1) + else if((match = lengthRegExp.match(line)).hasMatch()) { - if((number = lengthRegExp.cap(1).toInt()) > 0) + if((number = match.captured(1).toInt()) > 0) { while(number > out.count()) out << new PlayListTrack(); - out[number - 1]->setDuration(lengthRegExp.cap(2).toInt() * 1000); + out[number - 1]->setDuration(match.captured(2).toInt() * 1000); } else error = true; |
