diff options
Diffstat (limited to 'src/corelib/text')
-rw-r--r-- | src/corelib/text/qbytearray.cpp | 12 | ||||
-rw-r--r-- | src/corelib/text/qbytearray.h | 5 | ||||
-rw-r--r-- | src/corelib/text/qbytearray_p.h | 5 | ||||
-rw-r--r-- | src/corelib/text/qstring.cpp | 10 | ||||
-rw-r--r-- | src/corelib/text/qstring.h | 5 |
5 files changed, 32 insertions, 5 deletions
diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp index 3df77f179c..8e34ab0742 100644 --- a/src/corelib/text/qbytearray.cpp +++ b/src/corelib/text/qbytearray.cpp @@ -14,7 +14,6 @@ #include "private/qsimd_p.h" #include "qstringalgorithms_p.h" #include "qscopedpointer.h" -#include "qbytearray_p.h" #include "qstringconverter_p.h" #include <qdatastream.h> #include <qmath.h> @@ -780,7 +779,7 @@ QByteArray qUncompress(const uchar* data, qsizetype nbytes) return QByteArray(); } - constexpr auto MaxDecompressedSize = size_t(MaxByteArraySize); + constexpr auto MaxDecompressedSize = size_t(QByteArray::max_size()); if constexpr (MaxDecompressedSize < std::numeric_limits<CompressSizeHint_t>::max()) { if (expectedSize > MaxDecompressedSize) return tooMuchData(ZLibOp::Decompression); @@ -1389,6 +1388,15 @@ QByteArray &QByteArray::operator=(const char *str) \sa isEmpty(), resize() */ +/*! \fn qsizetype QByteArray::max_size() + \since 6.8 + + This function is provided for STL compatibility. + It returns the maximum number of elements that the byte array can + theoretically hold. In practice, the number can be much smaller, + limited by the amount of memory available to the system. +*/ + /*! \fn bool QByteArray::isEmpty() const Returns \c true if the byte array has size 0; otherwise returns \c false. diff --git a/src/corelib/text/qbytearray.h b/src/corelib/text/qbytearray.h index a673383438..248bcc0b7b 100644 --- a/src/corelib/text/qbytearray.h +++ b/src/corelib/text/qbytearray.h @@ -519,6 +519,11 @@ public: void shrink_to_fit() { squeeze(); } iterator erase(const_iterator first, const_iterator last); inline iterator erase(const_iterator it) { return erase(it, it + 1); } + static constexpr qsizetype max_size() noexcept + { + // -1 to deal with the NUL terminator + return Data::max_size() - 1; + } static QByteArray fromStdString(const std::string &s); std::string toStdString() const; diff --git a/src/corelib/text/qbytearray_p.h b/src/corelib/text/qbytearray_p.h index 8fc3d7e357..7103a0428a 100644 --- a/src/corelib/text/qbytearray_p.h +++ b/src/corelib/text/qbytearray_p.h @@ -16,13 +16,12 @@ // #include <QtCore/qbytearray.h> -#include "private/qtools_p.h" QT_BEGIN_NAMESPACE // -1 because of the terminating NUL -constexpr qsizetype MaxByteArraySize = MaxAllocSize - sizeof(std::remove_pointer<QByteArray::DataPointer>::type) - 1; -constexpr qsizetype MaxStringSize = (MaxAllocSize - sizeof(std::remove_pointer<QByteArray::DataPointer>::type)) / 2 - 1; +constexpr qsizetype MaxByteArraySize = QtPrivate::MaxAllocSize - sizeof(std::remove_pointer<QByteArray::DataPointer>::type) - 1; +constexpr qsizetype MaxStringSize = (QtPrivate::MaxAllocSize - sizeof(std::remove_pointer<QByteArray::DataPointer>::type)) / 2 - 1; QT_END_NAMESPACE diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index d3bb1d92d1..f8fab76d73 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -6261,6 +6261,16 @@ QString& QString::fill(QChar ch, qsizetype size) \sa isEmpty(), resize() */ +/*! + \fn qsizetype QString::max_size() + \since 6.8 + + This function is provided for STL compatibility. + It returns the maximum number of elements that the string can + theoretically hold. In practice, the number can be much smaller, + limited by the amount of memory available to the system. +*/ + /*! \fn bool QString::isNull() const Returns \c true if this string is null; otherwise returns \c false. diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index 780b3090c1..5936f76ed4 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -941,6 +941,11 @@ public: void shrink_to_fit() { squeeze(); } iterator erase(const_iterator first, const_iterator last); inline iterator erase(const_iterator it) { return erase(it, it + 1); } + static constexpr qsizetype max_size() noexcept + { + // -1 to deal with the NUL terminator + return Data::max_size() - 1; + } static inline QString fromStdString(const std::string &s); inline std::string toStdString() const; |