diff options
author | Sona Kurazyan <sona.kurazyan@qt.io> | 2022-02-24 14:26:05 +0100 |
---|---|---|
committer | Sona Kurazyan <sona.kurazyan@qt.io> | 2022-03-02 22:22:36 +0100 |
commit | 736213bf662b68c4e80075cef317e5a029b490dd (patch) | |
tree | b0d01bafb6902501f754d985effcdb8ce7c1bf3a /src/corelib | |
parent | 0e64165c2e7b14502a578f3508e5544b035e404e (diff) |
QLatin1String: add missing APIs for compatibility with Qt string views
As a drive-by, fixed misleading wording used in docs.
[ChangeLog][QtCore][Potentially Source-Incompatible Changes][QLatin1String]
Added QLatin1String(std::nullptr_t) constructor, which makes
QLatin1String(0) call ambiguous. To fix the ambiguity, nullptr
must be passed instead of 0.
Task-number: QTBUG-98433
Change-Id: I2b888aa23469343d78aa640dc39a6028b77165dd
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/text/qstring.cpp | 98 | ||||
-rw-r--r-- | src/corelib/text/qstring.h | 11 |
2 files changed, 104 insertions, 5 deletions
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index f1ee16901b..ae5f57ce41 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -9108,6 +9108,14 @@ QString &QString::setRawData(const QChar *unicode, qsizetype size) \sa data(), isEmpty(), isNull(), {Distinction Between Null and Empty Strings} */ +/*! \fn QLatin1String::QLatin1String(std::nullptr_t) + \since 6.4 + + Constructs a QLatin1String object that stores a \nullptr. + + \sa data(), isEmpty(), isNull(), {Distinction Between Null and Empty Strings} +*/ + /*! \fn QLatin1String::QLatin1String(const char *str) Constructs a QLatin1String object that stores \a str. @@ -9193,27 +9201,45 @@ QString &QString::setRawData(const QChar *unicode, qsizetype size) /*! \fn const char *QLatin1String::latin1() const - Returns the Latin-1 string stored in this object. + Returns the start of the Latin-1 string referenced by this object. */ /*! \fn const char *QLatin1String::data() const - Returns the Latin-1 string stored in this object. + Returns the start of the Latin-1 string referenced by this object. +*/ + +/*! \fn const char *QLatin1String::constData() const + \since 6.4 + + Returns the start of the Latin-1 string referenced by this object. + + This function is provided for compatibility with other Qt containers. + + \sa data() */ /*! \fn qsizetype QLatin1String::size() const - Returns the size of the Latin-1 string stored in this object. + Returns the size of the Latin-1 string referenced by this object. \note In version prior to Qt 6, this function returned \c{int}, restricting the amount of data that could be held in a QLatin1String on 64-bit architectures. */ +/*! \fn qsizetype QLatin1String::length() const + \since 6.4 + + Same as size(). + + This function is provided for compatibility with other Qt containers. +*/ + /*! \fn bool QLatin1String::isNull() const \since 5.10 - Returns whether the Latin-1 string stored in this object is null + Returns whether the Latin-1 string referenced by this object is null (\c{data() == nullptr}) or not. \sa isEmpty(), data() @@ -9222,12 +9248,23 @@ QString &QString::setRawData(const QChar *unicode, qsizetype size) /*! \fn bool QLatin1String::isEmpty() const \since 5.10 - Returns whether the Latin-1 string stored in this object is empty + Returns whether the Latin-1 string referenced by this object is empty (\c{size() == 0}) or not. \sa isNull(), size() */ +/*! \fn bool QLatin1String::empty() const + \since 6.4 + + Returns whether the Latin-1 string referenced by this object is empty + (\c{size() == 0}) or not. + + This function is provided for STL compatibility. + + \sa isEmpty(), isNull(), size() +*/ + /*! \fn QLatin1Char QLatin1String::at(qsizetype pos) const \since 5.8 @@ -9266,6 +9303,21 @@ QString &QString::setRawData(const QChar *unicode, qsizetype size) */ /*! + \fn QLatin1Char QLatin1String::first() const + \since 6.4 + + Returns the first character in the string. + Same as \c{at(0)} or front(). + + This function is provided for compatibility with other Qt containers. + + \warning Calling this function on an empty string constitutes + undefined behavior. + + \sa last(), front(), back() +*/ + +/*! \fn QLatin1Char QLatin1String::back() const \since 5.10 @@ -9281,6 +9333,21 @@ QString &QString::setRawData(const QChar *unicode, qsizetype size) */ /*! + \fn QLatin1Char QLatin1String::last() const + \since 6.4 + + Returns the last character in the string. + Same as \c{at(size() - 1)} or back(). + + This function is provided for compatibility with other Qt containers. + + \warning Calling this function on an empty string constitutes + undefined behavior. + + \sa first(), back(), front() +*/ + +/*! \fn int QLatin1String::compare(QStringView str, Qt::CaseSensitivity cs) const \fn int QLatin1String::compare(QLatin1String l1, Qt::CaseSensitivity cs) const \fn int QLatin1String::compare(QChar ch) const @@ -9447,6 +9514,17 @@ QString &QString::setRawData(const QChar *unicode, qsizetype size) */ /*! + \fn QLatin1String::const_iterator QLatin1String::constBegin() const + \since 6.4 + + Same as begin(). + + This function is provided for compatibility with other Qt containers. + + \sa constEnd(), begin(), cbegin(), data() +*/ + +/*! \fn QLatin1String::const_iterator QLatin1String::end() const \since 5.10 @@ -9468,6 +9546,16 @@ QString &QString::setRawData(const QChar *unicode, qsizetype size) \sa cbegin(), end(), crend() */ +/*! \fn QLatin1String::const_iterator QLatin1String::constEnd() const + \since 6.4 + + Same as end(). + + This function is provided for compatibility with other Qt containers. + + \sa constBegin(), end(), cend(), crend() +*/ + /*! \fn QLatin1String::const_reverse_iterator QLatin1String::rbegin() const \since 5.10 diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index 40e023be83..1c95b038c6 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -84,6 +84,7 @@ class QLatin1String { public: constexpr inline QLatin1String() noexcept : m_size(0), m_data(nullptr) {} + constexpr QLatin1String(std::nullptr_t) noexcept : QLatin1String() {} constexpr inline explicit QLatin1String(const char *s) noexcept : m_size(s ? qsizetype(strlen(s)) : 0), m_data(s) {} constexpr explicit QLatin1String(const char *f, const char *l) : QLatin1String(f, qsizetype(l - f)) {} @@ -96,10 +97,20 @@ public: constexpr const char *latin1() const noexcept { return m_data; } constexpr qsizetype size() const noexcept { return m_size; } constexpr const char *data() const noexcept { return m_data; } + [[nodiscard]] constexpr const char *constData() const noexcept { return data(); } + [[nodiscard]] constexpr const char *constBegin() const noexcept { return begin(); } + [[nodiscard]] constexpr const char *constEnd() const noexcept { return end(); } + + [[nodiscard]] constexpr QLatin1Char first() const { return front(); } + [[nodiscard]] constexpr QLatin1Char last() const { return back(); } + + [[nodiscard]] constexpr qsizetype length() const noexcept { return size(); } constexpr bool isNull() const noexcept { return !data(); } constexpr bool isEmpty() const noexcept { return !size(); } + [[nodiscard]] constexpr bool empty() const noexcept { return size() == 0; } + template <typename...Args> [[nodiscard]] inline QString arg(Args &&...args) const; |