diff --git a/src/core/song.cpp b/src/core/song.cpp index 9ec51794a..143612b39 100644 --- a/src/core/song.cpp +++ b/src/core/song.cpp @@ -38,7 +38,6 @@ #include #include #include -#include #include #include #include diff --git a/src/core/utilities.cpp b/src/core/utilities.cpp index 56572cd8c..ab5e864d1 100644 --- a/src/core/utilities.cpp +++ b/src/core/utilities.cpp @@ -51,7 +51,7 @@ #include #include #include -#include +#include #include #include #include @@ -604,8 +604,9 @@ bool ParseUntilElementCI(QXmlStreamReader *reader, const QString &name) { QDateTime ParseRFC822DateTime(const QString &text) { - QRegExp regexp("(\\d{1,2}) (\\w{3,12}) (\\d+) (\\d{1,2}):(\\d{1,2}):(\\d{1,2})"); - if (regexp.indexIn(text) == -1) { + QRegularExpression regexp("(\\d{1,2}) (\\w{3,12}) (\\d+) (\\d{1,2}):(\\d{1,2}):(\\d{1,2})"); + QRegularExpressionMatch re_match = regexp.match(text); + if (!re_match.hasMatch()) { return QDateTime(); } @@ -637,9 +638,9 @@ QDateTime ParseRFC822DateTime(const QString &text) { monthmap["November"] = 11; monthmap["December"] = 12; - const QDate date(regexp.cap(static_cast(MatchNames::YEARS)).toInt(), monthmap[regexp.cap(static_cast(MatchNames::MONTHS))], regexp.cap(static_cast(MatchNames::DAYS)).toInt()); + const QDate date(re_match.captured(static_cast(MatchNames::YEARS)).toInt(), monthmap[re_match.captured(static_cast(MatchNames::MONTHS))], re_match.captured(static_cast(MatchNames::DAYS)).toInt()); - const QTime time(regexp.cap(static_cast(MatchNames::HOURS)).toInt(), regexp.cap(static_cast(MatchNames::MINUTES)).toInt(), regexp.cap(static_cast(MatchNames::SECONDS)).toInt()); + const QTime time(re_match.captured(static_cast(MatchNames::HOURS)).toInt(), re_match.captured(static_cast(MatchNames::MINUTES)).toInt(), re_match.captured(static_cast(MatchNames::SECONDS)).toInt()); return QDateTime(date, time); @@ -923,16 +924,17 @@ QString MacAddress() { QString ReplaceMessage(const QString &message, const Song &song, const QString &newline) { - QRegExp variable_replacer("[%][a-z]+[%]"); + QRegularExpression variable_replacer("[%][a-z]+[%]"); QString copy(message); // Replace the first line int pos = 0; - variable_replacer.indexIn(message); - while ((pos = variable_replacer.indexIn(message, pos)) != -1) { - QStringList captured = variable_replacer.capturedTexts(); + QRegularExpressionMatch match; + for (match = variable_replacer.match(message, pos) ; match.hasMatch() ; match = variable_replacer.match(message, pos)) { + pos = match.capturedStart(); + QStringList captured = match.capturedTexts(); copy.replace(captured[0], ReplaceVariable(captured[0], song, newline)); - pos += variable_replacer.matchedLength(); + pos += match.capturedLength(); } int index_of = copy.indexOf(QRegularExpression(" - (>|$)")); diff --git a/src/device/cddalister.cpp b/src/device/cddalister.cpp index 446d0e964..8e064cd33 100644 --- a/src/device/cddalister.cpp +++ b/src/device/cddalister.cpp @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include // This must come after Qt includes @@ -123,7 +123,7 @@ bool CddaLister::Init() { } #ifdef Q_OS_MACOS // Every track is detected as a separate device on Darwin. The raw disk looks like /dev/rdisk1 - if (!device.contains(QRegExp("^/dev/rdisk[0-9]$"))) { + if (!device.contains(QRegularExpression("^/dev/rdisk[0-9]$"))) { continue; } #endif diff --git a/src/device/giolister.cpp b/src/device/giolister.cpp index f3e1fccb8..ddfc0841a 100644 --- a/src/device/giolister.cpp +++ b/src/device/giolister.cpp @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include #include @@ -237,11 +237,12 @@ QList GioLister::MakeDeviceUrls(const QString &id) { url.setScheme("ipod"); } - QRegExp device_re("usb/(\\d+)/(\\d+)"); - if (device_re.indexIn(unix_device) >= 0) { + QRegularExpression device_re("usb/(\\d+)/(\\d+)"); + QRegularExpressionMatch re_match = device_re.match(unix_device); + if (re_match.hasMatch()) { QUrlQuery url_query(url); - url_query.addQueryItem("busnum", device_re.cap(1)); - url_query.addQueryItem("devnum", device_re.cap(2)); + url_query.addQueryItem("busnum", re_match.captured(1)); + url_query.addQueryItem("devnum", re_match.captured(2)); url.setQuery(url_query); } diff --git a/src/device/mtpconnection.cpp b/src/device/mtpconnection.cpp index 7eace3c20..cb96b113e 100644 --- a/src/device/mtpconnection.cpp +++ b/src/device/mtpconnection.cpp @@ -27,9 +27,10 @@ #include #include #include -#include #include #include +#include +#include #include #include "core/logging.h" @@ -39,16 +40,17 @@ MtpConnection::MtpConnection(const QUrl &url) : device_(nullptr) { QString hostname = url.host(); // Parse the URL - QRegExp host_re("^usb-(\\d+)-(\\d+)$"); + QRegularExpression host_re("^usb-(\\d+)-(\\d+)$"); unsigned int bus_location = 0; unsigned int device_num = 0; QUrlQuery url_query(url); - if (host_re.indexIn(hostname) >= 0) { - bus_location = host_re.cap(1).toUInt(); - device_num = host_re.cap(2).toUInt(); + QRegularExpressionMatch re_match = host_re.match(hostname); + if (re_match.hasMatch()) { + bus_location = re_match.captured(1).toUInt(); + device_num = re_match.captured(2).toUInt(); } else if (url_query.hasQueryItem("busnum")) { bus_location = url_query.queryItemValue("busnum").toUInt(); diff --git a/src/internet/localredirectserver.cpp b/src/internet/localredirectserver.cpp index 767c56e8a..05121b717 100644 --- a/src/internet/localredirectserver.cpp +++ b/src/internet/localredirectserver.cpp @@ -36,7 +36,8 @@ #include #include #include -#include +#include +#include #include #include #include @@ -344,16 +345,18 @@ void LocalRedirectServer::WriteTemplate() const { page_file.open(QIODevice::ReadOnly); QString page_data = QString::fromUtf8(page_file.readAll()); - QRegExp tr_regexp("tr\\(\"([^\"]+)\"\\)"); + QRegularExpression tr_regexp("tr\\(\"([^\"]+)\"\\)"); int offset = 0; forever { - offset = tr_regexp.indexIn(page_data, offset); + QRegularExpressionMatch re_match = tr_regexp.match(page_data, offset); + if (!re_match.hasMatch()) break; + offset = re_match.capturedStart(); if (offset == -1) { break; } - page_data.replace(offset, tr_regexp.matchedLength(), tr(tr_regexp.cap(1).toUtf8())); - offset += tr_regexp.matchedLength(); + page_data.replace(offset, re_match.capturedLength(), tr(re_match.captured(1).toUtf8())); + offset += re_match.capturedLength(); } QBuffer image_buffer; diff --git a/src/musicbrainz/musicbrainzclient.cpp b/src/musicbrainz/musicbrainzclient.cpp index b7fa3a824..960732af1 100644 --- a/src/musicbrainz/musicbrainzclient.cpp +++ b/src/musicbrainz/musicbrainzclient.cpp @@ -31,7 +31,8 @@ #include #include #include -#include +#include +#include #include #include #include @@ -270,9 +271,10 @@ void MusicBrainzClient::DiscIdRequestFinished(const QString &discid, QNetworkRep album = reader.readElementText(); } else if (name == "date") { - QRegExp regex(kDateRegex); - if (regex.indexIn(reader.readElementText()) == 0) { - year = regex.cap(0).toInt(); + QRegularExpression regex(kDateRegex); + QRegularExpressionMatch re_match = regex.match(reader.readElementText()); + if (re_match.capturedStart() == 0) { + year = re_match.captured(0).toInt(); } } else if (name == "artist-credit") { @@ -465,9 +467,10 @@ MusicBrainzClient::Release MusicBrainzClient::ParseRelease(QXmlStreamReader *rea ret.SetStatusFromString(reader->readElementText()); } else if (name == "date") { - QRegExp regex(kDateRegex); - if (regex.indexIn(reader->readElementText()) == 0) { - ret.year_ = regex.cap(0).toInt(); + QRegularExpression regex(kDateRegex); + QRegularExpressionMatch re_match = regex.match(reader->readElementText()); + if (re_match.capturedStart() == 0) { + ret.year_ = re_match.captured(0).toInt(); } } else if (name == "track-list") { diff --git a/src/organise/organiseformat.cpp b/src/organise/organiseformat.cpp index 011208a7d..e9cd273b7 100644 --- a/src/organise/organiseformat.cpp +++ b/src/organise/organiseformat.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include #include @@ -180,30 +180,33 @@ QString OrganiseFormat::GetFilenameForSong(const Song &song) const { QString OrganiseFormat::ParseBlock(QString block, const Song &song, bool *any_empty) const { - QRegExp tag_regexp(kTagPattern); - QRegExp block_regexp(kBlockPattern); + QRegularExpression tag_regexp(kTagPattern); + QRegularExpression block_regexp(kBlockPattern); // Find any blocks first int pos = 0; - while ((pos = block_regexp.indexIn(block, pos)) != -1) { + QRegularExpressionMatch re_match; + for (re_match = block_regexp.match(block, pos) ; re_match.hasMatch() ; re_match = block_regexp.match(block, pos)) { + pos = re_match.capturedStart(); // Recursively parse the block bool empty = false; - QString value = ParseBlock(block_regexp.cap(1), song, &empty); + QString value = ParseBlock(re_match.captured(1), song, &empty); if (empty) value = ""; // Replace the block's value - block.replace(pos, block_regexp.matchedLength(), value); + block.replace(pos, re_match.capturedLength(), value); pos += value.length(); } // Now look for tags bool empty = false; pos = 0; - while ((pos = tag_regexp.indexIn(block, pos)) != -1) { - QString value = TagValue(tag_regexp.cap(1), song); + for (re_match = tag_regexp.match(block, pos) ; re_match.hasMatch() ; re_match = tag_regexp.match(block, pos)) { + pos = re_match.capturedStart(); + QString value = TagValue(re_match.captured(1), song); if (value.isEmpty()) empty = true; - block.replace(pos, tag_regexp.matchedLength(), value); + block.replace(pos, re_match.capturedLength(), value); pos += value.length(); } @@ -281,7 +284,7 @@ OrganiseFormat::Validator::Validator(QObject *parent) : QValidator(parent) {} QValidator::State OrganiseFormat::Validator::validate(QString &input, int&) const { - QRegExp tag_regexp(kTagPattern); + QRegularExpression tag_regexp(kTagPattern); // Make sure all the blocks match up int block_level = 0; @@ -297,12 +300,14 @@ QValidator::State OrganiseFormat::Validator::validate(QString &input, int&) cons if (block_level != 0) return QValidator::Invalid; // Make sure the tags are valid + QRegularExpressionMatch re_match; int pos = 0; - while ((pos = tag_regexp.indexIn(input, pos)) != -1) { - if (!OrganiseFormat::kKnownTags.contains(tag_regexp.cap(1))) + for (re_match = tag_regexp.match(input, pos) ; re_match.hasMatch() ; re_match = tag_regexp.match(input, pos)) { + pos = re_match.capturedStart(); + if (!OrganiseFormat::kKnownTags.contains(re_match.captured(1))) return QValidator::Invalid; - pos += tag_regexp.matchedLength(); + pos += re_match.capturedLength(); } return QValidator::Acceptable; @@ -325,8 +330,8 @@ void OrganiseFormat::SyntaxHighlighter::highlightBlock(const QString &text) { const QRgb valid_tag_color = light ? kValidTagColorLight : kValidTagColorDark; const QRgb invalid_tag_color = light ? kInvalidTagColorLight : kInvalidTagColorDark; - QRegExp tag_regexp(kTagPattern); - QRegExp block_regexp(kBlockPattern); + QRegularExpression tag_regexp(kTagPattern); + QRegularExpression block_regexp(kBlockPattern); QTextCharFormat block_format; block_format.setBackground(QColor(block_color)); @@ -335,20 +340,23 @@ void OrganiseFormat::SyntaxHighlighter::highlightBlock(const QString &text) { setFormat(0, text.length(), QTextCharFormat()); // Blocks + QRegularExpressionMatch re_match; int pos = 0; - while ((pos = block_regexp.indexIn(text, pos)) != -1) { - setFormat(pos, block_regexp.matchedLength(), block_format); - pos += block_regexp.matchedLength(); + for (re_match = block_regexp.match(text, pos) ; re_match.hasMatch() ; re_match = block_regexp.match(text, pos)) { + pos = re_match.capturedStart(); + setFormat(pos, re_match.capturedLength(), block_format); + pos += re_match.capturedLength(); } // Tags pos = 0; - while ((pos = tag_regexp.indexIn(text, pos)) != -1) { + for (re_match = tag_regexp.match(text, pos) ; re_match.hasMatch() ; re_match = tag_regexp.match(text, pos)) { + pos = re_match.capturedStart(); QTextCharFormat f = format(pos); - f.setForeground(QColor(OrganiseFormat::kKnownTags.contains(tag_regexp.cap(1)) ? valid_tag_color : invalid_tag_color)); + f.setForeground(QColor(OrganiseFormat::kKnownTags.contains(re_match.captured(1)) ? valid_tag_color : invalid_tag_color)); - setFormat(pos, tag_regexp.matchedLength(), f); - pos += tag_regexp.matchedLength(); + setFormat(pos, re_match.capturedLength(), f); + pos += re_match.capturedLength(); } } diff --git a/src/playlist/playlistdelegates.cpp b/src/playlist/playlistdelegates.cpp index 21e4910ae..3d893bdb7 100644 --- a/src/playlist/playlistdelegates.cpp +++ b/src/playlist/playlistdelegates.cpp @@ -42,7 +42,6 @@ #include #include #include -#include #include #include #include diff --git a/src/playlistparsers/asxparser.cpp b/src/playlistparsers/asxparser.cpp index 40befbe8b..f092217c5 100644 --- a/src/playlistparsers/asxparser.cpp +++ b/src/playlistparsers/asxparser.cpp @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include @@ -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;)"), "&"); - 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(); } diff --git a/src/playlistparsers/cueparser.cpp b/src/playlistparsers/cueparser.cpp index 229f302b5..373702c5b 100644 --- a/src/playlistparsers/cueparser.cpp +++ b/src/playlistparsers/cueparser.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include #include @@ -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; diff --git a/src/playlistparsers/plsparser.cpp b/src/playlistparsers/plsparser.cpp index 3395e9bde..daa581c3f 100644 --- a/src/playlistparsers/plsparser.cpp +++ b/src/playlistparsers/plsparser.cpp @@ -25,7 +25,8 @@ #include #include #include -#include +#include +#include #include #include "core/timeconstants.h" @@ -48,7 +49,7 @@ SongList PLSParser::Load(QIODevice *device, const QString &playlist_path, const Q_UNUSED(playlist_path); QMap 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); diff --git a/src/settings/behavioursettingspage.cpp b/src/settings/behavioursettingspage.cpp index 724092082..73dd9419c 100644 --- a/src/settings/behavioursettingspage.cpp +++ b/src/settings/behavioursettingspage.cpp @@ -26,7 +26,8 @@ #include #include #include -#include +#include +#include #include #include #include @@ -74,13 +75,15 @@ BehaviourSettingsPage::BehaviourSettingsPage(SettingsDialog *dialog) : SettingsP // Populate the language combo box. We do this by looking at all the compiled in translations. QDir dir(":/translations/"); QStringList codes(dir.entryList(QStringList() << "*.qm")); - QRegExp lang_re("^strawberry_(.*).qm$"); + QRegularExpression lang_re("^strawberry_(.*).qm$"); for (const QString &filename : codes) { - // The regex captures the "ru" from "strawberry_ru.qm" - if (!lang_re.exactMatch(filename)) continue; + QRegularExpressionMatch re_match = lang_re.match(filename); - QString code = lang_re.cap(1); + // The regex captures the "ru" from "strawberry_ru.qm" + if (!re_match.hasMatch()) continue; + + QString code = re_match.captured(1); QString lookup_code = QString(code) .replace("@latin", "_Latn") .replace("_CN", "_Hans_CN") diff --git a/src/subsonic/subsonicrequest.cpp b/src/subsonic/subsonicrequest.cpp index 8501e505d..8a4409bc7 100644 --- a/src/subsonic/subsonicrequest.cpp +++ b/src/subsonic/subsonicrequest.cpp @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include diff --git a/tests/src/tagreader_test.cpp b/tests/src/tagreader_test.cpp index 21d1a7ed6..b1884ff31 100644 --- a/tests/src/tagreader_test.cpp +++ b/tests/src/tagreader_test.cpp @@ -25,10 +25,6 @@ #include #include #include -#include -#include -#include -#include #include #include "core/song.h"