From 107ff4c1d6b5da2cb11c65b2bd9106817f7fdb02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Wed, 16 Sep 2020 12:04:31 +0200 Subject: 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 Reviewed-by: Lars Knoll --- src/corelib/text/qutf8stringview.qdoc | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'src/corelib/text/qutf8stringview.qdoc') diff --git a/src/corelib/text/qutf8stringview.qdoc b/src/corelib/text/qutf8stringview.qdoc index 9c0c620d88..031769440c 100644 --- a/src/corelib/text/qutf8stringview.qdoc +++ b/src/corelib/text/qutf8stringview.qdoc @@ -318,11 +318,9 @@ \fn template QUtf8StringView::QUtf8StringView(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 \c{Char(0)}. - If you need the full array, use the constructor from pointer and - size instead: - - \snippet code/src_corelib_text_qutf8stringview.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. @@ -331,6 +329,8 @@ is an actual array and if \c Char is a compatible character type. The compatible character types are: \c char8_t, \c char, \c{signed char} and \c{unsigned char}. + + \sa fromArray */ /*! @@ -352,6 +352,24 @@ \sa isNull(), isEmpty() */ +/*! + \fn template static QBasicUtf8StringView fromArray(const Char (&string)[Size]) + + 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 char8_t, \c char, \c{signed char} and \c{unsigned char}. +*/ + /*! \fn QString QUtf8StringView::toString() const -- cgit v1.2.3