summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2017-05-03 20:11:34 +0200
committerMarc Mutz <marc.mutz@kdab.com>2017-05-16 09:34:50 +0000
commit3c592a17f1b54c88a0d868b7251f5134dac421b6 (patch)
tree6719d9efc907a0edffe7df4ba102e72acf45c32f /src
parent221653cbeabea604db3644442b0134c718b6c2b6 (diff)
QStringView: add constructor from pointer pair
This is often more natural than (ptr, len), and I need it in the implementation of QStringView::trimmed(). Change-Id: I1d99b5ddaf76eee0582150b0233ef6ce9c37d25d Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qstringview.cpp20
-rw-r--r--src/corelib/tools/qstringview.h4
2 files changed, 24 insertions, 0 deletions
diff --git a/src/corelib/tools/qstringview.cpp b/src/corelib/tools/qstringview.cpp
index 0b1dac2f98..8d2fc996e9 100644
--- a/src/corelib/tools/qstringview.cpp
+++ b/src/corelib/tools/qstringview.cpp
@@ -240,6 +240,26 @@ QT_BEGIN_NAMESPACE
*/
/*!
+ \fn QStringView::QStringView(const Char *first, const Char *last)
+
+ Constructs a string view on \a first with length (\a last - \a first).
+
+ The range \c{[first,last)} must remain valid for the lifetime of
+ this string view object.
+
+ Passing \c nullptr as \a first is safe if \a last is nullptr, too,
+ and results in a null string view.
+
+ The behavior is undefined if \a last precedes \a first, or \a first
+ is \c nullptr and \a last is not.
+
+ This constructor only participates in overload resolution 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 QStringView::QStringView(const Char *str)
Constructs a string view on \a str. The length is determined
diff --git a/src/corelib/tools/qstringview.h b/src/corelib/tools/qstringview.h
index 62173f9765..fdbf644518 100644
--- a/src/corelib/tools/qstringview.h
+++ b/src/corelib/tools/qstringview.h
@@ -176,6 +176,10 @@ public:
: m_size((Q_ASSERT(len >= 0), Q_ASSERT(str || !len), len)),
m_data(castHelper(str)) {}
+ template <typename Char, if_compatible_char<Char> = true>
+ Q_DECL_CONSTEXPR QStringView(const Char *f, const Char *l)
+ : QStringView(f, l - f) {}
+
#ifdef Q_QDOC
template <typename Char, size_t N>
Q_DECL_CONSTEXPR QStringView(const Char (&array)[N]) Q_DECL_NOTHROW;