diff options
author | Mårten Nordheim <marten.nordheim@qt.io> | 2020-09-16 12:04:31 +0200 |
---|---|---|
committer | Mårten Nordheim <marten.nordheim@qt.io> | 2020-09-18 23:34:52 +0200 |
commit | 107ff4c1d6b5da2cb11c65b2bd9106817f7fdb02 (patch) | |
tree | e0c79bac217c10fd6d25fa9c4155f2003f6636df /src/corelib/text/qstringview.cpp | |
parent | bbe7570ddcc6fcce707a355b76d2d0024c44ea38 (diff) |
Q(Any|Utf8)StringView: move array size deduction feature to fromArray
The constructor taking an array literal will now stop at the first
null-terminator encountered.
And fromArray is introduced which only supports array literals.
Constructs a view of the full size. Explicit so it shouldn't be
surprising.
Change-Id: I1497c33a5c12453a95e87c990abe6335b2817081
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/text/qstringview.cpp')
-rw-r--r-- | src/corelib/text/qstringview.cpp | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/src/corelib/text/qstringview.cpp b/src/corelib/text/qstringview.cpp index 971d2ffd7a..aeec699f7f 100644 --- a/src/corelib/text/qstringview.cpp +++ b/src/corelib/text/qstringview.cpp @@ -278,11 +278,9 @@ QT_BEGIN_NAMESPACE \fn template <typename Char, size_t N> QStringView::QStringView(const Char (&string)[N]) Constructs a string view on the character string literal \a string. - The length is set to \c{N-1}, excluding the trailing \{Char(0)}. - If you need the full array, use the constructor from pointer and - size instead: - - \snippet code/src_corelib_text_qstringview.cpp 2 + The view covers the array until the first \c{Char(0)} is encountered, + or \c N, whichever comes first. + If you need the full array, use fromArray() instead. \a string must remain valid for the lifetime of this string view object. @@ -292,6 +290,8 @@ QT_BEGIN_NAMESPACE type. The compatible character types are: \c QChar, \c ushort, \c char16_t and (on platforms, such as Windows, where it is a 16-bit type) \c wchar_t. + + \sa fromArray */ /*! @@ -324,6 +324,25 @@ QT_BEGIN_NAMESPACE */ /*! + \fn template <typename Char, size_t Size> static QStringView fromArray(const Char (&string)[Size]) noexcept + + Constructs a string view on the full character string literal \a string, + including any trailing \c{Char(0)}. If you don't want the + null-terminator included in the view then you can chop() it off + when you are certain it is at the end. Alternatively you can use + the constructor overload taking an array literal which will create + a view up to, but not including, the first null-terminator in the data. + + \a string must remain valid for the lifetime of this string view + object. + + This function will work with any array literal if \c Char is a + compatible character type. The compatible character types are: \c QChar, \c ushort, \c + char16_t and (on platforms, such as Windows, where it is a 16-bit + type) \c wchar_t. +*/ + +/*! \fn QString QStringView::toString() const Returns a deep copy of this string view's data as a QString. |