cleanup: replace QRegExp with QRegularExpression

Qt 6 will drop support for QRegExp.
Use QRegularExpression instead.

The exactMatch in getVersion() was rather bogus, given the pattern.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2021-10-25 17:02:35 -07:00
parent 7d6552ff65
commit ee87d28d7b

View file

@ -996,30 +996,36 @@ bool QMLManager::checkDuration(struct dive *d, QString duration)
{ {
if (formatDiveDuration(d) != duration) { if (formatDiveDuration(d) != duration) {
int h = 0, m = 0, s = 0; int h = 0, m = 0, s = 0;
QRegExp r1(QStringLiteral("(\\d*)\\s*%1[\\s,:]*(\\d*)\\s*%2[\\s,:]*(\\d*)\\s*%3").arg(tr("h")).arg(tr("min")).arg(tr("sec")), Qt::CaseInsensitive); QRegularExpression r1(QStringLiteral("(\\d*)\\s*%1[\\s,:]*(\\d*)\\s*%2[\\s,:]*(\\d*)\\s*%3").arg(tr("h")).arg(tr("min")).arg(tr("sec")), QRegularExpression::CaseInsensitiveOption);
QRegExp r2(QStringLiteral("(\\d*)\\s*%1[\\s,:]*(\\d*)\\s*%2").arg(tr("h")).arg(tr("min")), Qt::CaseInsensitive); QRegularExpressionMatch m1 = r1.match(duration);
QRegExp r3(QStringLiteral("(\\d*)\\s*%1").arg(tr("min")), Qt::CaseInsensitive); QRegularExpression r2(QStringLiteral("(\\d*)\\s*%1[\\s,:]*(\\d*)\\s*%2").arg(tr("h")).arg(tr("min")), QRegularExpression::CaseInsensitiveOption);
QRegExp r4(QStringLiteral("(\\d*):(\\d*):(\\d*)")); QRegularExpressionMatch m2 = r2.match(duration);
QRegExp r5(QStringLiteral("(\\d*):(\\d*)")); QRegularExpression r3(QStringLiteral("(\\d*)\\s*%1").arg(tr("min")), QRegularExpression::CaseInsensitiveOption);
QRegExp r6(QStringLiteral("(\\d*)")); QRegularExpressionMatch m3 = r3.match(duration);
if (r1.indexIn(duration) >= 0) { QRegularExpression r4(QStringLiteral("(\\d*):(\\d*):(\\d*)"));
h = r1.cap(1).toInt(); QRegularExpressionMatch m4 = r4.match(duration);
m = r1.cap(2).toInt(); QRegularExpression r5(QStringLiteral("(\\d*):(\\d*)"));
s = r1.cap(3).toInt(); QRegularExpressionMatch m5 = r5.match(duration);
} else if (r2.indexIn(duration) >= 0) { QRegularExpression r6(QStringLiteral("(\\d*)"));
h = r2.cap(1).toInt(); QRegularExpressionMatch m6 = r6.match(duration);
m = r2.cap(2).toInt(); if (m1.hasMatch()) {
} else if (r3.indexIn(duration) >= 0) { h = m1.captured(1).toInt();
m = r3.cap(1).toInt(); m = m1.captured(2).toInt();
} else if (r4.indexIn(duration) >= 0) { s = m1.captured(3).toInt();
h = r4.cap(1).toInt(); } else if (m2.hasMatch()) {
m = r4.cap(2).toInt(); h = m2.captured(1).toInt();
s = r4.cap(3).toInt(); m = m2.captured(2).toInt();
} else if (r5.indexIn(duration) >= 0) { } else if (m3.hasMatch()) {
h = r5.cap(1).toInt(); m = m3.captured(1).toInt();
m = r5.cap(2).toInt(); } else if (m4.hasMatch()) {
} else if (r6.indexIn(duration) >= 0) { h = m4.captured(1).toInt();
m = r6.cap(1).toInt(); m = m4.captured(2).toInt();
s = m4.captured(3).toInt();
} else if (m5.hasMatch()) {
h = m5.captured(1).toInt();
m = m5.captured(2).toInt();
} else if (m6.hasMatch()) {
m = m6.captured(1).toInt();
} }
d->dc.duration.seconds = d->duration.seconds = h * 3600 + m * 60 + s; d->dc.duration.seconds = d->duration.seconds = h * 3600 + m * 60 + s;
if (same_string(d->dc.model, "manually added dive")) if (same_string(d->dc.model, "manually added dive"))
@ -1196,7 +1202,7 @@ void QMLManager::commitChanges(QString diveId, QString number, QString date, QSt
} }
if (d->buddy != buddy) { if (d->buddy != buddy) {
if (buddy.contains(",")){ if (buddy.contains(",")){
buddy = buddy.replace(QRegExp("\\s*,\\s*"), ", "); buddy = buddy.replace(QRegularExpression("\\s*,\\s*"), ", ");
} }
diveChanged = true; diveChanged = true;
free(d->buddy); free(d->buddy);
@ -1204,7 +1210,7 @@ void QMLManager::commitChanges(QString diveId, QString number, QString date, QSt
} }
if (d->divemaster != diveMaster) { if (d->divemaster != diveMaster) {
if (diveMaster.contains(",")){ if (diveMaster.contains(",")){
diveMaster = diveMaster.replace(QRegExp("\\s*,\\s*"), ", "); diveMaster = diveMaster.replace(QRegularExpression("\\s*,\\s*"), ", ");
} }
diveChanged = true; diveChanged = true;
free(d->divemaster); free(d->divemaster);
@ -1686,11 +1692,12 @@ QString QMLManager::getDate(const QString& diveId)
QString QMLManager::getVersion() const QString QMLManager::getVersion() const
{ {
QRegExp versionRe(".*:([()\\.,\\d]+).*"); QRegularExpression versionRe(":([()\\.,\\d]+)");
if (!versionRe.exactMatch(getUserAgent())) QRegularExpressionMatch match = versionRe.match(getUserAgent());
if (!match.hasMatch())
return QString(); return QString();
return versionRe.cap(1); return match.captured(1);
} }
QString QMLManager::getGpsFromSiteName(const QString &siteName) QString QMLManager::getGpsFromSiteName(const QString &siteName)
@ -2207,7 +2214,7 @@ void QMLManager::importCacheRepo(QString repo)
QStringList QMLManager::cloudCacheList() const QStringList QMLManager::cloudCacheList() const
{ {
QDir localCacheDir(QString("%1/cloudstorage/").arg(system_default_directory())); QDir localCacheDir(QString("%1/cloudstorage/").arg(system_default_directory()));
QStringList dirs = localCacheDir.entryList().filter(QRegExp("...+")); QStringList dirs = localCacheDir.entryList(QDir::NoDotAndDotDot);
QStringList result; QStringList result;
foreach(QString dir, dirs) { foreach(QString dir, dirs) {
QString originsDir = QString("%1/cloudstorage/%2/.git/refs/remotes/origin/").arg(system_default_directory()).arg(dir); QString originsDir = QString("%1/cloudstorage/%2/.git/refs/remotes/origin/").arg(system_default_directory()).arg(dir);
@ -2215,7 +2222,7 @@ QStringList QMLManager::cloudCacheList() const
if (dir == "localrepo") { if (dir == "localrepo") {
result << QString("localrepo[master]"); result << QString("localrepo[master]");
} else { } else {
foreach(QString branch, remote.entryList().filter(QRegExp("...+"))) { foreach(QString branch, remote.entryList().filter(QRegularExpression("...+"))) {
result << QString("%1[%2]").arg(dir).arg(branch); result << QString("%1[%2]").arg(dir).arg(branch);
} }
} }