summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2017-04-04 22:06:16 +0200
committerMarc Mutz <marc.mutz@kdab.com>2017-04-06 02:38:25 +0000
commitbe49235266f07cffc4f8e6008c98605de79a05a0 (patch)
treefc28292cca534c284991594290f0f939cb9f00af /src
parent7d5e516e67bcafad7b81f3da2005ec38f574e590 (diff)
QStringView: use qssize_t as size_type
Nothing changes, we've just given 'QIntegerForSizeof<size_t>::Signed' a better name in qglobal.h and now use it in QStringView API and users. Change-Id: Ibea1ae26e95b3a96708400fd4b0cd120459d57b6 Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru> Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qlocale.cpp2
-rw-r--r--src/corelib/tools/qstringiterator_p.h2
-rw-r--r--src/corelib/tools/qstringview.cpp20
-rw-r--r--src/corelib/tools/qstringview.h37
4 files changed, 31 insertions, 30 deletions
diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp
index 9be20e6676..a3995449f1 100644
--- a/src/corelib/tools/qlocale.cpp
+++ b/src/corelib/tools/qlocale.cpp
@@ -3374,7 +3374,7 @@ bool QLocaleData::validateChars(QStringView str, NumberMode numMode, QByteArray
bool dec = false;
int decDigitCnt = 0;
- for (QStringView::size_type i = 0; i < str.size(); ++i) {
+ for (qssize_t i = 0; i < str.size(); ++i) {
char c = digitToCLocale(str.at(i));
if (c >= '0' && c <= '9') {
diff --git a/src/corelib/tools/qstringiterator_p.h b/src/corelib/tools/qstringiterator_p.h
index 749ba0e62d..8b1a6a1cd3 100644
--- a/src/corelib/tools/qstringiterator_p.h
+++ b/src/corelib/tools/qstringiterator_p.h
@@ -62,7 +62,7 @@ class QStringIterator
QString::const_iterator i, pos, e;
Q_STATIC_ASSERT((std::is_same<QString::const_iterator, const QChar *>::value));
public:
- explicit QStringIterator(QStringView string, QStringView::size_type idx = 0)
+ explicit QStringIterator(QStringView string, qssize_t idx = 0)
: i(string.begin()),
pos(i + idx),
e(string.end())
diff --git a/src/corelib/tools/qstringview.cpp b/src/corelib/tools/qstringview.cpp
index a2dfb8b97a..adffe1800c 100644
--- a/src/corelib/tools/qstringview.cpp
+++ b/src/corelib/tools/qstringview.cpp
@@ -131,9 +131,9 @@ QT_BEGIN_NAMESPACE
/*!
\typedef QStringView::size_type
- Alias for \c{std::ptrdiff_t}. Provided for compatibility with the STL.
+ Alias for qssize_t. Provided for compatibility with the STL.
- Unlike other Qt classes, QStringView uses \c ptrdiff_t as its \c size_type, to allow
+ Unlike other Qt classes, QStringView uses qssize_t as its \c size_type, to allow
accepting data from \c{std::basic_string} without truncation. The Qt API functions,
for example length(), return \c int, while the STL-compatible functions, for example
size(), return \c size_type.
@@ -233,7 +233,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn QStringView::QStringView(const Char *str, size_type len)
+ \fn QStringView::QStringView(const Char *str, qssize_t len)
Constructs a string view on \a str with length \a len.
@@ -475,7 +475,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn QStringView::size_type QStringView::size() const
+ \fn qssize_t QStringView::size() const
Returns the size of this string view, in UTF-16 code points (that is,
surrogate pairs count as two for the purposes of this function, the same
@@ -499,7 +499,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn QChar QStringView::operator[](size_type n) const
+ \fn QChar QStringView::operator[](qssize_t n) const
Returns the character at position \a n in this string view.
@@ -509,7 +509,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn QChar QStringView::at(size_type n) const
+ \fn QChar QStringView::at(qssize_t n) const
Returns the character at position \a n in this string view.
@@ -571,7 +571,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn QStringView QStringView::mid(size_type start) const
+ \fn QStringView QStringView::mid(qssize_t start) const
Returns the substring starting at position \a start in this object,
and extending to the end of the string.
@@ -582,7 +582,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn QStringView QStringView::mid(size_type start, size_type length) const
+ \fn QStringView QStringView::mid(qssize_t start, qssize_t length) const
\overload
Returns the substring of length \a length starting at position
@@ -595,7 +595,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn QStringView QStringView::left(size_type length) const
+ \fn QStringView QStringView::left(qssize_t length) const
Returns the substring of length \a length starting at position
0 in this object.
@@ -606,7 +606,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn QStringView QStringView::right(size_type length) const
+ \fn QStringView QStringView::right(qssize_t length) const
Returns the substring of length \a length starting at position
size() - \a length in this object.
diff --git a/src/corelib/tools/qstringview.h b/src/corelib/tools/qstringview.h
index acf05a909c..b07e98d0a2 100644
--- a/src/corelib/tools/qstringview.h
+++ b/src/corelib/tools/qstringview.h
@@ -111,7 +111,7 @@ class QStringView
public:
typedef const QChar value_type;
typedef std::ptrdiff_t difference_type;
- typedef QIntegerForSizeof<size_t>::Signed size_type;
+ typedef qssize_t size_type;
typedef value_type &reference;
typedef value_type &const_reference;
typedef value_type *pointer;
@@ -139,21 +139,21 @@ private:
using if_compatible_qstring_like = typename std::enable_if<std::is_same<T, QString>::value || std::is_same<T, QStringRef>::value, bool>::type;
template <typename Char, size_t N>
- static Q_DECL_CONSTEXPR size_type lengthHelperArray(const Char (&)[N]) Q_DECL_NOTHROW
+ static Q_DECL_CONSTEXPR qssize_t lengthHelperArray(const Char (&)[N]) Q_DECL_NOTHROW
{
- return size_type(N - 1);
+ return qssize_t(N - 1);
}
template <typename Char>
- static Q_DECL_RELAXED_CONSTEXPR size_type lengthHelperPointer(const Char *str) Q_DECL_NOTHROW
+ static Q_DECL_RELAXED_CONSTEXPR qssize_t lengthHelperPointer(const Char *str) Q_DECL_NOTHROW
{
- size_type result = 0;
+ qssize_t result = 0;
while (*str++)
++result;
return result;
}
- static Q_DECL_RELAXED_CONSTEXPR size_type lengthHelperPointer(const QChar *str) Q_DECL_NOTHROW
+ static Q_DECL_RELAXED_CONSTEXPR qssize_t lengthHelperPointer(const QChar *str) Q_DECL_NOTHROW
{
- size_type result = 0;
+ qssize_t result = 0;
while (!str++->isNull())
++result;
return result;
@@ -176,7 +176,7 @@ public:
#endif
template <typename Char, if_compatible_char<Char> = true>
- Q_DECL_CONSTEXPR QStringView(const Char *str, size_type len)
+ Q_DECL_CONSTEXPR QStringView(const Char *str, qssize_t len)
: m_size((Q_ASSERT(len >= 0), Q_ASSERT(str || !len), len)),
m_data(castHelper(str)) {}
@@ -202,35 +202,36 @@ public:
#else
template <typename String, if_compatible_qstring_like<String> = true>
QStringView(const String &str) Q_DECL_NOTHROW
- : QStringView(str.isNull() ? nullptr : str.data(), size_type(str.size())) {}
+ : QStringView(str.isNull() ? nullptr : str.data(), qssize_t(str.size())) {}
#endif
template <typename StdBasicString, if_compatible_string<StdBasicString> = true>
QStringView(const StdBasicString &str) Q_DECL_NOTHROW
- : QStringView(str.data(), size_type(str.size())) {}
+ : QStringView(str.data(), qssize_t(str.size())) {}
QString toString() const { return Q_ASSERT(size() == length()), QString(data(), length()); }
- Q_DECL_CONSTEXPR size_type size() const Q_DECL_NOTHROW { return m_size; }
+ Q_DECL_CONSTEXPR qssize_t size() const Q_DECL_NOTHROW { return m_size; }
const_pointer data() const Q_DECL_NOTHROW { return reinterpret_cast<const_pointer>(m_data); }
Q_DECL_CONSTEXPR const storage_type *utf16() const Q_DECL_NOTHROW { return m_data; }
- Q_DECL_CONSTEXPR QChar operator[](size_type n) const
+ Q_DECL_CONSTEXPR QChar operator[](qssize_t n) const
{ return Q_ASSERT(n >= 0), Q_ASSERT(n < size()), QChar(m_data[n]); }
//
// QString API
//
- Q_DECL_CONSTEXPR QChar at(size_type n) const { return (*this)[n]; }
- Q_DECL_CONSTEXPR QStringView mid(size_type pos) const
+ Q_DECL_CONSTEXPR QChar at(qssize_t n) const { return (*this)[n]; }
+
+ Q_DECL_CONSTEXPR QStringView mid(qssize_t pos) const
{ return Q_ASSERT(pos >= 0), Q_ASSERT(pos <= size()), QStringView(m_data + pos, m_size - pos); }
- Q_DECL_CONSTEXPR QStringView mid(size_type pos, size_type n) const
+ Q_DECL_CONSTEXPR QStringView mid(qssize_t pos, qssize_t n) const
{ return Q_ASSERT(pos >= 0), Q_ASSERT(n >= 0), Q_ASSERT(pos + n <= size()), QStringView(m_data + pos, n); }
- Q_DECL_CONSTEXPR QStringView left(size_type n) const
+ Q_DECL_CONSTEXPR QStringView left(qssize_t n) const
{ return Q_ASSERT(n >= 0), Q_ASSERT(n <= size()), QStringView(m_data, n); }
- Q_DECL_CONSTEXPR QStringView right(size_type n) const
+ Q_DECL_CONSTEXPR QStringView right(qssize_t n) const
{ return Q_ASSERT(n >= 0), Q_ASSERT(n <= size()), QStringView(m_data + m_size - n, n); }
//
@@ -259,7 +260,7 @@ public:
Q_DECL_CONSTEXPR QChar first() const { return front(); }
Q_DECL_CONSTEXPR QChar last() const { return back(); }
private:
- size_type m_size;
+ qssize_t m_size;
const storage_type *m_data;
};
Q_DECLARE_TYPEINFO(QStringView, Q_MOVABLE_TYPE);