diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp index 78cfa05ec9..e38f8e70b9 100644 --- a/src/corelib/time/qdatetime.cpp +++ b/src/corelib/time/qdatetime.cpp @@ -156,7 +156,7 @@ static ParsedRfcDateTime rfcDateImpl(const QString &s) // or "ddd MMM dd[ hh:mm:ss] yyyy [±hhmm]" - permissive RFC 850, 1036 (read only) ParsedRfcDateTime result; - auto words = s.splitRef(QLatin1Char(' '), Qt::SkipEmptyParts); + auto words = QStringView{s}.split(QLatin1Char(' '), Qt::SkipEmptyParts); if (words.size() < 3 || words.size() > 6) return result; const QChar colon(QLatin1Char(':')); @@ -1440,7 +1440,7 @@ struct ParsedInt { int value = 0; bool ok = false; }; /* /internal - Read an int that must be the whole text. QStringRef::toInt() will ignore + Read an int that must be the whole text. QStringView ::toInt() will ignore spaces happily; but ISO date format should not. */ ParsedInt readInt(QStringView text) @@ -1477,7 +1477,7 @@ QDate QDate::fromString(const QString &string, Qt::DateFormat format) return rfcDateImpl(string).date; default: case Qt::TextDate: { - QVector parts = string.splitRef(QLatin1Char(' '), Qt::SkipEmptyParts); + auto parts = QStringView{string}.split(QLatin1Char(' '), Qt::SkipEmptyParts); if (parts.count() != 4) return QDate(); @@ -2384,7 +2384,7 @@ static QString qt_tzname(QDateTimePrivate::DaylightStatus daylightStatus) \internal Implemented here to share qt_tzname() */ -int QDateTimeParser::startsWithLocalTimeZone(const QStringRef name) +int QDateTimeParser::startsWithLocalTimeZone(QStringView name) { QDateTimePrivate::DaylightStatus zones[2] = { QDateTimePrivate::StandardTime, @@ -4752,7 +4752,7 @@ QDateTime QDateTime::fromString(const QString &string, Qt::DateFormat format) return QDateTime(date, time, spec, offset); } case Qt::TextDate: { - QVector parts = string.splitRef(QLatin1Char(' '), Qt::SkipEmptyParts); + QVector parts = QStringView{string}.split(QLatin1Char(' '), Qt::SkipEmptyParts); if ((parts.count() < 5) || (parts.count() > 6)) return QDateTime(); @@ -4787,7 +4787,7 @@ QDateTime QDateTime::fromString(const QString &string, Qt::DateFormat format) if (!ok || !month || !day) { month = fromShortMonthName(parts.at(2)); if (month) { - QStringRef dayStr = parts.at(1); + QStringView dayStr = parts.at(1); if (dayStr.endsWith(QLatin1Char('.'))) { dayStr = dayStr.left(dayStr.size() - 1); day = dayStr.toInt(&ok); @@ -4803,7 +4803,8 @@ QDateTime QDateTime::fromString(const QString &string, Qt::DateFormat format) if (!date.isValid()) return QDateTime(); - QVector timeParts = parts.at(timePart).split(QLatin1Char(':')); + // ### fixme, use QStringView::tokenize() when available + QVector timeParts = parts.at(timePart).split(QLatin1Char(':')); if (timeParts.count() < 2 || timeParts.count() > 3) return QDateTime(); @@ -4818,7 +4819,8 @@ QDateTime QDateTime::fromString(const QString &string, Qt::DateFormat format) int second = 0; int millisecond = 0; if (timeParts.count() > 2) { - const QVector secondParts = timeParts.at(2).split(QLatin1Char('.')); + // ### fixme, use QStringView::tokenize() when available + const QVector secondParts = timeParts.at(2).split(QLatin1Char('.')); if (secondParts.size() > 2) { return QDateTime(); } diff --git a/src/corelib/time/qdatetimeparser.cpp b/src/corelib/time/qdatetimeparser.cpp index 68ec73f471..1ca2f3735f 100644 --- a/src/corelib/time/qdatetimeparser.cpp +++ b/src/corelib/time/qdatetimeparser.cpp @@ -356,7 +356,7 @@ int QDateTimeParser::sectionPos(const SectionNode &sn) const */ -static QString unquote(const QStringRef &str) +static QString unquote(QStringView str) { const QChar quote(QLatin1Char('\'')); const QChar slash(QLatin1Char('\\')); @@ -393,7 +393,7 @@ static inline int countRepeat(const QString &str, int index, int maxCount) static inline void appendSeparator(QStringList *list, const QString &string, int from, int size, int lastQuote) { - const QStringRef separator = string.midRef(from, size); + const QStringView separator = QStringView(string).mid(from, size); list->append(lastQuote >= from ? unquote(separator) : separator.toString()); } @@ -510,7 +510,7 @@ bool QDateTimeParser::parseFormat(const QString &newFormat) if (parserType != QMetaType::QTime) { const SectionNode sn = { MonthSection, i - add, countRepeat(newFormat, i, 4), 0 }; newSectionNodes.append(sn); - newSeparators.append(unquote(newFormat.midRef(index, i - index))); + newSeparators.append(unquote(QStringView{newFormat}.mid(index, i - index))); i += sn.count - 1; index = i + 1; newDisplay |= MonthSection; @@ -759,7 +759,7 @@ QDateTimeParser::parseSection(const QDateTime ¤tValue, int sectionIndex, } const int sectionmaxsize = sectionMaxSize(sectionIndex); - QStringRef sectionTextRef = text->midRef(offset, sectionmaxsize); + QStringView sectionTextRef = QStringView{*text}.mid(offset, sectionmaxsize); QDTPDEBUG << "sectionValue for" << sn.name() << "with text" << *text << "and (at" << offset @@ -845,7 +845,7 @@ QDateTimeParser::parseSection(const QDateTime ¤tValue, int sectionIndex, int last = -1, used = -1; Q_ASSERT(sectiontextSize <= sectionmaxsize); - QStringRef digitsStr = sectionTextRef.left(sectiontextSize); + QStringView digitsStr = sectionTextRef.left(sectiontextSize); for (int digits = sectiontextSize; digits >= 1; --digits) { digitsStr.truncate(digits); int tmp = (int)loc.toUInt(digitsStr, &ok); @@ -1159,8 +1159,8 @@ QDateTimeParser::scanString(const QDateTime &defaultValue, for (int index = 0; index < sectionNodesCount; ++index) { Q_ASSERT(state != Invalid); const QString &separator = separators.at(index); - if (input->midRef(pos, separator.size()) != separator) { - QDTPDEBUG << "invalid because" << input->midRef(pos, separator.size()) + if (QStringView{*input}.mid(pos, separator.size()) != separator) { + QDTPDEBUG << "invalid because" << QStringView{*input}.mid(pos, separator.size()) << "!=" << separator << index << pos << currentSectionIndex; return StateNode(); @@ -1206,10 +1206,10 @@ QDateTimeParser::scanString(const QDateTime &defaultValue, current = &zoneOffset; if (sect.used > 0) { // Synchronize with what findTimeZone() found: - QStringRef zoneName = input->midRef(pos, sect.used); + QStringView zoneName = QStringView{*input}.mid(pos, sect.used); Q_ASSERT(!zoneName.isEmpty()); // sect.used > 0 - const QStringRef offsetStr = zoneName.startsWith(QLatin1String("UTC")) + const QStringView offsetStr = zoneName.startsWith(QLatin1String("UTC")) ? zoneName.mid(3) : zoneName; const bool isUtcOffset = offsetStr.startsWith(QLatin1Char('+')) || offsetStr.startsWith(QLatin1Char('-')); @@ -1271,8 +1271,8 @@ QDateTimeParser::scanString(const QDateTime &defaultValue, isSet |= sn.type; } - if (input->midRef(pos) != separators.last()) { - QDTPDEBUG << "invalid because" << input->midRef(pos) + if (QStringView{*input}.mid(pos) != separators.last()) { + QDTPDEBUG << "invalid because" << QStringView{*input}.mid(pos) << "!=" << separators.last() << pos; return StateNode(); } @@ -1653,7 +1653,7 @@ int QDateTimeParser::findDay(const QString &str1, int startDay, int sectionIndex Return's .value is UTC offset in seconds. The caller must verify that the offset is within a valid range. */ -QDateTimeParser::ParsedSection QDateTimeParser::findUtcOffset(QStringRef str) const +QDateTimeParser::ParsedSection QDateTimeParser::findUtcOffset(QStringView str) const { const bool startsWithUtc = str.startsWith(QLatin1String("UTC")); // Get rid of UTC prefix if it exists @@ -1673,7 +1673,7 @@ QDateTimeParser::ParsedSection QDateTimeParser::findUtcOffset(QStringRef str) co // We deal only with digits at this point (except ':'), so collect them const int digits = hasColon ? colonPosition + 3 : 4; int i = 0; - for (const int offsetLength = qMin(digits, str.size()); i < offsetLength; ++i) { + for (const int offsetLength = qMin(qsizetype(digits), str.size()); i < offsetLength; ++i) { if (i != colonPosition && !str.at(i).isDigit()) break; } @@ -1694,7 +1694,7 @@ QDateTimeParser::ParsedSection QDateTimeParser::findUtcOffset(QStringRef str) co const int hours = str.mid(0, hoursLength).toInt(&isInt); if (!isInt) return ParsedSection(); - const QStringRef minutesStr = str.mid(hasColon ? colonPosition + 1 : 2, 2); + const QStringView minutesStr = str.mid(hasColon ? colonPosition + 1 : 2, 2); const int minutes = minutesStr.isEmpty() ? 0 : minutesStr.toInt(&isInt); if (!isInt) return ParsedSection(); @@ -1724,7 +1724,7 @@ QDateTimeParser::ParsedSection QDateTimeParser::findUtcOffset(QStringRef str) co See QTimeZonePrivate::isValidId() for the format of zone names. */ QDateTimeParser::ParsedSection -QDateTimeParser::findTimeZoneName(QStringRef str, const QDateTime &when) const +QDateTimeParser::findTimeZoneName(QStringView str, const QDateTime &when) const { const int systemLength = startsWithLocalTimeZone(str); #if QT_CONFIG(timezone) @@ -1756,7 +1756,7 @@ QDateTimeParser::findTimeZoneName(QStringRef str, const QDateTime &when) const See QTimeZonePrivate::isValidId() for the format of zone names. */ QDateTimeParser::ParsedSection -QDateTimeParser::findTimeZone(QStringRef str, const QDateTime &when, +QDateTimeParser::findTimeZone(QStringView str, const QDateTime &when, int maxVal, int minVal) const { ParsedSection section = findUtcOffset(str); @@ -1800,7 +1800,7 @@ QDateTimeParser::AmPmFinder QDateTimeParser::findAmPm(QString &str, int sectionI } if (used) *used = str.size(); - if (QStringRef(&str).trimmed().isEmpty()) { + if (QStringView(str).trimmed().isEmpty()) { return PossibleBoth; } const QLatin1Char space(' '); @@ -1983,7 +1983,7 @@ QString QDateTimeParser::SectionNode::format() const number that is within min and max. */ -bool QDateTimeParser::potentialValue(const QStringRef &str, int min, int max, int index, +bool QDateTimeParser::potentialValue(QStringView str, int min, int max, int index, const QDateTime ¤tValue, int insert) const { if (str.isEmpty()) { @@ -2023,7 +2023,7 @@ bool QDateTimeParser::potentialValue(const QStringRef &str, int min, int max, in /*! \internal */ -bool QDateTimeParser::skipToNextSection(int index, const QDateTime ¤t, const QStringRef &text) const +bool QDateTimeParser::skipToNextSection(int index, const QDateTime ¤t, QStringView text) const { Q_ASSERT(text.size() < sectionMaxSize(index)); const SectionNode &node = sectionNode(index); diff --git a/src/corelib/time/qdatetimeparser_p.h b/src/corelib/time/qdatetimeparser_p.h index 535069b7b2..9a8bb7d5d9 100644 --- a/src/corelib/time/qdatetimeparser_p.h +++ b/src/corelib/time/qdatetimeparser_p.h @@ -220,12 +220,12 @@ private: int year, QString *monthName = nullptr, int *used = nullptr) const; int findDay(const QString &str1, int intDaystart, int sectionIndex, QString *dayName = nullptr, int *used = nullptr) const; - ParsedSection findUtcOffset(QStringRef str) const; - ParsedSection findTimeZoneName(QStringRef str, const QDateTime &when) const; - ParsedSection findTimeZone(QStringRef str, const QDateTime &when, + ParsedSection findUtcOffset(QStringView str) const; + ParsedSection findTimeZoneName(QStringView str, const QDateTime &when) const; + ParsedSection findTimeZone(QStringView str, const QDateTime &when, int maxVal, int minVal) const; // Implemented in qdatetime.cpp: - static int startsWithLocalTimeZone(const QStringRef name); + static int startsWithLocalTimeZone(const QStringView name); enum AmPmFinder { Neither = -1, @@ -238,12 +238,12 @@ private: AmPmFinder findAmPm(QString &str, int index, int *used = nullptr) const; #endif // datestring - bool potentialValue(const QStringRef &str, int min, int max, int index, + bool potentialValue(QStringView str, int min, int max, int index, const QDateTime ¤tValue, int insert) const; bool potentialValue(const QString &str, int min, int max, int index, const QDateTime ¤tValue, int insert) const { - return potentialValue(QStringRef(&str), min, max, index, currentValue, insert); + return potentialValue(QStringView(str), min, max, index, currentValue, insert); } protected: // for the benefit of QDateTimeEditPrivate @@ -261,10 +261,10 @@ protected: // for the benefit of QDateTimeEditPrivate int absoluteMax(int index, const QDateTime &value = QDateTime()) const; int absoluteMin(int index) const; - bool skipToNextSection(int section, const QDateTime ¤t, const QStringRef §ionText) const; + bool skipToNextSection(int section, const QDateTime ¤t, QStringView sectionText) const; bool skipToNextSection(int section, const QDateTime ¤t, const QString §ionText) const { - return skipToNextSection(section, current, QStringRef(§ionText)); + return skipToNextSection(section, current, QStringView(sectionText)); } QString stateName(State s) const; QString getAmPmText(AmPm ap, Case cs) const; diff --git a/src/corelib/time/qtimezoneprivate_tz.cpp b/src/corelib/time/qtimezoneprivate_tz.cpp index 2d113d1582..bbfd502bc2 100644 --- a/src/corelib/time/qtimezoneprivate_tz.cpp +++ b/src/corelib/time/qtimezoneprivate_tz.cpp @@ -95,7 +95,7 @@ static QTzTimeZoneHash loadTzTimeZones() // Comment lines are prefixed with a # if (!line.isEmpty() && line.at(0) != u'#') { // Data rows are tab-separated columns Region, Coordinates, ID, Optional Comments - const auto parts = line.splitRef(QLatin1Char('\t')); + const auto parts = QStringView{line}.split(QLatin1Char('\t')); QTzTimeZone zone; zone.country = QLocalePrivate::codeToCountry(parts.at(0)); if (parts.size() > 3)