Commit a1a3f2ab authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Use QStringView(..).mid

parent aad05bef
Pipeline #63956 passed with stage
in 53 minutes and 24 seconds
......@@ -29,14 +29,23 @@ QDateTime DateParser::parse(const QString &dateStr) const
for (int i = 0; i < mPattern.length(); ++i) {
if (mPattern[i] == QLatin1Char('y')) { // 19YY
if (currPos + 1 < dateStr.length()) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2)
year = 1900 + QStringView(dateStr).mid(currPos, 2).toInt();
#else
year = 1900 + dateStr.midRef(currPos, 2).toInt();
#endif
currPos += 2;
} else {
return QDateTime();
}
} else if (mPattern[i] == QLatin1Char('Y')) { // YYYY
if (currPos + 3 < dateStr.length()) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2)
year = QStringView(dateStr).mid(currPos, 4).toInt();
#else
year = dateStr.midRef(currPos, 4).toInt();
#endif
currPos += 4;
} else {
return QDateTime();
......@@ -45,7 +54,12 @@ QDateTime DateParser::parse(const QString &dateStr) const
if (currPos + 1 < dateStr.length()) {
if (dateStr[currPos].isDigit()) {
if (dateStr[currPos + 1].isDigit()) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2)
month = QStringView(dateStr).mid(currPos, 2).toInt();
#else
month = dateStr.midRef(currPos, 2).toInt();
#endif
currPos += 2;
continue;
}
......@@ -53,7 +67,12 @@ QDateTime DateParser::parse(const QString &dateStr) const
}
if (currPos < dateStr.length()) {
if (dateStr[currPos].isDigit()) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2)
month = QStringView(dateStr).mid(currPos, 1).toInt();
#else
month = dateStr.midRef(currPos, 1).toInt();
#endif
currPos++;
continue;
}
......@@ -62,7 +81,12 @@ QDateTime DateParser::parse(const QString &dateStr) const
return QDateTime();
} else if (mPattern[i] == QLatin1Char('M')) { // 0M or MM
if (currPos + 1 < dateStr.length()) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2)
month = QStringView(dateStr).mid(currPos, 2).toInt();
#else
month = dateStr.midRef(currPos, 2).toInt();
#endif
currPos += 2;
} else {
return QDateTime();
......@@ -71,7 +95,12 @@ QDateTime DateParser::parse(const QString &dateStr) const
if (currPos + 1 < dateStr.length()) {
if (dateStr[currPos].isDigit()) {
if (dateStr[currPos + 1].isDigit()) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2)
day = QStringView(dateStr).mid(currPos, 2).toInt();
#else
day = dateStr.midRef(currPos, 2).toInt();
#endif
currPos += 2;
continue;
}
......@@ -79,7 +108,12 @@ QDateTime DateParser::parse(const QString &dateStr) const
}
if (currPos < dateStr.length()) {
if (dateStr[currPos].isDigit()) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2)
day = QStringView(dateStr).mid(currPos, 1).toInt();
#else
day = dateStr.midRef(currPos, 1).toInt();
#endif
currPos++;
continue;
}
......@@ -88,28 +122,48 @@ QDateTime DateParser::parse(const QString &dateStr) const
return QDateTime();
} else if (mPattern[i] == QLatin1Char('D')) { // 0D or DD
if (currPos + 1 < dateStr.length()) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2)
day = QStringView(dateStr).mid(currPos, 2).toInt();
#else
day = dateStr.midRef(currPos, 2).toInt();
#endif
currPos += 2;
} else {
return QDateTime();
}
} else if (mPattern[i] == QLatin1Char('H')) { // 0H or HH
if (currPos + 1 < dateStr.length()) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2)
hour = QStringView(dateStr).mid(currPos, 2).toInt();
#else
hour = dateStr.midRef(currPos, 2).toInt();
#endif
currPos += 2;
} else {
return QDateTime();
}
} else if (mPattern[i] == QLatin1Char('I')) { // 0I or II
if (currPos + 1 < dateStr.length()) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2)
minute = QStringView(dateStr).mid(currPos, 2).toInt();
#else
minute = dateStr.midRef(currPos, 2).toInt();
#endif
currPos += 2;
} else {
return QDateTime();
}
} else if (mPattern[i] == QLatin1Char('S')) { // 0S or SS
if (currPos + 1 < dateStr.length()) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2)
second = QStringView(dateStr).mid(currPos, 2).toInt();
#else
second = dateStr.midRef(currPos, 2).toInt();
#endif
currPos += 2;
} else {
return QDateTime();
......
......@@ -66,7 +66,12 @@ bool ItineraryUrlHandler::handleClick(MessageViewer::Viewer *viewerInstance, Mim
const auto m = memento(part);
if (path.startsWith(QLatin1String("semanticExpand?"))) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2)
auto idx = QStringView(path).mid(15).toInt();
#else
auto idx = path.midRef(15).toInt();
#endif
m->toggleExpanded(idx);
const auto nodeHelper = part->nodeHelper();
Q_EMIT nodeHelper->update(MimeTreeParser::Delayed);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment