Replace use of QRegExp

This commit is contained in:
Jonas Kvinge
2020-07-20 00:57:42 +02:00
parent eb270df835
commit 0b7b7656b2
15 changed files with 105 additions and 85 deletions

View File

@@ -27,7 +27,7 @@
#include <QString>
#include <QStringBuilder>
#include <QRegularExpression>
#include <QRegExp>
#include <QRegularExpressionMatch>
#include <QUrl>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
@@ -49,14 +49,16 @@ SongList ASXParser::Load(QIODevice *device, const QString &playlist_path, const
QByteArray data = device->readAll();
// Some playlists have unescaped & characters in URLs :(
QRegExp ex("(href\\s*=\\s*\")([^\"]+)\"");
QRegularExpression ex("(href\\s*=\\s*\")([^\"]+)\"");
QRegularExpressionMatch re_match;
int index = 0;
while ((index = ex.indexIn(data, index)) != -1) {
QString url = ex.cap(2);
for (re_match = ex.match(data, index) ; re_match.hasMatch() ; re_match = ex.match(data, index)) {
index = re_match.capturedStart();
QString url = re_match.captured(2);
url.replace(QRegularExpression("&(?!amp;|quot;|apos;|lt;|gt;)"), "&amp;");
QByteArray replacement = QString(ex.cap(1) + url + "\"").toLocal8Bit();
data.replace(ex.cap(0).toLocal8Bit(), replacement);
QByteArray replacement = QString(re_match.captured(1) + url + "\"").toLocal8Bit();
data.replace(re_match.captured(0).toLocal8Bit(), replacement);
index += replacement.length();
}

View File

@@ -28,7 +28,7 @@
#include <QString>
#include <QStringList>
#include <QRegularExpression>
#include <QRegExp>
#include <QRegularExpressionMatch>
#include <QTextCodec>
#include <QTextStream>
#include <QtDebug>
@@ -272,13 +272,14 @@ SongList CueParser::Load(QIODevice *device, const QString &playlist_path, const
// line into logical parts and getting rid of all the unnecessary whitespaces and quoting.
QStringList CueParser::SplitCueLine(const QString &line) const {
QRegExp line_regexp(kFileLineRegExp);
if (!line_regexp.exactMatch(line.trimmed())) {
QRegularExpression line_regexp(kFileLineRegExp);
QRegularExpressionMatch re_match = line_regexp.match(line.trimmed());
if (!re_match.hasMatch()) {
return QStringList();
}
// Let's remove the empty entries while we're at it
return line_regexp.capturedTexts().filter(QRegularExpression(".+")).mid(1, -1);
return re_match.capturedTexts().filter(QRegularExpression(".+")).mid(1, -1);
}
@@ -336,12 +337,13 @@ bool CueParser::UpdateLastSong(const CueEntry &entry, Song *song) const {
qint64 CueParser::IndexToMarker(const QString &index) const {
QRegExp index_regexp(kIndexRegExp);
if (!index_regexp.exactMatch(index)) {
QRegularExpression index_regexp(kIndexRegExp);
QRegularExpressionMatch re_match = index_regexp.match(index);
if (!re_match.hasMatch()) {
return -1;
}
QStringList splitted = index_regexp.capturedTexts().mid(1, -1);
QStringList splitted = re_match.capturedTexts().mid(1, -1);
qlonglong frames = splitted.at(0).toLongLong() * 60 * 75 + splitted.at(1).toLongLong() * 75 + splitted.at(2).toLongLong();
return (frames * kNsecPerSec) / 75;

View File

@@ -25,7 +25,8 @@
#include <QMap>
#include <QByteArray>
#include <QString>
#include <QRegExp>
#include <QRegularExpression>
#include <QRegularExpressionMatch>
#include <QTextStream>
#include "core/timeconstants.h"
@@ -48,7 +49,7 @@ SongList PLSParser::Load(QIODevice *device, const QString &playlist_path, const
Q_UNUSED(playlist_path);
QMap<int, Song> songs;
QRegExp n_re("\\d+$");
QRegularExpression n_re("\\d+$");
while (!device->atEnd()) {
QString line = QString::fromUtf8(device->readLine()).trimmed();
@@ -56,8 +57,8 @@ SongList PLSParser::Load(QIODevice *device, const QString &playlist_path, const
QString key = line.left(equals).toLower();
QString value = line.mid(equals + 1);
n_re.indexIn(key);
int n = n_re.cap(0).toInt();
QRegularExpressionMatch re_match = n_re.match(key);
int n = re_match.captured(0).toInt();
if (key.startsWith("file")) {
Song song = LoadSong(value, 0, dir);