From 4f25e66f7a7269af0002bfe4b1c5caa941c6ee64 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Tue, 17 Jan 2012 21:04:42 +0100 Subject: [PATCH] Add a constructor that explicitly takes a size to QLatin1String MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is useful in a couple of situations where the size is known at runtime and one wants to avoid a call to strlen. Change-Id: Ic20587b0d365a4573d4636c5853c206b571b8d6b Reviewed-by: Thiago Macieira Reviewed-by: João Abecasis Reviewed-by: Robin Burchell --- src/corelib/tools/qstring.cpp | 13 +++++++++++++ src/corelib/tools/qstring.h | 1 + 2 files changed, 14 insertions(+) diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 1b6ff3c5df..4e5d806dbb 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -7164,6 +7164,19 @@ QString &QString::setRawData(const QChar *unicode, int size) \sa latin1() */ +/*! \fn QLatin1String::QLatin1String(const char *str, int size) + + Constructs a QLatin1String object that stores \a str with \a size. + Note that if \a str is 0, an empty string is created; this case + is handled by QString. + + The string data is \e not copied. The caller must be able to + guarantee that \a str will not be deleted or modified as long as + the QLatin1String object exists. + + \sa latin1() +*/ + /*! \fn const char *QLatin1String::latin1() const Returns the Latin-1 string stored in this object. diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index 9d92f403eb..f2d1de9c00 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -646,6 +646,7 @@ class QLatin1String { public: Q_DECL_CONSTEXPR inline explicit QLatin1String(const char *s) : m_size(s ? int(strlen(s)) : 0), m_data(s) {} + Q_DECL_CONSTEXPR inline explicit QLatin1String(const char *s, int size) : m_size(size), m_data(s) {} inline const char *latin1() const { return m_data; } inline int size() const { return m_size; }