summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
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:54 +0000
commit51e1374bae4ae449b04ddeb30c14bc67935705ca (patch)
treee343cd5056c1d06f09fd8c346435b4949f554a63 /src/corelib/tools
parent3c592a17f1b54c88a0d868b7251f5134dac421b6 (diff)
QLatin1String: add constructor from pointer pair
This is often more natural than (ptr, len), and I need it in the implementation of QLatin1String::trimmed(). [ChangeLog][QtCore][QLatin1String] Added a constructor taking two pointers, complementing the constructor that takes a pointer and a length. Change-Id: I0606fa0e3f820af1c3c1e261a340e5a941443e4f Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qstring.cpp18
-rw-r--r--src/corelib/tools/qstring.h2
2 files changed, 20 insertions, 0 deletions
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index bfa6fb63b5..a6295da45e 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -8792,6 +8792,24 @@ QString &QString::setRawData(const QChar *unicode, int size)
\sa latin1()
*/
+/*!
+ \fn QLatin1String::QLatin1String(const char *first, const char *last)
+ \since 5.10
+
+ Constructs a QLatin1String object that stores \a first with length
+ (\a last - \a first).
+
+ The range \c{[first,last)} must remain valid for the lifetime of
+ this Latin-1 string object.
+
+ Passing \c nullptr as \a first is safe if \a last is \c nullptr,
+ too, and results in a null Latin-1 string.
+
+ The behavior is undefined if \a last precedes \a first, \a first
+ is \c nullptr and \a last is not, or if \c{last - first >
+ INT_MAX}.
+*/
+
/*! \fn QLatin1String::QLatin1String(const QByteArray &str)
Constructs a QLatin1String object that stores \a str.
diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h
index ca61d95793..33ecba6cf8 100644
--- a/src/corelib/tools/qstring.h
+++ b/src/corelib/tools/qstring.h
@@ -93,6 +93,8 @@ class QLatin1String
public:
Q_DECL_CONSTEXPR inline QLatin1String() Q_DECL_NOTHROW : m_size(0), m_data(Q_NULLPTR) {}
Q_DECL_CONSTEXPR inline explicit QLatin1String(const char *s) Q_DECL_NOTHROW : m_size(s ? int(strlen(s)) : 0), m_data(s) {}
+ Q_DECL_CONSTEXPR explicit QLatin1String(const char *f, const char *l)
+ : QLatin1String(f, int(l - f)) {}
Q_DECL_CONSTEXPR inline explicit QLatin1String(const char *s, int sz) Q_DECL_NOTHROW : m_size(sz), m_data(s) {}
inline explicit QLatin1String(const QByteArray &s) Q_DECL_NOTHROW : m_size(int(qstrnlen(s.constData(), s.size()))), m_data(s.constData()) {}