summaryrefslogtreecommitdiffstats
path: root/src/corelib/text
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2021-04-09 18:14:42 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2021-04-15 01:09:44 +0200
commit86ad338aa4a6d60ae6b98c62bb2259cf36afee3e (patch)
tree79ffcbf71ab1dd9de21f2f57b2c8d44b1e55b088 /src/corelib/text
parent1d59fe368a0bd0c04264618e3e6f09d7ce289d33 (diff)
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>
Diffstat (limited to 'src/corelib/text')
-rw-r--r--src/corelib/text/qanystringview.h8
-rw-r--r--src/corelib/text/qanystringview.qdoc8
-rw-r--r--src/corelib/text/qbytearrayview.h8
-rw-r--r--src/corelib/text/qbytearrayview.qdoc12
-rw-r--r--src/corelib/text/qstringview.cpp11
-rw-r--r--src/corelib/text/qstringview.h4
-rw-r--r--src/corelib/text/qutf8stringview.h8
-rw-r--r--src/corelib/text/qutf8stringview.qdoc8
8 files changed, 12 insertions, 55 deletions
diff --git a/src/corelib/text/qanystringview.h b/src/corelib/text/qanystringview.h
index ff1f8a4050..68754931e9 100644
--- a/src/corelib/text/qanystringview.h
+++ b/src/corelib/text/qanystringview.h
@@ -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
diff --git a/src/corelib/text/qanystringview.qdoc b/src/corelib/text/qanystringview.qdoc
index c1a1681695..cb98fb0052 100644
--- a/src/corelib/text/qanystringview.qdoc
+++ b/src/corelib/text/qanystringview.qdoc
@@ -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()
*/
diff --git a/src/corelib/text/qbytearrayview.h b/src/corelib/text/qbytearrayview.h
index 4934294a81..02ce49613e 100644
--- a/src/corelib/text/qbytearrayview.h
+++ b/src/corelib/text/qbytearrayview.h
@@ -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(); }
diff --git a/src/corelib/text/qbytearrayview.qdoc b/src/corelib/text/qbytearrayview.qdoc
index 36571e53d4..91048c5dad 100644
--- a/src/corelib/text/qbytearrayview.qdoc
+++ b/src/corelib/text/qbytearrayview.qdoc
@@ -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
diff --git a/src/corelib/text/qstringview.cpp b/src/corelib/text/qstringview.cpp
index 1c3249fbfb..e003f257d7 100644
--- a/src/corelib/text/qstringview.cpp
+++ b/src/corelib/text/qstringview.cpp
@@ -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()
*/
diff --git a/src/corelib/text/qstringview.h b/src/corelib/text/qstringview.h
index c0082b70b5..e34418e956 100644
--- a/src/corelib/text/qstringview.h
+++ b/src/corelib/text/qstringview.h
@@ -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:
diff --git a/src/corelib/text/qutf8stringview.h b/src/corelib/text/qutf8stringview.h
index 5069bf7b07..a49aa08e4c 100644
--- a/src/corelib/text/qutf8stringview.h
+++ b/src/corelib/text/qutf8stringview.h
@@ -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
diff --git a/src/corelib/text/qutf8stringview.qdoc b/src/corelib/text/qutf8stringview.qdoc
index 8ff208ff23..36e09421a3 100644
--- a/src/corelib/text/qutf8stringview.qdoc
+++ b/src/corelib/text/qutf8stringview.qdoc
@@ -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()
*/