Q{*String,ByteArray}View::length(): use qsizetype, not int
Looks like these ones have been forgotten in the Qt 5 -> 6 upgrade to qsizetype. Change them to return qsizetype as well, and fix the docs. Being entirely inline, non-exported classes, we should be able to get away with it without affecting binary compatibility. Moreover, there's no reason for keeping them deprecated. Requires some minor adjustments, just like the ones done for size()'s changes. [ChangeLog][QtCore][QStringView] The length() function now returns `qsizetype`, not `int`, for consistency with the other string and container classes in Qt. Following this change, it has been un-deprecated. [ChangeLog][QtCore][QAnyStringView] The length() function now returns `qsizetype`, not `int`, for consistency with the other string and container classes in Qt. Following this change, it has been un-deprecated. [ChangeLog][QtCore][QUtf8StringView] The length() function now returns `qsizetype`, not `int`, for consistency with the other string and container classes in Qt. Following this change, it has been un-deprecated. [ChangeLog][QtCore][QByteArrayView] The length() function now returns `qsizetype`, not `int`, for consistency with the other string and container classes in Qt. Following this change, it has been un-deprecated. Fixes: QTBUG-92496 Change-Id: Ie0f4939d1083884e95d4725f891b6c6764532cb8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
1d59fe368a
commit
86ad338aa4
@ -1667,7 +1667,7 @@ static bool android_default_message_handler(QtMsgType type,
|
||||
#ifdef Q_OS_WIN
|
||||
static void win_outputDebugString_helper(QStringView message)
|
||||
{
|
||||
const int maxOutputStringLength = 32766;
|
||||
const qsizetype maxOutputStringLength = 32766;
|
||||
static QBasicMutex m;
|
||||
auto locker = qt_unique_lock(m);
|
||||
// fast path: Avoid string copies if one output is enough
|
||||
@ -1675,9 +1675,9 @@ static void win_outputDebugString_helper(QStringView message)
|
||||
OutputDebugString(reinterpret_cast<const wchar_t *>(message.utf16()));
|
||||
} else {
|
||||
wchar_t *messagePart = new wchar_t[maxOutputStringLength + 1];
|
||||
for (int i = 0; i < message.length(); i += maxOutputStringLength) {
|
||||
const int length = std::min(message.length() - i, maxOutputStringLength);
|
||||
const int len = message.mid(i, length).toWCharArray(messagePart);
|
||||
for (qsizetype i = 0; i < message.length(); i += maxOutputStringLength) {
|
||||
const qsizetype length = std::min(message.length() - i, maxOutputStringLength);
|
||||
const qsizetype len = message.mid(i, length).toWCharArray(messagePart);
|
||||
Q_ASSERT(len == length);
|
||||
messagePart[len] = 0;
|
||||
OutputDebugString(messagePart);
|
||||
|
@ -217,12 +217,8 @@ public:
|
||||
//
|
||||
[[nodiscard]] constexpr bool isNull() const noexcept { return !m_data; }
|
||||
[[nodiscard]] constexpr bool isEmpty() const noexcept { return empty(); }
|
||||
#if QT_DEPRECATED_SINCE(6, 0)
|
||||
[[nodiscard]]
|
||||
Q_DECL_DEPRECATED_X("Use size() and port callers to qsizetype.")
|
||||
constexpr int length() const /* not nothrow! */
|
||||
{ return Q_ASSERT(int(size()) == size()), int(size()); }
|
||||
#endif
|
||||
[[nodiscard]] constexpr qsizetype length() const noexcept
|
||||
{ return size(); }
|
||||
|
||||
private:
|
||||
[[nodiscard]] friend inline bool operator==(QAnyStringView lhs, QAnyStringView rhs) noexcept
|
||||
|
@ -322,17 +322,11 @@
|
||||
|
||||
/*!
|
||||
\fn int QAnyStringView::length() const
|
||||
\obsolete
|
||||
Use size() instead, and port callers to qsizetype.
|
||||
|
||||
Same as size(), except that it returns the result as an \c int.
|
||||
Same as size().
|
||||
|
||||
This function is provided for compatibility with other Qt containers.
|
||||
|
||||
\warning QAnyStringView can represent strings with more than 2\sup{31} characters.
|
||||
Calling this function on a string view for which size() returns a value greater
|
||||
than \c{INT_MAX} constitutes undefined behavior.
|
||||
|
||||
\sa size()
|
||||
*/
|
||||
|
||||
|
@ -291,12 +291,8 @@ public:
|
||||
//
|
||||
[[nodiscard]] constexpr bool isNull() const noexcept { return !m_data; }
|
||||
[[nodiscard]] constexpr bool isEmpty() const noexcept { return empty(); }
|
||||
#if QT_DEPRECATED_SINCE(6, 0)
|
||||
[[nodiscard]]
|
||||
Q_DECL_DEPRECATED_X("Use size() and port callers to qsizetype.")
|
||||
constexpr int length() const /* not nothrow! */
|
||||
{ Q_ASSERT(int(size()) == size()); return int(size()); }
|
||||
#endif
|
||||
[[nodiscard]] constexpr qsizetype length() const noexcept
|
||||
{ return size(); }
|
||||
[[nodiscard]] constexpr char first() const { return front(); }
|
||||
[[nodiscard]] constexpr char last() const { return back(); }
|
||||
|
||||
|
@ -470,23 +470,13 @@
|
||||
\sa empty(), isEmpty(), isNull()
|
||||
*/
|
||||
|
||||
#if QT_DEPRECATED_SINCE(6, 0)
|
||||
/*!
|
||||
\fn int QByteArrayView::length() const
|
||||
\obsolete
|
||||
Use size() and port callers to qsizetype.
|
||||
|
||||
Same as size(), but returns the result as an \c int.
|
||||
|
||||
This function is provided for compatibility with other Qt containers.
|
||||
|
||||
\warning QByteArrayView can represent data with more than 2\sup{31} bytes.
|
||||
Calling this function on a byte array view for which size() returns a value greater
|
||||
than \c{INT_MAX} constitutes undefined behavior.
|
||||
Same as size().
|
||||
|
||||
\sa empty(), isEmpty(), isNull(), size()
|
||||
*/
|
||||
#endif
|
||||
|
||||
/*!
|
||||
\fn char QByteArrayView::operator[](qsizetype n) const
|
||||
|
@ -130,11 +130,6 @@ QT_BEGIN_NAMESPACE
|
||||
\typedef QStringView::size_type
|
||||
|
||||
Alias for qsizetype. Provided for compatibility with the STL.
|
||||
|
||||
Unlike other Qt classes, QStringView uses qsizetype as its \c size_type, to allow
|
||||
accepting data from \c{std::basic_string} without truncation. The Qt API functions,
|
||||
for example length(), return \c int, while the STL-compatible functions, for example
|
||||
size(), return \c size_type.
|
||||
*/
|
||||
|
||||
/*!
|
||||
@ -530,14 +525,10 @@ QT_BEGIN_NAMESPACE
|
||||
/*!
|
||||
\fn int QStringView::length() const
|
||||
|
||||
Same as size(), except returns the result as an \c int.
|
||||
Same as size().
|
||||
|
||||
This function is provided for compatibility with other Qt containers.
|
||||
|
||||
\warning QStringView can represent strings with more than 2\sup{31} characters.
|
||||
Calling this function on a string view for which size() returns a value greater
|
||||
than \c{INT_MAX} constitutes undefined behavior.
|
||||
|
||||
\sa empty(), isEmpty(), isNull(), size()
|
||||
*/
|
||||
|
||||
|
@ -446,8 +446,8 @@ public:
|
||||
[[nodiscard]] const_iterator constEnd() const noexcept { return end(); }
|
||||
[[nodiscard]] constexpr bool isNull() const noexcept { return !m_data; }
|
||||
[[nodiscard]] constexpr bool isEmpty() const noexcept { return empty(); }
|
||||
[[nodiscard]] constexpr int length() const /* not nothrow! */
|
||||
{ return Q_ASSERT(int(size()) == size()), int(size()); }
|
||||
[[nodiscard]] constexpr qsizetype length() const noexcept
|
||||
{ return size(); }
|
||||
[[nodiscard]] constexpr QChar first() const { return front(); }
|
||||
[[nodiscard]] constexpr QChar last() const { return back(); }
|
||||
private:
|
||||
|
@ -306,12 +306,8 @@ public:
|
||||
//
|
||||
[[nodiscard]] constexpr bool isNull() const noexcept { return !m_data; }
|
||||
[[nodiscard]] constexpr bool isEmpty() const noexcept { return empty(); }
|
||||
#if QT_DEPRECATED_SINCE(6, 0)
|
||||
[[nodiscard]]
|
||||
Q_DECL_DEPRECATED_X("Use size() and port callers to qsizetype.")
|
||||
constexpr int length() const /* not nothrow! */
|
||||
{ return Q_ASSERT(int(size()) == size()), int(size()); }
|
||||
#endif
|
||||
[[nodiscard]] constexpr qsizetype length() const noexcept
|
||||
{ return size(); }
|
||||
|
||||
private:
|
||||
[[nodiscard]] static inline int compare(QBasicUtf8StringView lhs, QBasicUtf8StringView rhs) noexcept
|
||||
|
@ -526,17 +526,11 @@
|
||||
|
||||
/*!
|
||||
\fn int QUtf8StringView::length() const
|
||||
\obsolete
|
||||
Use size() and port callers to qsizetype.
|
||||
|
||||
Same as size(), except returns the result as an \c int.
|
||||
Same as size().
|
||||
|
||||
This function is provided for compatibility with other Qt containers.
|
||||
|
||||
\warning QUtf8StringView can represent strings with more than 2\sup{31} code points.
|
||||
Calling this function on a string view for which size() returns a value greater
|
||||
than \c{INT_MAX} constitutes undefined behavior.
|
||||
|
||||
\sa empty(), isEmpty(), isNull(), size()
|
||||
*/
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user