From 6a6314df1e7ae7b392d13f1dcf3d595d9e689658 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 15 May 2020 15:18:10 +0200 Subject: Add QStringView::constData() This is doing the same as data(), but the method is widely being used in Qt (e.g. in QString), so this will make it easier to change the type of a variable from QString(Ref) to QStringView in a source compatible way. Change-Id: Ic49bef688d3ce3c550336edf90130aa5cac8b497 Reviewed-by: Marc Mutz Reviewed-by: Thiago Macieira --- src/corelib/text/qstringview.cpp | 11 +++++++++++ src/corelib/text/qstringview.h | 1 + 2 files changed, 12 insertions(+) (limited to 'src/corelib') diff --git a/src/corelib/text/qstringview.cpp b/src/corelib/text/qstringview.cpp index abb7015b68..f4c3ccce66 100644 --- a/src/corelib/text/qstringview.cpp +++ b/src/corelib/text/qstringview.cpp @@ -359,6 +359,17 @@ QT_BEGIN_NAMESPACE \sa begin(), end(), utf16() */ +/*! + \fn const QChar *QStringView::constData() const + \since 6.0 + + Returns a const pointer to the first character in the string. + + \note The character array represented by the return value is \e not null-terminated. + + \sa data(), begin(), end(), utf16() +*/ + /*! \fn const storage_type *QStringView::utf16() const diff --git a/src/corelib/text/qstringview.h b/src/corelib/text/qstringview.h index e2e1abb62d..5890515652 100644 --- a/src/corelib/text/qstringview.h +++ b/src/corelib/text/qstringview.h @@ -236,6 +236,7 @@ public: Q_REQUIRED_RESULT Q_DECL_CONSTEXPR qsizetype size() const noexcept { return m_size; } Q_REQUIRED_RESULT const_pointer data() const noexcept { return reinterpret_cast(m_data); } + Q_REQUIRED_RESULT const_pointer constData() const noexcept { return data(); } Q_REQUIRED_RESULT Q_DECL_CONSTEXPR const storage_type *utf16() const noexcept { return m_data; } Q_REQUIRED_RESULT Q_DECL_CONSTEXPR QChar operator[](qsizetype n) const -- cgit v1.2.3