summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2021-06-10 16:52:17 +0200
committerMårten Nordheim <marten.nordheim@qt.io>2021-06-12 03:08:59 +0200
commite0ae1af278f3cc6df6c3f66e4118585cc8384b15 (patch)
treed18ecb98ef82d006dc67ef9e914e756e92b83424 /src
parent77d62727d0c1c638b904ada8fc720de2a4d60a6e (diff)
QLatin1String: Add a constructor taking QByteArrayView
Change-Id: Ie90645486431d7af3fe8128417b0fb6bd02a88b5 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/text/qstring.cpp14
-rw-r--r--src/corelib/text/qstring.h1
2 files changed, 15 insertions, 0 deletions
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp
index 3e4d95188d..a8f0c0b142 100644
--- a/src/corelib/text/qstring.cpp
+++ b/src/corelib/text/qstring.cpp
@@ -8910,6 +8910,20 @@ QString &QString::setRawData(const QChar *unicode, qsizetype size)
\sa latin1()
*/
+/*! \fn QLatin1String::QLatin1String(QByteArrayView str)
+ \since 6.3
+
+ Constructs a QLatin1String object that stores \a str.
+
+ The string data is \e not copied. The caller must be able to
+ guarantee that the data which \a str is pointing to will not
+ be deleted or modified as long as the QLatin1String object
+ exists. The size is obtained from \a str as-is, without checking
+ for a null-terminator.
+
+ \sa latin1()
+*/
+
/*!
\fn QString QLatin1String::toString() const
\since 6.0
diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h
index e17bcbfbf6..cce57cd578 100644
--- a/src/corelib/text/qstring.h
+++ b/src/corelib/text/qstring.h
@@ -89,6 +89,7 @@ public:
: QLatin1String(f, qsizetype(l - f)) {}
constexpr inline explicit QLatin1String(const char *s, qsizetype sz) noexcept : m_size(sz), m_data(s) {}
explicit QLatin1String(const QByteArray &s) noexcept : m_size(qsizetype(qstrnlen(s.constData(), s.size()))), m_data(s.constData()) {}
+ constexpr explicit QLatin1String(QByteArrayView s) noexcept : m_size(s.size()), m_data(s.data()) {}
inline QString toString() const;