diff options
Diffstat (limited to 'src/corelib/tools')
-rw-r--r-- | src/corelib/tools/qdatetime.cpp | 4 | ||||
-rw-r--r-- | src/corelib/tools/qdatetimeparser.cpp | 41 | ||||
-rw-r--r-- | src/corelib/tools/qdatetimeparser_p.h | 5 | ||||
-rw-r--r-- | src/corelib/tools/qlocale.cpp | 23 | ||||
-rw-r--r-- | src/corelib/tools/qstring.cpp | 50 | ||||
-rw-r--r-- | src/corelib/tools/qstringview.cpp | 8 | ||||
-rw-r--r-- | src/corelib/tools/qstringview.h | 1 | ||||
-rw-r--r-- | src/corelib/tools/qtimezoneprivate_tz.cpp | 23 | ||||
-rw-r--r-- | src/corelib/tools/qvector.h | 5 |
9 files changed, 91 insertions, 69 deletions
diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index f6fc672486..050f37dcd2 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -2227,7 +2227,7 @@ static QString qt_tzname(QDateTimePrivate::DaylightStatus daylightStatus) #endif // Q_OS_WIN } -#ifndef QT_BOOTSTRAPPED +#if QT_CONFIG(datetimeparser) && QT_CONFIG(timezone) /* \internal Implemented here to share qt_tzname() @@ -2245,7 +2245,7 @@ int QDateTimeParser::startsWithLocalTimeZone(const QStringRef name) } return 0; } -#endif // QT_BOOTSTRAPPED +#endif // datetimeparser && timezone // Calls the platform variant of mktime for the given date, time and daylightStatus, // and updates the date, time, daylightStatus and abbreviation with the returned values diff --git a/src/corelib/tools/qdatetimeparser.cpp b/src/corelib/tools/qdatetimeparser.cpp index 4b3777407c..1a56418aaf 100644 --- a/src/corelib/tools/qdatetimeparser.cpp +++ b/src/corelib/tools/qdatetimeparser.cpp @@ -195,9 +195,11 @@ bool QDateTimeParser::setDigit(QDateTime &v, int index, int newVal) const return false; // Preserve zone: - v = (tspec == Qt::TimeZone - ? QDateTime(newDate, newTime, v.timeZone()) - : QDateTime(newDate, newTime, tspec, offset)); + v = +#if QT_CONFIG(timezone) + tspec == Qt::TimeZone ? QDateTime(newDate, newTime, v.timeZone()) : +#endif + QDateTime(newDate, newTime, tspec, offset); return true; } @@ -213,7 +215,9 @@ int QDateTimeParser::absoluteMax(int s, const QDateTime &cur) const { const SectionNode &sn = sectionNode(s); switch (sn.type) { +#if QT_CONFIG(timezone) case TimeZoneSection: return QTimeZone::MaxUtcOffsetSecs; +#endif case Hour24Section: case Hour12Section: return 23; // this is special-cased in // parseSection. We want it to be @@ -248,7 +252,9 @@ int QDateTimeParser::absoluteMin(int s) const { const SectionNode &sn = sectionNode(s); switch (sn.type) { +#if QT_CONFIG(timezone) case TimeZoneSection: return QTimeZone::MinUtcOffsetSecs; +#endif case Hour24Section: case Hour12Section: case MinuteSection: @@ -766,9 +772,11 @@ QDateTimeParser::parseSection(const QDateTime ¤tValue, int sectionIndex, text->replace(offset, used, sectiontext.constData(), used); break; } case TimeZoneSection: +#if QT_CONFIG(timezone) result = findTimeZone(sectionTextRef, currentValue, absoluteMax(sectionIndex), absoluteMin(sectionIndex)); +#endif break; case MonthSection: case DayOfWeekSectionShort: @@ -1090,17 +1098,21 @@ QDateTimeParser::scanString(const QDateTime &defaultValue, int dayofweek = defaultDate.dayOfWeek(); Qt::TimeSpec tspec = defaultValue.timeSpec(); int zoneOffset = 0; // In seconds; local - UTC +#if QT_CONFIG(timezone) QTimeZone timeZone; +#endif switch (tspec) { case Qt::OffsetFromUTC: // timeZone is ignored zoneOffset = defaultValue.offsetFromUtc(); break; +#if QT_CONFIG(timezone) case Qt::TimeZone: timeZone = defaultValue.timeZone(); if (timeZone.isValid()) zoneOffset = timeZone.offsetFromUtc(defaultValue); // else: is there anything we can do about this ? break; +#endif default: // zoneOffset and timeZone are ignored break; } @@ -1125,9 +1137,11 @@ QDateTimeParser::scanString(const QDateTime &defaultValue, { const QDate date = actualDate(isSet, year, year2digits, month, day, dayofweek); const QTime time = actualTime(isSet, hour, hour12, ampm, minute, second, msec); - sect = parseSection(tspec == Qt::TimeZone - ? QDateTime(date, time, timeZone) - : QDateTime(date, time, tspec, zoneOffset), + sect = parseSection( +#if QT_CONFIG(timezone) + tspec == Qt::TimeZone ? QDateTime(date, time, timeZone) : +#endif + QDateTime(date, time, tspec, zoneOffset), index, pos, input); } @@ -1152,7 +1166,7 @@ QDateTimeParser::scanString(const QDateTime &defaultValue, case TimeZoneSection: current = &zoneOffset; if (sect.used > 0) { - // Synchronize with what findTimeZone() found: +#if QT_CONFIG(timezone) // Synchronize with what findTimeZone() found: QStringRef zoneName = input->midRef(pos, sect.used); Q_ASSERT(!zoneName.isEmpty()); // sect.used > 0 const QByteArray latinZone(zoneName == QLatin1String("Z") @@ -1163,6 +1177,9 @@ QDateTimeParser::scanString(const QDateTime &defaultValue, ? Qt::TimeZone : Qt::OffsetFromUTC) : (Q_ASSERT(startsWithLocalTimeZone(zoneName)), Qt::LocalTime); +#else + tspec = Qt::LocalTime; +#endif } break; case Hour24Section: current = &hour; break; @@ -1320,9 +1337,11 @@ QDateTimeParser::scanString(const QDateTime &defaultValue, const QDate date(year, month, day); const QTime time(hour, minute, second, msec); - return StateNode(tspec == Qt::TimeZone - ? QDateTime(date, time, timeZone) - : QDateTime(date, time, tspec, zoneOffset), + return StateNode( +#if QT_CONFIG(timezone) + tspec == Qt::TimeZone ? QDateTime(date, time, timeZone) : +#endif + QDateTime(date, time, tspec, zoneOffset), state, padding, conflicts); } @@ -1570,6 +1589,7 @@ QDateTimeParser::ParsedSection QDateTimeParser::findTimeZone(QStringRef str, const QDateTime &when, int maxVal, int minVal) const { +#if QT_CONFIG(timezone) int index = startsWithLocalTimeZone(str); int offset; @@ -1612,6 +1632,7 @@ QDateTimeParser::findTimeZone(QStringRef str, const QDateTime &when, if (index > 0 && maxVal >= offset && offset >= minVal) return ParsedSection(Acceptable, offset, index); +#endif // timezone return ParsedSection(); } diff --git a/src/corelib/tools/qdatetimeparser_p.h b/src/corelib/tools/qdatetimeparser_p.h index 75497f5c5a..c3ae08da71 100644 --- a/src/corelib/tools/qdatetimeparser_p.h +++ b/src/corelib/tools/qdatetimeparser_p.h @@ -223,7 +223,10 @@ private: QString *dayName = 0, int *used = 0) const; ParsedSection findTimeZone(QStringRef str, const QDateTime &when, int maxVal, int minVal) const; - static int startsWithLocalTimeZone(const QStringRef name); // implemented in qdatetime.cpp +#if QT_CONFIG(timezone) + // Implemented in qdatetime.cpp: + static int startsWithLocalTimeZone(const QStringRef name); +#endif enum AmPmFinder { Neither = -1, diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index 166cbe8dee..a072ea411c 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -3805,17 +3805,18 @@ QString QLocale::toCurrencyString(double value, const QString &symbol, int preci /*! \since 5.10 - Converts a size in bytes to a human-readable localized string, expressed in - a unit for which the numeric portion is at least 1 but as low as - possible. For example if \a bytes is 16384, \a precision is 2, and \a format - is \c DataSizeIecFormat (the default), this function returns "16.00 KiB"; - for 1330409069609 bytes it returns "1.21 GiB"; and so on. If \a format is \c - DataSizeIecFormat or \c DataSizeTraditionalFormat, the given number of bytes - is divided by a power of 1024, with result less than 1024; for \c - DataSizeSIFormat, it is divided by a power of 1000, with result less than - 1000. DataSizeIecFormat uses the new IEC standard quantifiers Ki, Mi and so - on, whereas DataSizeSIFormat uses and DataSizeTraditionalFormat abuses the - older SI quantifiers k, M, etc. + Converts a size in bytes to a human-readable localized string, comprising a + number and a quantified unit. The quantifier is chosen such that the number + is at least one, and as small as possible. For example if \a bytes is + 16384, \a precision is 2, and \a format is \l DataSizeIecFormat (the + default), this function returns "16.00 KiB"; for 1330409069609 bytes it + returns "1.21 GiB"; and so on. If \a format is \l DataSizeIecFormat or + \l DataSizeTraditionalFormat, the given number of bytes is divided by a + power of 1024, with result less than 1024; for \l DataSizeSIFormat, it is + divided by a power of 1000, with result less than 1000. + \c DataSizeIecFormat uses the new IEC standard quantifiers Ki, Mi and so on, + whereas \c DataSizeSIFormat uses the older SI quantifiers k, M, etc., and + \c DataSizeTraditionalFormat abuses them. */ QString QLocale::formattedDataSize(qint64 bytes, int precision, DataSizeFormats format) { diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index bba0a85319..4e59686d97 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -769,8 +769,6 @@ static int qt_compare_strings(QLatin1String lhs, QLatin1String rhs, Qt::CaseSens Case-sensitive comparison is based exclusively on the numeric Unicode values of the characters and is very fast, but is not what a human would expect. Consider sorting user-visible strings with QString::localeAwareCompare(). - - \snippet qstring/main.cpp qCompareStrings-QSV-QSV */ int QtPrivate::compareStrings(QStringView lhs, QStringView rhs, Qt::CaseSensitivity cs) Q_DECL_NOTHROW { @@ -4837,7 +4835,7 @@ static QByteArray qt_convert_to_local_8bit(QStringView string); locale, the returned byte array is undefined. Those characters may be suppressed or replaced by another. - \sa fromLocal8Bit(), toLatin1(), toUtf8(), QTextCodec, qConvertToLocal8Bit() + \sa fromLocal8Bit(), toLatin1(), toUtf8(), QTextCodec */ QByteArray QString::toLocal8Bit_helper(const QChar *data, int size) @@ -4871,8 +4869,7 @@ static QByteArray qt_convert_to_local_8bit(QStringView string) The behavior is undefined if \a string contains characters not supported by the locale's 8-bit encoding. - \sa QString::toLocal8Bit(), QStringView::toLocal8Bit(), QtPrivate::vonvertToLatin1(), - QtPrivate::convertToUtf8(), QtPrivate::convertToUcs4() + \sa QString::toLocal8Bit(), QStringView::toLocal8Bit() */ QByteArray QtPrivate::convertToLocal8Bit(QStringView string) { @@ -4915,8 +4912,7 @@ static QByteArray qt_convert_to_utf8(QStringView str) UTF-8 is a Unicode codec and can represent all characters in a Unicode string like QStringView. - \sa QString::toUtf8(), QStringView::toUtf8(), QtPrivate::convertToLatin1(), - QtPrivate::convertToLocal8Bit(), QtPrivate::convertToUcs4() + \sa QString::toUtf8(), QStringView::toUtf8() */ QByteArray QtPrivate::convertToUtf8(QStringView string) { @@ -5279,8 +5275,8 @@ namespace { } /*! - \fn QStringView qTrimmed(QStringView s) - \fn QLatin1String qTrimmed(QLatin1String s) + \fn QStringView QtPrivate::trimmed(QStringView s) + \fn QLatin1String QtPrivate::trimmed(QLatin1String s) \internal \relates QStringView \since 5.10 @@ -7250,6 +7246,16 @@ static ResultList splitString(const StringSource &source, const QChar *sep, \snippet qstring/main.cpp 62 + If \a sep is empty, split() returns an empty string, followed + by each of the string's characters, followed by another empty string: + + \snippet qstring/main.cpp 62-empty + + To understand this behavior, recall that the empty string matches + everywhere, so the above is qualitatively the same as: + + \snippet qstring/main.cpp 62-slashes + \sa QStringList::join(), section() */ QStringList QString::split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const @@ -7259,15 +7265,10 @@ QStringList QString::split(const QString &sep, SplitBehavior behavior, Qt::CaseS /*! Splits the string into substring references wherever \a sep occurs, and - returns the list of those strings. If \a sep does not match - anywhere in the string, splitRef() returns a single-element vector - containing this string reference. - - \a cs specifies whether \a sep should be matched case - sensitively or case insensitively. + returns the list of those strings. - If \a behavior is QString::SkipEmptyParts, empty entries don't - appear in the result. By default, empty entries are kept. + See QString::split() for how \a sep, \a behavior and \a cs interact to form + the result. \note All references are valid as long this string is alive. Destroying this string will cause all references be dangling pointers. @@ -7298,15 +7299,10 @@ QVector<QStringRef> QString::splitRef(QChar sep, SplitBehavior behavior, Qt::Cas /*! Splits the string into substrings references wherever \a sep occurs, and - returns the list of those strings. If \a sep does not match - anywhere in the string, split() returns a single-element vector - containing this string reference. - - \a cs specifies whether \a sep should be matched case - sensitively or case insensitively. + returns the list of those strings. - If \a behavior is QString::SkipEmptyParts, empty entries don't - appear in the result. By default, empty entries are kept. + See QString::split() for how \a sep, \a behavior and \a cs interact to form + the result. \note All references are valid as long this string is alive. Destroying this string will cause all references be dangling pointers. @@ -8996,7 +8992,7 @@ QString &QString::setRawData(const QChar *unicode, int size) If \a cs is Qt::CaseSensitive (the default), the search is case-sensitive; otherwise the search is case-insensitive. - \sa endsWith(), qStartsWith() + \sa endsWith() */ /*! @@ -9016,7 +9012,7 @@ QString &QString::setRawData(const QChar *unicode, int size) If \a cs is Qt::CaseSensitive (the default), the search is case-sensitive; otherwise the search is case-insensitive. - \sa startsWith(), qEndsWith() + \sa startsWith() */ /*! diff --git a/src/corelib/tools/qstringview.cpp b/src/corelib/tools/qstringview.cpp index bb22239b66..6321427a2d 100644 --- a/src/corelib/tools/qstringview.cpp +++ b/src/corelib/tools/qstringview.cpp @@ -672,8 +672,6 @@ QT_BEGIN_NAMESPACE Whitespace means any character for which QChar::isSpace() returns \c true. This includes the ASCII characters '\\t', '\\n', '\\v', '\\f', '\\r', and ' '. - - \sa qTrimmed() */ /*! @@ -689,7 +687,7 @@ QT_BEGIN_NAMESPACE If \a cs is Qt::CaseSensitive (the default), the search is case-sensitive; otherwise the search is case-insensitive. - \sa endsWith(), qStartsWith() + \sa endsWith() */ /*! @@ -705,7 +703,7 @@ QT_BEGIN_NAMESPACE If \a cs is Qt::CaseSensitive (the default), the search is case-sensitive; otherwise the search is case-insensitive. - \sa startsWith(), qEndsWith() + \sa startsWith() */ /*! @@ -730,7 +728,7 @@ QT_BEGIN_NAMESPACE The behavior is undefined if the string contains characters not supported by the locale's 8-bit encoding. - \sa toLatin1(), toUtf8(), QTextCodec, qConvertToLocal8Bit() + \sa toLatin1(), toUtf8(), QTextCodec */ /*! diff --git a/src/corelib/tools/qstringview.h b/src/corelib/tools/qstringview.h index 903d7ccb24..ef442e5b65 100644 --- a/src/corelib/tools/qstringview.h +++ b/src/corelib/tools/qstringview.h @@ -152,6 +152,7 @@ private: qsizetype result = 0; while (*str++) ++result; + return result; } #endif return QtPrivate::qustrlen(reinterpret_cast<const ushort *>(str)); diff --git a/src/corelib/tools/qtimezoneprivate_tz.cpp b/src/corelib/tools/qtimezoneprivate_tz.cpp index bcc1285472..6a5df6272a 100644 --- a/src/corelib/tools/qtimezoneprivate_tz.cpp +++ b/src/corelib/tools/qtimezoneprivate_tz.cpp @@ -1050,7 +1050,18 @@ QByteArray QTzTimeZonePrivate::systemTimeZoneId() const if (ianaId == "/etc/localtime") ianaId.clear(); - // On Debian Etch and later /etc/localtime is real file with name held in /etc/timezone + // On most distros /etc/localtime is a symlink to a real file so extract name from the path + if (ianaId.isEmpty()) { + const QString path = QFile::symLinkTarget(QStringLiteral("/etc/localtime")); + if (!path.isEmpty()) { + // /etc/localtime is a symlink to the current TZ file, so extract from path + int index = path.indexOf(QLatin1String("/zoneinfo/")); + if (index != -1) + ianaId = path.mid(index + 10).toUtf8(); + } + } + + // On Debian Etch up to Jessie, /etc/localtime is a regular file while the actual name is in /etc/timezone if (ianaId.isEmpty()) { QFile tzif(QStringLiteral("/etc/timezone")); if (tzif.open(QIODevice::ReadOnly)) { @@ -1061,16 +1072,6 @@ QByteArray QTzTimeZonePrivate::systemTimeZoneId() const } } - // On other distros /etc/localtime is symlink to real file so can extract name from the path - if (ianaId.isEmpty()) { - const QString path = QFile::symLinkTarget(QStringLiteral("/etc/localtime")); - if (!path.isEmpty()) { - // /etc/localtime is a symlink to the current TZ file, so extract from path - int index = path.indexOf(QLatin1String("/zoneinfo/")) + 10; - ianaId = path.mid(index).toUtf8(); - } - } - // On some Red Hat distros /etc/localtime is real file with name held in /etc/sysconfig/clock // in a line like ZONE="Europe/Oslo" or TIMEZONE="Europe/Oslo" if (ianaId.isEmpty()) { diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index 4daf894887..3a3d416775 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -164,9 +164,10 @@ public: const const_iterator ce = this->cend(), cit = std::find(this->cbegin(), ce, t); if (cit == ce) return 0; - // next operation detaches, so ce, cit may become invalidated: + // next operation detaches, so ce, cit, t may become invalidated: + const T tCopy = t; const int firstFoundIdx = std::distance(this->cbegin(), cit); - const iterator e = end(), it = std::remove(begin() + firstFoundIdx, e, t); + const iterator e = end(), it = std::remove(begin() + firstFoundIdx, e, tCopy); const int result = std::distance(it, e); erase(it, e); return result; |