Replace use of QRegExp
This commit is contained in:
@@ -38,7 +38,6 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QRegExp>
|
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
|
|||||||
@@ -51,7 +51,7 @@
|
|||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QRegExp>
|
#include <QRegularExpressionMatch>
|
||||||
#include <QTcpServer>
|
#include <QTcpServer>
|
||||||
#include <QTemporaryFile>
|
#include <QTemporaryFile>
|
||||||
#include <QPoint>
|
#include <QPoint>
|
||||||
@@ -604,8 +604,9 @@ bool ParseUntilElementCI(QXmlStreamReader *reader, const QString &name) {
|
|||||||
|
|
||||||
QDateTime ParseRFC822DateTime(const QString &text) {
|
QDateTime ParseRFC822DateTime(const QString &text) {
|
||||||
|
|
||||||
QRegExp regexp("(\\d{1,2}) (\\w{3,12}) (\\d+) (\\d{1,2}):(\\d{1,2}):(\\d{1,2})");
|
QRegularExpression regexp("(\\d{1,2}) (\\w{3,12}) (\\d+) (\\d{1,2}):(\\d{1,2}):(\\d{1,2})");
|
||||||
if (regexp.indexIn(text) == -1) {
|
QRegularExpressionMatch re_match = regexp.match(text);
|
||||||
|
if (!re_match.hasMatch()) {
|
||||||
return QDateTime();
|
return QDateTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -637,9 +638,9 @@ QDateTime ParseRFC822DateTime(const QString &text) {
|
|||||||
monthmap["November"] = 11;
|
monthmap["November"] = 11;
|
||||||
monthmap["December"] = 12;
|
monthmap["December"] = 12;
|
||||||
|
|
||||||
const QDate date(regexp.cap(static_cast<int>(MatchNames::YEARS)).toInt(), monthmap[regexp.cap(static_cast<int>(MatchNames::MONTHS))], regexp.cap(static_cast<int>(MatchNames::DAYS)).toInt());
|
const QDate date(re_match.captured(static_cast<int>(MatchNames::YEARS)).toInt(), monthmap[re_match.captured(static_cast<int>(MatchNames::MONTHS))], re_match.captured(static_cast<int>(MatchNames::DAYS)).toInt());
|
||||||
|
|
||||||
const QTime time(regexp.cap(static_cast<int>(MatchNames::HOURS)).toInt(), regexp.cap(static_cast<int>(MatchNames::MINUTES)).toInt(), regexp.cap(static_cast<int>(MatchNames::SECONDS)).toInt());
|
const QTime time(re_match.captured(static_cast<int>(MatchNames::HOURS)).toInt(), re_match.captured(static_cast<int>(MatchNames::MINUTES)).toInt(), re_match.captured(static_cast<int>(MatchNames::SECONDS)).toInt());
|
||||||
|
|
||||||
return QDateTime(date, time);
|
return QDateTime(date, time);
|
||||||
|
|
||||||
@@ -923,16 +924,17 @@ QString MacAddress() {
|
|||||||
|
|
||||||
QString ReplaceMessage(const QString &message, const Song &song, const QString &newline) {
|
QString ReplaceMessage(const QString &message, const Song &song, const QString &newline) {
|
||||||
|
|
||||||
QRegExp variable_replacer("[%][a-z]+[%]");
|
QRegularExpression variable_replacer("[%][a-z]+[%]");
|
||||||
QString copy(message);
|
QString copy(message);
|
||||||
|
|
||||||
// Replace the first line
|
// Replace the first line
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
variable_replacer.indexIn(message);
|
QRegularExpressionMatch match;
|
||||||
while ((pos = variable_replacer.indexIn(message, pos)) != -1) {
|
for (match = variable_replacer.match(message, pos) ; match.hasMatch() ; match = variable_replacer.match(message, pos)) {
|
||||||
QStringList captured = variable_replacer.capturedTexts();
|
pos = match.capturedStart();
|
||||||
|
QStringList captured = match.capturedTexts();
|
||||||
copy.replace(captured[0], ReplaceVariable(captured[0], song, newline));
|
copy.replace(captured[0], ReplaceVariable(captured[0], song, newline));
|
||||||
pos += variable_replacer.matchedLength();
|
pos += match.capturedLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
int index_of = copy.indexOf(QRegularExpression(" - (>|$)"));
|
int index_of = copy.indexOf(QRegularExpression(" - (>|$)"));
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringBuilder>
|
#include <QStringBuilder>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QRegExp>
|
#include <QRegularExpression>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
// This must come after Qt includes
|
// This must come after Qt includes
|
||||||
@@ -123,7 +123,7 @@ bool CddaLister::Init() {
|
|||||||
}
|
}
|
||||||
#ifdef Q_OS_MACOS
|
#ifdef Q_OS_MACOS
|
||||||
// Every track is detected as a separate device on Darwin. The raw disk looks like /dev/rdisk1
|
// 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;
|
continue;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QRegExp>
|
#include <QRegularExpressionMatch>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QUrlQuery>
|
#include <QUrlQuery>
|
||||||
|
|
||||||
@@ -237,11 +237,12 @@ QList<QUrl> GioLister::MakeDeviceUrls(const QString &id) {
|
|||||||
url.setScheme("ipod");
|
url.setScheme("ipod");
|
||||||
}
|
}
|
||||||
|
|
||||||
QRegExp device_re("usb/(\\d+)/(\\d+)");
|
QRegularExpression device_re("usb/(\\d+)/(\\d+)");
|
||||||
if (device_re.indexIn(unix_device) >= 0) {
|
QRegularExpressionMatch re_match = device_re.match(unix_device);
|
||||||
|
if (re_match.hasMatch()) {
|
||||||
QUrlQuery url_query(url);
|
QUrlQuery url_query(url);
|
||||||
url_query.addQueryItem("busnum", device_re.cap(1));
|
url_query.addQueryItem("busnum", re_match.captured(1));
|
||||||
url_query.addQueryItem("devnum", device_re.cap(2));
|
url_query.addQueryItem("devnum", re_match.captured(2));
|
||||||
url.setQuery(url_query);
|
url.setQuery(url_query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,9 +27,10 @@
|
|||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QRegExp>
|
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QUrlQuery>
|
#include <QUrlQuery>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
#include <QRegularExpressionMatch>
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
|
|
||||||
#include "core/logging.h"
|
#include "core/logging.h"
|
||||||
@@ -39,16 +40,17 @@ MtpConnection::MtpConnection(const QUrl &url) : device_(nullptr) {
|
|||||||
|
|
||||||
QString hostname = url.host();
|
QString hostname = url.host();
|
||||||
// Parse the URL
|
// Parse the URL
|
||||||
QRegExp host_re("^usb-(\\d+)-(\\d+)$");
|
QRegularExpression host_re("^usb-(\\d+)-(\\d+)$");
|
||||||
|
|
||||||
unsigned int bus_location = 0;
|
unsigned int bus_location = 0;
|
||||||
unsigned int device_num = 0;
|
unsigned int device_num = 0;
|
||||||
|
|
||||||
QUrlQuery url_query(url);
|
QUrlQuery url_query(url);
|
||||||
|
|
||||||
if (host_re.indexIn(hostname) >= 0) {
|
QRegularExpressionMatch re_match = host_re.match(hostname);
|
||||||
bus_location = host_re.cap(1).toUInt();
|
if (re_match.hasMatch()) {
|
||||||
device_num = host_re.cap(2).toUInt();
|
bus_location = re_match.captured(1).toUInt();
|
||||||
|
device_num = re_match.captured(2).toUInt();
|
||||||
}
|
}
|
||||||
else if (url_query.hasQueryItem("busnum")) {
|
else if (url_query.hasQueryItem("busnum")) {
|
||||||
bus_location = url_query.queryItemValue("busnum").toUInt();
|
bus_location = url_query.queryItemValue("busnum").toUInt();
|
||||||
|
|||||||
@@ -36,7 +36,8 @@
|
|||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QRegExp>
|
#include <QRegularExpression>
|
||||||
|
#include <QRegularExpressionMatch>
|
||||||
#include <QStyle>
|
#include <QStyle>
|
||||||
#include <QHostAddress>
|
#include <QHostAddress>
|
||||||
#include <QSsl>
|
#include <QSsl>
|
||||||
@@ -344,16 +345,18 @@ void LocalRedirectServer::WriteTemplate() const {
|
|||||||
page_file.open(QIODevice::ReadOnly);
|
page_file.open(QIODevice::ReadOnly);
|
||||||
QString page_data = QString::fromUtf8(page_file.readAll());
|
QString page_data = QString::fromUtf8(page_file.readAll());
|
||||||
|
|
||||||
QRegExp tr_regexp("tr\\(\"([^\"]+)\"\\)");
|
QRegularExpression tr_regexp("tr\\(\"([^\"]+)\"\\)");
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
forever {
|
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) {
|
if (offset == -1) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
page_data.replace(offset, tr_regexp.matchedLength(), tr(tr_regexp.cap(1).toUtf8()));
|
page_data.replace(offset, re_match.capturedLength(), tr(re_match.captured(1).toUtf8()));
|
||||||
offset += tr_regexp.matchedLength();
|
offset += re_match.capturedLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
QBuffer image_buffer;
|
QBuffer image_buffer;
|
||||||
|
|||||||
@@ -31,7 +31,8 @@
|
|||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QUrlQuery>
|
#include <QUrlQuery>
|
||||||
#include <QRegExp>
|
#include <QRegularExpression>
|
||||||
|
#include <QRegularExpressionMatch>
|
||||||
#include <QtAlgorithms>
|
#include <QtAlgorithms>
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
@@ -270,9 +271,10 @@ void MusicBrainzClient::DiscIdRequestFinished(const QString &discid, QNetworkRep
|
|||||||
album = reader.readElementText();
|
album = reader.readElementText();
|
||||||
}
|
}
|
||||||
else if (name == "date") {
|
else if (name == "date") {
|
||||||
QRegExp regex(kDateRegex);
|
QRegularExpression regex(kDateRegex);
|
||||||
if (regex.indexIn(reader.readElementText()) == 0) {
|
QRegularExpressionMatch re_match = regex.match(reader.readElementText());
|
||||||
year = regex.cap(0).toInt();
|
if (re_match.capturedStart() == 0) {
|
||||||
|
year = re_match.captured(0).toInt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (name == "artist-credit") {
|
else if (name == "artist-credit") {
|
||||||
@@ -465,9 +467,10 @@ MusicBrainzClient::Release MusicBrainzClient::ParseRelease(QXmlStreamReader *rea
|
|||||||
ret.SetStatusFromString(reader->readElementText());
|
ret.SetStatusFromString(reader->readElementText());
|
||||||
}
|
}
|
||||||
else if (name == "date") {
|
else if (name == "date") {
|
||||||
QRegExp regex(kDateRegex);
|
QRegularExpression regex(kDateRegex);
|
||||||
if (regex.indexIn(reader->readElementText()) == 0) {
|
QRegularExpressionMatch re_match = regex.match(reader->readElementText());
|
||||||
ret.year_ = regex.cap(0).toInt();
|
if (re_match.capturedStart() == 0) {
|
||||||
|
ret.year_ = re_match.captured(0).toInt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (name == "track-list") {
|
else if (name == "track-list") {
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
#include <QStringBuilder>
|
#include <QStringBuilder>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QRegExp>
|
#include <QRegularExpressionMatch>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
@@ -180,30 +180,33 @@ QString OrganiseFormat::GetFilenameForSong(const Song &song) const {
|
|||||||
|
|
||||||
QString OrganiseFormat::ParseBlock(QString block, const Song &song, bool *any_empty) const {
|
QString OrganiseFormat::ParseBlock(QString block, const Song &song, bool *any_empty) const {
|
||||||
|
|
||||||
QRegExp tag_regexp(kTagPattern);
|
QRegularExpression tag_regexp(kTagPattern);
|
||||||
QRegExp block_regexp(kBlockPattern);
|
QRegularExpression block_regexp(kBlockPattern);
|
||||||
|
|
||||||
// Find any blocks first
|
// Find any blocks first
|
||||||
int pos = 0;
|
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
|
// Recursively parse the block
|
||||||
bool empty = false;
|
bool empty = false;
|
||||||
QString value = ParseBlock(block_regexp.cap(1), song, &empty);
|
QString value = ParseBlock(re_match.captured(1), song, &empty);
|
||||||
if (empty) value = "";
|
if (empty) value = "";
|
||||||
|
|
||||||
// Replace the block's value
|
// Replace the block's value
|
||||||
block.replace(pos, block_regexp.matchedLength(), value);
|
block.replace(pos, re_match.capturedLength(), value);
|
||||||
pos += value.length();
|
pos += value.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now look for tags
|
// Now look for tags
|
||||||
bool empty = false;
|
bool empty = false;
|
||||||
pos = 0;
|
pos = 0;
|
||||||
while ((pos = tag_regexp.indexIn(block, pos)) != -1) {
|
for (re_match = tag_regexp.match(block, pos) ; re_match.hasMatch() ; re_match = tag_regexp.match(block, pos)) {
|
||||||
QString value = TagValue(tag_regexp.cap(1), song);
|
pos = re_match.capturedStart();
|
||||||
|
QString value = TagValue(re_match.captured(1), song);
|
||||||
if (value.isEmpty()) empty = true;
|
if (value.isEmpty()) empty = true;
|
||||||
|
|
||||||
block.replace(pos, tag_regexp.matchedLength(), value);
|
block.replace(pos, re_match.capturedLength(), value);
|
||||||
pos += value.length();
|
pos += value.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,7 +284,7 @@ OrganiseFormat::Validator::Validator(QObject *parent) : QValidator(parent) {}
|
|||||||
|
|
||||||
QValidator::State OrganiseFormat::Validator::validate(QString &input, int&) const {
|
QValidator::State OrganiseFormat::Validator::validate(QString &input, int&) const {
|
||||||
|
|
||||||
QRegExp tag_regexp(kTagPattern);
|
QRegularExpression tag_regexp(kTagPattern);
|
||||||
|
|
||||||
// Make sure all the blocks match up
|
// Make sure all the blocks match up
|
||||||
int block_level = 0;
|
int block_level = 0;
|
||||||
@@ -297,12 +300,14 @@ QValidator::State OrganiseFormat::Validator::validate(QString &input, int&) cons
|
|||||||
if (block_level != 0) return QValidator::Invalid;
|
if (block_level != 0) return QValidator::Invalid;
|
||||||
|
|
||||||
// Make sure the tags are valid
|
// Make sure the tags are valid
|
||||||
|
QRegularExpressionMatch re_match;
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
while ((pos = tag_regexp.indexIn(input, pos)) != -1) {
|
for (re_match = tag_regexp.match(input, pos) ; re_match.hasMatch() ; re_match = tag_regexp.match(input, pos)) {
|
||||||
if (!OrganiseFormat::kKnownTags.contains(tag_regexp.cap(1)))
|
pos = re_match.capturedStart();
|
||||||
|
if (!OrganiseFormat::kKnownTags.contains(re_match.captured(1)))
|
||||||
return QValidator::Invalid;
|
return QValidator::Invalid;
|
||||||
|
|
||||||
pos += tag_regexp.matchedLength();
|
pos += re_match.capturedLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
return QValidator::Acceptable;
|
return QValidator::Acceptable;
|
||||||
@@ -325,8 +330,8 @@ void OrganiseFormat::SyntaxHighlighter::highlightBlock(const QString &text) {
|
|||||||
const QRgb valid_tag_color = light ? kValidTagColorLight : kValidTagColorDark;
|
const QRgb valid_tag_color = light ? kValidTagColorLight : kValidTagColorDark;
|
||||||
const QRgb invalid_tag_color = light ? kInvalidTagColorLight : kInvalidTagColorDark;
|
const QRgb invalid_tag_color = light ? kInvalidTagColorLight : kInvalidTagColorDark;
|
||||||
|
|
||||||
QRegExp tag_regexp(kTagPattern);
|
QRegularExpression tag_regexp(kTagPattern);
|
||||||
QRegExp block_regexp(kBlockPattern);
|
QRegularExpression block_regexp(kBlockPattern);
|
||||||
|
|
||||||
QTextCharFormat block_format;
|
QTextCharFormat block_format;
|
||||||
block_format.setBackground(QColor(block_color));
|
block_format.setBackground(QColor(block_color));
|
||||||
@@ -335,20 +340,23 @@ void OrganiseFormat::SyntaxHighlighter::highlightBlock(const QString &text) {
|
|||||||
setFormat(0, text.length(), QTextCharFormat());
|
setFormat(0, text.length(), QTextCharFormat());
|
||||||
|
|
||||||
// Blocks
|
// Blocks
|
||||||
|
QRegularExpressionMatch re_match;
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
while ((pos = block_regexp.indexIn(text, pos)) != -1) {
|
for (re_match = block_regexp.match(text, pos) ; re_match.hasMatch() ; re_match = block_regexp.match(text, pos)) {
|
||||||
setFormat(pos, block_regexp.matchedLength(), block_format);
|
pos = re_match.capturedStart();
|
||||||
pos += block_regexp.matchedLength();
|
setFormat(pos, re_match.capturedLength(), block_format);
|
||||||
|
pos += re_match.capturedLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tags
|
// Tags
|
||||||
pos = 0;
|
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);
|
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);
|
setFormat(pos, re_match.capturedLength(), f);
|
||||||
pos += tag_regexp.matchedLength();
|
pos += re_match.capturedLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,6 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringBuilder>
|
#include <QStringBuilder>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QRegExp>
|
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringBuilder>
|
#include <QStringBuilder>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QRegExp>
|
#include <QRegularExpressionMatch>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QXmlStreamReader>
|
#include <QXmlStreamReader>
|
||||||
#include <QXmlStreamWriter>
|
#include <QXmlStreamWriter>
|
||||||
@@ -49,14 +49,16 @@ SongList ASXParser::Load(QIODevice *device, const QString &playlist_path, const
|
|||||||
QByteArray data = device->readAll();
|
QByteArray data = device->readAll();
|
||||||
|
|
||||||
// Some playlists have unescaped & characters in URLs :(
|
// Some playlists have unescaped & characters in URLs :(
|
||||||
QRegExp ex("(href\\s*=\\s*\")([^\"]+)\"");
|
QRegularExpression ex("(href\\s*=\\s*\")([^\"]+)\"");
|
||||||
|
QRegularExpressionMatch re_match;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
while ((index = ex.indexIn(data, index)) != -1) {
|
for (re_match = ex.match(data, index) ; re_match.hasMatch() ; re_match = ex.match(data, index)) {
|
||||||
QString url = ex.cap(2);
|
index = re_match.capturedStart();
|
||||||
|
QString url = re_match.captured(2);
|
||||||
url.replace(QRegularExpression("&(?!amp;|quot;|apos;|lt;|gt;)"), "&");
|
url.replace(QRegularExpression("&(?!amp;|quot;|apos;|lt;|gt;)"), "&");
|
||||||
|
|
||||||
QByteArray replacement = QString(ex.cap(1) + url + "\"").toLocal8Bit();
|
QByteArray replacement = QString(re_match.captured(1) + url + "\"").toLocal8Bit();
|
||||||
data.replace(ex.cap(0).toLocal8Bit(), replacement);
|
data.replace(re_match.captured(0).toLocal8Bit(), replacement);
|
||||||
index += replacement.length();
|
index += replacement.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QRegExp>
|
#include <QRegularExpressionMatch>
|
||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QtDebug>
|
#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.
|
// line into logical parts and getting rid of all the unnecessary whitespaces and quoting.
|
||||||
QStringList CueParser::SplitCueLine(const QString &line) const {
|
QStringList CueParser::SplitCueLine(const QString &line) const {
|
||||||
|
|
||||||
QRegExp line_regexp(kFileLineRegExp);
|
QRegularExpression line_regexp(kFileLineRegExp);
|
||||||
if (!line_regexp.exactMatch(line.trimmed())) {
|
QRegularExpressionMatch re_match = line_regexp.match(line.trimmed());
|
||||||
|
if (!re_match.hasMatch()) {
|
||||||
return QStringList();
|
return QStringList();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let's remove the empty entries while we're at it
|
// 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 {
|
qint64 CueParser::IndexToMarker(const QString &index) const {
|
||||||
|
|
||||||
QRegExp index_regexp(kIndexRegExp);
|
QRegularExpression index_regexp(kIndexRegExp);
|
||||||
if (!index_regexp.exactMatch(index)) {
|
QRegularExpressionMatch re_match = index_regexp.match(index);
|
||||||
|
if (!re_match.hasMatch()) {
|
||||||
return -1;
|
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();
|
qlonglong frames = splitted.at(0).toLongLong() * 60 * 75 + splitted.at(1).toLongLong() * 75 + splitted.at(2).toLongLong();
|
||||||
return (frames * kNsecPerSec) / 75;
|
return (frames * kNsecPerSec) / 75;
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,8 @@
|
|||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QRegExp>
|
#include <QRegularExpression>
|
||||||
|
#include <QRegularExpressionMatch>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
|
|
||||||
#include "core/timeconstants.h"
|
#include "core/timeconstants.h"
|
||||||
@@ -48,7 +49,7 @@ SongList PLSParser::Load(QIODevice *device, const QString &playlist_path, const
|
|||||||
Q_UNUSED(playlist_path);
|
Q_UNUSED(playlist_path);
|
||||||
|
|
||||||
QMap<int, Song> songs;
|
QMap<int, Song> songs;
|
||||||
QRegExp n_re("\\d+$");
|
QRegularExpression n_re("\\d+$");
|
||||||
|
|
||||||
while (!device->atEnd()) {
|
while (!device->atEnd()) {
|
||||||
QString line = QString::fromUtf8(device->readLine()).trimmed();
|
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 key = line.left(equals).toLower();
|
||||||
QString value = line.mid(equals + 1);
|
QString value = line.mid(equals + 1);
|
||||||
|
|
||||||
n_re.indexIn(key);
|
QRegularExpressionMatch re_match = n_re.match(key);
|
||||||
int n = n_re.cap(0).toInt();
|
int n = re_match.captured(0).toInt();
|
||||||
|
|
||||||
if (key.startsWith("file")) {
|
if (key.startsWith("file")) {
|
||||||
Song song = LoadSong(value, 0, dir);
|
Song song = LoadSong(value, 0, dir);
|
||||||
|
|||||||
@@ -26,7 +26,8 @@
|
|||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QRegExp>
|
#include <QRegularExpression>
|
||||||
|
#include <QRegularExpressionMatch>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QLocale>
|
#include <QLocale>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
@@ -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.
|
// Populate the language combo box. We do this by looking at all the compiled in translations.
|
||||||
QDir dir(":/translations/");
|
QDir dir(":/translations/");
|
||||||
QStringList codes(dir.entryList(QStringList() << "*.qm"));
|
QStringList codes(dir.entryList(QStringList() << "*.qm"));
|
||||||
QRegExp lang_re("^strawberry_(.*).qm$");
|
QRegularExpression lang_re("^strawberry_(.*).qm$");
|
||||||
for (const QString &filename : codes) {
|
for (const QString &filename : codes) {
|
||||||
|
|
||||||
// The regex captures the "ru" from "strawberry_ru.qm"
|
QRegularExpressionMatch re_match = lang_re.match(filename);
|
||||||
if (!lang_re.exactMatch(filename)) continue;
|
|
||||||
|
|
||||||
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)
|
QString lookup_code = QString(code)
|
||||||
.replace("@latin", "_Latn")
|
.replace("@latin", "_Latn")
|
||||||
.replace("_CN", "_Hans_CN")
|
.replace("_CN", "_Hans_CN")
|
||||||
|
|||||||
@@ -28,7 +28,6 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QUrlQuery>
|
#include <QUrlQuery>
|
||||||
#include <QRegExp>
|
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QImageReader>
|
#include <QImageReader>
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
|
|||||||
@@ -25,10 +25,6 @@
|
|||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringList>
|
|
||||||
#include <QTemporaryFile>
|
|
||||||
#include <QTextCodec>
|
|
||||||
#include <QRegExp>
|
|
||||||
#include <QCryptographicHash>
|
#include <QCryptographicHash>
|
||||||
|
|
||||||
#include "core/song.h"
|
#include "core/song.h"
|
||||||
|
|||||||
Reference in New Issue
Block a user