From 89f38b68c3a0c4a85b755006bf602d76fdc37875 Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Tue, 27 Oct 2020 18:39:24 +0000 Subject: 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 --- .../PlayListFormats/m3u/m3uplaylistformat.cpp | 21 +++++++----- .../PlayListFormats/pls/plsplaylistformat.cpp | 38 ++++++++++++---------- 2 files changed, 32 insertions(+), 27 deletions(-) (limited to 'src/plugins/PlayListFormats') 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 #include +#include #include #include "m3uplaylistformat.h" @@ -39,8 +40,8 @@ QList 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 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 -#include +#include #include #include "plsplaylistformat.h" @@ -49,57 +49,59 @@ QList 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; -- cgit v1.2.3-13-gbd6f