From 51e1374bae4ae449b04ddeb30c14bc67935705ca Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 3 May 2017 20:11:34 +0200 Subject: [PATCH] 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 Reviewed-by: Edward Welbourne --- src/corelib/tools/qstring.cpp | 18 ++++++++++++++++++ src/corelib/tools/qstring.h | 2 ++ 2 files changed, 20 insertions(+) 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()) {}