diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2020-05-04 11:33:10 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2020-05-04 17:38:40 +0200 |
commit | 0f7987f0c934b311bd39a5a496ffb0c6128eb8df (patch) | |
tree | dea392deb3c43e377a224271c4f450dcff3fc76f /src/corelib | |
parent | ea7d85457d30e915ad470919d2e74867cba9cad8 (diff) | |
parent | f0ea852d4dd6b3139869a952ee92e74cd367866d (diff) |
Merge remote-tracking branch 'origin/5.15' into dev
Conflicts:
src/corelib/text/qlocale.cpp
src/network/access/qnetworkaccessmanager.cpp
Regenerated tests/auto/testlib/selftests/float/CMakeLists.txt
Change-Id: I5a8ae42511380ca49a38b13c6fa8a3c5df8bed01
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/serialization/qcborvalue.cpp | 45 | ||||
-rw-r--r-- | src/corelib/serialization/qjsonobject.cpp | 8 | ||||
-rw-r--r-- | src/corelib/text/qstring.cpp | 32 | ||||
-rw-r--r-- | src/corelib/tools/qcommandlineparser.cpp | 29 |
4 files changed, 54 insertions, 60 deletions
diff --git a/src/corelib/serialization/qcborvalue.cpp b/src/corelib/serialization/qcborvalue.cpp index a3f93e5eed..7d6782cd7f 100644 --- a/src/corelib/serialization/qcborvalue.cpp +++ b/src/corelib/serialization/qcborvalue.cpp @@ -788,17 +788,34 @@ static QCborValue::Type convertToExtendedType(QCborContainerPrivate *d) // The data is supposed to be US-ASCII. If it isn't (contains UTF-8), // QDateTime::fromString will fail anyway. dt = QDateTime::fromString(b->asLatin1(), Qt::ISODateWithMs); - } else if (tag == qint64(QCborKnownTags::UnixTime_t) && e.type == QCborValue::Integer) { - dt = QDateTime::fromSecsSinceEpoch(e.value, Qt::UTC); - } else if (tag == qint64(QCborKnownTags::UnixTime_t) && e.type == QCborValue::Double) { - dt = QDateTime::fromMSecsSinceEpoch(qint64(e.fpvalue() * 1000), Qt::UTC); + } else if (tag == qint64(QCborKnownTags::UnixTime_t)) { + qint64 msecs; + bool ok = false; + if (e.type == QCborValue::Integer) { +#if QT_POINTER_SIZE == 8 + // we don't have a fast 64-bit mul_overflow implementation on + // 32-bit architectures. + ok = !mul_overflow(e.value, qint64(1000), &msecs); +#else + static const qint64 Limit = std::numeric_limits<qint64>::max() / 1000; + ok = (e.value > -Limit && e.value < Limit); + if (ok) + msecs = e.value * 1000; +#endif + } else if (e.type == QCborValue::Double) { + ok = convertDoubleTo(round(e.fpvalue() * 1000), &msecs); + } + if (ok) + dt = QDateTime::fromMSecsSinceEpoch(msecs, Qt::UTC); } if (dt.isValid()) { QByteArray text = dt.toString(Qt::ISODateWithMs).toLatin1(); - replaceByteData(text, text.size(), Element::StringIsAscii); - e.type = QCborValue::String; - d->elements[0].value = qint64(QCborKnownTags::DateTimeString); - return QCborValue::DateTime; + if (!text.isEmpty()) { + replaceByteData(text, text.size(), Element::StringIsAscii); + e.type = QCborValue::String; + d->elements[0].value = qint64(QCborKnownTags::DateTimeString); + return QCborValue::DateTime; + } } break; } @@ -810,9 +827,11 @@ static QCborValue::Type convertToExtendedType(QCborContainerPrivate *d) // normalize to a short (decoded) form, so as to save space QUrl url(e.flags & Element::StringIsUtf16 ? b->asQStringRaw() : - b->toUtf8String()); - QByteArray encoded = url.toString(QUrl::DecodeReserved).toUtf8(); - replaceByteData(encoded, encoded.size(), {}); + b->toUtf8String(), QUrl::StrictMode); + if (url.isValid()) { + QByteArray encoded = url.toString(QUrl::DecodeReserved).toUtf8(); + replaceByteData(encoded, encoded.size(), {}); + } } return QCborValue::Url; } @@ -1561,8 +1580,6 @@ void QCborContainerPrivate::decodeStringFromCbor(QCborStreamReader &reader) if (newSize > MaxByteArraySize) return -1; - // since usedData <= data.size(), this can't overflow - usedData += increment; data.resize(newSize); return offset; }; @@ -1635,7 +1652,7 @@ void QCborContainerPrivate::decodeStringFromCbor(QCborStreamReader &reader) } // update size - if (e.flags & Element::HasByteData) { + if (r.status == QCborStreamReader::EndOfString && e.flags & Element::HasByteData) { auto b = new (dataPtr() + e.value) ByteData; b->len = data.size() - e.value - int(sizeof(*b)); usedData += b->len; diff --git a/src/corelib/serialization/qjsonobject.cpp b/src/corelib/serialization/qjsonobject.cpp index a03855d4a3..bf2bdb957d 100644 --- a/src/corelib/serialization/qjsonobject.cpp +++ b/src/corelib/serialization/qjsonobject.cpp @@ -577,7 +577,7 @@ void QJsonObject::removeImpl(T key) if (!keyExists) return; - removeAt(index); + removeAt(index / 2); } #if QT_STRINGVIEW_LEVEL < 2 @@ -629,7 +629,7 @@ QJsonValue QJsonObject::takeImpl(T key) return QJsonValue(QJsonValue::Undefined); const QJsonValue v = QJsonPrivate::Value::fromTrustedCbor(o->extractAt(index + 1)); - removeAt(index); + removeAt(index / 2); return v; } @@ -1486,8 +1486,8 @@ void QJsonObject::setValueAt(int i, const QJsonValue &val) void QJsonObject::removeAt(int index) { detach2(); - o->removeAt(index + 1); - o->removeAt(index); + o->removeAt(2 * index + 1); + o->removeAt(2 * index); } size_t qHash(const QJsonObject &object, size_t seed) diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index 6eb84f6c99..f87cf41bf1 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -1781,57 +1781,39 @@ const QString::Null QString::null = { }; /*! \typedef QString::const_iterator - This typedef provides an STL-style const iterator for QString. - \sa QString::iterator */ /*! \typedef QString::iterator - The QString::iterator typedef provides an STL-style non-const - iterator for QString. - \sa QString::const_iterator */ /*! \typedef QString::const_reverse_iterator \since 5.6 - This typedef provides an STL-style const reverse iterator for QString. - \sa QString::reverse_iterator, QString::const_iterator */ /*! \typedef QString::reverse_iterator \since 5.6 - This typedef provides an STL-style non-const reverse iterator for QString. - \sa QString::const_reverse_iterator, QString::iterator */ /*! \typedef QString::size_type - - The QString::size_type typedef provides an STL-style type for sizes (int). */ /*! \typedef QString::difference_type - - The QString::size_type typedef provides an STL-style type for difference between pointers. */ /*! \typedef QString::const_reference - - This typedef provides an STL-style const reference for a QString element (QChar). */ /*! \typedef QString::reference - - This typedef provides an STL-style - reference for a QString element (QChar). */ /*! @@ -1849,8 +1831,6 @@ const QString::Null QString::null = { }; /*! \typedef QString::value_type - - This typedef provides an STL-style value type for QString. */ /*! \fn QString::iterator QString::begin() @@ -9397,8 +9377,6 @@ QString &QString::setRawData(const QChar *unicode, int size) \typedef QLatin1String::iterator \since 5.10 - This typedef provides an STL-style const iterator for QLatin1String. - QLatin1String does not support mutable iterators, so this is the same as const_iterator. @@ -9409,8 +9387,6 @@ QString &QString::setRawData(const QChar *unicode, int size) \typedef QLatin1String::const_iterator \since 5.10 - This typedef provides an STL-style const iterator for QLatin1String. - \sa iterator, const_reverse_iterator */ @@ -9418,8 +9394,6 @@ QString &QString::setRawData(const QChar *unicode, int size) \typedef QLatin1String::reverse_iterator \since 5.10 - This typedef provides an STL-style const reverse iterator for QLatin1String. - QLatin1String does not support mutable reverse iterators, so this is the same as const_reverse_iterator. @@ -9430,8 +9404,6 @@ QString &QString::setRawData(const QChar *unicode, int size) \typedef QLatin1String::const_reverse_iterator \since 5.10 - This typedef provides an STL-style const reverse iterator for QLatin1String. - \sa reverse_iterator, const_iterator */ @@ -10332,8 +10304,6 @@ QDataStream &operator>>(QDataStream &in, QString &str) \typedef QStringRef::const_iterator \since 5.4 - This typedef provides an STL-style const iterator for QStringRef. - \sa QStringRef::const_reverse_iterator */ @@ -10341,8 +10311,6 @@ QDataStream &operator>>(QDataStream &in, QString &str) \typedef QStringRef::const_reverse_iterator \since 5.7 - This typedef provides an STL-style const reverse iterator for QStringRef. - \sa QStringRef::const_iterator */ diff --git a/src/corelib/tools/qcommandlineparser.cpp b/src/corelib/tools/qcommandlineparser.cpp index 48501f5271..a3d2a2f7c0 100644 --- a/src/corelib/tools/qcommandlineparser.cpp +++ b/src/corelib/tools/qcommandlineparser.cpp @@ -1063,18 +1063,23 @@ QString QCommandLineParser::helpText() const return d->helpText(false); } -static QString wrapText(const QString &names, int longestOptionNameString, const QString &description) +static QString wrapText(const QString &names, int optionNameMaxWidth, const QString &description) { const QLatin1Char nl('\n'); const QLatin1String indentation(" "); - if (description.isEmpty()) - return indentation + names + nl; - QString text = indentation + names.leftJustified(longestOptionNameString) + QLatin1Char(' '); - const int indent = text.length(); + // In case the list of option names is very long, wrap it as well + int nameIndex = 0; + auto nextNameSection = [&]() { + QString section = names.mid(nameIndex, optionNameMaxWidth); + nameIndex += section.size(); + return section; + }; + + QString text; int lineStart = 0; int lastBreakable = -1; - const int max = 79 - indent; + const int max = 79 - (indentation.size() + optionNameMaxWidth + 1); int x = 0; const int len = description.length(); @@ -1103,8 +1108,7 @@ static QString wrapText(const QString &names, int longestOptionNameString, const if (breakAt != -1) { const int numChars = breakAt - lineStart; //qDebug() << "breakAt=" << description.at(breakAt) << "breakAtSpace=" << breakAtSpace << lineStart << "to" << breakAt << description.mid(lineStart, numChars); - if (lineStart > 0) - text += QString(indent, QLatin1Char(' ')); + text += indentation + nextNameSection().leftJustified(optionNameMaxWidth) + QLatin1Char(' '); text += description.midRef(lineStart, numChars) + nl; x = 0; lastBreakable = -1; @@ -1115,6 +1119,10 @@ static QString wrapText(const QString &names, int longestOptionNameString, const } } + while (nameIndex < names.size()) { + text += indentation + nextNameSection() + nl; + } + return text; } @@ -1158,11 +1166,12 @@ QString QCommandLineParserPrivate::helpText(bool includeQtOptions) const longestOptionNameString = qMax(longestOptionNameString, optionNamesString.length()); } ++longestOptionNameString; + const int optionNameMaxWidth = qMin(50, longestOptionNameString); auto optionNameIterator = optionNameList.cbegin(); for (const QCommandLineOption &option : qAsConst(options)) { if (option.flags() & QCommandLineOption::HiddenFromHelp) continue; - text += wrapText(*optionNameIterator, longestOptionNameString, option.description()); + text += wrapText(*optionNameIterator, optionNameMaxWidth, option.description()); ++optionNameIterator; } if (!positionalArgumentDefinitions.isEmpty()) { @@ -1170,7 +1179,7 @@ QString QCommandLineParserPrivate::helpText(bool includeQtOptions) const text += nl; text += QCommandLineParser::tr("Arguments:") + nl; for (const PositionalArgumentDefinition &arg : positionalArgumentDefinitions) - text += wrapText(arg.name, longestOptionNameString, arg.description); + text += wrapText(arg.name, optionNameMaxWidth, arg.description); } return text; } |