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>
This commit is contained in:
Marc Mutz 2017-05-03 20:11:34 +02:00
parent 3c592a17f1
commit 51e1374bae
2 changed files with 20 additions and 0 deletions

View File

@ -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.

View File

@ -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()) {}