summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qalgorithms.h6
-rw-r--r--src/corelib/tools/qarraydata.cpp19
-rw-r--r--src/corelib/tools/qarraydata.h4
-rw-r--r--src/corelib/tools/qarraydatapointer.h6
-rw-r--r--src/corelib/tools/qbitarray.h6
-rw-r--r--src/corelib/tools/qbytearray.cpp235
-rw-r--r--src/corelib/tools/qbytearray.h57
-rw-r--r--src/corelib/tools/qbytearraymatcher.h8
-rw-r--r--src/corelib/tools/qcache.h4
-rw-r--r--src/corelib/tools/qchar.h125
-rw-r--r--src/corelib/tools/qcollator.h10
-rw-r--r--src/corelib/tools/qcommandlineparser.cpp68
-rw-r--r--src/corelib/tools/qdatetime.cpp115
-rw-r--r--src/corelib/tools/qdatetime.h16
-rw-r--r--src/corelib/tools/qdatetime_mac.mm76
-rw-r--r--src/corelib/tools/qdatetime_p.h3
-rw-r--r--src/corelib/tools/qeasingcurve.cpp105
-rw-r--r--src/corelib/tools/qeasingcurve.h2
-rw-r--r--src/corelib/tools/qelapsedtimer_generic.cpp4
-rw-r--r--src/corelib/tools/qelapsedtimer_unix.cpp14
-rw-r--r--src/corelib/tools/qhash.cpp159
-rw-r--r--src/corelib/tools/qhash.h92
-rw-r--r--src/corelib/tools/qlist.cpp8
-rw-r--r--src/corelib/tools/qlist.h28
-rw-r--r--src/corelib/tools/qlocale.cpp25
-rw-r--r--src/corelib/tools/qlocale.h7
-rw-r--r--src/corelib/tools/qlocale_tools.cpp53
-rw-r--r--src/corelib/tools/qmap.cpp43
-rw-r--r--src/corelib/tools/qmap.h18
-rw-r--r--src/corelib/tools/qmargins.h213
-rw-r--r--src/corelib/tools/qpair.h23
-rw-r--r--src/corelib/tools/qpair.qdoc25
-rw-r--r--src/corelib/tools/qpoint.h72
-rw-r--r--src/corelib/tools/qrect.cpp28
-rw-r--r--src/corelib/tools/qrect.h649
-rw-r--r--src/corelib/tools/qregexp.cpp3
-rw-r--r--src/corelib/tools/qregularexpression.cpp131
-rw-r--r--src/corelib/tools/qregularexpression.h22
-rw-r--r--src/corelib/tools/qringbuffer_p.h48
-rw-r--r--src/corelib/tools/qset.h9
-rw-r--r--src/corelib/tools/qset.qdoc11
-rw-r--r--src/corelib/tools/qshareddata.h26
-rw-r--r--src/corelib/tools/qsize.cpp8
-rw-r--r--src/corelib/tools/qsize.h248
-rw-r--r--src/corelib/tools/qstring.cpp649
-rw-r--r--src/corelib/tools/qstring.h130
-rw-r--r--src/corelib/tools/qstring_compat.cpp49
-rw-r--r--src/corelib/tools/qstringalgorithms_p.h156
-rw-r--r--src/corelib/tools/qstringiterator_p.h5
-rw-r--r--src/corelib/tools/qstringlist.cpp45
-rw-r--r--src/corelib/tools/qstringlist.h138
-rw-r--r--src/corelib/tools/qstringmatcher.h8
-rw-r--r--src/corelib/tools/qtimeline.h2
-rw-r--r--src/corelib/tools/qtimezone.cpp27
-rw-r--r--src/corelib/tools/qtimezone.h6
-rw-r--r--src/corelib/tools/qtimezoneprivate_android.cpp287
-rw-r--r--src/corelib/tools/qtimezoneprivate_p.h60
-rw-r--r--src/corelib/tools/qtools_p.h31
-rw-r--r--src/corelib/tools/qunicodetables.cpp16
-rw-r--r--src/corelib/tools/qunicodetables_p.h20
-rw-r--r--src/corelib/tools/qvector.cpp12
-rw-r--r--src/corelib/tools/qvector.h28
-rw-r--r--src/corelib/tools/qversionnumber.cpp8
-rw-r--r--src/corelib/tools/qversionnumber_p.h14
-rw-r--r--src/corelib/tools/tools.pri14
65 files changed, 2788 insertions, 1749 deletions
diff --git a/src/corelib/tools/qalgorithms.h b/src/corelib/tools/qalgorithms.h
index 0ba3cad5e9..cffe0128b0 100644
--- a/src/corelib/tools/qalgorithms.h
+++ b/src/corelib/tools/qalgorithms.h
@@ -37,7 +37,9 @@
#include <QtCore/qglobal.h>
QT_BEGIN_NAMESPACE
-
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_GCC("-Wdeprecated-declarations")
+QT_WARNING_DISABLE_CLANG("-Wdeprecated-declarations")
/*
Warning: The contents of QAlgorithmsPrivate is not a part of the public Qt API
@@ -582,7 +584,7 @@ Q_DECL_CONSTEXPR inline uint qPopulationCount(long unsigned int v)
#undef QALGORITHMS_USE_BUILTIN_POPCOUNT
#endif
-
+QT_WARNING_POP
QT_END_NAMESPACE
#endif // QALGORITHMS_H
diff --git a/src/corelib/tools/qarraydata.cpp b/src/corelib/tools/qarraydata.cpp
index 98c484c1dd..dc419c3758 100644
--- a/src/corelib/tools/qarraydata.cpp
+++ b/src/corelib/tools/qarraydata.cpp
@@ -85,8 +85,20 @@ QArrayData *QArrayData::allocate(size_t objectSize, size_t alignment,
headerSize += (alignment - Q_ALIGNOF(QArrayData));
// Allocate additional space if array is growing
- if (options & Grow)
- capacity = qAllocMore(int(objectSize * capacity), int(headerSize)) / int(objectSize);
+ if (options & Grow) {
+
+ // Guard against integer overflow when multiplying.
+ if (capacity > std::numeric_limits<size_t>::max() / objectSize)
+ return 0;
+
+ size_t alloc = objectSize * capacity;
+
+ // Make sure qAllocMore won't overflow.
+ if (headerSize > size_t(MaxAllocSize) || alloc > size_t(MaxAllocSize) - headerSize)
+ return 0;
+
+ capacity = qAllocMore(int(alloc), int(headerSize)) / int(objectSize);
+ }
size_t allocSize = headerSize + objectSize * capacity;
@@ -118,7 +130,8 @@ void QArrayData::deallocate(QArrayData *data, size_t objectSize,
return;
#endif
- Q_ASSERT_X(!data->ref.isStatic(), "QArrayData::deallocate", "Static data can not be deleted");
+ Q_ASSERT_X(data == 0 || !data->ref.isStatic(), "QArrayData::deallocate",
+ "Static data can not be deleted");
::free(data);
}
diff --git a/src/corelib/tools/qarraydata.h b/src/corelib/tools/qarraydata.h
index 2119b3d4ac..df44503a8e 100644
--- a/src/corelib/tools/qarraydata.h
+++ b/src/corelib/tools/qarraydata.h
@@ -113,7 +113,7 @@ struct Q_CORE_EXPORT QArrayData
size_t alignment) Q_DECL_NOTHROW;
static const QArrayData shared_null[2];
- static QArrayData *sharedNull() { return const_cast<QArrayData*>(shared_null); }
+ static QArrayData *sharedNull() Q_DECL_NOTHROW { return const_cast<QArrayData*>(shared_null); }
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QArrayData::AllocationOptions)
@@ -237,7 +237,7 @@ struct QTypedArrayData
return result;
}
- static QTypedArrayData *sharedNull()
+ static QTypedArrayData *sharedNull() Q_DECL_NOTHROW
{
Q_STATIC_ASSERT(sizeof(QTypedArrayData) == sizeof(QArrayData));
return static_cast<QTypedArrayData *>(QArrayData::sharedNull());
diff --git a/src/corelib/tools/qarraydatapointer.h b/src/corelib/tools/qarraydatapointer.h
index f2cd3ec983..aef38bc20b 100644
--- a/src/corelib/tools/qarraydatapointer.h
+++ b/src/corelib/tools/qarraydatapointer.h
@@ -169,8 +169,10 @@ public:
private:
Data *clone(QArrayData::AllocationOptions options) const Q_REQUIRED_RESULT
{
- QArrayDataPointer copy(Data::allocate(d->detachCapacity(d->size),
- options));
+ Data *x = Data::allocate(d->detachCapacity(d->size), options);
+ Q_CHECK_PTR(x);
+ QArrayDataPointer copy(x);
+
if (d->size)
copy->copyAppend(d->begin(), d->end());
diff --git a/src/corelib/tools/qbitarray.h b/src/corelib/tools/qbitarray.h
index 768dfa912d..8d550554ff 100644
--- a/src/corelib/tools/qbitarray.h
+++ b/src/corelib/tools/qbitarray.h
@@ -53,12 +53,12 @@ public:
QBitArray(const QBitArray &other) : d(other.d) {}
inline QBitArray &operator=(const QBitArray &other) { d = other.d; return *this; }
#ifdef Q_COMPILER_RVALUE_REFS
- inline QBitArray(QBitArray &&other) : d(std::move(other.d)) {}
- inline QBitArray &operator=(QBitArray &&other)
+ inline QBitArray(QBitArray &&other) Q_DECL_NOTHROW : d(std::move(other.d)) {}
+ inline QBitArray &operator=(QBitArray &&other) Q_DECL_NOTHROW
{ qSwap(d, other.d); return *this; }
#endif
- inline void swap(QBitArray &other) { qSwap(d, other.d); }
+ inline void swap(QBitArray &other) Q_DECL_NOTHROW { qSwap(d, other.d); }
inline int size() const { return (d.size() << 3) - *d.constData(); }
inline int count() const { return (d.size() << 3) - *d.constData(); }
diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp
index bd0215902c..7f6dab38c0 100644
--- a/src/corelib/tools/qbytearray.cpp
+++ b/src/corelib/tools/qbytearray.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Intel Corporation.
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -38,6 +39,7 @@
#include "qlist.h"
#include "qlocale.h"
#include "qlocale_p.h"
+#include "qstringalgorithms_p.h"
#include "qscopedpointer.h"
#include <qdatastream.h>
#include <qmath.h>
@@ -55,6 +57,64 @@
QT_BEGIN_NAMESPACE
+// Latin 1 case system, used by QByteArray::to{Upper,Lower}() and qstr(n)icmp():
+/*
+#!/usr/bin/perl -l
+use feature "unicode_strings";
+for (0..255) {
+ $up = uc(chr($_));
+ $up = chr($_) if ord($up) > 0x100 || length $up > 1;
+ printf "0x%02x,", ord($up);
+ print "" if ($_ & 0xf) == 0xf;
+}
+*/
+static const uchar latin1_uppercased[256] = {
+ 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
+ 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,
+ 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,
+ 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,
+ 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,
+ 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f,
+ 0x60,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,
+ 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x7b,0x7c,0x7d,0x7e,0x7f,
+ 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,
+ 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,
+ 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,
+ 0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf,
+ 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,
+ 0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf,
+ 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,
+ 0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xf7,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xff
+};
+
+/*
+#!/usr/bin/perl -l
+use feature "unicode_strings";
+for (0..255) {
+ $up = lc(chr($_));
+ $up = chr($_) if ord($up) > 0x100 || length $up > 1;
+ printf "0x%02x,", ord($up);
+ print "" if ($_ & 0xf) == 0xf;
+}
+*/
+static const uchar latin1_lowercased[256] = {
+ 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
+ 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,
+ 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,
+ 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,
+ 0x40,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,
+ 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x5b,0x5c,0x5d,0x5e,0x5f,
+ 0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,
+ 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f,
+ 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,
+ 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,
+ 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,
+ 0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf,
+ 0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xef,
+ 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xd7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xdf,
+ 0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xef,
+ 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
+};
int qFindByteArray(
const char *haystack0, int haystackLen, int from,
@@ -249,7 +309,7 @@ int qstricmp(const char *str1, const char *str2)
uchar c;
if (!s1 || !s2)
return s1 ? 1 : (s2 ? -1 : 0);
- for (; !(res = (c = QChar::toLower((ushort)*s1)) - QChar::toLower((ushort)*s2)); s1++, s2++)
+ for (; !(res = (c = latin1_lowercased[*s1]) - latin1_lowercased[*s2]); s1++, s2++)
if (!c) // strings are equal
break;
return res;
@@ -284,7 +344,7 @@ int qstrnicmp(const char *str1, const char *str2, uint len)
if (!s1 || !s2)
return s1 ? 1 : (s2 ? -1 : 0);
for (; len--; s1++, s2++) {
- if ((res = (c = QChar::toLower((ushort)*s1)) - QChar::toLower((ushort)*s2)))
+ if ((res = (c = latin1_lowercased[*s1]) - latin1_lowercased[*s2]))
return res;
if (!c) // strings are equal
break;
@@ -925,7 +985,7 @@ static inline char qToLower(char c)
Assigns \a other to this byte array and returns a reference to
this byte array.
*/
-QByteArray &QByteArray::operator=(const QByteArray & other)
+QByteArray &QByteArray::operator=(const QByteArray & other) Q_DECL_NOTHROW
{
other.d->ref.ref();
if (!d->ref.deref())
@@ -1495,8 +1555,11 @@ void QByteArray::reallocData(uint alloc, Data::AllocationOptions options)
Data::deallocate(d);
d = x;
} else {
- if (options & Data::Grow)
+ if (options & Data::Grow) {
+ if (alloc > uint(MaxAllocSize) - uint(sizeof(Data)))
+ qBadAlloc();
alloc = qAllocMore(alloc, sizeof(Data));
+ }
Data *x = static_cast<Data *>(::realloc(d, sizeof(Data) + alloc));
Q_CHECK_PTR(x);
x->alloc = alloc;
@@ -2687,6 +2750,8 @@ QByteArray QByteArray::mid(int pos, int len) const
}
/*!
+ \fn QByteArray QByteArray::toLower() const
+
Returns a lowercase copy of the byte array. The bytearray is
interpreted as a Latin-1 encoded string.
@@ -2695,21 +2760,52 @@ QByteArray QByteArray::mid(int pos, int len) const
\sa toUpper(), {8-bit Character Comparisons}
*/
-QByteArray QByteArray::toLower() const
+
+// prevent the compiler from inlining the function in each of
+// toLower and toUpper when the only difference is the table being used
+// (even with constant propagation, there's no gain in performance).
+template <typename T>
+Q_NEVER_INLINE
+static QByteArray toCase_template(T &input, const uchar * table)
{
- QByteArray s(*this);
- uchar *p = reinterpret_cast<uchar *>(s.data());
- uchar *e = reinterpret_cast<uchar *>(s.end());
- if (p) {
- while (p != e) {
- *p = QChar::toLower((ushort)*p);
- p++;
- }
+ // find the first bad character in input
+ const char *orig_begin = input.constBegin();
+ const char *firstBad = orig_begin;
+ const char *e = input.constEnd();
+ for ( ; firstBad != e ; ++firstBad) {
+ uchar ch = uchar(*firstBad);
+ uchar converted = table[ch];
+ if (ch != converted)
+ break;
+ }
+
+ if (firstBad == e)
+ return qMove(input);
+
+ // transform the rest
+ QByteArray s = qMove(input); // will copy if T is const QByteArray
+ char *b = s.begin(); // will detach if necessary
+ char *p = b + (firstBad - orig_begin);
+ e = b + s.size();
+ for ( ; p != e; ++p) {
+ *p = char(uchar(table[uchar(*p)]));
}
return s;
}
+QByteArray QByteArray::toLower_helper(const QByteArray &a)
+{
+ return toCase_template(a, latin1_lowercased);
+}
+
+QByteArray QByteArray::toLower_helper(QByteArray &a)
+{
+ return toCase_template(a, latin1_lowercased);
+}
+
/*!
+ \fn QByteArray QByteArray::toUpper() const
+
Returns an uppercase copy of the byte array. The bytearray is
interpreted as a Latin-1 encoded string.
@@ -2719,18 +2815,14 @@ QByteArray QByteArray::toLower() const
\sa toLower(), {8-bit Character Comparisons}
*/
-QByteArray QByteArray::toUpper() const
+QByteArray QByteArray::toUpper_helper(const QByteArray &a)
{
- QByteArray s(*this);
- uchar *p = reinterpret_cast<uchar *>(s.data());
- uchar *e = reinterpret_cast<uchar *>(s.end());
- if (p) {
- while (p != e) {
- *p = QChar::toUpper((ushort)*p);
- p++;
- }
- }
- return s;
+ return toCase_template(a, latin1_uppercased);
+}
+
+QByteArray QByteArray::toUpper_helper(QByteArray &a)
+{
+ return toCase_template(a, latin1_uppercased);
}
/*! \fn void QByteArray::clear()
@@ -3110,6 +3202,8 @@ QDataStream &operator>>(QDataStream &in, QByteArray &ba)
*/
/*!
+ \fn QByteArray QByteArray::simplified() const
+
Returns a byte array that has whitespace removed from the start
and the end, and which has each sequence of internal whitespace
replaced with a single space.
@@ -3124,32 +3218,19 @@ QDataStream &operator>>(QDataStream &in, QByteArray &ba)
\sa trimmed()
*/
-QByteArray QByteArray::simplified() const
+QByteArray QByteArray::simplified_helper(const QByteArray &a)
{
- if (d->size == 0)
- return *this;
- QByteArray result(d->size, Qt::Uninitialized);
- const char *from = d->data();
- const char *fromend = from + d->size;
- int outc=0;
- char *to = result.d->data();
- for (;;) {
- while (from!=fromend && ascii_isspace(uchar(*from)))
- from++;
- while (from!=fromend && !ascii_isspace(uchar(*from)))
- to[outc++] = *from++;
- if (from!=fromend)
- to[outc++] = ' ';
- else
- break;
- }
- if (outc > 0 && to[outc-1] == ' ')
- outc--;
- result.resize(outc);
- return result;
+ return QStringAlgorithms<const QByteArray>::simplified_helper(a);
+}
+
+QByteArray QByteArray::simplified_helper(QByteArray &a)
+{
+ return QStringAlgorithms<QByteArray>::simplified_helper(a);
}
/*!
+ \fn QByteArray QByteArray::trimmed() const
+
Returns a byte array that has whitespace removed from the start
and the end.
@@ -3164,29 +3245,17 @@ QByteArray QByteArray::simplified() const
\sa simplified()
*/
-QByteArray QByteArray::trimmed() const
+QByteArray QByteArray::trimmed_helper(const QByteArray &a)
{
- if (d->size == 0)
- return *this;
- const char *s = d->data();
- if (!ascii_isspace(uchar(*s)) && !ascii_isspace(uchar(s[d->size-1])))
- return *this;
- int start = 0;
- int end = d->size - 1;
- while (start<=end && ascii_isspace(uchar(s[start]))) // skip white space from start
- start++;
- if (start <= end) { // only white space
- while (end && ascii_isspace(uchar(s[end]))) // skip white space from end
- end--;
- }
- int l = end - start + 1;
- if (l <= 0) {
- QByteArrayDataPtr empty = { Data::allocate(0) };
- return QByteArray(empty);
- }
- return QByteArray(s+start, l);
+ return QStringAlgorithms<const QByteArray>::trimmed_helper(a);
}
+QByteArray QByteArray::trimmed_helper(QByteArray &a)
+{
+ return QStringAlgorithms<QByteArray>::trimmed_helper(a);
+}
+
+
/*!
Returns a byte array of size \a width that contains this byte
array padded by the \a fill character.
@@ -4062,15 +4131,9 @@ QByteArray QByteArray::fromHex(const QByteArray &hexEncoded)
bool odd_digit = true;
for (int i = hexEncoded.size() - 1; i >= 0; --i) {
- int ch = hexEncoded.at(i);
- int tmp;
- if (ch >= '0' && ch <= '9')
- tmp = ch - '0';
- else if (ch >= 'a' && ch <= 'f')
- tmp = ch - 'a' + 10;
- else if (ch >= 'A' && ch <= 'F')
- tmp = ch - 'A' + 10;
- else
+ uchar ch = uchar(hexEncoded.at(i));
+ int tmp = QtMiscUtils::fromHex(ch);
+ if (tmp == -1)
continue;
if (odd_digit) {
--result;
@@ -4098,16 +4161,8 @@ QByteArray QByteArray::toHex() const
char *hexData = hex.data();
const uchar *data = (const uchar *)d->data();
for (int i = 0; i < d->size; ++i) {
- int j = (data[i] >> 4) & 0xf;
- if (j <= 9)
- hexData[i*2] = (j + '0');
- else
- hexData[i*2] = (j + 'a' - 10);
- j = data[i] & 0xf;
- if (j <= 9)
- hexData[i*2+1] = (j + '0');
- else
- hexData[i*2+1] = (j + 'a' - 10);
+ hexData[i*2] = QtMiscUtils::toHexLower(data[i] >> 4);
+ hexData[i*2+1] = QtMiscUtils::toHexLower(data[i] & 0xf);
}
return hex;
}
@@ -4302,12 +4357,6 @@ static inline bool q_strchr(const char str[], char chr)
return false;
}
-static inline char toHexHelper(char c)
-{
- static const char hexnumbers[] = "0123456789ABCDEF";
- return hexnumbers[c & 0xf];
-}
-
static void q_toPercentEncoding(QByteArray *ba, const char *dontEncode, const char *alsoEncode, char percent)
{
if (ba->isEmpty())
@@ -4340,8 +4389,8 @@ static void q_toPercentEncoding(QByteArray *ba, const char *dontEncode, const ch
output = ba->data();
}
output[length++] = percent;
- output[length++] = toHexHelper((c & 0xf0) >> 4);
- output[length++] = toHexHelper(c & 0xf);
+ output[length++] = QtMiscUtils::toHexUpper((c & 0xf0) >> 4);
+ output[length++] = QtMiscUtils::toHexUpper(c & 0xf);
}
}
if (output)
diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h
index 3bcc7b1f2a..0daf2535bc 100644
--- a/src/corelib/tools/qbytearray.h
+++ b/src/corelib/tools/qbytearray.h
@@ -185,22 +185,23 @@ public:
};
Q_DECLARE_FLAGS(Base64Options, Base64Option)
- inline QByteArray();
+ inline QByteArray() Q_DECL_NOTHROW;
QByteArray(const char *, int size = -1);
QByteArray(int size, char c);
QByteArray(int size, Qt::Initialization);
- inline QByteArray(const QByteArray &);
+ inline QByteArray(const QByteArray &) Q_DECL_NOTHROW;
inline ~QByteArray();
- QByteArray &operator=(const QByteArray &);
+ QByteArray &operator=(const QByteArray &) Q_DECL_NOTHROW;
QByteArray &operator=(const char *str);
#ifdef Q_COMPILER_RVALUE_REFS
- inline QByteArray(QByteArray && other) : d(other.d) { other.d = Data::sharedNull(); }
- inline QByteArray &operator=(QByteArray &&other)
+ inline QByteArray(QByteArray && other) Q_DECL_NOTHROW : d(other.d) { other.d = Data::sharedNull(); }
+ inline QByteArray &operator=(QByteArray &&other) Q_DECL_NOTHROW
{ qSwap(d, other.d); return *this; }
#endif
- inline void swap(QByteArray &other) { qSwap(d, other.d); }
+ inline void swap(QByteArray &other) Q_DECL_NOTHROW
+ { qSwap(d, other.d); }
inline int size() const;
bool isEmpty() const;
@@ -259,11 +260,40 @@ public:
void truncate(int pos);
void chop(int n);
+#if defined(Q_COMPILER_REF_QUALIFIERS) && !defined(QT_COMPILING_QSTRING_COMPAT_CPP)
+# if defined(Q_CC_GNU)
+ // required due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61941
+# pragma push_macro("Q_REQUIRED_RESULT")
+# undef Q_REQUIRED_RESULT
+# define Q_REQUIRED_RESULT
+# define Q_REQUIRED_RESULT_pushed
+# endif
+ QByteArray toLower() const & Q_REQUIRED_RESULT
+ { return toLower_helper(*this); }
+ QByteArray toLower() && Q_REQUIRED_RESULT
+ { return toLower_helper(*this); }
+ QByteArray toUpper() const & Q_REQUIRED_RESULT
+ { return toUpper_helper(*this); }
+ QByteArray toUpper() && Q_REQUIRED_RESULT
+ { return toUpper_helper(*this); }
+ QByteArray trimmed() const & Q_REQUIRED_RESULT
+ { return trimmed_helper(*this); }
+ QByteArray trimmed() && Q_REQUIRED_RESULT
+ { return trimmed_helper(*this); }
+ QByteArray simplified() const & Q_REQUIRED_RESULT
+ { return simplified_helper(*this); }
+ QByteArray simplified() && Q_REQUIRED_RESULT
+ { return simplified_helper(*this); }
+# ifdef Q_REQUIRED_RESULT_pushed
+# pragma pop_macro("Q_REQUIRED_RESULT")
+# endif
+#else
QByteArray toLower() const Q_REQUIRED_RESULT;
QByteArray toUpper() const Q_REQUIRED_RESULT;
-
QByteArray trimmed() const Q_REQUIRED_RESULT;
QByteArray simplified() const Q_REQUIRED_RESULT;
+#endif
+
QByteArray leftJustified(int width, char fill = ' ', bool truncate = false) const Q_REQUIRED_RESULT;
QByteArray rightJustified(int width, char fill = ' ', bool truncate = false) const Q_REQUIRED_RESULT;
@@ -417,6 +447,15 @@ private:
void expand(int i);
QByteArray nulTerminated() const;
+ static QByteArray toLower_helper(const QByteArray &a);
+ static QByteArray toLower_helper(QByteArray &a);
+ static QByteArray toUpper_helper(const QByteArray &a);
+ static QByteArray toUpper_helper(QByteArray &a);
+ static QByteArray trimmed_helper(const QByteArray &a);
+ static QByteArray trimmed_helper(QByteArray &a);
+ static QByteArray simplified_helper(const QByteArray &a);
+ static QByteArray simplified_helper(QByteArray &a);
+
friend class QByteRef;
friend class QString;
friend Q_CORE_EXPORT QByteArray qUncompress(const uchar *data, int nbytes);
@@ -427,7 +466,7 @@ public:
Q_DECLARE_OPERATORS_FOR_FLAGS(QByteArray::Base64Options)
-inline QByteArray::QByteArray(): d(Data::sharedNull()) { }
+inline QByteArray::QByteArray() Q_DECL_NOTHROW : d(Data::sharedNull()) { }
inline QByteArray::~QByteArray() { if (!d->ref.deref()) Data::deallocate(d); }
inline int QByteArray::size() const
{ return d->size; }
@@ -457,7 +496,7 @@ inline void QByteArray::detach()
{ if (d->ref.isShared() || (d->offset != sizeof(QByteArrayData))) reallocData(uint(d->size) + 1u, d->detachFlags()); }
inline bool QByteArray::isDetached() const
{ return !d->ref.isShared(); }
-inline QByteArray::QByteArray(const QByteArray &a) : d(a.d)
+inline QByteArray::QByteArray(const QByteArray &a) Q_DECL_NOTHROW : d(a.d)
{ d->ref.ref(); }
inline int QByteArray::capacity() const
diff --git a/src/corelib/tools/qbytearraymatcher.h b/src/corelib/tools/qbytearraymatcher.h
index c7b83a98cc..a49ae2fd9d 100644
--- a/src/corelib/tools/qbytearraymatcher.h
+++ b/src/corelib/tools/qbytearraymatcher.h
@@ -66,11 +66,6 @@ public:
private:
QByteArrayMatcherPrivate *d;
QByteArray q_pattern;
-#ifdef Q_CC_RVCT
-// explicitly allow anonymous unions for RVCT to prevent compiler warnings
-# pragma push
-# pragma anon_unions
-#endif
struct Data {
uchar q_skiptable[256];
const uchar *p;
@@ -80,9 +75,6 @@ private:
uint dummy[256];
Data p;
};
-#ifdef Q_CC_RVCT
-# pragma pop
-#endif
};
QT_END_NAMESPACE
diff --git a/src/corelib/tools/qcache.h b/src/corelib/tools/qcache.h
index 960e0422a1..80fdb8c9cd 100644
--- a/src/corelib/tools/qcache.h
+++ b/src/corelib/tools/qcache.h
@@ -83,7 +83,7 @@ class QCache
Q_DISABLE_COPY(QCache)
public:
- inline explicit QCache(int maxCost = 100);
+ inline explicit QCache(int maxCost = 100) Q_DECL_NOTHROW;
inline ~QCache() { clear(); }
inline int maxCost() const { return mx; }
@@ -110,7 +110,7 @@ private:
};
template <class Key, class T>
-inline QCache<Key, T>::QCache(int amaxCost)
+inline QCache<Key, T>::QCache(int amaxCost) Q_DECL_NOTHROW
: f(0), l(0), mx(amaxCost), total(0) {}
template <class Key, class T>
diff --git a/src/corelib/tools/qchar.h b/src/corelib/tools/qchar.h
index 4db09e0f82..547c1ffda2 100644
--- a/src/corelib/tools/qchar.h
+++ b/src/corelib/tools/qchar.h
@@ -83,8 +83,10 @@ public:
#ifndef QT_NO_CAST_FROM_ASCII
QT_ASCII_CAST_WARN Q_DECL_CONSTEXPR explicit QChar(char c) : ucs(uchar(c)) { }
+#ifndef QT_RESTRICTED_CAST_FROM_ASCII
QT_ASCII_CAST_WARN Q_DECL_CONSTEXPR explicit QChar(uchar c) : ucs(c) { }
#endif
+#endif
// Unicode information
enum Category
@@ -377,68 +379,77 @@ public:
inline UnicodeVersion unicodeVersion() const { return QChar::unicodeVersion(ucs); }
#if QT_DEPRECATED_SINCE(5, 0)
- QT_DEPRECATED inline char toAscii() const { return toLatin1(); }
+ QT_DEPRECATED Q_DECL_CONSTEXPR inline char toAscii() const { return toLatin1(); }
#endif
- inline char toLatin1() const;
+ Q_DECL_CONSTEXPR inline char toLatin1() const;
Q_DECL_CONSTEXPR inline ushort unicode() const { return ucs; }
inline ushort &unicode() { return ucs; }
#if QT_DEPRECATED_SINCE(5, 0)
- QT_DEPRECATED static inline QChar fromAscii(char c)
+ QT_DEPRECATED static Q_DECL_CONSTEXPR inline QChar fromAscii(char c)
{ return fromLatin1(c); }
#endif
- static inline QChar fromLatin1(char c);
+ Q_DECL_CONSTEXPR static inline QChar fromLatin1(char c);
- inline bool isNull() const { return ucs == 0; }
+ Q_DECL_CONSTEXPR inline bool isNull() const { return ucs == 0; }
inline bool isPrint() const { return QChar::isPrint(ucs); }
- inline bool isSpace() const { return QChar::isSpace(ucs); }
+ Q_DECL_CONSTEXPR inline bool isSpace() const { return QChar::isSpace(ucs); }
inline bool isMark() const { return QChar::isMark(ucs); }
inline bool isPunct() const { return QChar::isPunct(ucs); }
inline bool isSymbol() const { return QChar::isSymbol(ucs); }
- inline bool isLetter() const { return QChar::isLetter(ucs); }
- inline bool isNumber() const { return QChar::isNumber(ucs); }
- inline bool isLetterOrNumber() const { return QChar::isLetterOrNumber(ucs); }
- inline bool isDigit() const { return QChar::isDigit(ucs); }
- inline bool isLower() const { return QChar::isLower(ucs); }
- inline bool isUpper() const { return QChar::isUpper(ucs); }
- inline bool isTitleCase() const { return QChar::isTitleCase(ucs); }
-
- inline bool isNonCharacter() const { return QChar::isNonCharacter(ucs); }
- inline bool isHighSurrogate() const { return QChar::isHighSurrogate(ucs); }
- inline bool isLowSurrogate() const { return QChar::isLowSurrogate(ucs); }
- inline bool isSurrogate() const { return QChar::isSurrogate(ucs); }
-
- inline uchar cell() const { return uchar(ucs & 0xff); }
- inline uchar row() const { return uchar((ucs>>8)&0xff); }
+ Q_DECL_CONSTEXPR inline bool isLetter() const { return QChar::isLetter(ucs); }
+ Q_DECL_CONSTEXPR inline bool isNumber() const { return QChar::isNumber(ucs); }
+ Q_DECL_CONSTEXPR inline bool isLetterOrNumber() const { return QChar::isLetterOrNumber(ucs); }
+ Q_DECL_CONSTEXPR inline bool isDigit() const { return QChar::isDigit(ucs); }
+ Q_DECL_CONSTEXPR inline bool isLower() const { return QChar::isLower(ucs); }
+ Q_DECL_CONSTEXPR inline bool isUpper() const { return QChar::isUpper(ucs); }
+ Q_DECL_CONSTEXPR inline bool isTitleCase() const { return QChar::isTitleCase(ucs); }
+
+ Q_DECL_CONSTEXPR inline bool isNonCharacter() const { return QChar::isNonCharacter(ucs); }
+ Q_DECL_CONSTEXPR inline bool isHighSurrogate() const { return QChar::isHighSurrogate(ucs); }
+ Q_DECL_CONSTEXPR inline bool isLowSurrogate() const { return QChar::isLowSurrogate(ucs); }
+ Q_DECL_CONSTEXPR inline bool isSurrogate() const { return QChar::isSurrogate(ucs); }
+
+ Q_DECL_CONSTEXPR inline uchar cell() const { return uchar(ucs & 0xff); }
+ Q_DECL_CONSTEXPR inline uchar row() const { return uchar((ucs>>8)&0xff); }
inline void setCell(uchar cell);
inline void setRow(uchar row);
- static inline bool isNonCharacter(uint ucs4) {
+ static Q_DECL_CONSTEXPR inline bool isNonCharacter(uint ucs4)
+ {
return ucs4 >= 0xfdd0 && (ucs4 <= 0xfdef || (ucs4 & 0xfffe) == 0xfffe);
}
- static inline bool isHighSurrogate(uint ucs4) {
+ static Q_DECL_CONSTEXPR inline bool isHighSurrogate(uint ucs4)
+ {
return ((ucs4 & 0xfffffc00) == 0xd800);
}
- static inline bool isLowSurrogate(uint ucs4) {
+ static Q_DECL_CONSTEXPR inline bool isLowSurrogate(uint ucs4)
+ {
return ((ucs4 & 0xfffffc00) == 0xdc00);
}
- static inline bool isSurrogate(uint ucs4) {
+ static Q_DECL_CONSTEXPR inline bool isSurrogate(uint ucs4)
+ {
return (ucs4 - 0xd800u < 2048u);
}
- static inline bool requiresSurrogates(uint ucs4) {
+ static Q_DECL_CONSTEXPR inline bool requiresSurrogates(uint ucs4)
+ {
return (ucs4 >= 0x10000);
}
- static inline uint surrogateToUcs4(ushort high, ushort low) {
+ static Q_DECL_CONSTEXPR inline uint surrogateToUcs4(ushort high, ushort low)
+ {
return (uint(high)<<10) + low - 0x35fdc00;
}
- static inline uint surrogateToUcs4(QChar high, QChar low) {
- return surrogateToUcs4(high.unicode(), low.unicode());
+ static Q_DECL_CONSTEXPR inline uint surrogateToUcs4(QChar high, QChar low)
+ {
+ return surrogateToUcs4(high.ucs, low.ucs);
}
- static inline ushort highSurrogate(uint ucs4) {
+ static Q_DECL_CONSTEXPR inline ushort highSurrogate(uint ucs4)
+ {
return ushort((ucs4>>10) + 0xd7c0);
}
- static inline ushort lowSurrogate(uint ucs4) {
+ static Q_DECL_CONSTEXPR inline ushort lowSurrogate(uint ucs4)
+ {
return ushort(ucs4%0x400 + 0xdc00);
}
@@ -469,17 +480,17 @@ public:
static UnicodeVersion QT_FASTCALL currentUnicodeVersion() Q_DECL_CONST_FUNCTION;
static bool QT_FASTCALL isPrint(uint ucs4) Q_DECL_CONST_FUNCTION;
- static inline bool isSpace(uint ucs4) Q_DECL_CONST_FUNCTION;
+ static Q_DECL_CONSTEXPR inline bool isSpace(uint ucs4) Q_DECL_CONST_FUNCTION;
static bool QT_FASTCALL isMark(uint ucs4) Q_DECL_CONST_FUNCTION;
static bool QT_FASTCALL isPunct(uint ucs4) Q_DECL_CONST_FUNCTION;
static bool QT_FASTCALL isSymbol(uint ucs4) Q_DECL_CONST_FUNCTION;
- static inline bool isLetter(uint ucs4) Q_DECL_CONST_FUNCTION;
- static inline bool isNumber(uint ucs4) Q_DECL_CONST_FUNCTION;
- static inline bool isLetterOrNumber(uint ucs4) Q_DECL_CONST_FUNCTION;
- static inline bool isDigit(uint ucs4) Q_DECL_CONST_FUNCTION;
- static inline bool isLower(uint ucs4) Q_DECL_CONST_FUNCTION;
- static inline bool isUpper(uint ucs4) Q_DECL_CONST_FUNCTION;
- static inline bool isTitleCase(uint ucs4) Q_DECL_CONST_FUNCTION;
+ static Q_DECL_CONSTEXPR inline bool isLetter(uint ucs4) Q_DECL_CONST_FUNCTION;
+ static Q_DECL_CONSTEXPR inline bool isNumber(uint ucs4) Q_DECL_CONST_FUNCTION;
+ static Q_DECL_CONSTEXPR inline bool isLetterOrNumber(uint ucs4) Q_DECL_CONST_FUNCTION;
+ static Q_DECL_CONSTEXPR inline bool isDigit(uint ucs4) Q_DECL_CONST_FUNCTION;
+ static Q_DECL_CONSTEXPR inline bool isLower(uint ucs4) Q_DECL_CONST_FUNCTION;
+ static Q_DECL_CONSTEXPR inline bool isUpper(uint ucs4) Q_DECL_CONST_FUNCTION;
+ static Q_DECL_CONSTEXPR inline bool isTitleCase(uint ucs4) Q_DECL_CONST_FUNCTION;
private:
static bool QT_FASTCALL isSpace_helper(uint ucs4) Q_DECL_CONST_FUNCTION;
@@ -491,53 +502,57 @@ private:
QChar(char c);
QChar(uchar c);
#endif
+
+ friend Q_DECL_CONSTEXPR bool operator==(QChar, QChar);
+ friend Q_DECL_CONSTEXPR bool operator< (QChar, QChar);
ushort ucs;
};
Q_DECLARE_TYPEINFO(QChar, Q_MOVABLE_TYPE);
-inline char QChar::toLatin1() const { return ucs > 0xff ? '\0' : char(ucs); }
-inline QChar QChar::fromLatin1(char c) { return QChar(ushort(uchar(c))); }
+Q_DECL_CONSTEXPR inline char QChar::toLatin1() const { return ucs > 0xff ? '\0' : char(ucs); }
+Q_DECL_CONSTEXPR inline QChar QChar::fromLatin1(char c) { return QChar(ushort(uchar(c))); }
inline void QChar::setCell(uchar acell)
{ ucs = ushort((ucs & 0xff00) + acell); }
inline void QChar::setRow(uchar arow)
{ ucs = ushort((ushort(arow)<<8) + (ucs&0xff)); }
-inline bool QChar::isSpace(uint ucs4)
+Q_DECL_CONSTEXPR inline bool QChar::isSpace(uint ucs4)
{
// note that [0x09..0x0d] + 0x85 are exceptional Cc-s and must be handled explicitly
return ucs4 == 0x20 || (ucs4 <= 0x0d && ucs4 >= 0x09)
|| (ucs4 > 127 && (ucs4 == 0x85 || ucs4 == 0xa0 || QChar::isSpace_helper(ucs4)));
}
-inline bool QChar::isLetter(uint ucs4)
+Q_DECL_CONSTEXPR inline bool QChar::isLetter(uint ucs4)
{
return (ucs4 >= 'A' && ucs4 <= 'z' && (ucs4 >= 'a' || ucs4 <= 'Z'))
|| (ucs4 > 127 && QChar::isLetter_helper(ucs4));
}
-inline bool QChar::isNumber(uint ucs4)
+Q_DECL_CONSTEXPR inline bool QChar::isNumber(uint ucs4)
{ return (ucs4 <= '9' && ucs4 >= '0') || (ucs4 > 127 && QChar::isNumber_helper(ucs4)); }
-inline bool QChar::isLetterOrNumber(uint ucs4)
+Q_DECL_CONSTEXPR inline bool QChar::isLetterOrNumber(uint ucs4)
{
return (ucs4 >= 'A' && ucs4 <= 'z' && (ucs4 >= 'a' || ucs4 <= 'Z'))
|| (ucs4 >= '0' && ucs4 <= '9')
|| (ucs4 > 127 && QChar::isLetterOrNumber_helper(ucs4));
}
-inline bool QChar::isDigit(uint ucs4)
+Q_DECL_CONSTEXPR inline bool QChar::isDigit(uint ucs4)
{ return (ucs4 <= '9' && ucs4 >= '0') || (ucs4 > 127 && QChar::category(ucs4) == Number_DecimalDigit); }
-inline bool QChar::isLower(uint ucs4)
+Q_DECL_CONSTEXPR inline bool QChar::isLower(uint ucs4)
{ return (ucs4 <= 'z' && ucs4 >= 'a') || (ucs4 > 127 && QChar::category(ucs4) == Letter_Lowercase); }
-inline bool QChar::isUpper(uint ucs4)
+Q_DECL_CONSTEXPR inline bool QChar::isUpper(uint ucs4)
{ return (ucs4 <= 'Z' && ucs4 >= 'A') || (ucs4 > 127 && QChar::category(ucs4) == Letter_Uppercase); }
-inline bool QChar::isTitleCase(uint ucs4)
+Q_DECL_CONSTEXPR inline bool QChar::isTitleCase(uint ucs4)
{ return ucs4 > 127 && QChar::category(ucs4) == Letter_Titlecase; }
-inline bool operator==(QChar c1, QChar c2) { return c1.unicode() == c2.unicode(); }
-inline bool operator!=(QChar c1, QChar c2) { return c1.unicode() != c2.unicode(); }
-inline bool operator<=(QChar c1, QChar c2) { return c1.unicode() <= c2.unicode(); }
-inline bool operator>=(QChar c1, QChar c2) { return c1.unicode() >= c2.unicode(); }
-inline bool operator<(QChar c1, QChar c2) { return c1.unicode() < c2.unicode(); }
-inline bool operator>(QChar c1, QChar c2) { return c1.unicode() > c2.unicode(); }
+Q_DECL_CONSTEXPR inline bool operator==(QChar c1, QChar c2) { return c1.ucs == c2.ucs; }
+Q_DECL_CONSTEXPR inline bool operator< (QChar c1, QChar c2) { return c1.ucs < c2.ucs; }
+
+Q_DECL_CONSTEXPR inline bool operator!=(QChar c1, QChar c2) { return !operator==(c1, c2); }
+Q_DECL_CONSTEXPR inline bool operator>=(QChar c1, QChar c2) { return !operator< (c1, c2); }
+Q_DECL_CONSTEXPR inline bool operator> (QChar c1, QChar c2) { return operator< (c2, c1); }
+Q_DECL_CONSTEXPR inline bool operator<=(QChar c1, QChar c2) { return !operator< (c2, c1); }
#ifndef QT_NO_DATASTREAM
Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, QChar);
diff --git a/src/corelib/tools/qcollator.h b/src/corelib/tools/qcollator.h
index f9ae44cf6b..98f06bcc1f 100644
--- a/src/corelib/tools/qcollator.h
+++ b/src/corelib/tools/qcollator.h
@@ -52,10 +52,10 @@ public:
~QCollatorSortKey();
QCollatorSortKey &operator=(const QCollatorSortKey &other);
#ifdef Q_COMPILER_RVALUE_REFS
- inline QCollatorSortKey &operator=(QCollatorSortKey &&other)
+ inline QCollatorSortKey &operator=(QCollatorSortKey &&other) Q_DECL_NOTHROW
{ swap(other); return *this; }
#endif
- void swap(QCollatorSortKey &other)
+ void swap(QCollatorSortKey &other) Q_DECL_NOTHROW
{ d.swap(other.d); }
int compare(const QCollatorSortKey &key) const;
@@ -82,13 +82,13 @@ public:
~QCollator();
QCollator &operator=(const QCollator &);
#ifdef Q_COMPILER_RVALUE_REFS
- QCollator(QCollator &&other)
+ QCollator(QCollator &&other) Q_DECL_NOTHROW
: d(other.d) { other.d = 0; }
- QCollator &operator=(QCollator &&other)
+ QCollator &operator=(QCollator &&other) Q_DECL_NOTHROW
{ swap(other); return *this; }
#endif
- void swap(QCollator &other)
+ void swap(QCollator &other) Q_DECL_NOTHROW
{ qSwap(d, other.d); }
void setLocale(const QLocale &locale);
diff --git a/src/corelib/tools/qcommandlineparser.cpp b/src/corelib/tools/qcommandlineparser.cpp
index 01772b2ad5..117ce381f1 100644
--- a/src/corelib/tools/qcommandlineparser.cpp
+++ b/src/corelib/tools/qcommandlineparser.cpp
@@ -37,6 +37,10 @@
#include <qcoreapplication.h>
#include <qhash.h>
#include <qvector.h>
+#include <qdebug.h>
+#if defined(Q_OS_WIN) && !defined(QT_BOOTSTRAPPED) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT)
+# include <qt_windows.h>
+#endif
#include <stdio.h>
#include <stdlib.h>
@@ -209,7 +213,10 @@ QStringList QCommandLineParserPrivate::aliases(const QString &optionName) const
platforms. These applications may not use the standard output or error channels
since the output is either discarded or not accessible.
- For such GUI applications, it is recommended to display help texts and error messages
+ On Windows, QCommandLineParser uses message boxes to display usage information
+ and errors if no console window can be obtained.
+
+ For other platforms, it is recommended to display help texts and error messages
using a QMessageBox. To preserve the formatting of the help text, rich text
with \c <pre> elements should be used:
@@ -219,36 +226,20 @@ QStringList QCommandLineParserPrivate::aliases(const QString &optionName) const
case CommandLineOk:
break;
case CommandLineError:
-#ifdef Q_OS_WIN
QMessageBox::warning(0, QGuiApplication::applicationDisplayName(),
"<html><head/><body><h2>" + errorMessage + "</h2><pre>"
+ parser.helpText() + "</pre></body></html>");
-#else
- fputs(qPrintable(errorMessage), stderr);
- fputs("\n\n", stderr);
- fputs(qPrintable(parser.helpText()), stderr);
-#endif
return 1;
case CommandLineVersionRequested:
-#ifdef Q_OS_WIN
QMessageBox::information(0, QGuiApplication::applicationDisplayName(),
QGuiApplication::applicationDisplayName() + ' '
+ QCoreApplication::applicationVersion());
-#else
- printf("%s %s\n", QGuiApplication::applicationDisplayName(),
- qPrintable(QCoreApplication::applicationVersion()));
-#endif
return 0;
case CommandLineHelpRequested:
-#ifdef Q_OS_WIN
QMessageBox::warning(0, QGuiApplication::applicationDisplayName(),
"<html><head/><body><pre>"
+ parser.helpText() + "</pre></body></html>");
return 0;
-#else
- parser.showHelp();
- Q_UNREACHABLE();
-#endif
}
\endcode
@@ -491,6 +482,41 @@ QString QCommandLineParser::errorText() const
return QString();
}
+enum MessageType { UsageMessage, ErrorMessage };
+
+#if defined(Q_OS_WIN) && !defined(QT_BOOTSTRAPPED) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT)
+// Return whether to use a message box. Use handles if a console can be obtained
+// or we are run with redirected handles (for example, by QProcess).
+static inline bool displayMessageBox()
+{
+ if (GetConsoleWindow())
+ return false;
+ STARTUPINFO startupInfo;
+ startupInfo.cb = sizeof(STARTUPINFO);
+ GetStartupInfo(&startupInfo);
+ return !(startupInfo.dwFlags & STARTF_USESTDHANDLES);
+}
+#endif // Q_OS_WIN && !QT_BOOTSTRAPPED && !Q_OS_WIN && !Q_OS_WINRT
+
+static void showParserMessage(const QString &message, MessageType type)
+{
+#if defined(Q_OS_WIN) && !defined(QT_BOOTSTRAPPED) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT)
+ if (displayMessageBox()) {
+ const UINT flags = MB_OK | MB_TOPMOST | MB_SETFOREGROUND
+ | (type == UsageMessage ? MB_ICONINFORMATION : MB_ICONERROR);
+ QString title;
+ if (QCoreApplication::instance())
+ title = QCoreApplication::instance()->property("applicationDisplayName").toString();
+ if (title.isEmpty())
+ title = QCoreApplication::applicationName();
+ MessageBoxW(0, reinterpret_cast<const wchar_t *>(message.utf16()),
+ reinterpret_cast<const wchar_t *>(title.utf16()), flags);
+ return;
+ }
+#endif // Q_OS_WIN && !QT_BOOTSTRAPPED && !Q_OS_WIN && !Q_OS_WINRT
+ fputs(qPrintable(message), type == UsageMessage ? stdout : stderr);
+}
+
/*!
Processes the command line \a arguments.
@@ -507,7 +533,7 @@ QString QCommandLineParser::errorText() const
void QCommandLineParser::process(const QStringList &arguments)
{
if (!d->parse(arguments)) {
- fprintf(stderr, "%s\n", qPrintable(errorText()));
+ showParserMessage(errorText() + QLatin1Char('\n'), ErrorMessage);
::exit(EXIT_FAILURE);
}
@@ -913,7 +939,9 @@ QStringList QCommandLineParser::unknownOptionNames() const
*/
Q_NORETURN void QCommandLineParser::showVersion()
{
- fprintf(stdout, "%s %s\n", qPrintable(QCoreApplication::applicationName()), qPrintable(QCoreApplication::applicationVersion()));
+ showParserMessage(QCoreApplication::applicationName() + QLatin1Char(' ')
+ + QCoreApplication::applicationVersion() + QLatin1Char('\n'),
+ UsageMessage);
::exit(EXIT_SUCCESS);
}
@@ -930,7 +958,7 @@ Q_NORETURN void QCommandLineParser::showVersion()
*/
Q_NORETURN void QCommandLineParser::showHelp(int exitCode)
{
- fprintf(stdout, "%s", qPrintable(d->helpText()));
+ showParserMessage(d->helpText(), UsageMessage);
::exit(exitCode);
}
diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp
index 082b721e82..b95ccc0874 100644
--- a/src/corelib/tools/qdatetime.cpp
+++ b/src/corelib/tools/qdatetime.cpp
@@ -249,7 +249,7 @@ static QString toOffsetString(Qt::DateFormat format, int offset)
}
// Parse offset in [+-]HH[[:]mm] format
-static int fromOffsetString(const QString &offsetString, bool *valid)
+static int fromOffsetString(const QStringRef &offsetString, bool *valid)
{
*valid = false;
@@ -270,15 +270,15 @@ static int fromOffsetString(const QString &offsetString, bool *valid)
return 0;
// Split the hour and minute parts
- QStringList parts = offsetString.mid(1).split(QLatin1Char(':'));
+ QVector<QStringRef> parts = offsetString.mid(1).split(QLatin1Char(':'));
if (parts.count() == 1) {
// [+-]HHmm or [+-]HH format
- parts.append(parts.at(0).mid(2));
- parts[0] = parts.at(0).left(2);
+ parts.append(parts.first().mid(2));
+ parts[0] = parts.first().left(2);
}
bool ok = false;
- const int hour = parts.at(0).toInt(&ok);
+ const int hour = parts.first().toInt(&ok);
if (!ok)
return 0;
@@ -898,18 +898,18 @@ QString QDate::toString(Qt::DateFormat format) const
#ifndef QT_NO_TEXTDATE
case Qt::TextDate:
getDateFromJulianDay(jd, &y, &m, &d);
- return QString::fromUtf8("%1 %2 %3 %4").arg(shortDayName(dayOfWeek()))
- .arg(shortMonthName(m))
- .arg(d)
- .arg(y);
+ return QString::fromLatin1("%1 %2 %3 %4").arg(shortDayName(dayOfWeek()))
+ .arg(shortMonthName(m))
+ .arg(d)
+ .arg(y);
#endif
case Qt::ISODate:
getDateFromJulianDay(jd, &y, &m, &d);
if (y < 0 || y > 9999)
return QString();
- return QString::fromUtf8("%1-%2-%3").arg(y, 4, 10, QLatin1Char('0'))
- .arg(m, 2, 10, QLatin1Char('0'))
- .arg(d, 2, 10, QLatin1Char('0'));
+ return QString::fromLatin1("%1-%2-%3").arg(y, 4, 10, QLatin1Char('0'))
+ .arg(m, 2, 10, QLatin1Char('0'))
+ .arg(d, 2, 10, QLatin1Char('0'));
}
}
@@ -1247,12 +1247,12 @@ QDate QDate::fromString(const QString& string, Qt::DateFormat format)
default:
#ifndef QT_NO_TEXTDATE
case Qt::TextDate: {
- QStringList parts = string.split(QLatin1Char(' '), QString::SkipEmptyParts);
+ QVector<QStringRef> parts = string.splitRef(QLatin1Char(' '), QString::SkipEmptyParts);
if (parts.count() != 4)
return QDate();
- QString monthName = parts.at(1);
+ QStringRef monthName = parts.at(1);
int month = -1;
// Assume that English monthnames are the default
for (int i = 0; i < 12; ++i) {
@@ -1288,10 +1288,10 @@ QDate QDate::fromString(const QString& string, Qt::DateFormat format)
|| (string.size() > 10 && string.at(10).isDigit())) {
return QDate();
}
- const int year = string.mid(0, 4).toInt();
+ const int year = string.midRef(0, 4).toInt();
if (year <= 0 || year > 9999)
return QDate();
- return QDate(year, string.mid(5, 2).toInt(), string.mid(8, 2).toInt());
+ return QDate(year, string.midRef(5, 2).toInt(), string.midRef(8, 2).toInt());
}
}
return QDate();
@@ -1649,9 +1649,9 @@ QString QTime::toString(Qt::DateFormat format) const
case Qt::ISODate:
case Qt::TextDate:
default:
- return QString::fromUtf8("%1:%2:%3").arg(hour(), 2, 10, QLatin1Char('0'))
- .arg(minute(), 2, 10, QLatin1Char('0'))
- .arg(second(), 2, 10, QLatin1Char('0'));
+ return QString::fromLatin1("%1:%2:%3").arg(hour(), 2, 10, QLatin1Char('0'))
+ .arg(minute(), 2, 10, QLatin1Char('0'))
+ .arg(second(), 2, 10, QLatin1Char('0'));
}
}
@@ -3186,13 +3186,11 @@ QTimeZone QDateTime::timeZone() const
d->m_timeZone = QTimeZone(d->m_offsetFromUtc);
return d->m_timeZone;
case Qt::UTC:
- if (!d->m_timeZone.isValid())
- d->m_timeZone = QTimeZone(QTimeZonePrivate::utcQByteArray());
- return d->m_timeZone;
- case Qt::TimeZone :
+ return QTimeZone::utc();
+ case Qt::TimeZone:
return d->m_timeZone;
case Qt::LocalTime:
- return QTimeZone(QTimeZone::systemTimeZoneId());
+ return QTimeZone::systemTimeZone();
}
return QTimeZone();
}
@@ -3603,11 +3601,11 @@ QString QDateTime::toString(Qt::DateFormat format) const
QTime tm;
d->getDateTime(&dt, &tm);
//We cant use date.toString(Qt::TextDate) as we need to insert the time before the year
- buf = QString::fromUtf8("%1 %2 %3 %4 %5").arg(dt.shortDayName(dt.dayOfWeek()))
- .arg(dt.shortMonthName(dt.month()))
- .arg(dt.day())
- .arg(tm.toString(Qt::TextDate))
- .arg(dt.year());
+ buf = QString::fromLatin1("%1 %2 %3 %4 %5").arg(dt.shortDayName(dt.dayOfWeek()))
+ .arg(dt.shortMonthName(dt.month()))
+ .arg(dt.day())
+ .arg(tm.toString(Qt::TextDate))
+ .arg(dt.year());
if (timeSpec() != Qt::LocalTime) {
buf += QStringLiteral(" GMT");
if (d->m_spec == Qt::OffsetFromUTC)
@@ -3747,7 +3745,7 @@ QDateTime QDateTime::addDays(qint64 ndays) const
localMSecsToEpochMSecs(timeToMSecs(date, time), &date, &time);
#ifndef QT_BOOTSTRAPPED
else if (d->m_spec == Qt::TimeZone)
- d->zoneMSecsToEpochMSecs(timeToMSecs(date, time), d->m_timeZone, &date, &time);
+ QDateTimePrivate::zoneMSecsToEpochMSecs(timeToMSecs(date, time), d->m_timeZone, &date, &time);
#endif // QT_BOOTSTRAPPED
dt.d->setDateTime(date, time);
return dt;
@@ -3781,7 +3779,7 @@ QDateTime QDateTime::addMonths(int nmonths) const
localMSecsToEpochMSecs(timeToMSecs(date, time), &date, &time);
#ifndef QT_BOOTSTRAPPED
else if (d->m_spec == Qt::TimeZone)
- d->zoneMSecsToEpochMSecs(timeToMSecs(date, time), d->m_timeZone, &date, &time);
+ QDateTimePrivate::zoneMSecsToEpochMSecs(timeToMSecs(date, time), d->m_timeZone, &date, &time);
#endif // QT_BOOTSTRAPPED
dt.d->setDateTime(date, time);
return dt;
@@ -3815,7 +3813,7 @@ QDateTime QDateTime::addYears(int nyears) const
localMSecsToEpochMSecs(timeToMSecs(date, time), &date, &time);
#ifndef QT_BOOTSTRAPPED
else if (d->m_spec == Qt::TimeZone)
- d->zoneMSecsToEpochMSecs(timeToMSecs(date, time), d->m_timeZone, &date, &time);
+ QDateTimePrivate::zoneMSecsToEpochMSecs(timeToMSecs(date, time), d->m_timeZone, &date, &time);
#endif // QT_BOOTSTRAPPED
dt.d->setDateTime(date, time);
return dt;
@@ -4204,6 +4202,39 @@ qint64 QDateTime::currentMSecsSinceEpoch() Q_DECL_NOTHROW
#error "What system is this?"
#endif
+/*! \fn QDateTime QDateTime::fromCFDate(CFDateRef date)
+ \since 5.5
+
+ Constructs a new QDateTime containing a copy of the CFDate \a date.
+
+ \sa toCFDate()
+*/
+
+/*! \fn CFDateRef QDateTime::toCFDate() const
+ \since 5.5
+
+ Creates a CFDate from a QDateTime. The caller owns the CFDate object
+ and is responsible for releasing it.
+
+ \sa fromCFDate()
+*/
+
+/*! \fn QDateTime QDateTime::fromNSDate(const NSDate *date)
+ \since 5.5
+
+ Constructs a new QDateTime containing a copy of the NSDate \a date.
+
+ \sa toNSDate()
+*/
+
+/*! \fn NSDate QDateTime::toNSDate() const
+ \since 5.5
+
+ Creates an NSDate from a QDateTime. The NSDate object is autoreleased.
+
+ \sa fromNSDate()
+*/
+
/*!
\since 4.2
@@ -4358,7 +4389,7 @@ int QDateTime::utcOffset() const
#ifndef QT_NO_DATESTRING
-static int fromShortMonthName(const QString &monthName)
+static int fromShortMonthName(const QStringRef &monthName)
{
// Assume that English monthnames are the default
for (int i = 0; i < 12; ++i) {
@@ -4449,7 +4480,7 @@ QDateTime QDateTime::fromString(const QString& string, Qt::DateFormat format)
if (found) {
bool ok;
- offset = fromOffsetString(isoString.mid(signIndex).toString(), &ok);
+ offset = fromOffsetString(isoString.mid(signIndex), &ok);
if (!ok)
return QDateTime();
isoString = isoString.left(signIndex);
@@ -4469,7 +4500,7 @@ QDateTime QDateTime::fromString(const QString& string, Qt::DateFormat format)
}
#if !defined(QT_NO_TEXTDATE)
case Qt::TextDate: {
- QStringList parts = string.split(QLatin1Char(' '), QString::SkipEmptyParts);
+ QVector<QStringRef> parts = string.splitRef(QLatin1Char(' '), QString::SkipEmptyParts);
if ((parts.count() < 5) || (parts.count() > 6))
return QDateTime();
@@ -4488,9 +4519,9 @@ QDateTime QDateTime::fromString(const QString& string, Qt::DateFormat format)
if (!month || !day) {
month = fromShortMonthName(parts.at(2));
if (month) {
- QString dayStr = parts.at(1);
+ QStringRef dayStr = parts.at(1);
if (dayStr.endsWith(QLatin1Char('.'))) {
- dayStr.chop(1);
+ dayStr = dayStr.left(dayStr.size() - 1);
day = dayStr.toInt();
}
}
@@ -4523,7 +4554,7 @@ QDateTime QDateTime::fromString(const QString& string, Qt::DateFormat format)
if (!date.isValid())
return QDateTime();
- QStringList timeParts = parts.at(timePart).split(QLatin1Char(':'));
+ QVector<QStringRef> timeParts = parts.at(timePart).split(QLatin1Char(':'));
if (timeParts.count() < 2 || timeParts.count() > 3)
return QDateTime();
@@ -4538,7 +4569,7 @@ QDateTime QDateTime::fromString(const QString& string, Qt::DateFormat format)
int second = 0;
int millisecond = 0;
if (timeParts.count() > 2) {
- QStringList secondParts = timeParts.at(2).split(QLatin1Char('.'));
+ QVector<QStringRef> secondParts = timeParts.at(2).split(QLatin1Char('.'));
if (secondParts.size() > 2) {
return QDateTime();
}
@@ -4563,10 +4594,10 @@ QDateTime QDateTime::fromString(const QString& string, Qt::DateFormat format)
if (parts.count() == 5)
return QDateTime(date, time, Qt::LocalTime);
- QString tz = parts.at(5);
+ QStringRef tz = parts.at(5);
if (!tz.startsWith(QLatin1String("GMT"), Qt::CaseInsensitive))
return QDateTime();
- tz.remove(0, 3);
+ tz = tz.mid(3);
if (!tz.isEmpty()) {
int offset = fromOffsetString(tz, &ok);
if (!ok)
@@ -4993,7 +5024,7 @@ QDebug operator<<(QDebug dbg, const QDateTime &date)
spec = QStringLiteral(" Qt::UTC");
break;
case Qt::OffsetFromUTC:
- spec = QString::fromUtf8(" Qt::OffsetFromUTC %1s").arg(date.offsetFromUtc());
+ spec = QString::fromLatin1(" Qt::OffsetFromUTC %1s").arg(date.offsetFromUtc());
break;
case Qt::TimeZone:
#ifndef QT_BOOTSTRAPPED
diff --git a/src/corelib/tools/qdatetime.h b/src/corelib/tools/qdatetime.h
index a75d7d9bc8..5bcd01a587 100644
--- a/src/corelib/tools/qdatetime.h
+++ b/src/corelib/tools/qdatetime.h
@@ -40,6 +40,13 @@
#include <limits>
+#ifdef Q_OS_MAC
+Q_FORWARD_DECLARE_CF_TYPE(CFDate);
+# ifdef __OBJC__
+Q_FORWARD_DECLARE_OBJC_CLASS(NSDate);
+# endif
+#endif
+
QT_BEGIN_NAMESPACE
class QTimeZone;
@@ -296,6 +303,15 @@ public:
#endif
static qint64 currentMSecsSinceEpoch() Q_DECL_NOTHROW;
+#if defined(Q_OS_MAC) || defined(Q_QDOC)
+ static QDateTime fromCFDate(CFDateRef date);
+ CFDateRef toCFDate() const Q_DECL_CF_RETURNS_RETAINED;
+# if defined(__OBJC__) || defined(Q_QDOC)
+ static QDateTime fromNSDate(const NSDate *date);
+ NSDate *toNSDate() const Q_DECL_NS_RETURNS_AUTORELEASED;
+# endif
+#endif
+
private:
friend class QDateTimePrivate;
void detach();
diff --git a/src/corelib/tools/qdatetime_mac.mm b/src/corelib/tools/qdatetime_mac.mm
new file mode 100644
index 0000000000..c8a1d22928
--- /dev/null
+++ b/src/corelib/tools/qdatetime_mac.mm
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Petroules Corporation.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qdatetime.h"
+
+#import <Foundation/Foundation.h>
+
+QT_BEGIN_NAMESPACE
+
+QDateTime QDateTime::fromCFDate(CFDateRef date)
+{
+ if (!date)
+ return QDateTime();
+ return QDateTime::fromMSecsSinceEpoch(static_cast<qint64>((CFDateGetAbsoluteTime(date)
+ + kCFAbsoluteTimeIntervalSince1970) * 1000));
+}
+
+CFDateRef QDateTime::toCFDate() const
+{
+ return CFDateCreate(kCFAllocatorDefault, (static_cast<CFAbsoluteTime>(toMSecsSinceEpoch())
+ / 1000) - kCFAbsoluteTimeIntervalSince1970);
+}
+
+QDateTime QDateTime::fromNSDate(const NSDate *date)
+{
+ if (!date)
+ return QDateTime();
+ return QDateTime::fromMSecsSinceEpoch(static_cast<qint64>([date timeIntervalSince1970] * 1000));
+}
+
+NSDate *QDateTime::toNSDate() const
+{
+ return [NSDate
+ dateWithTimeIntervalSince1970:static_cast<NSTimeInterval>(toMSecsSinceEpoch()) / 1000];
+}
+
+QT_END_NAMESPACE
diff --git a/src/corelib/tools/qdatetime_p.h b/src/corelib/tools/qdatetime_p.h
index 78484f30ed..7c7f7f2a6a 100644
--- a/src/corelib/tools/qdatetime_p.h
+++ b/src/corelib/tools/qdatetime_p.h
@@ -111,6 +111,9 @@ public:
m_status(other.m_status)
{}
+ // ### XXX: when the tooling situation improves, look at fixing the padding.
+ // 4 bytes padding
+
qint64 m_msecs;
Qt::TimeSpec m_spec;
int m_offsetFromUtc;
diff --git a/src/corelib/tools/qeasingcurve.cpp b/src/corelib/tools/qeasingcurve.cpp
index a3dd4d9a60..e6fb531d7d 100644
--- a/src/corelib/tools/qeasingcurve.cpp
+++ b/src/corelib/tools/qeasingcurve.cpp
@@ -347,9 +347,7 @@ typedef QVector<TCBPoint> TCBPoints;
class QEasingCurveFunction
{
public:
- enum Type { In, Out, InOut, OutIn };
-
- QEasingCurveFunction(QEasingCurveFunction::Type type = In, qreal period = 0.3, qreal amplitude = 1.0,
+ QEasingCurveFunction(QEasingCurve::Type type, qreal period = 0.3, qreal amplitude = 1.0,
qreal overshoot = 1.70158)
: _t(type), _p(period), _a(amplitude), _o(overshoot)
{ }
@@ -358,7 +356,7 @@ public:
virtual QEasingCurveFunction *copy() const;
bool operator==(const QEasingCurveFunction &other) const;
- Type _t;
+ QEasingCurve::Type _t;
qreal _p;
qreal _a;
qreal _o;
@@ -367,9 +365,12 @@ public:
};
+static QEasingCurve::EasingFunction curveToFunc(QEasingCurve::Type curve);
+
qreal QEasingCurveFunction::value(qreal t)
{
- return t;
+ QEasingCurve::EasingFunction func = curveToFunc(_t);
+ return func(t);
}
QEasingCurveFunction *QEasingCurveFunction::copy() const
@@ -430,8 +431,8 @@ struct BezierEase : public QEasingCurveFunction
bool _init;
bool _valid;
- BezierEase()
- : QEasingCurveFunction(InOut), _curves(10), _intervals(10), _init(false), _valid(false)
+ BezierEase(QEasingCurve::Type type = QEasingCurve::BezierSpline)
+ : QEasingCurveFunction(type), _curves(10), _intervals(10), _init(false), _valid(false)
{ }
void init()
@@ -488,7 +489,7 @@ struct BezierEase : public QEasingCurveFunction
}
}
- QEasingCurveFunction *copy() const
+ QEasingCurveFunction *copy() const Q_DECL_OVERRIDE
{
BezierEase *rv = new BezierEase();
rv->_t = _t;
@@ -524,7 +525,7 @@ struct BezierEase : public QEasingCurveFunction
return newT;
}
- qreal value(qreal x)
+ qreal value(qreal x) Q_DECL_OVERRIDE
{
Q_ASSERT(_bezierCurves.count() % 3 == 0);
@@ -814,7 +815,11 @@ struct BezierEase : public QEasingCurveFunction
struct TCBEase : public BezierEase
{
- qreal value(qreal x)
+ TCBEase()
+ : BezierEase(QEasingCurve::TCBSpline)
+ { }
+
+ qreal value(qreal x) Q_DECL_OVERRIDE
{
Q_ASSERT(_bezierCurves.count() % 3 == 0);
@@ -830,11 +835,11 @@ struct TCBEase : public BezierEase
struct ElasticEase : public QEasingCurveFunction
{
- ElasticEase(Type type)
+ ElasticEase(QEasingCurve::Type type)
: QEasingCurveFunction(type, qreal(0.3), qreal(1.0))
{ }
- QEasingCurveFunction *copy() const
+ QEasingCurveFunction *copy() const Q_DECL_OVERRIDE
{
ElasticEase *rv = new ElasticEase(_t);
rv->_p = _p;
@@ -844,18 +849,18 @@ struct ElasticEase : public QEasingCurveFunction
return rv;
}
- qreal value(qreal t)
+ qreal value(qreal t) Q_DECL_OVERRIDE
{
qreal p = (_p < 0) ? qreal(0.3) : _p;
qreal a = (_a < 0) ? qreal(1.0) : _a;
switch(_t) {
- case In:
+ case QEasingCurve::InElastic:
return easeInElastic(t, a, p);
- case Out:
+ case QEasingCurve::OutElastic:
return easeOutElastic(t, a, p);
- case InOut:
+ case QEasingCurve::InOutElastic:
return easeInOutElastic(t, a, p);
- case OutIn:
+ case QEasingCurve::OutInElastic:
return easeOutInElastic(t, a, p);
default:
return t;
@@ -865,11 +870,11 @@ struct ElasticEase : public QEasingCurveFunction
struct BounceEase : public QEasingCurveFunction
{
- BounceEase(Type type)
+ BounceEase(QEasingCurve::Type type)
: QEasingCurveFunction(type, qreal(0.3), qreal(1.0))
{ }
- QEasingCurveFunction *copy() const
+ QEasingCurveFunction *copy() const Q_DECL_OVERRIDE
{
BounceEase *rv = new BounceEase(_t);
rv->_a = _a;
@@ -878,17 +883,17 @@ struct BounceEase : public QEasingCurveFunction
return rv;
}
- qreal value(qreal t)
+ qreal value(qreal t) Q_DECL_OVERRIDE
{
qreal a = (_a < 0) ? qreal(1.0) : _a;
switch(_t) {
- case In:
+ case QEasingCurve::InBounce:
return easeInBounce(t, a);
- case Out:
+ case QEasingCurve::OutBounce:
return easeOutBounce(t, a);
- case InOut:
+ case QEasingCurve::InOutBounce:
return easeInOutBounce(t, a);
- case OutIn:
+ case QEasingCurve::OutInBounce:
return easeOutInBounce(t, a);
default:
return t;
@@ -898,11 +903,11 @@ struct BounceEase : public QEasingCurveFunction
struct BackEase : public QEasingCurveFunction
{
- BackEase(Type type)
+ BackEase(QEasingCurve::Type type)
: QEasingCurveFunction(type, qreal(0.3), qreal(1.0), qreal(1.70158))
{ }
- QEasingCurveFunction *copy() const
+ QEasingCurveFunction *copy() const Q_DECL_OVERRIDE
{
BackEase *rv = new BackEase(_t);
rv->_o = _o;
@@ -911,17 +916,17 @@ struct BackEase : public QEasingCurveFunction
return rv;
}
- qreal value(qreal t)
+ qreal value(qreal t) Q_DECL_OVERRIDE
{
qreal o = (_o < 0) ? qreal(1.70158) : _o;
switch(_t) {
- case In:
+ case QEasingCurve::InBack:
return easeInBack(t, o);
- case Out:
+ case QEasingCurve::OutBack:
return easeOutBack(t, o);
- case InOut:
+ case QEasingCurve::InOutBack:
return easeInOutBack(t, o);
- case OutIn:
+ case QEasingCurve::OutInBack:
return easeOutInBack(t, o);
default:
return t;
@@ -1006,55 +1011,31 @@ static QEasingCurve::EasingFunction curveToFunc(QEasingCurve::Type curve)
static QEasingCurveFunction *curveToFunctionObject(QEasingCurve::Type type)
{
- QEasingCurveFunction *curveFunc = 0;
switch(type) {
case QEasingCurve::InElastic:
- curveFunc = new ElasticEase(ElasticEase::In);
- break;
case QEasingCurve::OutElastic:
- curveFunc = new ElasticEase(ElasticEase::Out);
- break;
case QEasingCurve::InOutElastic:
- curveFunc = new ElasticEase(ElasticEase::InOut);
- break;
case QEasingCurve::OutInElastic:
- curveFunc = new ElasticEase(ElasticEase::OutIn);
- break;
+ return new ElasticEase(type);
case QEasingCurve::OutBounce:
- curveFunc = new BounceEase(BounceEase::Out);
- break;
case QEasingCurve::InBounce:
- curveFunc = new BounceEase(BounceEase::In);
- break;
case QEasingCurve::OutInBounce:
- curveFunc = new BounceEase(BounceEase::OutIn);
- break;
case QEasingCurve::InOutBounce:
- curveFunc = new BounceEase(BounceEase::InOut);
- break;
+ return new BounceEase(type);
case QEasingCurve::InBack:
- curveFunc = new BackEase(BackEase::In);
- break;
case QEasingCurve::OutBack:
- curveFunc = new BackEase(BackEase::Out);
- break;
case QEasingCurve::InOutBack:
- curveFunc = new BackEase(BackEase::InOut);
- break;
case QEasingCurve::OutInBack:
- curveFunc = new BackEase(BackEase::OutIn);
- break;
+ return new BackEase(type);
case QEasingCurve::BezierSpline:
- curveFunc = new BezierEase();
- break;
+ return new BezierEase;
case QEasingCurve::TCBSpline:
- curveFunc = new TCBEase();
- break;
+ return new TCBEase;
default:
- curveFunc = new QEasingCurveFunction(QEasingCurveFunction::In, qreal(0.3), qreal(1.0), qreal(1.70158));
+ return new QEasingCurveFunction(type, qreal(0.3), qreal(1.0), qreal(1.70158));
}
- return curveFunc;
+ return 0;
}
/*!
diff --git a/src/corelib/tools/qeasingcurve.h b/src/corelib/tools/qeasingcurve.h
index 702842eb68..a3866c72a2 100644
--- a/src/corelib/tools/qeasingcurve.h
+++ b/src/corelib/tools/qeasingcurve.h
@@ -50,7 +50,6 @@ class QPointF;
class Q_CORE_EXPORT QEasingCurve
{
Q_GADGET
- Q_ENUMS(Type)
public:
enum Type {
Linear,
@@ -67,6 +66,7 @@ public:
InCurve, OutCurve, SineCurve, CosineCurve,
BezierSpline, TCBSpline, Custom, NCurveTypes
};
+ Q_ENUM(Type)
QEasingCurve(Type type = Linear);
QEasingCurve(const QEasingCurve &other);
diff --git a/src/corelib/tools/qelapsedtimer_generic.cpp b/src/corelib/tools/qelapsedtimer_generic.cpp
index f1f17b7fe5..734f693072 100644
--- a/src/corelib/tools/qelapsedtimer_generic.cpp
+++ b/src/corelib/tools/qelapsedtimer_generic.cpp
@@ -134,6 +134,10 @@ qint64 QElapsedTimer::elapsed() const Q_DECL_NOTHROW
number of milliseconds since January 1st, 1970 at 0:00 UTC (that is, it
is the Unix time expressed in milliseconds).
+ On Linux, Windows and OS X/iOS systems, this value is usually the time
+ since the system boot, though it usually does not include the time the
+ system has spent in sleep states.
+
\sa clockType(), elapsed()
*/
qint64 QElapsedTimer::msecsSinceReference() const Q_DECL_NOTHROW
diff --git a/src/corelib/tools/qelapsedtimer_unix.cpp b/src/corelib/tools/qelapsedtimer_unix.cpp
index d29447fa03..922aa487d7 100644
--- a/src/corelib/tools/qelapsedtimer_unix.cpp
+++ b/src/corelib/tools/qelapsedtimer_unix.cpp
@@ -140,11 +140,6 @@ static int unixCheckClockType()
#endif
}
-static inline qint64 fractionAdjustment()
-{
- return 1000*1000ull;
-}
-
bool QElapsedTimer::isMonotonic() Q_DECL_NOTHROW
{
return clockType() == MonotonicClock;
@@ -196,7 +191,7 @@ static qint64 elapsedAndRestart(qint64 sec, qint64 frac,
do_gettime(nowsec, nowfrac);
sec = *nowsec - sec;
frac = *nowfrac - frac;
- return sec * Q_INT64_C(1000) + frac / fractionAdjustment();
+ return (sec * Q_INT64_C(1000000000) + frac) / Q_INT64_C(1000000);
}
void QElapsedTimer::start() Q_DECL_NOTHROW
@@ -220,20 +215,19 @@ qint64 QElapsedTimer::nsecsElapsed() const Q_DECL_NOTHROW
qint64 QElapsedTimer::elapsed() const Q_DECL_NOTHROW
{
- qint64 sec, frac;
- return elapsedAndRestart(t1, t2, &sec, &frac);
+ return nsecsElapsed() / Q_INT64_C(1000000);
}
qint64 QElapsedTimer::msecsSinceReference() const Q_DECL_NOTHROW
{
- return t1 * Q_INT64_C(1000) + t2 / fractionAdjustment();
+ return t1 * Q_INT64_C(1000) + t2 / Q_INT64_C(1000000);
}
qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const Q_DECL_NOTHROW
{
qint64 secs = other.t1 - t1;
qint64 fraction = other.t2 - t2;
- return secs * Q_INT64_C(1000) + fraction / fractionAdjustment();
+ return (secs * Q_INT64_C(1000000000) + fraction) / Q_INT64_C(1000000);
}
qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const Q_DECL_NOTHROW
diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp
index fe8c52d103..cd198743bf 100644
--- a/src/corelib/tools/qhash.cpp
+++ b/src/corelib/tools/qhash.cpp
@@ -259,9 +259,7 @@ static uint qt_create_qhash_seed()
quintptr seedPtr = reinterpret_cast<quintptr>(&seed);
seed ^= seedPtr;
-#if QT_POINTER_SIZE == 8
- seed ^= (seedPtr >> 32);
-#endif
+ seed ^= (qulonglong(seedPtr) >> 32); // no-op on 32-bit platforms
#endif // QT_BOOTSTRAPPED
return seed;
@@ -420,7 +418,7 @@ QHashData *QHashData::detach_helper(void (*node_duplicate)(Node *, void *),
Node *e;
};
if (this == &shared_null)
- qt_initialize_qhash_seed();
+ qt_initialize_qhash_seed(); // may throw
d = new QHashData;
d->fakeNext = 0;
d->buckets = 0;
@@ -430,7 +428,7 @@ QHashData *QHashData::detach_helper(void (*node_duplicate)(Node *, void *),
d->userNumBits = userNumBits;
d->numBits = numBits;
d->numBuckets = numBuckets;
- d->seed = uint(qt_qhash_seed.load());
+ d->seed = (this == &shared_null) ? uint(qt_qhash_seed.load()) : seed;
d->sharable = true;
d->strictAlignment = nodeAlign > 8;
d->reserved = 0;
@@ -667,6 +665,85 @@ void QHashData::checkSanity()
Types \c T1 and \c T2 must be supported by qHash().
*/
+/*! \fn uint qHashRange(InputIterator first, InputIterator last, uint seed = 0)
+ \relates QHash
+ \since 5.5
+
+ Returns the hash value for the range [\a{first},\a{last}), using \a seed
+ to seed the calculation, by successively applying qHash() to each
+ element and combining the hash values into a single one.
+
+ The return value of this function depends on the order of elements
+ in the range. That means that
+
+ \code
+ {0, 1, 2}
+ \endcode
+
+ and
+ \code
+ {1, 2, 0}
+ \endcode
+
+ hash to \b{different} values. If order does not matter, for example for hash
+ tables, use qHashRangeCommutative() instead. If you are hashing raw
+ memory, use qHashBits().
+
+ Use this function only to implement qHash() for your own custom
+ types. For example, here's how you could implement a qHash() overload for
+ std::vector<int>:
+
+ \snippet code/src_corelib_tools_qhash.cpp qhashrange
+
+ It bears repeating that the implementation of qHashRange() - like
+ the qHash() overloads offered by Qt - may change at any time. You
+ \b{must not} rely on the fact that qHashRange() will give the same
+ results (for the same inputs) across different Qt versions, even
+ if qHash() for the element type would.
+
+ \sa qHashBits(), qHashRangeCommutative()
+*/
+
+/*! \fn uint qHashRangeCommutative(InputIterator first, InputIterator last, uint seed = 0)
+ \relates QHash
+ \since 5.5
+
+ Returns the hash value for the range [\a{first},\a{last}), using \a seed
+ to seed the calculation, by successively applying qHash() to each
+ element and combining the hash values into a single one.
+
+ The return value of this function does not depend on the order of
+ elements in the range. That means that
+
+ \code
+ {0, 1, 2}
+ \endcode
+
+ and
+ \code
+ {1, 2, 0}
+ \endcode
+
+ hash to the \b{same} values. If order matters, for example, for vectors
+ and arrays, use qHashRange() instead. If you are hashing raw
+ memory, use qHashBits().
+
+ Use this function only to implement qHash() for your own custom
+ types. For example, here's how you could implement a qHash() overload for
+ std::unordered_set<int>:
+
+ \snippet code/src_corelib_tools_qhash.cpp qhashrangecommutative
+
+ It bears repeating that the implementation of
+ qHashRangeCommutative() - like the qHash() overloads offered by Qt
+ - may change at any time. You \b{must not} rely on the fact that
+ qHashRangeCommutative() will give the same results (for the same
+ inputs) across different Qt versions, even if qHash() for the
+ element type would.
+
+ \sa qHashBits(), qHashRange()
+*/
+
/*! \fn uint qHashBits(const void *p, size_t len, uint seed = 0)
\relates QHash
\since 5.4
@@ -675,15 +752,21 @@ void QHashData::checkSanity()
to by \a p, using \a seed to seed the calculation.
Use this function only to implement qHash() for your own custom
- types. E.g., here's how you could implement a qHash() overload for
+ types. For example, here's how you could implement a qHash() overload for
std::vector<int>:
\snippet code/src_corelib_tools_qhash.cpp qhashbits
+ This takes advantage of the fact that std::vector lays out its data
+ contiguously. If that is not the case, or the contained type has
+ padding, you should use qHashRange() instead.
+
It bears repeating that the implementation of qHashBits() - like
the qHash() overloads offered by Qt - may change at any time. You
\b{must not} rely on the fact that qHashBits() will give the same
results (for the same inputs) across different Qt versions.
+
+ \sa qHashRange(), qHashRangeCommutative()
*/
/*! \fn uint qHash(char key, uint seed = 0)
@@ -1047,7 +1130,7 @@ uint qHash(long double key, uint seed) Q_DECL_NOTHROW
This randomization of QHash is enabled by default. Even though programs
should never depend on a particular QHash ordering, there may be situations
- where you temporarily need deterministic behavior, e.g. for debugging or
+ where you temporarily need deterministic behavior, for example for debugging or
regression testing. To disable the randomization, define the environment
variable \c QT_HASH_SEED. The contents of that variable, interpreted as a
decimal value, will be used as the seed for qHash().
@@ -1063,7 +1146,7 @@ uint qHash(long double key, uint seed) Q_DECL_NOTHROW
*/
/*!
- \fn QHash::QHash(QHash<Key, T> &&other)
+ \fn QHash::QHash(QHash &&other)
Move-constructs a QHash instance, making it point at the same
object that \a other was pointing to.
@@ -1081,7 +1164,7 @@ uint qHash(long double key, uint seed) Q_DECL_NOTHROW
compiled in C++11 mode.
*/
-/*! \fn QHash::QHash(const QHash<Key, T> &other)
+/*! \fn QHash::QHash(const QHash &other)
Constructs a copy of \a other.
@@ -1099,34 +1182,34 @@ uint qHash(long double key, uint seed) Q_DECL_NOTHROW
iterators of this hash become invalid.
*/
-/*! \fn QHash<Key, T> &QHash::operator=(const QHash<Key, T> &other)
+/*! \fn QHash &QHash::operator=(const QHash &other)
Assigns \a other to this hash and returns a reference to this hash.
*/
/*!
- \fn QHash<Key, T> &QHash::operator=(QHash<Key, T> &&other)
+ \fn QHash &QHash::operator=(QHash &&other)
Move-assigns \a other to this QHash instance.
\since 5.2
*/
-/*! \fn void QHash::swap(QHash<Key, T> &other)
+/*! \fn void QHash::swap(QHash &other)
\since 4.8
Swaps hash \a other with this hash. This operation is very
fast and never fails.
*/
-/*! \fn void QMultiHash::swap(QMultiHash<Key, T> &other)
+/*! \fn void QMultiHash::swap(QMultiHash &other)
\since 4.8
Swaps hash \a other with this hash. This operation is very
fast and never fails.
*/
-/*! \fn bool QHash::operator==(const QHash<Key, T> &other) const
+/*! \fn bool QHash::operator==(const QHash &other) const
Returns \c true if \a other is equal to this hash; otherwise returns
false.
@@ -1139,7 +1222,7 @@ uint qHash(long double key, uint seed) Q_DECL_NOTHROW
\sa operator!=()
*/
-/*! \fn bool QHash::operator!=(const QHash<Key, T> &other) const
+/*! \fn bool QHash::operator!=(const QHash &other) const
Returns \c true if \a other is not equal to this hash; otherwise
returns \c false.
@@ -1239,7 +1322,7 @@ uint qHash(long double key, uint seed) Q_DECL_NOTHROW
\internal
*/
-/*! \fn bool QHash::isSharedWith(const QHash<Key, T> &other) const
+/*! \fn bool QHash::isSharedWith(const QHash &other) const
\internal
*/
@@ -1561,7 +1644,7 @@ uint qHash(long double key, uint seed) Q_DECL_NOTHROW
\sa insert(), values()
*/
-/*! \fn QHash<Key, T> &QHash::unite(const QHash<Key, T> &other)
+/*! \fn QHash &QHash::unite(const QHash &other)
Inserts all the items in the \a other hash into this hash. If a
key is common to both hashes, the resulting hash will contain the
@@ -2227,12 +2310,6 @@ uint qHash(long double key, uint seed) Q_DECL_NOTHROW
*/
/*!
- \fn bool QMultiHash::contains(const Key &key) const
- \overload
- \sa QHash::contains()
-*/
-
-/*!
\fn int QMultiHash::remove(const Key &key, const T &value)
\since 4.3
@@ -2243,12 +2320,6 @@ uint qHash(long double key, uint seed) Q_DECL_NOTHROW
*/
/*!
- \fn int QMultiHash::remove(const Key &key)
- \overload
- \sa QHash::remove()
-*/
-
-/*!
\fn int QMultiHash::count(const Key &key, const T &value) const
\since 4.3
@@ -2258,18 +2329,6 @@ uint qHash(long double key, uint seed) Q_DECL_NOTHROW
*/
/*!
- \fn int QMultiHash::count(const Key &key) const
- \overload
- \sa QHash::count()
-*/
-
-/*!
- \fn int QMultiHash::count() const
- \overload
- \sa QHash::count()
-*/
-
-/*!
\fn typename QHash<Key, T>::iterator QMultiHash::find(const Key &key, const T &value)
\since 4.3
@@ -2283,24 +2342,12 @@ uint qHash(long double key, uint seed) Q_DECL_NOTHROW
*/
/*!
- \fn typename QHash<Key, T>::iterator QMultiHash::find(const Key &key)
- \overload
- \sa QHash::find()
-*/
-
-/*!
\fn typename QHash<Key, T>::const_iterator QMultiHash::find(const Key &key, const T &value) const
\since 4.3
\overload
*/
/*!
- \fn typename QHash<Key, T>::const_iterator QMultiHash::find(const Key &key) const
- \overload
- \sa QHash::find()
-*/
-
-/*!
\fn typename QHash<Key, T>::const_iterator QMultiHash::constFind(const Key &key, const T &value) const
\since 4.3
@@ -2313,10 +2360,4 @@ uint qHash(long double key, uint seed) Q_DECL_NOTHROW
\sa QHash::constFind()
*/
-/*!
- \fn typename QHash<Key, T>::const_iterator QMultiHash::constFind(const Key &key) const
- \overload
- \sa QHash::constFind()
-*/
-
QT_END_NAMESPACE
diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h
index 59a5251c50..e0387d4644 100644
--- a/src/corelib/tools/qhash.h
+++ b/src/corelib/tools/qhash.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2015 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@kdab.com>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -40,6 +41,7 @@
#include <QtCore/qpair.h>
#include <QtCore/qrefcount.h>
+#include <numeric> // for std::accumulate
#ifdef Q_COMPILER_INITIALIZER_LISTS
#include <initializer_list>
#endif
@@ -101,6 +103,44 @@ template<typename T> inline uint qHash(const T &t, uint seed)
Q_DECL_NOEXCEPT_EXPR(noexcept(qHash(t)))
{ return (qHash(t) ^ seed); }
+namespace QtPrivate {
+
+struct QHashCombine {
+ typedef uint result_type;
+ template <typename T>
+ Q_DECL_CONSTEXPR result_type operator()(uint seed, const T &t) const Q_DECL_NOEXCEPT_EXPR(noexcept(qHash(t)))
+ // combiner taken from N3876 / boost::hash_combine
+ { return seed ^ (qHash(t) + 0x9e3779b9 + (seed << 6) + (seed >> 2)) ; }
+};
+
+struct QHashCombineCommutative {
+ // QHashCombine is a good hash combiner, but is not commutative,
+ // ie. it depends on the order of the input elements. That is
+ // usually what we want: {0,1,3} should hash differently than
+ // {1,3,0}. Except when it isn't (e.g. for QSet and
+ // QHash). Therefore, provide a commutative combiner, too.
+ typedef uint result_type;
+ template <typename T>
+ Q_DECL_CONSTEXPR result_type operator()(uint seed, const T &t) const Q_DECL_NOEXCEPT_EXPR(noexcept(qHash(t)))
+ { return seed + qHash(t); } // don't use xor!
+};
+
+} // namespace QtPrivate
+
+template <typename InputIterator>
+inline uint qHashRange(InputIterator first, InputIterator last, uint seed = 0)
+ Q_DECL_NOEXCEPT_EXPR(noexcept(qHash(*first))) // assume iterator operations don't throw
+{
+ return std::accumulate(first, last, seed, QtPrivate::QHashCombine());
+}
+
+template <typename InputIterator>
+inline uint qHashRangeCommutative(InputIterator first, InputIterator last, uint seed = 0)
+ Q_DECL_NOEXCEPT_EXPR(noexcept(qHash(*first))) // assume iterator operations don't throw
+{
+ return std::accumulate(first, last, seed, QtPrivate::QHashCombineCommutative());
+}
+
template <typename T1, typename T2> inline uint qHash(const QPair<T1, T2> &key, uint seed = 0)
Q_DECL_NOEXCEPT_EXPR(noexcept(qHash(key.first, seed)) && noexcept(qHash(key.second, seed)))
{
@@ -288,7 +328,7 @@ class QHash
static inline int alignOfNode() { return qMax<int>(sizeof(void*), Q_ALIGNOF(Node)); }
public:
- inline QHash() : d(const_cast<QHashData *>(&QHashData::shared_null)) { }
+ inline QHash() Q_DECL_NOTHROW : d(const_cast<QHashData *>(&QHashData::shared_null)) { }
#ifdef Q_COMPILER_INITIALIZER_LISTS
inline QHash(std::initializer_list<std::pair<Key,T> > list)
: d(const_cast<QHashData *>(&QHashData::shared_null))
@@ -298,19 +338,19 @@ public:
insert(it->first, it->second);
}
#endif
- inline QHash(const QHash<Key, T> &other) : d(other.d) { d->ref.ref(); if (!d->sharable) detach(); }
- inline ~QHash() { if (!d->ref.deref()) freeData(d); }
+ QHash(const QHash &other) : d(other.d) { d->ref.ref(); if (!d->sharable) detach(); }
+ ~QHash() { if (!d->ref.deref()) freeData(d); }
- QHash<Key, T> &operator=(const QHash<Key, T> &other);
+ QHash &operator=(const QHash &other);
#ifdef Q_COMPILER_RVALUE_REFS
- inline QHash(QHash<Key, T> &&other) : d(other.d) { other.d = const_cast<QHashData *>(&QHashData::shared_null); }
- inline QHash<Key, T> &operator=(QHash<Key, T> &&other)
+ QHash(QHash &&other) Q_DECL_NOTHROW : d(other.d) { other.d = const_cast<QHashData *>(&QHashData::shared_null); }
+ QHash &operator=(QHash &&other) Q_DECL_NOTHROW
{ qSwap(d, other.d); return *this; }
#endif
- inline void swap(QHash<Key, T> &other) { qSwap(d, other.d); }
+ void swap(QHash &other) Q_DECL_NOTHROW { qSwap(d, other.d); }
- bool operator==(const QHash<Key, T> &other) const;
- inline bool operator!=(const QHash<Key, T> &other) const { return !(*this == other); }
+ bool operator==(const QHash &other) const;
+ bool operator!=(const QHash &other) const { return !(*this == other); }
inline int size() const { return d->size; }
@@ -325,7 +365,7 @@ public:
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
inline void setSharable(bool sharable) { if (!sharable) detach(); if (d != &QHashData::shared_null) d->sharable = sharable; }
#endif
- inline bool isSharedWith(const QHash<Key, T> &other) const { return d == other.d; }
+ bool isSharedWith(const QHash &other) const { return d == other.d; }
void clear();
@@ -488,7 +528,7 @@ public:
const_iterator constFind(const Key &key) const;
iterator insert(const Key &key, const T &value);
iterator insertMulti(const Key &key, const T &value);
- QHash<Key, T> &unite(const QHash<Key, T> &other);
+ QHash &unite(const QHash &other);
// STL compatibility
typedef T mapped_type;
@@ -564,9 +604,9 @@ QHash<Key, T>::createNode(uint ah, const Key &akey, const T &avalue, Node **anex
}
template <class Key, class T>
-Q_INLINE_TEMPLATE QHash<Key, T> &QHash<Key, T>::unite(const QHash<Key, T> &other)
+Q_INLINE_TEMPLATE QHash<Key, T> &QHash<Key, T>::unite(const QHash &other)
{
- QHash<Key, T> copy(other);
+ QHash copy(other);
const_iterator it = copy.constEnd();
while (it != copy.constBegin()) {
--it;
@@ -584,7 +624,7 @@ Q_OUTOFLINE_TEMPLATE void QHash<Key, T>::freeData(QHashData *x)
template <class Key, class T>
Q_INLINE_TEMPLATE void QHash<Key, T>::clear()
{
- *this = QHash<Key,T>();
+ *this = QHash();
}
template <class Key, class T>
@@ -597,7 +637,7 @@ Q_OUTOFLINE_TEMPLATE void QHash<Key, T>::detach_helper()
}
template <class Key, class T>
-Q_INLINE_TEMPLATE QHash<Key, T> &QHash<Key, T>::operator=(const QHash<Key, T> &other)
+Q_INLINE_TEMPLATE QHash<Key, T> &QHash<Key, T>::operator=(const QHash &other)
{
if (d != other.d) {
QHashData *o = other.d;
@@ -925,7 +965,7 @@ Q_OUTOFLINE_TEMPLATE typename QHash<Key, T>::Node **QHash<Key, T>::findNode(cons
}
template <class Key, class T>
-Q_OUTOFLINE_TEMPLATE bool QHash<Key, T>::operator==(const QHash<Key, T> &other) const
+Q_OUTOFLINE_TEMPLATE bool QHash<Key, T>::operator==(const QHash &other) const
{
if (size() != other.size())
return false;
@@ -964,7 +1004,7 @@ public:
}
#endif
QMultiHash(const QHash<Key, T> &other) : QHash<Key, T>(other) {}
- inline void swap(QMultiHash<Key, T> &other) { QHash<Key, T>::swap(other); } // prevent QMultiHash<->QHash swaps
+ void swap(QMultiHash &other) { QHash<Key, T>::swap(other); } // prevent QMultiHash<->QHash swaps
inline typename QHash<Key, T>::iterator replace(const Key &key, const T &value)
{ return QHash<Key, T>::insert(key, value); }
@@ -977,29 +1017,11 @@ public:
inline QMultiHash operator+(const QMultiHash &other) const
{ QMultiHash result = *this; result += other; return result; }
-#if !defined(Q_NO_USING_KEYWORD) && !defined(Q_CC_RVCT)
- // RVCT compiler doesn't handle using-keyword right when used functions are overloaded in child class
using QHash<Key, T>::contains;
using QHash<Key, T>::remove;
using QHash<Key, T>::count;
using QHash<Key, T>::find;
using QHash<Key, T>::constFind;
-#else
- inline bool contains(const Key &key) const
- { return QHash<Key, T>::contains(key); }
- inline int remove(const Key &key)
- { return QHash<Key, T>::remove(key); }
- inline int count(const Key &key) const
- { return QHash<Key, T>::count(key); }
- inline int count() const
- { return QHash<Key, T>::count(); }
- inline typename QHash<Key, T>::iterator find(const Key &key)
- { return QHash<Key, T>::find(key); }
- inline typename QHash<Key, T>::const_iterator find(const Key &key) const
- { return QHash<Key, T>::find(key); }
- inline typename QHash<Key, T>::const_iterator constFind(const Key &key) const
- { return QHash<Key, T>::constFind(key); }
-#endif
bool contains(const Key &key, const T &value) const;
diff --git a/src/corelib/tools/qlist.cpp b/src/corelib/tools/qlist.cpp
index fe5e0f33b4..a5e43e2ca5 100644
--- a/src/corelib/tools/qlist.cpp
+++ b/src/corelib/tools/qlist.cpp
@@ -55,6 +55,8 @@ const QListData::Data QListData::shared_null = { Q_REFCOUNT_INITIALIZE_STATIC, 0
static int grow(int size)
{
+ if (size_t(size) > (MaxAllocSize - QListData::DataHeaderSize) / sizeof(void *))
+ qBadAlloc();
// dear compiler: don't optimize me out.
volatile int x = qAllocMore(size * sizeof(void *), QListData::DataHeaderSize) / sizeof(void *);
return x;
@@ -473,6 +475,12 @@ void **QListData::erase(void **xi)
If T is a QByteArray, this class has a couple more members that can be
used. See the documentation for QByteArrayList for more information.
+ If T is QString, this class has the following additional members:
+ \l{QStringList::filter()}{filter},
+ \l{QStringList::join()}{join},
+ \l{QStringList::removeDuplicates()}{removeDuplicates},
+ \l{QStringList::sort()}{sort}.
+
\sa QListIterator, QMutableListIterator, QLinkedList, QVector
*/
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h
index e33be9a2f1..2031c32069 100644
--- a/src/corelib/tools/qlist.h
+++ b/src/corelib/tools/qlist.h
@@ -112,7 +112,7 @@ class QList : public QListSpecialMethods<T>
union { QListData p; QListData::Data *d; };
public:
- inline QList() : d(const_cast<QListData::Data *>(&QListData::shared_null)) { }
+ inline QList() Q_DECL_NOTHROW : d(const_cast<QListData::Data *>(&QListData::shared_null)) { }
QList(const QList<T> &l);
~QList();
QList<T> &operator=(const QList<T> &l);
@@ -628,9 +628,7 @@ inline void QList<T>::swap(int i, int j)
Q_ASSERT_X(i >= 0 && i < p.size() && j >= 0 && j < p.size(),
"QList<T>::swap", "index out of range");
detach();
- void *t = d->array[d->begin + i];
- d->array[d->begin + i] = d->array[d->begin + j];
- d->array[d->begin + j] = t;
+ std::swap(d->array[d->begin + i], d->array[d->begin + j]);
}
template <typename T>
@@ -773,11 +771,10 @@ Q_OUTOFLINE_TEMPLATE bool QList<T>::operator==(const QList<T> &l) const
return true;
if (p.size() != l.p.size())
return false;
- Node *i = reinterpret_cast<Node *>(p.end());
- Node *b = reinterpret_cast<Node *>(p.begin());
- Node *li = reinterpret_cast<Node *>(l.p.end());
- while (i != b) {
- --i; --li;
+ Node *i = reinterpret_cast<Node *>(p.begin());
+ Node *e = reinterpret_cast<Node *>(p.end());
+ Node *li = reinterpret_cast<Node *>(l.p.begin());
+ for (; i != e; ++i, ++li) {
if (!(i->t() == li->t()))
return false;
}
@@ -925,9 +922,9 @@ Q_OUTOFLINE_TEMPLATE int QList<T>::lastIndexOf(const T &t, int from) const
template <typename T>
Q_OUTOFLINE_TEMPLATE bool QList<T>::contains(const T &t) const
{
- Node *b = reinterpret_cast<Node *>(p.begin());
- Node *i = reinterpret_cast<Node *>(p.end());
- while (i-- != b)
+ Node *e = reinterpret_cast<Node *>(p.end());
+ Node *i = reinterpret_cast<Node *>(p.begin());
+ for (; i != e; ++i)
if (i->t() == t)
return true;
return false;
@@ -937,9 +934,9 @@ template <typename T>
Q_OUTOFLINE_TEMPLATE int QList<T>::count(const T &t) const
{
int c = 0;
- Node *b = reinterpret_cast<Node *>(p.begin());
- Node *i = reinterpret_cast<Node *>(p.end());
- while (i-- != b)
+ Node *e = reinterpret_cast<Node *>(p.end());
+ Node *i = reinterpret_cast<Node *>(p.begin());
+ for (; i != e; ++i)
if (i->t() == t)
++c;
return c;
@@ -951,6 +948,7 @@ Q_DECLARE_MUTABLE_SEQUENTIAL_ITERATOR(List)
QT_END_NAMESPACE
#include <QtCore/qbytearraylist.h>
+#include <QtCore/qstringlist.h>
#ifdef Q_CC_MSVC
#pragma warning( pop )
diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp
index a923be50c0..78334563dd 100644
--- a/src/corelib/tools/qlocale.cpp
+++ b/src/corelib/tools/qlocale.cpp
@@ -2744,30 +2744,6 @@ QString QLocaleData::doubleToString(const QChar _zero, const QChar plus, const Q
int decpt, sign;
QString digits;
-#ifdef QT_QLOCALE_USES_FCVT
- // NOT thread safe!
- if (form == DFDecimal) {
- digits = QLatin1String(fcvt(d, precision, &decpt, &sign));
- } else {
- int pr = precision;
- if (form == DFExponent)
- ++pr;
- else if (form == DFSignificantDigits && pr == 0)
- pr = 1;
- digits = QLatin1String(ecvt(d, pr, &decpt, &sign));
-
- // Chop trailing zeros
- if (digits.length() > 0) {
- int last_nonzero_idx = digits.length() - 1;
- while (last_nonzero_idx > 0
- && digits.unicode()[last_nonzero_idx] == QLatin1Char('0'))
- --last_nonzero_idx;
- digits.truncate(last_nonzero_idx + 1);
- }
-
- }
-
-#else
int mode;
if (form == DFDecimal)
mode = 3;
@@ -2795,7 +2771,6 @@ QString QLocaleData::doubleToString(const QChar _zero, const QChar plus, const Q
}
if (buff != 0)
free(buff);
-#endif // QT_QLOCALE_USES_FCVT
if (_zero.unicode() != '0') {
ushort z = _zero.unicode() - '0';
diff --git a/src/corelib/tools/qlocale.h b/src/corelib/tools/qlocale.h
index f965ae6562..145b67f9f1 100644
--- a/src/corelib/tools/qlocale.h
+++ b/src/corelib/tools/qlocale.h
@@ -55,9 +55,6 @@ class QLocalePrivate;
class Q_CORE_EXPORT QLocale
{
Q_GADGET
- Q_ENUMS(Language)
- Q_ENUMS(Country)
- Q_ENUMS(MeasurementSystem)
friend class QString;
friend class QStringRef;
friend class QByteArray;
@@ -781,12 +778,16 @@ public:
};
// GENERATED PART ENDS HERE
+ Q_ENUM(Language)
+ Q_ENUM(Country)
+
enum MeasurementSystem {
MetricSystem,
ImperialUSSystem,
ImperialUKSystem,
ImperialSystem = ImperialUSSystem // Qt 4 compatibility
};
+ Q_ENUM(MeasurementSystem)
enum FormatType { LongFormat, ShortFormat, NarrowFormat };
enum NumberOption {
diff --git a/src/corelib/tools/qlocale_tools.cpp b/src/corelib/tools/qlocale_tools.cpp
index 1b246a29de..fa4843361c 100644
--- a/src/corelib/tools/qlocale_tools.cpp
+++ b/src/corelib/tools/qlocale_tools.cpp
@@ -63,10 +63,8 @@
QT_BEGIN_NAMESPACE
-#ifndef QT_QLOCALE_USES_FCVT
static char *_qdtoa( NEEDS_VOLATILE double d, int mode, int ndigits, int *decpt,
int *sign, char **rve, char **digits_str);
-#endif
QString qulltoa(qulonglong l, int base, const QChar _zero)
{
@@ -390,8 +388,6 @@ qlonglong qstrtoll(const char *nptr, const char **endptr, int base, bool *ok)
return acc;
}
-#ifndef QT_QLOCALE_USES_FCVT
-
/* From: NetBSD: strtod.c,v 1.26 1998/02/03 18:44:21 perry Exp */
/* $FreeBSD: src/lib/libc/stdlib/netbsd_strtod.c,v 1.2.2.2 2001/03/02 17:14:15 tegge Exp $ */
@@ -2780,54 +2776,5 @@ static char *_qdtoa( NEEDS_VOLATILE double d, int mode, int ndigits, int *decpt,
*rve = s;
return s0;
}
-#else
-// NOT thread safe!
-
-#include <errno.h>
-
-Q_CORE_EXPORT char *qdtoa( double d, int mode, int ndigits, int *decpt, int *sign, char **rve, char **resultp)
-{
- if(rve)
- *rve = 0;
-
- char *res;
- if (mode == 0)
- ndigits = 80;
-
- if (mode == 3)
- res = fcvt(d, ndigits, decpt, sign);
- else
- res = ecvt(d, ndigits, decpt, sign);
-
- int n = qstrlen(res);
- if (mode == 0) { // remove trailing 0's
- const int stop = qMax(1, *decpt);
- int i;
- for (i = n-1; i >= stop; --i) {
- if (res[i] != '0')
- break;
- }
- n = i + 1;
- }
- *resultp = static_cast<char*>(malloc(n + 1));
- Q_CHECK_PTR(resultp);
- qstrncpy(*resultp, res, n + 1);
- return *resultp;
-}
-
-Q_CORE_EXPORT double qstrtod(const char *s00, const char **se, bool *ok)
-{
- double ret = strtod((char*)s00, (char**)se);
- if (ok) {
- if((ret == 0.0l && errno == ERANGE)
- || ret == HUGE_VAL || ret == -HUGE_VAL)
- *ok = false;
- else
- *ok = true; // the result will be that we don't report underflow in this case
- }
- return ret;
-}
-
-#endif // QT_QLOCALE_USES_FCVT
QT_END_NAMESPACE
diff --git a/src/corelib/tools/qmap.cpp b/src/corelib/tools/qmap.cpp
index 38b4c0ad7e..ef5fbac377 100644
--- a/src/corelib/tools/qmap.cpp
+++ b/src/corelib/tools/qmap.cpp
@@ -1798,12 +1798,6 @@ void QMapDataBase::freeData(QMapDataBase *d)
*/
/*!
- \fn bool QMultiMap::contains(const Key &key) const
- \overload
- \sa QMap::contains()
-*/
-
-/*!
\fn int QMultiMap::remove(const Key &key, const T &value)
\since 4.3
@@ -1814,12 +1808,6 @@ void QMapDataBase::freeData(QMapDataBase *d)
*/
/*!
- \fn int QMultiMap::remove(const Key &key)
- \overload
- \sa QMap::remove()
-*/
-
-/*!
\fn int QMultiMap::count(const Key &key, const T &value) const
\since 4.3
@@ -1829,18 +1817,6 @@ void QMapDataBase::freeData(QMapDataBase *d)
*/
/*!
- \fn int QMultiMap::count(const Key &key) const
- \overload
- \sa QMap::count()
-*/
-
-/*!
- \fn int QMultiMap::count() const
- \overload
- \sa QMap::count()
-*/
-
-/*!
\fn typename QMap<Key, T>::iterator QMultiMap::find(const Key &key, const T &value)
\since 4.3
@@ -1857,12 +1833,6 @@ void QMapDataBase::freeData(QMapDataBase *d)
*/
/*!
- \fn typename QMap<Key, T>::iterator QMultiMap::find(const Key &key)
- \overload
- \sa QMap::find()
-*/
-
-/*!
\fn typename QMap<Key, T>::const_iterator QMultiMap::find(const Key &key, const T &value) const
\since 4.3
\overload
@@ -1880,13 +1850,6 @@ void QMapDataBase::freeData(QMapDataBase *d)
*/
/*!
- \fn typename QMap<Key, T>::const_iterator QMultiMap::find(const Key &key) const
- \since 4.3
- \overload
- \sa QMap::find()
-*/
-
-/*!
\fn typename QMap<Key, T>::const_iterator QMultiMap::constFind(const Key &key, const T &value) const
\since 4.3
@@ -1899,10 +1862,4 @@ void QMapDataBase::freeData(QMapDataBase *d)
\sa QMap::constFind()
*/
-/*!
- \fn typename QMap<Key, T>::const_iterator QMultiMap::constFind(const Key &key) const
- \overload
- \sa QMap::constFind()
-*/
-
QT_END_NAMESPACE
diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h
index a776e2eb4d..4b1fc65b22 100644
--- a/src/corelib/tools/qmap.h
+++ b/src/corelib/tools/qmap.h
@@ -1157,29 +1157,11 @@ public:
inline QMultiMap operator+(const QMultiMap &other) const
{ QMultiMap result = *this; result += other; return result; }
-#if !defined(Q_NO_USING_KEYWORD) && !defined(Q_CC_RVCT)
- // RVCT compiler doesn't handle using-keyword right when used functions are overloaded in child class
using QMap<Key, T>::contains;
using QMap<Key, T>::remove;
using QMap<Key, T>::count;
using QMap<Key, T>::find;
using QMap<Key, T>::constFind;
-#else
- inline bool contains(const Key &key) const
- { return QMap<Key, T>::contains(key); }
- inline int remove(const Key &key)
- { return QMap<Key, T>::remove(key); }
- inline int count(const Key &key) const
- { return QMap<Key, T>::count(key); }
- inline int count() const
- { return QMap<Key, T>::count(); }
- inline typename QMap<Key, T>::iterator find(const Key &key)
- { return QMap<Key, T>::find(key); }
- inline typename QMap<Key, T>::const_iterator find(const Key &key) const
- { return QMap<Key, T>::find(key); }
- inline typename QMap<Key, T>::const_iterator constFind(const Key &key) const
- { return QMap<Key, T>::constFind(key); }
-#endif
bool contains(const Key &key, const T &value) const;
diff --git a/src/corelib/tools/qmargins.h b/src/corelib/tools/qmargins.h
index 33a2766345..a0c88f61e3 100644
--- a/src/corelib/tools/qmargins.h
+++ b/src/corelib/tools/qmargins.h
@@ -45,29 +45,29 @@ QT_BEGIN_NAMESPACE
class QMargins
{
public:
- Q_DECL_CONSTEXPR QMargins();
- Q_DECL_CONSTEXPR QMargins(int left, int top, int right, int bottom);
-
- Q_DECL_CONSTEXPR bool isNull() const;
-
- Q_DECL_CONSTEXPR int left() const;
- Q_DECL_CONSTEXPR int top() const;
- Q_DECL_CONSTEXPR int right() const;
- Q_DECL_CONSTEXPR int bottom() const;
-
- void setLeft(int left);
- void setTop(int top);
- void setRight(int right);
- void setBottom(int bottom);
-
- QMargins &operator+=(const QMargins &margins);
- QMargins &operator-=(const QMargins &margins);
- QMargins &operator+=(int);
- QMargins &operator-=(int);
- QMargins &operator*=(int);
- QMargins &operator/=(int);
- QMargins &operator*=(qreal);
- QMargins &operator/=(qreal);
+ Q_DECL_CONSTEXPR QMargins() Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR QMargins(int left, int top, int right, int bottom) Q_DECL_NOTHROW;
+
+ Q_DECL_CONSTEXPR bool isNull() const Q_DECL_NOTHROW;
+
+ Q_DECL_CONSTEXPR int left() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR int top() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR int right() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR int bottom() const Q_DECL_NOTHROW;
+
+ Q_DECL_RELAXED_CONSTEXPR void setLeft(int left) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR void setTop(int top) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR void setRight(int right) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR void setBottom(int bottom) Q_DECL_NOTHROW;
+
+ Q_DECL_RELAXED_CONSTEXPR QMargins &operator+=(const QMargins &margins) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR QMargins &operator-=(const QMargins &margins) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR QMargins &operator+=(int) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR QMargins &operator-=(int) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR QMargins &operator*=(int) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR QMargins &operator/=(int);
+ Q_DECL_RELAXED_CONSTEXPR QMargins &operator*=(qreal) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR QMargins &operator/=(qreal);
private:
int m_left;
@@ -75,8 +75,8 @@ private:
int m_right;
int m_bottom;
- friend Q_DECL_CONSTEXPR inline bool operator==(const QMargins &, const QMargins &);
- friend Q_DECL_CONSTEXPR inline bool operator!=(const QMargins &, const QMargins &);
+ friend Q_DECL_CONSTEXPR inline bool operator==(const QMargins &, const QMargins &) Q_DECL_NOTHROW;
+ friend Q_DECL_CONSTEXPR inline bool operator!=(const QMargins &, const QMargins &) Q_DECL_NOTHROW;
};
Q_DECLARE_TYPEINFO(QMargins, Q_MOVABLE_TYPE);
@@ -93,40 +93,40 @@ Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QMargins &);
QMargins inline functions
*****************************************************************************/
-Q_DECL_CONSTEXPR inline QMargins::QMargins() : m_left(0), m_top(0), m_right(0), m_bottom(0) {}
+Q_DECL_CONSTEXPR inline QMargins::QMargins() Q_DECL_NOTHROW : m_left(0), m_top(0), m_right(0), m_bottom(0) {}
-Q_DECL_CONSTEXPR inline QMargins::QMargins(int aleft, int atop, int aright, int abottom)
+Q_DECL_CONSTEXPR inline QMargins::QMargins(int aleft, int atop, int aright, int abottom) Q_DECL_NOTHROW
: m_left(aleft), m_top(atop), m_right(aright), m_bottom(abottom) {}
-Q_DECL_CONSTEXPR inline bool QMargins::isNull() const
+Q_DECL_CONSTEXPR inline bool QMargins::isNull() const Q_DECL_NOTHROW
{ return m_left==0 && m_top==0 && m_right==0 && m_bottom==0; }
-Q_DECL_CONSTEXPR inline int QMargins::left() const
+Q_DECL_CONSTEXPR inline int QMargins::left() const Q_DECL_NOTHROW
{ return m_left; }
-Q_DECL_CONSTEXPR inline int QMargins::top() const
+Q_DECL_CONSTEXPR inline int QMargins::top() const Q_DECL_NOTHROW
{ return m_top; }
-Q_DECL_CONSTEXPR inline int QMargins::right() const
+Q_DECL_CONSTEXPR inline int QMargins::right() const Q_DECL_NOTHROW
{ return m_right; }
-Q_DECL_CONSTEXPR inline int QMargins::bottom() const
+Q_DECL_CONSTEXPR inline int QMargins::bottom() const Q_DECL_NOTHROW
{ return m_bottom; }
-inline void QMargins::setLeft(int aleft)
+Q_DECL_RELAXED_CONSTEXPR inline void QMargins::setLeft(int aleft) Q_DECL_NOTHROW
{ m_left = aleft; }
-inline void QMargins::setTop(int atop)
+Q_DECL_RELAXED_CONSTEXPR inline void QMargins::setTop(int atop) Q_DECL_NOTHROW
{ m_top = atop; }
-inline void QMargins::setRight(int aright)
+Q_DECL_RELAXED_CONSTEXPR inline void QMargins::setRight(int aright) Q_DECL_NOTHROW
{ m_right = aright; }
-inline void QMargins::setBottom(int abottom)
+Q_DECL_RELAXED_CONSTEXPR inline void QMargins::setBottom(int abottom) Q_DECL_NOTHROW
{ m_bottom = abottom; }
-Q_DECL_CONSTEXPR inline bool operator==(const QMargins &m1, const QMargins &m2)
+Q_DECL_CONSTEXPR inline bool operator==(const QMargins &m1, const QMargins &m2) Q_DECL_NOTHROW
{
return
m1.m_left == m2.m_left &&
@@ -135,7 +135,7 @@ Q_DECL_CONSTEXPR inline bool operator==(const QMargins &m1, const QMargins &m2)
m1.m_bottom == m2.m_bottom;
}
-Q_DECL_CONSTEXPR inline bool operator!=(const QMargins &m1, const QMargins &m2)
+Q_DECL_CONSTEXPR inline bool operator!=(const QMargins &m1, const QMargins &m2) Q_DECL_NOTHROW
{
return
m1.m_left != m2.m_left ||
@@ -144,55 +144,55 @@ Q_DECL_CONSTEXPR inline bool operator!=(const QMargins &m1, const QMargins &m2)
m1.m_bottom != m2.m_bottom;
}
-Q_DECL_CONSTEXPR inline QMargins operator+(const QMargins &m1, const QMargins &m2)
+Q_DECL_CONSTEXPR inline QMargins operator+(const QMargins &m1, const QMargins &m2) Q_DECL_NOTHROW
{
return QMargins(m1.left() + m2.left(), m1.top() + m2.top(),
m1.right() + m2.right(), m1.bottom() + m2.bottom());
}
-Q_DECL_CONSTEXPR inline QMargins operator-(const QMargins &m1, const QMargins &m2)
+Q_DECL_CONSTEXPR inline QMargins operator-(const QMargins &m1, const QMargins &m2) Q_DECL_NOTHROW
{
return QMargins(m1.left() - m2.left(), m1.top() - m2.top(),
m1.right() - m2.right(), m1.bottom() - m2.bottom());
}
-Q_DECL_CONSTEXPR inline QMargins operator+(const QMargins &lhs, int rhs)
+Q_DECL_CONSTEXPR inline QMargins operator+(const QMargins &lhs, int rhs) Q_DECL_NOTHROW
{
return QMargins(lhs.left() + rhs, lhs.top() + rhs,
lhs.right() + rhs, lhs.bottom() + rhs);
}
-Q_DECL_CONSTEXPR inline QMargins operator+(int lhs, const QMargins &rhs)
+Q_DECL_CONSTEXPR inline QMargins operator+(int lhs, const QMargins &rhs) Q_DECL_NOTHROW
{
return QMargins(rhs.left() + lhs, rhs.top() + lhs,
rhs.right() + lhs, rhs.bottom() + lhs);
}
-Q_DECL_CONSTEXPR inline QMargins operator-(const QMargins &lhs, int rhs)
+Q_DECL_CONSTEXPR inline QMargins operator-(const QMargins &lhs, int rhs) Q_DECL_NOTHROW
{
return QMargins(lhs.left() - rhs, lhs.top() - rhs,
lhs.right() - rhs, lhs.bottom() - rhs);
}
-Q_DECL_CONSTEXPR inline QMargins operator*(const QMargins &margins, int factor)
+Q_DECL_CONSTEXPR inline QMargins operator*(const QMargins &margins, int factor) Q_DECL_NOTHROW
{
return QMargins(margins.left() * factor, margins.top() * factor,
margins.right() * factor, margins.bottom() * factor);
}
-Q_DECL_CONSTEXPR inline QMargins operator*(int factor, const QMargins &margins)
+Q_DECL_CONSTEXPR inline QMargins operator*(int factor, const QMargins &margins) Q_DECL_NOTHROW
{
return QMargins(margins.left() * factor, margins.top() * factor,
margins.right() * factor, margins.bottom() * factor);
}
-Q_DECL_CONSTEXPR inline QMargins operator*(const QMargins &margins, qreal factor)
+Q_DECL_CONSTEXPR inline QMargins operator*(const QMargins &margins, qreal factor) Q_DECL_NOTHROW
{
return QMargins(qRound(margins.left() * factor), qRound(margins.top() * factor),
qRound(margins.right() * factor), qRound(margins.bottom() * factor));
}
-Q_DECL_CONSTEXPR inline QMargins operator*(qreal factor, const QMargins &margins)
+Q_DECL_CONSTEXPR inline QMargins operator*(qreal factor, const QMargins &margins) Q_DECL_NOTHROW
{
return QMargins(qRound(margins.left() * factor), qRound(margins.top() * factor),
qRound(margins.right() * factor), qRound(margins.bottom() * factor));
@@ -210,17 +210,17 @@ Q_DECL_CONSTEXPR inline QMargins operator/(const QMargins &margins, qreal diviso
qRound(margins.right() / divisor), qRound(margins.bottom() / divisor));
}
-inline QMargins &QMargins::operator+=(const QMargins &margins)
+Q_DECL_RELAXED_CONSTEXPR inline QMargins &QMargins::operator+=(const QMargins &margins) Q_DECL_NOTHROW
{
return *this = *this + margins;
}
-inline QMargins &QMargins::operator-=(const QMargins &margins)
+Q_DECL_RELAXED_CONSTEXPR inline QMargins &QMargins::operator-=(const QMargins &margins) Q_DECL_NOTHROW
{
return *this = *this - margins;
}
-inline QMargins &QMargins::operator+=(int margin)
+Q_DECL_RELAXED_CONSTEXPR inline QMargins &QMargins::operator+=(int margin) Q_DECL_NOTHROW
{
m_left += margin;
m_top += margin;
@@ -229,7 +229,7 @@ inline QMargins &QMargins::operator+=(int margin)
return *this;
}
-inline QMargins &QMargins::operator-=(int margin)
+Q_DECL_RELAXED_CONSTEXPR inline QMargins &QMargins::operator-=(int margin) Q_DECL_NOTHROW
{
m_left -= margin;
m_top -= margin;
@@ -238,32 +238,32 @@ inline QMargins &QMargins::operator-=(int margin)
return *this;
}
-inline QMargins &QMargins::operator*=(int factor)
+Q_DECL_RELAXED_CONSTEXPR inline QMargins &QMargins::operator*=(int factor) Q_DECL_NOTHROW
{
return *this = *this * factor;
}
-inline QMargins &QMargins::operator/=(int divisor)
+Q_DECL_RELAXED_CONSTEXPR inline QMargins &QMargins::operator/=(int divisor)
{
return *this = *this / divisor;
}
-inline QMargins &QMargins::operator*=(qreal factor)
+Q_DECL_RELAXED_CONSTEXPR inline QMargins &QMargins::operator*=(qreal factor) Q_DECL_NOTHROW
{
return *this = *this * factor;
}
-inline QMargins &QMargins::operator/=(qreal divisor)
+Q_DECL_RELAXED_CONSTEXPR inline QMargins &QMargins::operator/=(qreal divisor)
{
return *this = *this / divisor;
}
-Q_DECL_CONSTEXPR inline QMargins operator+(const QMargins &margins)
+Q_DECL_CONSTEXPR inline QMargins operator+(const QMargins &margins) Q_DECL_NOTHROW
{
return margins;
}
-Q_DECL_CONSTEXPR inline QMargins operator-(const QMargins &margins)
+Q_DECL_CONSTEXPR inline QMargins operator-(const QMargins &margins) Q_DECL_NOTHROW
{
return QMargins(-margins.left(), -margins.top(), -margins.right(), -margins.bottom());
}
@@ -279,30 +279,30 @@ Q_CORE_EXPORT QDebug operator<<(QDebug, const QMargins &);
class QMarginsF
{
public:
- Q_DECL_CONSTEXPR QMarginsF();
- Q_DECL_CONSTEXPR QMarginsF(qreal left, qreal top, qreal right, qreal bottom);
- Q_DECL_CONSTEXPR QMarginsF(const QMargins &margins);
+ Q_DECL_CONSTEXPR QMarginsF() Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR QMarginsF(qreal left, qreal top, qreal right, qreal bottom) Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR QMarginsF(const QMargins &margins) Q_DECL_NOTHROW;
- Q_DECL_CONSTEXPR bool isNull() const;
+ Q_DECL_CONSTEXPR bool isNull() const Q_DECL_NOTHROW;
- Q_DECL_CONSTEXPR qreal left() const;
- Q_DECL_CONSTEXPR qreal top() const;
- Q_DECL_CONSTEXPR qreal right() const;
- Q_DECL_CONSTEXPR qreal bottom() const;
+ Q_DECL_CONSTEXPR qreal left() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR qreal top() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR qreal right() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR qreal bottom() const Q_DECL_NOTHROW;
- void setLeft(qreal left);
- void setTop(qreal top);
- void setRight(qreal right);
- void setBottom(qreal bottom);
+ Q_DECL_RELAXED_CONSTEXPR void setLeft(qreal left) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR void setTop(qreal top) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR void setRight(qreal right) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR void setBottom(qreal bottom) Q_DECL_NOTHROW;
- QMarginsF &operator+=(const QMarginsF &margins);
- QMarginsF &operator-=(const QMarginsF &margins);
- QMarginsF &operator+=(qreal addend);
- QMarginsF &operator-=(qreal subtrahend);
- QMarginsF &operator*=(qreal factor);
- QMarginsF &operator/=(qreal divisor);
+ Q_DECL_RELAXED_CONSTEXPR QMarginsF &operator+=(const QMarginsF &margins) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR QMarginsF &operator-=(const QMarginsF &margins) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR QMarginsF &operator+=(qreal addend) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR QMarginsF &operator-=(qreal subtrahend) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR QMarginsF &operator*=(qreal factor) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR QMarginsF &operator/=(qreal divisor);
- Q_DECL_CONSTEXPR inline QMargins toMargins() const;
+ Q_DECL_CONSTEXPR inline QMargins toMargins() const Q_DECL_NOTHROW;
private:
qreal m_left;
@@ -326,43 +326,44 @@ Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QMarginsF &);
QMarginsF inline functions
*****************************************************************************/
-Q_DECL_CONSTEXPR inline QMarginsF::QMarginsF() : m_left(0), m_top(0), m_right(0), m_bottom(0) {}
+Q_DECL_CONSTEXPR inline QMarginsF::QMarginsF() Q_DECL_NOTHROW
+ : m_left(0), m_top(0), m_right(0), m_bottom(0) {}
-Q_DECL_CONSTEXPR inline QMarginsF::QMarginsF(qreal aleft, qreal atop, qreal aright, qreal abottom)
+Q_DECL_CONSTEXPR inline QMarginsF::QMarginsF(qreal aleft, qreal atop, qreal aright, qreal abottom) Q_DECL_NOTHROW
: m_left(aleft), m_top(atop), m_right(aright), m_bottom(abottom) {}
-Q_DECL_CONSTEXPR inline QMarginsF::QMarginsF(const QMargins &margins)
+Q_DECL_CONSTEXPR inline QMarginsF::QMarginsF(const QMargins &margins) Q_DECL_NOTHROW
: m_left(margins.left()), m_top(margins.top()), m_right(margins.right()), m_bottom(margins.bottom()) {}
-Q_DECL_CONSTEXPR inline bool QMarginsF::isNull() const
+Q_DECL_CONSTEXPR inline bool QMarginsF::isNull() const Q_DECL_NOTHROW
{ return qFuzzyIsNull(m_left) && qFuzzyIsNull(m_top) && qFuzzyIsNull(m_right) && qFuzzyIsNull(m_bottom); }
-Q_DECL_CONSTEXPR inline qreal QMarginsF::left() const
+Q_DECL_CONSTEXPR inline qreal QMarginsF::left() const Q_DECL_NOTHROW
{ return m_left; }
-Q_DECL_CONSTEXPR inline qreal QMarginsF::top() const
+Q_DECL_CONSTEXPR inline qreal QMarginsF::top() const Q_DECL_NOTHROW
{ return m_top; }
-Q_DECL_CONSTEXPR inline qreal QMarginsF::right() const
+Q_DECL_CONSTEXPR inline qreal QMarginsF::right() const Q_DECL_NOTHROW
{ return m_right; }
-Q_DECL_CONSTEXPR inline qreal QMarginsF::bottom() const
+Q_DECL_CONSTEXPR inline qreal QMarginsF::bottom() const Q_DECL_NOTHROW
{ return m_bottom; }
-inline void QMarginsF::setLeft(qreal aleft)
+Q_DECL_RELAXED_CONSTEXPR inline void QMarginsF::setLeft(qreal aleft) Q_DECL_NOTHROW
{ m_left = aleft; }
-inline void QMarginsF::setTop(qreal atop)
+Q_DECL_RELAXED_CONSTEXPR inline void QMarginsF::setTop(qreal atop) Q_DECL_NOTHROW
{ m_top = atop; }
-inline void QMarginsF::setRight(qreal aright)
+Q_DECL_RELAXED_CONSTEXPR inline void QMarginsF::setRight(qreal aright) Q_DECL_NOTHROW
{ m_right = aright; }
-inline void QMarginsF::setBottom(qreal abottom)
+Q_DECL_RELAXED_CONSTEXPR inline void QMarginsF::setBottom(qreal abottom) Q_DECL_NOTHROW
{ m_bottom = abottom; }
-Q_DECL_CONSTEXPR inline bool operator==(const QMarginsF &lhs, const QMarginsF &rhs)
+Q_DECL_CONSTEXPR inline bool operator==(const QMarginsF &lhs, const QMarginsF &rhs) Q_DECL_NOTHROW
{
return qFuzzyCompare(lhs.left(), rhs.left())
&& qFuzzyCompare(lhs.top(), rhs.top())
@@ -370,48 +371,48 @@ Q_DECL_CONSTEXPR inline bool operator==(const QMarginsF &lhs, const QMarginsF &r
&& qFuzzyCompare(lhs.bottom(), rhs.bottom());
}
-Q_DECL_CONSTEXPR inline bool operator!=(const QMarginsF &lhs, const QMarginsF &rhs)
+Q_DECL_CONSTEXPR inline bool operator!=(const QMarginsF &lhs, const QMarginsF &rhs) Q_DECL_NOTHROW
{
return !operator==(lhs, rhs);
}
-Q_DECL_CONSTEXPR inline QMarginsF operator+(const QMarginsF &lhs, const QMarginsF &rhs)
+Q_DECL_CONSTEXPR inline QMarginsF operator+(const QMarginsF &lhs, const QMarginsF &rhs) Q_DECL_NOTHROW
{
return QMarginsF(lhs.left() + rhs.left(), lhs.top() + rhs.top(),
lhs.right() + rhs.right(), lhs.bottom() + rhs.bottom());
}
-Q_DECL_CONSTEXPR inline QMarginsF operator-(const QMarginsF &lhs, const QMarginsF &rhs)
+Q_DECL_CONSTEXPR inline QMarginsF operator-(const QMarginsF &lhs, const QMarginsF &rhs) Q_DECL_NOTHROW
{
return QMarginsF(lhs.left() - rhs.left(), lhs.top() - rhs.top(),
lhs.right() - rhs.right(), lhs.bottom() - rhs.bottom());
}
-Q_DECL_CONSTEXPR inline QMarginsF operator+(const QMarginsF &lhs, qreal rhs)
+Q_DECL_CONSTEXPR inline QMarginsF operator+(const QMarginsF &lhs, qreal rhs) Q_DECL_NOTHROW
{
return QMarginsF(lhs.left() + rhs, lhs.top() + rhs,
lhs.right() + rhs, lhs.bottom() + rhs);
}
-Q_DECL_CONSTEXPR inline QMarginsF operator+(qreal lhs, const QMarginsF &rhs)
+Q_DECL_CONSTEXPR inline QMarginsF operator+(qreal lhs, const QMarginsF &rhs) Q_DECL_NOTHROW
{
return QMarginsF(rhs.left() + lhs, rhs.top() + lhs,
rhs.right() + lhs, rhs.bottom() + lhs);
}
-Q_DECL_CONSTEXPR inline QMarginsF operator-(const QMarginsF &lhs, qreal rhs)
+Q_DECL_CONSTEXPR inline QMarginsF operator-(const QMarginsF &lhs, qreal rhs) Q_DECL_NOTHROW
{
return QMarginsF(lhs.left() - rhs, lhs.top() - rhs,
lhs.right() - rhs, lhs.bottom() - rhs);
}
-Q_DECL_CONSTEXPR inline QMarginsF operator*(const QMarginsF &lhs, qreal rhs)
+Q_DECL_CONSTEXPR inline QMarginsF operator*(const QMarginsF &lhs, qreal rhs) Q_DECL_NOTHROW
{
return QMarginsF(lhs.left() * rhs, lhs.top() * rhs,
lhs.right() * rhs, lhs.bottom() * rhs);
}
-Q_DECL_CONSTEXPR inline QMarginsF operator*(qreal lhs, const QMarginsF &rhs)
+Q_DECL_CONSTEXPR inline QMarginsF operator*(qreal lhs, const QMarginsF &rhs) Q_DECL_NOTHROW
{
return QMarginsF(rhs.left() * lhs, rhs.top() * lhs,
rhs.right() * lhs, rhs.bottom() * lhs);
@@ -423,17 +424,17 @@ Q_DECL_CONSTEXPR inline QMarginsF operator/(const QMarginsF &lhs, qreal divisor)
lhs.right() / divisor, lhs.bottom() / divisor);
}
-inline QMarginsF &QMarginsF::operator+=(const QMarginsF &margins)
+Q_DECL_RELAXED_CONSTEXPR inline QMarginsF &QMarginsF::operator+=(const QMarginsF &margins) Q_DECL_NOTHROW
{
return *this = *this + margins;
}
-inline QMarginsF &QMarginsF::operator-=(const QMarginsF &margins)
+Q_DECL_RELAXED_CONSTEXPR inline QMarginsF &QMarginsF::operator-=(const QMarginsF &margins) Q_DECL_NOTHROW
{
return *this = *this - margins;
}
-inline QMarginsF &QMarginsF::operator+=(qreal addend)
+Q_DECL_RELAXED_CONSTEXPR inline QMarginsF &QMarginsF::operator+=(qreal addend) Q_DECL_NOTHROW
{
m_left += addend;
m_top += addend;
@@ -442,7 +443,7 @@ inline QMarginsF &QMarginsF::operator+=(qreal addend)
return *this;
}
-inline QMarginsF &QMarginsF::operator-=(qreal subtrahend)
+Q_DECL_RELAXED_CONSTEXPR inline QMarginsF &QMarginsF::operator-=(qreal subtrahend) Q_DECL_NOTHROW
{
m_left -= subtrahend;
m_top -= subtrahend;
@@ -451,27 +452,27 @@ inline QMarginsF &QMarginsF::operator-=(qreal subtrahend)
return *this;
}
-inline QMarginsF &QMarginsF::operator*=(qreal factor)
+Q_DECL_RELAXED_CONSTEXPR inline QMarginsF &QMarginsF::operator*=(qreal factor) Q_DECL_NOTHROW
{
return *this = *this * factor;
}
-inline QMarginsF &QMarginsF::operator/=(qreal divisor)
+Q_DECL_RELAXED_CONSTEXPR inline QMarginsF &QMarginsF::operator/=(qreal divisor)
{
return *this = *this / divisor;
}
-Q_DECL_CONSTEXPR inline QMarginsF operator+(const QMarginsF &margins)
+Q_DECL_CONSTEXPR inline QMarginsF operator+(const QMarginsF &margins) Q_DECL_NOTHROW
{
return margins;
}
-Q_DECL_CONSTEXPR inline QMarginsF operator-(const QMarginsF &margins)
+Q_DECL_CONSTEXPR inline QMarginsF operator-(const QMarginsF &margins) Q_DECL_NOTHROW
{
return QMarginsF(-margins.left(), -margins.top(), -margins.right(), -margins.bottom());
}
-Q_DECL_CONSTEXPR inline QMargins QMarginsF::toMargins() const
+Q_DECL_CONSTEXPR inline QMargins QMarginsF::toMargins() const Q_DECL_NOTHROW
{
return QMargins(qRound(m_left), qRound(m_top), qRound(m_right), qRound(m_bottom));
}
diff --git a/src/corelib/tools/qpair.h b/src/corelib/tools/qpair.h
index 76b7abd263..4cba0a8421 100644
--- a/src/corelib/tools/qpair.h
+++ b/src/corelib/tools/qpair.h
@@ -52,7 +52,7 @@ struct QPair
template <typename TT1, typename TT2>
Q_DECL_CONSTEXPR QPair(const QPair<TT1, TT2> &p) : first(p.first), second(p.second) {}
template <typename TT1, typename TT2>
- QPair &operator=(const QPair<TT1, TT2> &p)
+ Q_DECL_RELAXED_CONSTEXPR QPair &operator=(const QPair<TT1, TT2> &p)
{ first = p.first; second = p.second; return *this; }
#ifdef Q_COMPILER_RVALUE_REFS
template <typename TT1, typename TT2>
@@ -60,14 +60,26 @@ struct QPair
// can't use std::move here as it's not constexpr in C++11:
: first(static_cast<TT1 &&>(p.first)), second(static_cast<TT2 &&>(p.second)) {}
template <typename TT1, typename TT2>
- QPair &operator=(QPair<TT1, TT2> &&p)
+ Q_DECL_RELAXED_CONSTEXPR QPair &operator=(QPair<TT1, TT2> &&p)
{ first = std::move(p.first); second = std::move(p.second); return *this; }
#endif
+ Q_DECL_RELAXED_CONSTEXPR void swap(QPair &other)
+ Q_DECL_NOEXCEPT_EXPR(noexcept(qSwap(other.first, other.first)) && noexcept(qSwap(other.second, other.second)))
+ {
+ // use qSwap() to pick up ADL swaps automatically:
+ qSwap(first, other.first);
+ qSwap(second, other.second);
+ }
+
T1 first;
T2 second;
};
+template <typename T1, typename T2>
+void swap(QPair<T1, T2> &lhs, QPair<T1, T2> &rhs) Q_DECL_NOEXCEPT_EXPR(noexcept(lhs.swap(rhs)))
+{ lhs.swap(rhs); }
+
// mark QPair<T1,T2> as complex/movable/primitive depending on the
// typeinfos of the constituents:
template<class T1, class T2>
@@ -75,38 +87,45 @@ class QTypeInfo<QPair<T1, T2> > : public QTypeInfoMerger<QPair<T1, T2>, T1, T2>
template <class T1, class T2>
Q_DECL_CONSTEXPR Q_INLINE_TEMPLATE bool operator==(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2)
+ Q_DECL_NOEXCEPT_EXPR(noexcept(p1.first == p2.first && p1.second == p2.second))
{ return p1.first == p2.first && p1.second == p2.second; }
template <class T1, class T2>
Q_DECL_CONSTEXPR Q_INLINE_TEMPLATE bool operator!=(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2)
+ Q_DECL_NOEXCEPT_EXPR(noexcept(!(p1 == p2)))
{ return !(p1 == p2); }
template <class T1, class T2>
Q_DECL_CONSTEXPR Q_INLINE_TEMPLATE bool operator<(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2)
+ Q_DECL_NOEXCEPT_EXPR(noexcept(p1.first < p2.first || (!(p2.first < p1.first) && p1.second < p2.second)))
{
return p1.first < p2.first || (!(p2.first < p1.first) && p1.second < p2.second);
}
template <class T1, class T2>
Q_DECL_CONSTEXPR Q_INLINE_TEMPLATE bool operator>(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2)
+ Q_DECL_NOEXCEPT_EXPR(noexcept(p2 < p1))
{
return p2 < p1;
}
template <class T1, class T2>
Q_DECL_CONSTEXPR Q_INLINE_TEMPLATE bool operator<=(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2)
+ Q_DECL_NOEXCEPT_EXPR(noexcept(!(p2 < p1)))
{
return !(p2 < p1);
}
template <class T1, class T2>
Q_DECL_CONSTEXPR Q_INLINE_TEMPLATE bool operator>=(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2)
+ Q_DECL_NOEXCEPT_EXPR(noexcept(!(p1 < p2)))
{
return !(p1 < p2);
}
template <class T1, class T2>
Q_DECL_CONSTEXPR Q_OUTOFLINE_TEMPLATE QPair<T1, T2> qMakePair(const T1 &x, const T2 &y)
+ Q_DECL_NOEXCEPT_EXPR(noexcept(QPair<T1, T2>(x, y)))
{
return QPair<T1, T2>(x, y);
}
diff --git a/src/corelib/tools/qpair.qdoc b/src/corelib/tools/qpair.qdoc
index be329a0df0..f7b3c05db0 100644
--- a/src/corelib/tools/qpair.qdoc
+++ b/src/corelib/tools/qpair.qdoc
@@ -116,6 +116,31 @@
\sa qMakePair()
*/
+/*!
+ \fn void QPair::swap(QPair &other)
+ \since 5.5
+
+ Swaps this pair with \a other.
+
+ Equivalent to
+ \code
+ qSwap(this->first, other.first);
+ qSwap(this->second, other.second);
+ \endcode
+
+ Swap overloads are found in namespace \c std as well as via
+ argument-dependent lookup (ADL) in \c{T}'s namespace.
+*/
+
+/*!
+ \fn void swap(QPair<T1, T2> &lhs, QPair<T1, T2> &rhs)
+ \overload
+ \relates QPair
+ \since 5.5
+
+ Swaps \a lhs with \a rhs.
+*/
+
/*! \fn bool operator==(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2)
\relates QPair
diff --git a/src/corelib/tools/qpoint.h b/src/corelib/tools/qpoint.h
index 5cf97b9052..70474b6d59 100644
--- a/src/corelib/tools/qpoint.h
+++ b/src/corelib/tools/qpoint.h
@@ -49,22 +49,22 @@ public:
Q_DECL_CONSTEXPR inline int x() const;
Q_DECL_CONSTEXPR inline int y() const;
- inline void setX(int x);
- inline void setY(int y);
+ Q_DECL_RELAXED_CONSTEXPR inline void setX(int x);
+ Q_DECL_RELAXED_CONSTEXPR inline void setY(int y);
Q_DECL_CONSTEXPR inline int manhattanLength() const;
- inline int &rx();
- inline int &ry();
+ Q_DECL_RELAXED_CONSTEXPR inline int &rx();
+ Q_DECL_RELAXED_CONSTEXPR inline int &ry();
- inline QPoint &operator+=(const QPoint &p);
- inline QPoint &operator-=(const QPoint &p);
+ Q_DECL_RELAXED_CONSTEXPR inline QPoint &operator+=(const QPoint &p);
+ Q_DECL_RELAXED_CONSTEXPR inline QPoint &operator-=(const QPoint &p);
- inline QPoint &operator*=(float factor);
- inline QPoint &operator*=(double factor);
- inline QPoint &operator*=(int factor);
+ Q_DECL_RELAXED_CONSTEXPR inline QPoint &operator*=(float factor);
+ Q_DECL_RELAXED_CONSTEXPR inline QPoint &operator*=(double factor);
+ Q_DECL_RELAXED_CONSTEXPR inline QPoint &operator*=(int factor);
- inline QPoint &operator/=(qreal divisor);
+ Q_DECL_RELAXED_CONSTEXPR inline QPoint &operator/=(qreal divisor);
Q_DECL_CONSTEXPR static inline int dotProduct(const QPoint &p1, const QPoint &p2)
{ return p1.xp * p2.xp + p1.yp * p2.yp; }
@@ -116,34 +116,34 @@ Q_DECL_CONSTEXPR inline int QPoint::x() const
Q_DECL_CONSTEXPR inline int QPoint::y() const
{ return yp; }
-inline void QPoint::setX(int xpos)
+Q_DECL_RELAXED_CONSTEXPR inline void QPoint::setX(int xpos)
{ xp = xpos; }
-inline void QPoint::setY(int ypos)
+Q_DECL_RELAXED_CONSTEXPR inline void QPoint::setY(int ypos)
{ yp = ypos; }
inline int Q_DECL_CONSTEXPR QPoint::manhattanLength() const
{ return qAbs(x())+qAbs(y()); }
-inline int &QPoint::rx()
+Q_DECL_RELAXED_CONSTEXPR inline int &QPoint::rx()
{ return xp; }
-inline int &QPoint::ry()
+Q_DECL_RELAXED_CONSTEXPR inline int &QPoint::ry()
{ return yp; }
-inline QPoint &QPoint::operator+=(const QPoint &p)
+Q_DECL_RELAXED_CONSTEXPR inline QPoint &QPoint::operator+=(const QPoint &p)
{ xp+=p.xp; yp+=p.yp; return *this; }
-inline QPoint &QPoint::operator-=(const QPoint &p)
+Q_DECL_RELAXED_CONSTEXPR inline QPoint &QPoint::operator-=(const QPoint &p)
{ xp-=p.xp; yp-=p.yp; return *this; }
-inline QPoint &QPoint::operator*=(float factor)
+Q_DECL_RELAXED_CONSTEXPR inline QPoint &QPoint::operator*=(float factor)
{ xp = qRound(xp*factor); yp = qRound(yp*factor); return *this; }
-inline QPoint &QPoint::operator*=(double factor)
+Q_DECL_RELAXED_CONSTEXPR inline QPoint &QPoint::operator*=(double factor)
{ xp = qRound(xp*factor); yp = qRound(yp*factor); return *this; }
-inline QPoint &QPoint::operator*=(int factor)
+Q_DECL_RELAXED_CONSTEXPR inline QPoint &QPoint::operator*=(int factor)
{ xp = xp*factor; yp = yp*factor; return *this; }
Q_DECL_CONSTEXPR inline bool operator==(const QPoint &p1, const QPoint &p2)
@@ -182,7 +182,7 @@ Q_DECL_CONSTEXPR inline const QPoint operator+(const QPoint &p)
Q_DECL_CONSTEXPR inline const QPoint operator-(const QPoint &p)
{ return QPoint(-p.xp, -p.yp); }
-inline QPoint &QPoint::operator/=(qreal c)
+Q_DECL_RELAXED_CONSTEXPR inline QPoint &QPoint::operator/=(qreal c)
{
xp = qRound(xp/c);
yp = qRound(yp/c);
@@ -215,16 +215,16 @@ public:
Q_DECL_CONSTEXPR inline qreal x() const;
Q_DECL_CONSTEXPR inline qreal y() const;
- inline void setX(qreal x);
- inline void setY(qreal y);
+ Q_DECL_RELAXED_CONSTEXPR inline void setX(qreal x);
+ Q_DECL_RELAXED_CONSTEXPR inline void setY(qreal y);
- inline qreal &rx();
- inline qreal &ry();
+ Q_DECL_RELAXED_CONSTEXPR inline qreal &rx();
+ Q_DECL_RELAXED_CONSTEXPR inline qreal &ry();
- inline QPointF &operator+=(const QPointF &p);
- inline QPointF &operator-=(const QPointF &p);
- inline QPointF &operator*=(qreal c);
- inline QPointF &operator/=(qreal c);
+ Q_DECL_RELAXED_CONSTEXPR inline QPointF &operator+=(const QPointF &p);
+ Q_DECL_RELAXED_CONSTEXPR inline QPointF &operator-=(const QPointF &p);
+ Q_DECL_RELAXED_CONSTEXPR inline QPointF &operator*=(qreal c);
+ Q_DECL_RELAXED_CONSTEXPR inline QPointF &operator/=(qreal c);
Q_DECL_CONSTEXPR static inline qreal dotProduct(const QPointF &p1, const QPointF &p2)
{ return p1.xp * p2.xp + p1.yp * p2.yp; }
@@ -289,39 +289,39 @@ Q_DECL_CONSTEXPR inline qreal QPointF::y() const
return yp;
}
-inline void QPointF::setX(qreal xpos)
+Q_DECL_RELAXED_CONSTEXPR inline void QPointF::setX(qreal xpos)
{
xp = xpos;
}
-inline void QPointF::setY(qreal ypos)
+Q_DECL_RELAXED_CONSTEXPR inline void QPointF::setY(qreal ypos)
{
yp = ypos;
}
-inline qreal &QPointF::rx()
+Q_DECL_RELAXED_CONSTEXPR inline qreal &QPointF::rx()
{
return xp;
}
-inline qreal &QPointF::ry()
+Q_DECL_RELAXED_CONSTEXPR inline qreal &QPointF::ry()
{
return yp;
}
-inline QPointF &QPointF::operator+=(const QPointF &p)
+Q_DECL_RELAXED_CONSTEXPR inline QPointF &QPointF::operator+=(const QPointF &p)
{
xp+=p.xp;
yp+=p.yp;
return *this;
}
-inline QPointF &QPointF::operator-=(const QPointF &p)
+Q_DECL_RELAXED_CONSTEXPR inline QPointF &QPointF::operator-=(const QPointF &p)
{
xp-=p.xp; yp-=p.yp; return *this;
}
-inline QPointF &QPointF::operator*=(qreal c)
+Q_DECL_RELAXED_CONSTEXPR inline QPointF &QPointF::operator*=(qreal c)
{
xp*=c; yp*=c; return *this;
}
@@ -366,7 +366,7 @@ Q_DECL_CONSTEXPR inline const QPointF operator-(const QPointF &p)
return QPointF(-p.xp, -p.yp);
}
-inline QPointF &QPointF::operator/=(qreal divisor)
+Q_DECL_RELAXED_CONSTEXPR inline QPointF &QPointF::operator/=(qreal divisor)
{
xp/=divisor;
yp/=divisor;
diff --git a/src/corelib/tools/qrect.cpp b/src/corelib/tools/qrect.cpp
index dc46f85fb5..ed53db0838 100644
--- a/src/corelib/tools/qrect.cpp
+++ b/src/corelib/tools/qrect.cpp
@@ -36,8 +36,6 @@
#include "qdebug.h"
#include "qmath.h"
-#include <math.h>
-
QT_BEGIN_NAMESPACE
/*!
@@ -295,7 +293,7 @@ QT_BEGIN_NAMESPACE
\sa isValid(), isEmpty()
*/
-QRect QRect::normalized() const
+QRect QRect::normalized() const Q_DECL_NOTHROW
{
QRect r;
if (x2 < x1 - 1) { // swap bad x values
@@ -804,7 +802,7 @@ QRect QRect::normalized() const
\sa intersects()
*/
-bool QRect::contains(const QPoint &p, bool proper) const
+bool QRect::contains(const QPoint &p, bool proper) const Q_DECL_NOTHROW
{
int l, r;
if (x2 < x1 - 1) {
@@ -868,7 +866,7 @@ bool QRect::contains(const QPoint &p, bool proper) const
rectangle (not on the edge).
*/
-bool QRect::contains(const QRect &r, bool proper) const
+bool QRect::contains(const QRect &r, bool proper) const Q_DECL_NOTHROW
{
if (isNull() || r.isNull())
return false;
@@ -946,7 +944,7 @@ bool QRect::contains(const QRect &r, bool proper) const
\sa operator|=(), united()
*/
-QRect QRect::operator|(const QRect &r) const
+QRect QRect::operator|(const QRect &r) const Q_DECL_NOTHROW
{
if (isNull())
return r;
@@ -1017,7 +1015,7 @@ QRect QRect::operator|(const QRect &r) const
\sa operator&=(), intersected()
*/
-QRect QRect::operator&(const QRect &r) const
+QRect QRect::operator&(const QRect &r) const Q_DECL_NOTHROW
{
if (isNull() || r.isNull())
return QRect();
@@ -1096,7 +1094,7 @@ QRect QRect::operator&(const QRect &r) const
\sa contains()
*/
-bool QRect::intersects(const QRect &r) const
+bool QRect::intersects(const QRect &r) const Q_DECL_NOTHROW
{
if (isNull() || r.isNull())
return false;
@@ -1522,7 +1520,7 @@ QDebug operator<<(QDebug dbg, const QRect &r)
\sa isValid(), isEmpty()
*/
-QRectF QRectF::normalized() const
+QRectF QRectF::normalized() const Q_DECL_NOTHROW
{
QRectF r = *this;
if (r.w < 0) {
@@ -1935,7 +1933,7 @@ QRectF QRectF::normalized() const
\sa intersects()
*/
-bool QRectF::contains(const QPointF &p) const
+bool QRectF::contains(const QPointF &p) const Q_DECL_NOTHROW
{
qreal l = xp;
qreal r = xp;
@@ -1981,7 +1979,7 @@ bool QRectF::contains(const QPointF &p) const
otherwise returns \c false.
*/
-bool QRectF::contains(const QRectF &r) const
+bool QRectF::contains(const QRectF &r) const Q_DECL_NOTHROW
{
qreal l1 = xp;
qreal r1 = xp;
@@ -2119,7 +2117,7 @@ bool QRectF::contains(const QRectF &r) const
\sa united(), operator|=()
*/
-QRectF QRectF::operator|(const QRectF &r) const
+QRectF QRectF::operator|(const QRectF &r) const Q_DECL_NOTHROW
{
if (isNull())
return r;
@@ -2188,7 +2186,7 @@ QRectF QRectF::operator|(const QRectF &r) const
\sa operator&=(), intersected()
*/
-QRectF QRectF::operator&(const QRectF &r) const
+QRectF QRectF::operator&(const QRectF &r) const Q_DECL_NOTHROW
{
qreal l1 = xp;
qreal r1 = xp;
@@ -2273,7 +2271,7 @@ QRectF QRectF::operator&(const QRectF &r) const
\sa contains()
*/
-bool QRectF::intersects(const QRectF &r) const
+bool QRectF::intersects(const QRectF &r) const Q_DECL_NOTHROW
{
qreal l1 = xp;
qreal r1 = xp;
@@ -2340,7 +2338,7 @@ bool QRectF::intersects(const QRectF &r) const
\sa toRect()
*/
-QRect QRectF::toAlignedRect() const
+QRect QRectF::toAlignedRect() const Q_DECL_NOTHROW
{
int xmin = int(qFloor(xp));
int xmax = int(qCeil(xp + w));
diff --git a/src/corelib/tools/qrect.h b/src/corelib/tools/qrect.h
index b5be5724af..a98ef565f7 100644
--- a/src/corelib/tools/qrect.h
+++ b/src/corelib/tools/qrect.h
@@ -47,100 +47,100 @@ QT_BEGIN_NAMESPACE
class Q_CORE_EXPORT QRect
{
public:
- Q_DECL_CONSTEXPR QRect() : x1(0), y1(0), x2(-1), y2(-1) {}
- Q_DECL_CONSTEXPR QRect(const QPoint &topleft, const QPoint &bottomright);
- Q_DECL_CONSTEXPR QRect(const QPoint &topleft, const QSize &size);
- Q_DECL_CONSTEXPR QRect(int left, int top, int width, int height);
-
- Q_DECL_CONSTEXPR inline bool isNull() const;
- Q_DECL_CONSTEXPR inline bool isEmpty() const;
- Q_DECL_CONSTEXPR inline bool isValid() const;
-
- Q_DECL_CONSTEXPR inline int left() const;
- Q_DECL_CONSTEXPR inline int top() const;
- Q_DECL_CONSTEXPR inline int right() const;
- Q_DECL_CONSTEXPR inline int bottom() const;
- QRect normalized() const Q_REQUIRED_RESULT;
-
- Q_DECL_CONSTEXPR inline int x() const;
- Q_DECL_CONSTEXPR inline int y() const;
- inline void setLeft(int pos);
- inline void setTop(int pos);
- inline void setRight(int pos);
- inline void setBottom(int pos);
- inline void setX(int x);
- inline void setY(int y);
-
- inline void setTopLeft(const QPoint &p);
- inline void setBottomRight(const QPoint &p);
- inline void setTopRight(const QPoint &p);
- inline void setBottomLeft(const QPoint &p);
-
- Q_DECL_CONSTEXPR inline QPoint topLeft() const;
- Q_DECL_CONSTEXPR inline QPoint bottomRight() const;
- Q_DECL_CONSTEXPR inline QPoint topRight() const;
- Q_DECL_CONSTEXPR inline QPoint bottomLeft() const;
- Q_DECL_CONSTEXPR inline QPoint center() const;
-
- inline void moveLeft(int pos);
- inline void moveTop(int pos);
- inline void moveRight(int pos);
- inline void moveBottom(int pos);
- inline void moveTopLeft(const QPoint &p);
- inline void moveBottomRight(const QPoint &p);
- inline void moveTopRight(const QPoint &p);
- inline void moveBottomLeft(const QPoint &p);
- inline void moveCenter(const QPoint &p);
-
- inline void translate(int dx, int dy);
- inline void translate(const QPoint &p);
- Q_DECL_CONSTEXPR inline QRect translated(int dx, int dy) const Q_REQUIRED_RESULT;
- Q_DECL_CONSTEXPR inline QRect translated(const QPoint &p) const Q_REQUIRED_RESULT;
-
- inline void moveTo(int x, int t);
- inline void moveTo(const QPoint &p);
-
- inline void setRect(int x, int y, int w, int h);
- inline void getRect(int *x, int *y, int *w, int *h) const;
-
- inline void setCoords(int x1, int y1, int x2, int y2);
- inline void getCoords(int *x1, int *y1, int *x2, int *y2) const;
-
- inline void adjust(int x1, int y1, int x2, int y2);
- Q_DECL_CONSTEXPR inline QRect adjusted(int x1, int y1, int x2, int y2) const Q_REQUIRED_RESULT;
-
- Q_DECL_CONSTEXPR inline QSize size() const;
- Q_DECL_CONSTEXPR inline int width() const;
- Q_DECL_CONSTEXPR inline int height() const;
- inline void setWidth(int w);
- inline void setHeight(int h);
- inline void setSize(const QSize &s);
-
- QRect operator|(const QRect &r) const;
- QRect operator&(const QRect &r) const;
- inline QRect& operator|=(const QRect &r);
- inline QRect& operator&=(const QRect &r);
-
- bool contains(const QRect &r, bool proper = false) const;
- bool contains(const QPoint &p, bool proper=false) const;
- inline bool contains(int x, int y) const;
- inline bool contains(int x, int y, bool proper) const;
- inline QRect united(const QRect &other) const Q_REQUIRED_RESULT;
- inline QRect intersected(const QRect &other) const Q_REQUIRED_RESULT;
- bool intersects(const QRect &r) const;
-
- Q_DECL_CONSTEXPR inline QRect marginsAdded(const QMargins &margins) const;
- Q_DECL_CONSTEXPR inline QRect marginsRemoved(const QMargins &margins) const;
- inline QRect &operator+=(const QMargins &margins);
- inline QRect &operator-=(const QMargins &margins);
+ Q_DECL_CONSTEXPR QRect() Q_DECL_NOTHROW : x1(0), y1(0), x2(-1), y2(-1) {}
+ Q_DECL_CONSTEXPR QRect(const QPoint &topleft, const QPoint &bottomright) Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR QRect(const QPoint &topleft, const QSize &size) Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR QRect(int left, int top, int width, int height) Q_DECL_NOTHROW;
+
+ Q_DECL_CONSTEXPR inline bool isNull() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline bool isEmpty() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline bool isValid() const Q_DECL_NOTHROW;
+
+ Q_DECL_CONSTEXPR inline int left() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline int top() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline int right() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline int bottom() const Q_DECL_NOTHROW;
+ QRect normalized() const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+
+ Q_DECL_CONSTEXPR inline int x() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline int y() const Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setLeft(int pos) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setTop(int pos) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setRight(int pos) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setBottom(int pos) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setX(int x) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setY(int y) Q_DECL_NOTHROW;
+
+ Q_DECL_RELAXED_CONSTEXPR inline void setTopLeft(const QPoint &p) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setBottomRight(const QPoint &p) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setTopRight(const QPoint &p) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setBottomLeft(const QPoint &p) Q_DECL_NOTHROW;
+
+ Q_DECL_CONSTEXPR inline QPoint topLeft() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline QPoint bottomRight() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline QPoint topRight() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline QPoint bottomLeft() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline QPoint center() const Q_DECL_NOTHROW;
+
+ Q_DECL_RELAXED_CONSTEXPR inline void moveLeft(int pos) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void moveTop(int pos) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void moveRight(int pos) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void moveBottom(int pos) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void moveTopLeft(const QPoint &p) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void moveBottomRight(const QPoint &p) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void moveTopRight(const QPoint &p) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void moveBottomLeft(const QPoint &p) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void moveCenter(const QPoint &p) Q_DECL_NOTHROW;
+
+ Q_DECL_RELAXED_CONSTEXPR inline void translate(int dx, int dy) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void translate(const QPoint &p) Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline QRect translated(int dx, int dy) const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+ Q_DECL_CONSTEXPR inline QRect translated(const QPoint &p) const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+
+ Q_DECL_RELAXED_CONSTEXPR inline void moveTo(int x, int t) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void moveTo(const QPoint &p) Q_DECL_NOTHROW;
+
+ Q_DECL_RELAXED_CONSTEXPR inline void setRect(int x, int y, int w, int h) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void getRect(int *x, int *y, int *w, int *h) const;
+
+ Q_DECL_RELAXED_CONSTEXPR inline void setCoords(int x1, int y1, int x2, int y2) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void getCoords(int *x1, int *y1, int *x2, int *y2) const;
+
+ Q_DECL_RELAXED_CONSTEXPR inline void adjust(int x1, int y1, int x2, int y2) Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline QRect adjusted(int x1, int y1, int x2, int y2) const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+
+ Q_DECL_CONSTEXPR inline QSize size() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline int width() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline int height() const Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setWidth(int w) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setHeight(int h) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setSize(const QSize &s) Q_DECL_NOTHROW;
+
+ QRect operator|(const QRect &r) const Q_DECL_NOTHROW;
+ QRect operator&(const QRect &r) const Q_DECL_NOTHROW;
+ inline QRect& operator|=(const QRect &r) Q_DECL_NOTHROW;
+ inline QRect& operator&=(const QRect &r) Q_DECL_NOTHROW;
+
+ bool contains(const QRect &r, bool proper = false) const Q_DECL_NOTHROW;
+ bool contains(const QPoint &p, bool proper=false) const Q_DECL_NOTHROW;
+ inline bool contains(int x, int y) const Q_DECL_NOTHROW;
+ inline bool contains(int x, int y, bool proper) const Q_DECL_NOTHROW;
+ inline QRect united(const QRect &other) const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+ inline QRect intersected(const QRect &other) const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+ bool intersects(const QRect &r) const Q_DECL_NOTHROW;
+
+ Q_DECL_CONSTEXPR inline QRect marginsAdded(const QMargins &margins) const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline QRect marginsRemoved(const QMargins &margins) const Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline QRect &operator+=(const QMargins &margins) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline QRect &operator-=(const QMargins &margins) Q_DECL_NOTHROW;
#if QT_DEPRECATED_SINCE(5, 0)
- QT_DEPRECATED QRect unite(const QRect &r) const Q_REQUIRED_RESULT { return united(r); }
- QT_DEPRECATED QRect intersect(const QRect &r) const Q_REQUIRED_RESULT { return intersected(r); }
+ QT_DEPRECATED QRect unite(const QRect &r) const Q_DECL_NOTHROW Q_REQUIRED_RESULT { return united(r); }
+ QT_DEPRECATED QRect intersect(const QRect &r) const Q_DECL_NOTHROW Q_REQUIRED_RESULT { return intersected(r); }
#endif
- friend Q_DECL_CONSTEXPR inline bool operator==(const QRect &, const QRect &);
- friend Q_DECL_CONSTEXPR inline bool operator!=(const QRect &, const QRect &);
+ friend Q_DECL_CONSTEXPR inline bool operator==(const QRect &, const QRect &) Q_DECL_NOTHROW;
+ friend Q_DECL_CONSTEXPR inline bool operator!=(const QRect &, const QRect &) Q_DECL_NOTHROW;
private:
int x1;
@@ -150,8 +150,8 @@ private:
};
Q_DECLARE_TYPEINFO(QRect, Q_MOVABLE_TYPE);
-Q_DECL_CONSTEXPR inline bool operator==(const QRect &, const QRect &);
-Q_DECL_CONSTEXPR inline bool operator!=(const QRect &, const QRect &);
+Q_DECL_CONSTEXPR inline bool operator==(const QRect &, const QRect &) Q_DECL_NOTHROW;
+Q_DECL_CONSTEXPR inline bool operator!=(const QRect &, const QRect &) Q_DECL_NOTHROW;
/*****************************************************************************
@@ -166,97 +166,97 @@ Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QRect &);
QRect inline member functions
*****************************************************************************/
-Q_DECL_CONSTEXPR inline QRect::QRect(int aleft, int atop, int awidth, int aheight)
+Q_DECL_CONSTEXPR inline QRect::QRect(int aleft, int atop, int awidth, int aheight) Q_DECL_NOTHROW
: x1(aleft), y1(atop), x2(aleft + awidth - 1), y2(atop + aheight - 1) {}
-Q_DECL_CONSTEXPR inline QRect::QRect(const QPoint &atopLeft, const QPoint &abottomRight)
+Q_DECL_CONSTEXPR inline QRect::QRect(const QPoint &atopLeft, const QPoint &abottomRight) Q_DECL_NOTHROW
: x1(atopLeft.x()), y1(atopLeft.y()), x2(abottomRight.x()), y2(abottomRight.y()) {}
-Q_DECL_CONSTEXPR inline QRect::QRect(const QPoint &atopLeft, const QSize &asize)
+Q_DECL_CONSTEXPR inline QRect::QRect(const QPoint &atopLeft, const QSize &asize) Q_DECL_NOTHROW
: x1(atopLeft.x()), y1(atopLeft.y()), x2(atopLeft.x()+asize.width() - 1), y2(atopLeft.y()+asize.height() - 1) {}
-Q_DECL_CONSTEXPR inline bool QRect::isNull() const
+Q_DECL_CONSTEXPR inline bool QRect::isNull() const Q_DECL_NOTHROW
{ return x2 == x1 - 1 && y2 == y1 - 1; }
-Q_DECL_CONSTEXPR inline bool QRect::isEmpty() const
+Q_DECL_CONSTEXPR inline bool QRect::isEmpty() const Q_DECL_NOTHROW
{ return x1 > x2 || y1 > y2; }
-Q_DECL_CONSTEXPR inline bool QRect::isValid() const
+Q_DECL_CONSTEXPR inline bool QRect::isValid() const Q_DECL_NOTHROW
{ return x1 <= x2 && y1 <= y2; }
-Q_DECL_CONSTEXPR inline int QRect::left() const
+Q_DECL_CONSTEXPR inline int QRect::left() const Q_DECL_NOTHROW
{ return x1; }
-Q_DECL_CONSTEXPR inline int QRect::top() const
+Q_DECL_CONSTEXPR inline int QRect::top() const Q_DECL_NOTHROW
{ return y1; }
-Q_DECL_CONSTEXPR inline int QRect::right() const
+Q_DECL_CONSTEXPR inline int QRect::right() const Q_DECL_NOTHROW
{ return x2; }
-Q_DECL_CONSTEXPR inline int QRect::bottom() const
+Q_DECL_CONSTEXPR inline int QRect::bottom() const Q_DECL_NOTHROW
{ return y2; }
-Q_DECL_CONSTEXPR inline int QRect::x() const
+Q_DECL_CONSTEXPR inline int QRect::x() const Q_DECL_NOTHROW
{ return x1; }
-Q_DECL_CONSTEXPR inline int QRect::y() const
+Q_DECL_CONSTEXPR inline int QRect::y() const Q_DECL_NOTHROW
{ return y1; }
-inline void QRect::setLeft(int pos)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setLeft(int pos) Q_DECL_NOTHROW
{ x1 = pos; }
-inline void QRect::setTop(int pos)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setTop(int pos) Q_DECL_NOTHROW
{ y1 = pos; }
-inline void QRect::setRight(int pos)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setRight(int pos) Q_DECL_NOTHROW
{ x2 = pos; }
-inline void QRect::setBottom(int pos)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setBottom(int pos) Q_DECL_NOTHROW
{ y2 = pos; }
-inline void QRect::setTopLeft(const QPoint &p)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setTopLeft(const QPoint &p) Q_DECL_NOTHROW
{ x1 = p.x(); y1 = p.y(); }
-inline void QRect::setBottomRight(const QPoint &p)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setBottomRight(const QPoint &p) Q_DECL_NOTHROW
{ x2 = p.x(); y2 = p.y(); }
-inline void QRect::setTopRight(const QPoint &p)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setTopRight(const QPoint &p) Q_DECL_NOTHROW
{ x2 = p.x(); y1 = p.y(); }
-inline void QRect::setBottomLeft(const QPoint &p)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setBottomLeft(const QPoint &p) Q_DECL_NOTHROW
{ x1 = p.x(); y2 = p.y(); }
-inline void QRect::setX(int ax)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setX(int ax) Q_DECL_NOTHROW
{ x1 = ax; }
-inline void QRect::setY(int ay)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setY(int ay) Q_DECL_NOTHROW
{ y1 = ay; }
-Q_DECL_CONSTEXPR inline QPoint QRect::topLeft() const
+Q_DECL_CONSTEXPR inline QPoint QRect::topLeft() const Q_DECL_NOTHROW
{ return QPoint(x1, y1); }
-Q_DECL_CONSTEXPR inline QPoint QRect::bottomRight() const
+Q_DECL_CONSTEXPR inline QPoint QRect::bottomRight() const Q_DECL_NOTHROW
{ return QPoint(x2, y2); }
-Q_DECL_CONSTEXPR inline QPoint QRect::topRight() const
+Q_DECL_CONSTEXPR inline QPoint QRect::topRight() const Q_DECL_NOTHROW
{ return QPoint(x2, y1); }
-Q_DECL_CONSTEXPR inline QPoint QRect::bottomLeft() const
+Q_DECL_CONSTEXPR inline QPoint QRect::bottomLeft() const Q_DECL_NOTHROW
{ return QPoint(x1, y2); }
-Q_DECL_CONSTEXPR inline QPoint QRect::center() const
+Q_DECL_CONSTEXPR inline QPoint QRect::center() const Q_DECL_NOTHROW
{ return QPoint((x1+x2)/2, (y1+y2)/2); }
-Q_DECL_CONSTEXPR inline int QRect::width() const
+Q_DECL_CONSTEXPR inline int QRect::width() const Q_DECL_NOTHROW
{ return x2 - x1 + 1; }
-Q_DECL_CONSTEXPR inline int QRect::height() const
+Q_DECL_CONSTEXPR inline int QRect::height() const Q_DECL_NOTHROW
{ return y2 - y1 + 1; }
-Q_DECL_CONSTEXPR inline QSize QRect::size() const
+Q_DECL_CONSTEXPR inline QSize QRect::size() const Q_DECL_NOTHROW
{ return QSize(width(), height()); }
-inline void QRect::translate(int dx, int dy)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::translate(int dx, int dy) Q_DECL_NOTHROW
{
x1 += dx;
y1 += dy;
@@ -264,7 +264,7 @@ inline void QRect::translate(int dx, int dy)
y2 += dy;
}
-inline void QRect::translate(const QPoint &p)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::translate(const QPoint &p) Q_DECL_NOTHROW
{
x1 += p.x();
y1 += p.y();
@@ -272,13 +272,13 @@ inline void QRect::translate(const QPoint &p)
y2 += p.y();
}
-Q_DECL_CONSTEXPR inline QRect QRect::translated(int dx, int dy) const
+Q_DECL_CONSTEXPR inline QRect QRect::translated(int dx, int dy) const Q_DECL_NOTHROW
{ return QRect(QPoint(x1 + dx, y1 + dy), QPoint(x2 + dx, y2 + dy)); }
-Q_DECL_CONSTEXPR inline QRect QRect::translated(const QPoint &p) const
+Q_DECL_CONSTEXPR inline QRect QRect::translated(const QPoint &p) const Q_DECL_NOTHROW
{ return QRect(QPoint(x1 + p.x(), y1 + p.y()), QPoint(x2 + p.x(), y2 + p.y())); }
-inline void QRect::moveTo(int ax, int ay)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveTo(int ax, int ay) Q_DECL_NOTHROW
{
x2 += ax - x1;
y2 += ay - y1;
@@ -286,7 +286,7 @@ inline void QRect::moveTo(int ax, int ay)
y1 = ay;
}
-inline void QRect::moveTo(const QPoint &p)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveTo(const QPoint &p) Q_DECL_NOTHROW
{
x2 += p.x() - x1;
y2 += p.y() - y1;
@@ -294,49 +294,49 @@ inline void QRect::moveTo(const QPoint &p)
y1 = p.y();
}
-inline void QRect::moveLeft(int pos)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveLeft(int pos) Q_DECL_NOTHROW
{ x2 += (pos - x1); x1 = pos; }
-inline void QRect::moveTop(int pos)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveTop(int pos) Q_DECL_NOTHROW
{ y2 += (pos - y1); y1 = pos; }
-inline void QRect::moveRight(int pos)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveRight(int pos) Q_DECL_NOTHROW
{
x1 += (pos - x2);
x2 = pos;
}
-inline void QRect::moveBottom(int pos)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveBottom(int pos) Q_DECL_NOTHROW
{
y1 += (pos - y2);
y2 = pos;
}
-inline void QRect::moveTopLeft(const QPoint &p)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveTopLeft(const QPoint &p) Q_DECL_NOTHROW
{
moveLeft(p.x());
moveTop(p.y());
}
-inline void QRect::moveBottomRight(const QPoint &p)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveBottomRight(const QPoint &p) Q_DECL_NOTHROW
{
moveRight(p.x());
moveBottom(p.y());
}
-inline void QRect::moveTopRight(const QPoint &p)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveTopRight(const QPoint &p) Q_DECL_NOTHROW
{
moveRight(p.x());
moveTop(p.y());
}
-inline void QRect::moveBottomLeft(const QPoint &p)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveBottomLeft(const QPoint &p) Q_DECL_NOTHROW
{
moveLeft(p.x());
moveBottom(p.y());
}
-inline void QRect::moveCenter(const QPoint &p)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveCenter(const QPoint &p) Q_DECL_NOTHROW
{
int w = x2 - x1;
int h = y2 - y1;
@@ -346,7 +346,7 @@ inline void QRect::moveCenter(const QPoint &p)
y2 = y1 + h;
}
-inline void QRect::getRect(int *ax, int *ay, int *aw, int *ah) const
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::getRect(int *ax, int *ay, int *aw, int *ah) const
{
*ax = x1;
*ay = y1;
@@ -354,7 +354,7 @@ inline void QRect::getRect(int *ax, int *ay, int *aw, int *ah) const
*ah = y2 - y1 + 1;
}
-inline void QRect::setRect(int ax, int ay, int aw, int ah)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setRect(int ax, int ay, int aw, int ah) Q_DECL_NOTHROW
{
x1 = ax;
y1 = ay;
@@ -362,7 +362,7 @@ inline void QRect::setRect(int ax, int ay, int aw, int ah)
y2 = (ay + ah - 1);
}
-inline void QRect::getCoords(int *xp1, int *yp1, int *xp2, int *yp2) const
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::getCoords(int *xp1, int *yp1, int *xp2, int *yp2) const
{
*xp1 = x1;
*yp1 = y1;
@@ -370,7 +370,7 @@ inline void QRect::getCoords(int *xp1, int *yp1, int *xp2, int *yp2) const
*yp2 = y2;
}
-inline void QRect::setCoords(int xp1, int yp1, int xp2, int yp2)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setCoords(int xp1, int yp1, int xp2, int yp2) Q_DECL_NOTHROW
{
x1 = xp1;
y1 = yp1;
@@ -378,10 +378,10 @@ inline void QRect::setCoords(int xp1, int yp1, int xp2, int yp2)
y2 = yp2;
}
-Q_DECL_CONSTEXPR inline QRect QRect::adjusted(int xp1, int yp1, int xp2, int yp2) const
+Q_DECL_CONSTEXPR inline QRect QRect::adjusted(int xp1, int yp1, int xp2, int yp2) const Q_DECL_NOTHROW
{ return QRect(QPoint(x1 + xp1, y1 + yp1), QPoint(x2 + xp2, y2 + yp2)); }
-inline void QRect::adjust(int dx1, int dy1, int dx2, int dy2)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::adjust(int dx1, int dy1, int dx2, int dy2) Q_DECL_NOTHROW
{
x1 += dx1;
y1 += dy1;
@@ -389,97 +389,97 @@ inline void QRect::adjust(int dx1, int dy1, int dx2, int dy2)
y2 += dy2;
}
-inline void QRect::setWidth(int w)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setWidth(int w) Q_DECL_NOTHROW
{ x2 = (x1 + w - 1); }
-inline void QRect::setHeight(int h)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setHeight(int h) Q_DECL_NOTHROW
{ y2 = (y1 + h - 1); }
-inline void QRect::setSize(const QSize &s)
+Q_DECL_RELAXED_CONSTEXPR inline void QRect::setSize(const QSize &s) Q_DECL_NOTHROW
{
x2 = (s.width() + x1 - 1);
y2 = (s.height() + y1 - 1);
}
-inline bool QRect::contains(int ax, int ay, bool aproper) const
+inline bool QRect::contains(int ax, int ay, bool aproper) const Q_DECL_NOTHROW
{
return contains(QPoint(ax, ay), aproper);
}
-inline bool QRect::contains(int ax, int ay) const
+inline bool QRect::contains(int ax, int ay) const Q_DECL_NOTHROW
{
return contains(QPoint(ax, ay), false);
}
-inline QRect& QRect::operator|=(const QRect &r)
+inline QRect& QRect::operator|=(const QRect &r) Q_DECL_NOTHROW
{
*this = *this | r;
return *this;
}
-inline QRect& QRect::operator&=(const QRect &r)
+inline QRect& QRect::operator&=(const QRect &r) Q_DECL_NOTHROW
{
*this = *this & r;
return *this;
}
-inline QRect QRect::intersected(const QRect &other) const
+inline QRect QRect::intersected(const QRect &other) const Q_DECL_NOTHROW
{
return *this & other;
}
-inline QRect QRect::united(const QRect &r) const
+inline QRect QRect::united(const QRect &r) const Q_DECL_NOTHROW
{
return *this | r;
}
-Q_DECL_CONSTEXPR inline bool operator==(const QRect &r1, const QRect &r2)
+Q_DECL_CONSTEXPR inline bool operator==(const QRect &r1, const QRect &r2) Q_DECL_NOTHROW
{
return r1.x1==r2.x1 && r1.x2==r2.x2 && r1.y1==r2.y1 && r1.y2==r2.y2;
}
-Q_DECL_CONSTEXPR inline bool operator!=(const QRect &r1, const QRect &r2)
+Q_DECL_CONSTEXPR inline bool operator!=(const QRect &r1, const QRect &r2) Q_DECL_NOTHROW
{
return r1.x1!=r2.x1 || r1.x2!=r2.x2 || r1.y1!=r2.y1 || r1.y2!=r2.y2;
}
-Q_DECL_CONSTEXPR inline QRect operator+(const QRect &rectangle, const QMargins &margins)
+Q_DECL_CONSTEXPR inline QRect operator+(const QRect &rectangle, const QMargins &margins) Q_DECL_NOTHROW
{
return QRect(QPoint(rectangle.left() - margins.left(), rectangle.top() - margins.top()),
QPoint(rectangle.right() + margins.right(), rectangle.bottom() + margins.bottom()));
}
-Q_DECL_CONSTEXPR inline QRect operator+(const QMargins &margins, const QRect &rectangle)
+Q_DECL_CONSTEXPR inline QRect operator+(const QMargins &margins, const QRect &rectangle) Q_DECL_NOTHROW
{
return QRect(QPoint(rectangle.left() - margins.left(), rectangle.top() - margins.top()),
QPoint(rectangle.right() + margins.right(), rectangle.bottom() + margins.bottom()));
}
-Q_DECL_CONSTEXPR inline QRect operator-(const QRect &lhs, const QMargins &rhs)
+Q_DECL_CONSTEXPR inline QRect operator-(const QRect &lhs, const QMargins &rhs) Q_DECL_NOTHROW
{
return QRect(QPoint(lhs.left() + rhs.left(), lhs.top() + rhs.top()),
QPoint(lhs.right() - rhs.right(), lhs.bottom() - rhs.bottom()));
}
-Q_DECL_CONSTEXPR inline QRect QRect::marginsAdded(const QMargins &margins) const
+Q_DECL_CONSTEXPR inline QRect QRect::marginsAdded(const QMargins &margins) const Q_DECL_NOTHROW
{
return QRect(QPoint(x1 - margins.left(), y1 - margins.top()),
QPoint(x2 + margins.right(), y2 + margins.bottom()));
}
-Q_DECL_CONSTEXPR inline QRect QRect::marginsRemoved(const QMargins &margins) const
+Q_DECL_CONSTEXPR inline QRect QRect::marginsRemoved(const QMargins &margins) const Q_DECL_NOTHROW
{
return QRect(QPoint(x1 + margins.left(), y1 + margins.top()),
QPoint(x2 - margins.right(), y2 - margins.bottom()));
}
-inline QRect &QRect::operator+=(const QMargins &margins)
+Q_DECL_RELAXED_CONSTEXPR inline QRect &QRect::operator+=(const QMargins &margins) Q_DECL_NOTHROW
{
*this = marginsAdded(margins);
return *this;
}
-inline QRect &QRect::operator-=(const QMargins &margins)
+Q_DECL_RELAXED_CONSTEXPR inline QRect &QRect::operator-=(const QMargins &margins) Q_DECL_NOTHROW
{
*this = marginsRemoved(margins);
return *this;
@@ -493,104 +493,104 @@ Q_CORE_EXPORT QDebug operator<<(QDebug, const QRect &);
class Q_CORE_EXPORT QRectF
{
public:
- Q_DECL_CONSTEXPR QRectF() : xp(0.), yp(0.), w(0.), h(0.) {}
- Q_DECL_CONSTEXPR QRectF(const QPointF &topleft, const QSizeF &size);
- Q_DECL_CONSTEXPR QRectF(const QPointF &topleft, const QPointF &bottomRight);
- Q_DECL_CONSTEXPR QRectF(qreal left, qreal top, qreal width, qreal height);
- Q_DECL_CONSTEXPR QRectF(const QRect &rect);
-
- Q_DECL_CONSTEXPR inline bool isNull() const;
- Q_DECL_CONSTEXPR inline bool isEmpty() const;
- Q_DECL_CONSTEXPR inline bool isValid() const;
- QRectF normalized() const Q_REQUIRED_RESULT;
-
- Q_DECL_CONSTEXPR inline qreal left() const { return xp; }
- Q_DECL_CONSTEXPR inline qreal top() const { return yp; }
- Q_DECL_CONSTEXPR inline qreal right() const { return xp + w; }
- Q_DECL_CONSTEXPR inline qreal bottom() const { return yp + h; }
-
- Q_DECL_CONSTEXPR inline qreal x() const;
- Q_DECL_CONSTEXPR inline qreal y() const;
- inline void setLeft(qreal pos);
- inline void setTop(qreal pos);
- inline void setRight(qreal pos);
- inline void setBottom(qreal pos);
- inline void setX(qreal pos) { setLeft(pos); }
- inline void setY(qreal pos) { setTop(pos); }
-
- Q_DECL_CONSTEXPR inline QPointF topLeft() const { return QPointF(xp, yp); }
- Q_DECL_CONSTEXPR inline QPointF bottomRight() const { return QPointF(xp+w, yp+h); }
- Q_DECL_CONSTEXPR inline QPointF topRight() const { return QPointF(xp+w, yp); }
- Q_DECL_CONSTEXPR inline QPointF bottomLeft() const { return QPointF(xp, yp+h); }
- Q_DECL_CONSTEXPR inline QPointF center() const;
-
- inline void setTopLeft(const QPointF &p);
- inline void setBottomRight(const QPointF &p);
- inline void setTopRight(const QPointF &p);
- inline void setBottomLeft(const QPointF &p);
-
- inline void moveLeft(qreal pos);
- inline void moveTop(qreal pos);
- inline void moveRight(qreal pos);
- inline void moveBottom(qreal pos);
- inline void moveTopLeft(const QPointF &p);
- inline void moveBottomRight(const QPointF &p);
- inline void moveTopRight(const QPointF &p);
- inline void moveBottomLeft(const QPointF &p);
- inline void moveCenter(const QPointF &p);
-
- inline void translate(qreal dx, qreal dy);
- inline void translate(const QPointF &p);
-
- Q_DECL_CONSTEXPR inline QRectF translated(qreal dx, qreal dy) const Q_REQUIRED_RESULT;
- Q_DECL_CONSTEXPR inline QRectF translated(const QPointF &p) const Q_REQUIRED_RESULT;
-
- inline void moveTo(qreal x, qreal y);
- inline void moveTo(const QPointF &p);
-
- inline void setRect(qreal x, qreal y, qreal w, qreal h);
- inline void getRect(qreal *x, qreal *y, qreal *w, qreal *h) const;
-
- inline void setCoords(qreal x1, qreal y1, qreal x2, qreal y2);
- inline void getCoords(qreal *x1, qreal *y1, qreal *x2, qreal *y2) const;
-
- inline void adjust(qreal x1, qreal y1, qreal x2, qreal y2);
- Q_DECL_CONSTEXPR inline QRectF adjusted(qreal x1, qreal y1, qreal x2, qreal y2) const Q_REQUIRED_RESULT;
-
- Q_DECL_CONSTEXPR inline QSizeF size() const;
- Q_DECL_CONSTEXPR inline qreal width() const;
- Q_DECL_CONSTEXPR inline qreal height() const;
- inline void setWidth(qreal w);
- inline void setHeight(qreal h);
- inline void setSize(const QSizeF &s);
-
- QRectF operator|(const QRectF &r) const;
- QRectF operator&(const QRectF &r) const;
- inline QRectF& operator|=(const QRectF &r);
- inline QRectF& operator&=(const QRectF &r);
-
- bool contains(const QRectF &r) const;
- bool contains(const QPointF &p) const;
- inline bool contains(qreal x, qreal y) const;
- inline QRectF united(const QRectF &other) const Q_REQUIRED_RESULT;
- inline QRectF intersected(const QRectF &other) const Q_REQUIRED_RESULT;
- bool intersects(const QRectF &r) const;
-
- Q_DECL_CONSTEXPR inline QRectF marginsAdded(const QMarginsF &margins) const;
- Q_DECL_CONSTEXPR inline QRectF marginsRemoved(const QMarginsF &margins) const;
- inline QRectF &operator+=(const QMarginsF &margins);
- inline QRectF &operator-=(const QMarginsF &margins);
+ Q_DECL_CONSTEXPR QRectF() Q_DECL_NOTHROW : xp(0.), yp(0.), w(0.), h(0.) {}
+ Q_DECL_CONSTEXPR QRectF(const QPointF &topleft, const QSizeF &size) Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR QRectF(const QPointF &topleft, const QPointF &bottomRight) Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR QRectF(qreal left, qreal top, qreal width, qreal height) Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR QRectF(const QRect &rect) Q_DECL_NOTHROW;
+
+ Q_DECL_CONSTEXPR inline bool isNull() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline bool isEmpty() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline bool isValid() const Q_DECL_NOTHROW;
+ QRectF normalized() const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+
+ Q_DECL_CONSTEXPR inline qreal left() const Q_DECL_NOTHROW { return xp; }
+ Q_DECL_CONSTEXPR inline qreal top() const Q_DECL_NOTHROW { return yp; }
+ Q_DECL_CONSTEXPR inline qreal right() const Q_DECL_NOTHROW { return xp + w; }
+ Q_DECL_CONSTEXPR inline qreal bottom() const Q_DECL_NOTHROW { return yp + h; }
+
+ Q_DECL_CONSTEXPR inline qreal x() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline qreal y() const Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setLeft(qreal pos) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setTop(qreal pos) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setRight(qreal pos) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setBottom(qreal pos) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setX(qreal pos) Q_DECL_NOTHROW { setLeft(pos); }
+ Q_DECL_RELAXED_CONSTEXPR inline void setY(qreal pos) Q_DECL_NOTHROW { setTop(pos); }
+
+ Q_DECL_CONSTEXPR inline QPointF topLeft() const Q_DECL_NOTHROW { return QPointF(xp, yp); }
+ Q_DECL_CONSTEXPR inline QPointF bottomRight() const Q_DECL_NOTHROW { return QPointF(xp+w, yp+h); }
+ Q_DECL_CONSTEXPR inline QPointF topRight() const Q_DECL_NOTHROW { return QPointF(xp+w, yp); }
+ Q_DECL_CONSTEXPR inline QPointF bottomLeft() const Q_DECL_NOTHROW { return QPointF(xp, yp+h); }
+ Q_DECL_CONSTEXPR inline QPointF center() const Q_DECL_NOTHROW;
+
+ Q_DECL_RELAXED_CONSTEXPR inline void setTopLeft(const QPointF &p) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setBottomRight(const QPointF &p) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setTopRight(const QPointF &p) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setBottomLeft(const QPointF &p) Q_DECL_NOTHROW;
+
+ Q_DECL_RELAXED_CONSTEXPR inline void moveLeft(qreal pos) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void moveTop(qreal pos) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void moveRight(qreal pos) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void moveBottom(qreal pos) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void moveTopLeft(const QPointF &p) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void moveBottomRight(const QPointF &p) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void moveTopRight(const QPointF &p) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void moveBottomLeft(const QPointF &p) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void moveCenter(const QPointF &p) Q_DECL_NOTHROW;
+
+ Q_DECL_RELAXED_CONSTEXPR inline void translate(qreal dx, qreal dy) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void translate(const QPointF &p) Q_DECL_NOTHROW;
+
+ Q_DECL_CONSTEXPR inline QRectF translated(qreal dx, qreal dy) const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+ Q_DECL_CONSTEXPR inline QRectF translated(const QPointF &p) const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+
+ Q_DECL_RELAXED_CONSTEXPR inline void moveTo(qreal x, qreal y) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void moveTo(const QPointF &p) Q_DECL_NOTHROW;
+
+ Q_DECL_RELAXED_CONSTEXPR inline void setRect(qreal x, qreal y, qreal w, qreal h) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void getRect(qreal *x, qreal *y, qreal *w, qreal *h) const;
+
+ Q_DECL_RELAXED_CONSTEXPR inline void setCoords(qreal x1, qreal y1, qreal x2, qreal y2) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void getCoords(qreal *x1, qreal *y1, qreal *x2, qreal *y2) const;
+
+ Q_DECL_RELAXED_CONSTEXPR inline void adjust(qreal x1, qreal y1, qreal x2, qreal y2) Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline QRectF adjusted(qreal x1, qreal y1, qreal x2, qreal y2) const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+
+ Q_DECL_CONSTEXPR inline QSizeF size() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline qreal width() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline qreal height() const Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setWidth(qreal w) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setHeight(qreal h) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setSize(const QSizeF &s) Q_DECL_NOTHROW;
+
+ QRectF operator|(const QRectF &r) const Q_DECL_NOTHROW;
+ QRectF operator&(const QRectF &r) const Q_DECL_NOTHROW;
+ inline QRectF& operator|=(const QRectF &r) Q_DECL_NOTHROW;
+ inline QRectF& operator&=(const QRectF &r) Q_DECL_NOTHROW;
+
+ bool contains(const QRectF &r) const Q_DECL_NOTHROW;
+ bool contains(const QPointF &p) const Q_DECL_NOTHROW;
+ inline bool contains(qreal x, qreal y) const Q_DECL_NOTHROW;
+ inline QRectF united(const QRectF &other) const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+ inline QRectF intersected(const QRectF &other) const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+ bool intersects(const QRectF &r) const Q_DECL_NOTHROW;
+
+ Q_DECL_CONSTEXPR inline QRectF marginsAdded(const QMarginsF &margins) const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline QRectF marginsRemoved(const QMarginsF &margins) const Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline QRectF &operator+=(const QMarginsF &margins) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline QRectF &operator-=(const QMarginsF &margins) Q_DECL_NOTHROW;
#if QT_DEPRECATED_SINCE(5, 0)
- QT_DEPRECATED QRectF unite(const QRectF &r) const Q_REQUIRED_RESULT { return united(r); }
- QT_DEPRECATED QRectF intersect(const QRectF &r) const Q_REQUIRED_RESULT { return intersected(r); }
+ QT_DEPRECATED QRectF unite(const QRectF &r) const Q_DECL_NOTHROW Q_REQUIRED_RESULT { return united(r); }
+ QT_DEPRECATED QRectF intersect(const QRectF &r) const Q_DECL_NOTHROW Q_REQUIRED_RESULT { return intersected(r); }
#endif
- friend Q_DECL_CONSTEXPR inline bool operator==(const QRectF &, const QRectF &);
- friend Q_DECL_CONSTEXPR inline bool operator!=(const QRectF &, const QRectF &);
+ friend Q_DECL_CONSTEXPR inline bool operator==(const QRectF &, const QRectF &) Q_DECL_NOTHROW;
+ friend Q_DECL_CONSTEXPR inline bool operator!=(const QRectF &, const QRectF &) Q_DECL_NOTHROW;
- Q_DECL_CONSTEXPR inline QRect toRect() const Q_REQUIRED_RESULT;
- QRect toAlignedRect() const Q_REQUIRED_RESULT;
+ Q_DECL_CONSTEXPR inline QRect toRect() const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+ QRect toAlignedRect() const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
private:
qreal xp;
@@ -600,8 +600,8 @@ private:
};
Q_DECLARE_TYPEINFO(QRectF, Q_MOVABLE_TYPE);
-Q_DECL_CONSTEXPR inline bool operator==(const QRectF &, const QRectF &);
-Q_DECL_CONSTEXPR inline bool operator!=(const QRectF &, const QRectF &);
+Q_DECL_CONSTEXPR inline bool operator==(const QRectF &, const QRectF &) Q_DECL_NOTHROW;
+Q_DECL_CONSTEXPR inline bool operator!=(const QRectF &, const QRectF &) Q_DECL_NOTHROW;
/*****************************************************************************
@@ -616,119 +616,136 @@ Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QRectF &);
QRectF inline member functions
*****************************************************************************/
-Q_DECL_CONSTEXPR inline QRectF::QRectF(qreal aleft, qreal atop, qreal awidth, qreal aheight)
+Q_DECL_CONSTEXPR inline QRectF::QRectF(qreal aleft, qreal atop, qreal awidth, qreal aheight) Q_DECL_NOTHROW
: xp(aleft), yp(atop), w(awidth), h(aheight)
{
}
-Q_DECL_CONSTEXPR inline QRectF::QRectF(const QPointF &atopLeft, const QSizeF &asize)
+Q_DECL_CONSTEXPR inline QRectF::QRectF(const QPointF &atopLeft, const QSizeF &asize) Q_DECL_NOTHROW
: xp(atopLeft.x()), yp(atopLeft.y()), w(asize.width()), h(asize.height())
{
}
-Q_DECL_CONSTEXPR inline QRectF::QRectF(const QPointF &atopLeft, const QPointF &abottomRight)
+Q_DECL_CONSTEXPR inline QRectF::QRectF(const QPointF &atopLeft, const QPointF &abottomRight) Q_DECL_NOTHROW
: xp(atopLeft.x()), yp(atopLeft.y()), w(abottomRight.x() - atopLeft.x()), h(abottomRight.y() - atopLeft.y())
{
}
-Q_DECL_CONSTEXPR inline QRectF::QRectF(const QRect &r)
+Q_DECL_CONSTEXPR inline QRectF::QRectF(const QRect &r) Q_DECL_NOTHROW
: xp(r.x()), yp(r.y()), w(r.width()), h(r.height())
{
}
-Q_DECL_CONSTEXPR inline bool QRectF::isNull() const
+Q_DECL_CONSTEXPR inline bool QRectF::isNull() const Q_DECL_NOTHROW
{ return w == 0. && h == 0.; }
-Q_DECL_CONSTEXPR inline bool QRectF::isEmpty() const
+Q_DECL_CONSTEXPR inline bool QRectF::isEmpty() const Q_DECL_NOTHROW
{ return w <= 0. || h <= 0.; }
-Q_DECL_CONSTEXPR inline bool QRectF::isValid() const
+Q_DECL_CONSTEXPR inline bool QRectF::isValid() const Q_DECL_NOTHROW
{ return w > 0. && h > 0.; }
-Q_DECL_CONSTEXPR inline qreal QRectF::x() const
+Q_DECL_CONSTEXPR inline qreal QRectF::x() const Q_DECL_NOTHROW
{ return xp; }
-Q_DECL_CONSTEXPR inline qreal QRectF::y() const
+Q_DECL_CONSTEXPR inline qreal QRectF::y() const Q_DECL_NOTHROW
{ return yp; }
-inline void QRectF::setLeft(qreal pos) { qreal diff = pos - xp; xp += diff; w -= diff; }
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setLeft(qreal pos) Q_DECL_NOTHROW
+{ qreal diff = pos - xp; xp += diff; w -= diff; }
-inline void QRectF::setRight(qreal pos) { w = pos - xp; }
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setRight(qreal pos) Q_DECL_NOTHROW
+{ w = pos - xp; }
-inline void QRectF::setTop(qreal pos) { qreal diff = pos - yp; yp += diff; h -= diff; }
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setTop(qreal pos) Q_DECL_NOTHROW
+{ qreal diff = pos - yp; yp += diff; h -= diff; }
-inline void QRectF::setBottom(qreal pos) { h = pos - yp; }
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setBottom(qreal pos) Q_DECL_NOTHROW
+{ h = pos - yp; }
-inline void QRectF::setTopLeft(const QPointF &p) { setLeft(p.x()); setTop(p.y()); }
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setTopLeft(const QPointF &p) Q_DECL_NOTHROW
+{ setLeft(p.x()); setTop(p.y()); }
-inline void QRectF::setTopRight(const QPointF &p) { setRight(p.x()); setTop(p.y()); }
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setTopRight(const QPointF &p) Q_DECL_NOTHROW
+{ setRight(p.x()); setTop(p.y()); }
-inline void QRectF::setBottomLeft(const QPointF &p) { setLeft(p.x()); setBottom(p.y()); }
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setBottomLeft(const QPointF &p) Q_DECL_NOTHROW
+{ setLeft(p.x()); setBottom(p.y()); }
-inline void QRectF::setBottomRight(const QPointF &p) { setRight(p.x()); setBottom(p.y()); }
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setBottomRight(const QPointF &p) Q_DECL_NOTHROW
+{ setRight(p.x()); setBottom(p.y()); }
-Q_DECL_CONSTEXPR inline QPointF QRectF::center() const
+Q_DECL_CONSTEXPR inline QPointF QRectF::center() const Q_DECL_NOTHROW
{ return QPointF(xp + w/2, yp + h/2); }
-inline void QRectF::moveLeft(qreal pos) { xp = pos; }
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveLeft(qreal pos) Q_DECL_NOTHROW
+{ xp = pos; }
-inline void QRectF::moveTop(qreal pos) { yp = pos; }
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveTop(qreal pos) Q_DECL_NOTHROW
+{ yp = pos; }
-inline void QRectF::moveRight(qreal pos) { xp = pos - w; }
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveRight(qreal pos) Q_DECL_NOTHROW
+{ xp = pos - w; }
-inline void QRectF::moveBottom(qreal pos) { yp = pos - h; }
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveBottom(qreal pos) Q_DECL_NOTHROW
+{ yp = pos - h; }
-inline void QRectF::moveTopLeft(const QPointF &p) { moveLeft(p.x()); moveTop(p.y()); }
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveTopLeft(const QPointF &p) Q_DECL_NOTHROW
+{ moveLeft(p.x()); moveTop(p.y()); }
-inline void QRectF::moveTopRight(const QPointF &p) { moveRight(p.x()); moveTop(p.y()); }
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveTopRight(const QPointF &p) Q_DECL_NOTHROW
+{ moveRight(p.x()); moveTop(p.y()); }
-inline void QRectF::moveBottomLeft(const QPointF &p) { moveLeft(p.x()); moveBottom(p.y()); }
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveBottomLeft(const QPointF &p) Q_DECL_NOTHROW
+{ moveLeft(p.x()); moveBottom(p.y()); }
-inline void QRectF::moveBottomRight(const QPointF &p) { moveRight(p.x()); moveBottom(p.y()); }
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveBottomRight(const QPointF &p) Q_DECL_NOTHROW
+{ moveRight(p.x()); moveBottom(p.y()); }
-inline void QRectF::moveCenter(const QPointF &p) { xp = p.x() - w/2; yp = p.y() - h/2; }
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveCenter(const QPointF &p) Q_DECL_NOTHROW
+{ xp = p.x() - w/2; yp = p.y() - h/2; }
-Q_DECL_CONSTEXPR inline qreal QRectF::width() const
+Q_DECL_CONSTEXPR inline qreal QRectF::width() const Q_DECL_NOTHROW
{ return w; }
-Q_DECL_CONSTEXPR inline qreal QRectF::height() const
+Q_DECL_CONSTEXPR inline qreal QRectF::height() const Q_DECL_NOTHROW
{ return h; }
-Q_DECL_CONSTEXPR inline QSizeF QRectF::size() const
+Q_DECL_CONSTEXPR inline QSizeF QRectF::size() const Q_DECL_NOTHROW
{ return QSizeF(w, h); }
-inline void QRectF::translate(qreal dx, qreal dy)
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::translate(qreal dx, qreal dy) Q_DECL_NOTHROW
{
xp += dx;
yp += dy;
}
-inline void QRectF::translate(const QPointF &p)
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::translate(const QPointF &p) Q_DECL_NOTHROW
{
xp += p.x();
yp += p.y();
}
-inline void QRectF::moveTo(qreal ax, qreal ay)
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveTo(qreal ax, qreal ay) Q_DECL_NOTHROW
{
xp = ax;
yp = ay;
}
-inline void QRectF::moveTo(const QPointF &p)
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::moveTo(const QPointF &p) Q_DECL_NOTHROW
{
xp = p.x();
yp = p.y();
}
-Q_DECL_CONSTEXPR inline QRectF QRectF::translated(qreal dx, qreal dy) const
+Q_DECL_CONSTEXPR inline QRectF QRectF::translated(qreal dx, qreal dy) const Q_DECL_NOTHROW
{ return QRectF(xp + dx, yp + dy, w, h); }
-Q_DECL_CONSTEXPR inline QRectF QRectF::translated(const QPointF &p) const
+Q_DECL_CONSTEXPR inline QRectF QRectF::translated(const QPointF &p) const Q_DECL_NOTHROW
{ return QRectF(xp + p.x(), yp + p.y(), w, h); }
-inline void QRectF::getRect(qreal *ax, qreal *ay, qreal *aaw, qreal *aah) const
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::getRect(qreal *ax, qreal *ay, qreal *aaw, qreal *aah) const
{
*ax = this->xp;
*ay = this->yp;
@@ -736,7 +753,7 @@ inline void QRectF::getRect(qreal *ax, qreal *ay, qreal *aaw, qreal *aah) const
*aah = this->h;
}
-inline void QRectF::setRect(qreal ax, qreal ay, qreal aaw, qreal aah)
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setRect(qreal ax, qreal ay, qreal aaw, qreal aah) Q_DECL_NOTHROW
{
this->xp = ax;
this->yp = ay;
@@ -744,7 +761,7 @@ inline void QRectF::setRect(qreal ax, qreal ay, qreal aaw, qreal aah)
this->h = aah;
}
-inline void QRectF::getCoords(qreal *xp1, qreal *yp1, qreal *xp2, qreal *yp2) const
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::getCoords(qreal *xp1, qreal *yp1, qreal *xp2, qreal *yp2) const
{
*xp1 = xp;
*yp1 = yp;
@@ -752,7 +769,7 @@ inline void QRectF::getCoords(qreal *xp1, qreal *yp1, qreal *xp2, qreal *yp2) co
*yp2 = yp + h;
}
-inline void QRectF::setCoords(qreal xp1, qreal yp1, qreal xp2, qreal yp2)
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setCoords(qreal xp1, qreal yp1, qreal xp2, qreal yp2) Q_DECL_NOTHROW
{
xp = xp1;
yp = yp1;
@@ -760,105 +777,105 @@ inline void QRectF::setCoords(qreal xp1, qreal yp1, qreal xp2, qreal yp2)
h = yp2 - yp1;
}
-inline void QRectF::adjust(qreal xp1, qreal yp1, qreal xp2, qreal yp2)
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::adjust(qreal xp1, qreal yp1, qreal xp2, qreal yp2) Q_DECL_NOTHROW
{ xp += xp1; yp += yp1; w += xp2 - xp1; h += yp2 - yp1; }
-Q_DECL_CONSTEXPR inline QRectF QRectF::adjusted(qreal xp1, qreal yp1, qreal xp2, qreal yp2) const
+Q_DECL_CONSTEXPR inline QRectF QRectF::adjusted(qreal xp1, qreal yp1, qreal xp2, qreal yp2) const Q_DECL_NOTHROW
{ return QRectF(xp + xp1, yp + yp1, w + xp2 - xp1, h + yp2 - yp1); }
-inline void QRectF::setWidth(qreal aw)
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setWidth(qreal aw) Q_DECL_NOTHROW
{ this->w = aw; }
-inline void QRectF::setHeight(qreal ah)
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setHeight(qreal ah) Q_DECL_NOTHROW
{ this->h = ah; }
-inline void QRectF::setSize(const QSizeF &s)
+Q_DECL_RELAXED_CONSTEXPR inline void QRectF::setSize(const QSizeF &s) Q_DECL_NOTHROW
{
w = s.width();
h = s.height();
}
-inline bool QRectF::contains(qreal ax, qreal ay) const
+inline bool QRectF::contains(qreal ax, qreal ay) const Q_DECL_NOTHROW
{
return contains(QPointF(ax, ay));
}
-inline QRectF& QRectF::operator|=(const QRectF &r)
+inline QRectF& QRectF::operator|=(const QRectF &r) Q_DECL_NOTHROW
{
*this = *this | r;
return *this;
}
-inline QRectF& QRectF::operator&=(const QRectF &r)
+inline QRectF& QRectF::operator&=(const QRectF &r) Q_DECL_NOTHROW
{
*this = *this & r;
return *this;
}
-inline QRectF QRectF::intersected(const QRectF &r) const
+inline QRectF QRectF::intersected(const QRectF &r) const Q_DECL_NOTHROW
{
return *this & r;
}
-inline QRectF QRectF::united(const QRectF &r) const
+inline QRectF QRectF::united(const QRectF &r) const Q_DECL_NOTHROW
{
return *this | r;
}
-Q_DECL_CONSTEXPR inline bool operator==(const QRectF &r1, const QRectF &r2)
+Q_DECL_CONSTEXPR inline bool operator==(const QRectF &r1, const QRectF &r2) Q_DECL_NOTHROW
{
return qFuzzyCompare(r1.xp, r2.xp) && qFuzzyCompare(r1.yp, r2.yp)
&& qFuzzyCompare(r1.w, r2.w) && qFuzzyCompare(r1.h, r2.h);
}
-Q_DECL_CONSTEXPR inline bool operator!=(const QRectF &r1, const QRectF &r2)
+Q_DECL_CONSTEXPR inline bool operator!=(const QRectF &r1, const QRectF &r2) Q_DECL_NOTHROW
{
return !qFuzzyCompare(r1.xp, r2.xp) || !qFuzzyCompare(r1.yp, r2.yp)
|| !qFuzzyCompare(r1.w, r2.w) || !qFuzzyCompare(r1.h, r2.h);
}
-Q_DECL_CONSTEXPR inline QRect QRectF::toRect() const
+Q_DECL_CONSTEXPR inline QRect QRectF::toRect() const Q_DECL_NOTHROW
{
return QRect(qRound(xp), qRound(yp), qRound(w), qRound(h));
}
-Q_DECL_CONSTEXPR inline QRectF operator+(const QRectF &lhs, const QMarginsF &rhs)
+Q_DECL_CONSTEXPR inline QRectF operator+(const QRectF &lhs, const QMarginsF &rhs) Q_DECL_NOTHROW
{
return QRectF(QPointF(lhs.left() - rhs.left(), lhs.top() - rhs.top()),
QSizeF(lhs.width() + rhs.left() + rhs.right(), lhs.height() + rhs.top() + rhs.bottom()));
}
-Q_DECL_CONSTEXPR inline QRectF operator+(const QMarginsF &lhs, const QRectF &rhs)
+Q_DECL_CONSTEXPR inline QRectF operator+(const QMarginsF &lhs, const QRectF &rhs) Q_DECL_NOTHROW
{
return QRectF(QPointF(rhs.left() - lhs.left(), rhs.top() - lhs.top()),
QSizeF(rhs.width() + lhs.left() + lhs.right(), rhs.height() + lhs.top() + lhs.bottom()));
}
-Q_DECL_CONSTEXPR inline QRectF operator-(const QRectF &lhs, const QMarginsF &rhs)
+Q_DECL_CONSTEXPR inline QRectF operator-(const QRectF &lhs, const QMarginsF &rhs) Q_DECL_NOTHROW
{
return QRectF(QPointF(lhs.left() + rhs.left(), lhs.top() + rhs.top()),
QSizeF(lhs.width() - rhs.left() - rhs.right(), lhs.height() - rhs.top() - rhs.bottom()));
}
-Q_DECL_CONSTEXPR inline QRectF QRectF::marginsAdded(const QMarginsF &margins) const
+Q_DECL_CONSTEXPR inline QRectF QRectF::marginsAdded(const QMarginsF &margins) const Q_DECL_NOTHROW
{
return QRectF(QPointF(xp - margins.left(), yp - margins.top()),
QSizeF(w + margins.left() + margins.right(), h + margins.top() + margins.bottom()));
}
-Q_DECL_CONSTEXPR inline QRectF QRectF::marginsRemoved(const QMarginsF &margins) const
+Q_DECL_CONSTEXPR inline QRectF QRectF::marginsRemoved(const QMarginsF &margins) const Q_DECL_NOTHROW
{
return QRectF(QPointF(xp + margins.left(), yp + margins.top()),
QSizeF(w - margins.left() - margins.right(), h - margins.top() - margins.bottom()));
}
-inline QRectF &QRectF::operator+=(const QMarginsF &margins)
+Q_DECL_RELAXED_CONSTEXPR inline QRectF &QRectF::operator+=(const QMarginsF &margins) Q_DECL_NOTHROW
{
*this = marginsAdded(margins);
return *this;
}
-inline QRectF &QRectF::operator-=(const QMarginsF &margins)
+Q_DECL_RELAXED_CONSTEXPR inline QRectF &QRectF::operator-=(const QMarginsF &margins) Q_DECL_NOTHROW
{
*this = marginsRemoved(margins);
return *this;
diff --git a/src/corelib/tools/qregexp.cpp b/src/corelib/tools/qregexp.cpp
index b679377fc0..71d897082b 100644
--- a/src/corelib/tools/qregexp.cpp
+++ b/src/corelib/tools/qregexp.cpp
@@ -45,7 +45,6 @@
#include "qstringlist.h"
#include "qstringmatcher.h"
#include "qvector.h"
-#include "private/qfunctions_p.h"
#include <limits.h>
#include <algorithm>
@@ -877,7 +876,7 @@ struct QRegExpEngineKey
}
};
-Q_STATIC_GLOBAL_OPERATOR bool operator==(const QRegExpEngineKey &key1, const QRegExpEngineKey &key2)
+static bool operator==(const QRegExpEngineKey &key1, const QRegExpEngineKey &key2)
{
return key1.pattern == key2.pattern && key1.patternSyntax == key2.patternSyntax
&& key1.cs == key2.cs;
diff --git a/src/corelib/tools/qregularexpression.cpp b/src/corelib/tools/qregularexpression.cpp
index 33894927fe..228ee5b842 100644
--- a/src/corelib/tools/qregularexpression.cpp
+++ b/src/corelib/tools/qregularexpression.cpp
@@ -835,6 +835,8 @@ struct QRegularExpressionPrivate : QSharedData
};
QRegularExpressionMatchPrivate *doMatch(const QString &subject,
+ int subjectStartPos,
+ int subjectLength,
int offset,
QRegularExpression::MatchType matchType,
QRegularExpression::MatchOptions matchOptions,
@@ -872,6 +874,8 @@ struct QRegularExpressionMatchPrivate : QSharedData
{
QRegularExpressionMatchPrivate(const QRegularExpression &re,
const QString &subject,
+ int subjectStart,
+ int subjectLength,
QRegularExpression::MatchType matchType,
QRegularExpression::MatchOptions matchOptions,
int capturingCount = 0);
@@ -884,6 +888,9 @@ struct QRegularExpressionMatchPrivate : QSharedData
// for each captured substring
QVector<int> capturedOffsets;
+ const int subjectStart;
+ const int subjectLength;
+
const QRegularExpression::MatchType matchType;
const QRegularExpression::MatchOptions matchOptions;
@@ -1219,14 +1226,21 @@ static int pcre16SafeExec(const pcre16 *code, const pcre16_extra *extra,
/*!
\internal
- Performs a match of type \a matchType on the given \a subject string with
- options \a matchOptions and returns the QRegularExpressionMatchPrivate of
- the result. It also advances a match if a previous result is given as \a
+ Performs a match on the substring of the given \a subject string,
+ substring which starts from \a subjectStart and up to
+ (but not including) \a subjectStart + \a subjectLength. The match
+ will be of type \a matchType and using the options \a matchOptions;
+ the matching \a offset is relative the substring,
+ and if negative, it's taken as an offset from the end of the substring.
+
+ It also advances a match if a previous result is given as \a
previous. The \a subject string goes a Unicode validity check if
\a checkSubjectString is CheckSubjectString and the match options don't
include DontCheckSubjectStringMatchOption (PCRE doesn't like illegal
UTF-16 sequences).
+ Returns the QRegularExpressionMatchPrivate of the result.
+
Advancing a match is a tricky algorithm. If the previous match matched a
non-empty string, we just do an ordinary match at the offset position.
@@ -1239,6 +1253,8 @@ static int pcre16SafeExec(const pcre16 *code, const pcre16_extra *extra,
must advance over it.
*/
QRegularExpressionMatchPrivate *QRegularExpressionPrivate::doMatch(const QString &subject,
+ int subjectStart,
+ int subjectLength,
int offset,
QRegularExpression::MatchType matchType,
QRegularExpression::MatchOptions matchOptions,
@@ -1246,21 +1262,22 @@ QRegularExpressionMatchPrivate *QRegularExpressionPrivate::doMatch(const QString
const QRegularExpressionMatchPrivate *previous) const
{
if (offset < 0)
- offset += subject.length();
+ offset += subjectLength;
QRegularExpression re(*const_cast<QRegularExpressionPrivate *>(this));
- if (offset < 0 || offset > subject.length())
- return new QRegularExpressionMatchPrivate(re, subject, matchType, matchOptions);
+ if (offset < 0 || offset > subjectLength)
+ return new QRegularExpressionMatchPrivate(re, subject, subjectStart, subjectLength, matchType, matchOptions);
if (!compiledPattern) {
qWarning("QRegularExpressionPrivate::doMatch(): called on an invalid QRegularExpression object");
- return new QRegularExpressionMatchPrivate(re, subject, matchType, matchOptions);
+ return new QRegularExpressionMatchPrivate(re, subject, subjectStart, subjectLength, matchType, matchOptions);
}
// skip optimizing and doing the actual matching if NoMatch type was requested
if (matchType == QRegularExpression::NoMatch) {
QRegularExpressionMatchPrivate *priv = new QRegularExpressionMatchPrivate(re, subject,
+ subjectStart, subjectLength,
matchType, matchOptions);
priv->isValid = true;
return priv;
@@ -1268,6 +1285,7 @@ QRegularExpressionMatchPrivate *QRegularExpressionPrivate::doMatch(const QString
// capturingCount doesn't include the implicit "0" capturing group
QRegularExpressionMatchPrivate *priv = new QRegularExpressionMatchPrivate(re, subject,
+ subjectStart, subjectLength,
matchType, matchOptions,
capturingCount + 1);
@@ -1307,45 +1325,49 @@ QRegularExpressionMatchPrivate *QRegularExpressionPrivate::doMatch(const QString
int * const captureOffsets = priv->capturedOffsets.data();
const int captureOffsetsCount = priv->capturedOffsets.size();
+ int realOffset = offset + subjectStart;
+ const int realSubjectLength = subjectLength + subjectStart;
+
const unsigned short * const subjectUtf16 = subject.utf16();
- const int subjectLength = subject.length();
int result;
if (!previousMatchWasEmpty) {
result = pcre16SafeExec(compiledPattern, currentStudyData,
- subjectUtf16, subjectLength,
- offset, pcreOptions,
+ subjectUtf16, realSubjectLength,
+ realOffset, pcreOptions,
captureOffsets, captureOffsetsCount);
} else {
result = pcre16SafeExec(compiledPattern, currentStudyData,
- subjectUtf16, subjectLength,
- offset, pcreOptions | PCRE_NOTEMPTY_ATSTART | PCRE_ANCHORED,
+ subjectUtf16, realSubjectLength,
+ realOffset, pcreOptions | PCRE_NOTEMPTY_ATSTART | PCRE_ANCHORED,
captureOffsets, captureOffsetsCount);
if (result == PCRE_ERROR_NOMATCH) {
- ++offset;
+ ++realOffset;
if (usingCrLfNewlines
- && offset < subjectLength
- && subjectUtf16[offset - 1] == QLatin1Char('\r')
- && subjectUtf16[offset] == QLatin1Char('\n')) {
- ++offset;
- } else if (offset < subjectLength
- && QChar::isLowSurrogate(subjectUtf16[offset])) {
- ++offset;
+ && realOffset < realSubjectLength
+ && subjectUtf16[realOffset - 1] == QLatin1Char('\r')
+ && subjectUtf16[realOffset] == QLatin1Char('\n')) {
+ ++realOffset;
+ } else if (realOffset < realSubjectLength
+ && QChar::isLowSurrogate(subjectUtf16[realOffset])) {
+ ++realOffset;
}
result = pcre16SafeExec(compiledPattern, currentStudyData,
- subjectUtf16, subjectLength,
- offset, pcreOptions,
+ subjectUtf16, realSubjectLength,
+ realOffset, pcreOptions,
captureOffsets, captureOffsetsCount);
}
}
#ifdef QREGULAREXPRESSION_DEBUG
qDebug() << "Matching" << pattern << "against" << subject
- << offset << matchType << matchOptions << previousMatchWasEmpty
+ << "starting at" << subjectStart << "len" << subjectLength << "real len" << realSubjectLength
+ << "offset" << offset << "real offset" << realOffset
+ << matchType << matchOptions << previousMatchWasEmpty
<< "result" << result;
#endif
@@ -1383,10 +1405,13 @@ QRegularExpressionMatchPrivate *QRegularExpressionPrivate::doMatch(const QString
*/
QRegularExpressionMatchPrivate::QRegularExpressionMatchPrivate(const QRegularExpression &re,
const QString &subject,
+ int subjectStart,
+ int subjectLength,
QRegularExpression::MatchType matchType,
QRegularExpression::MatchOptions matchOptions,
int capturingCount)
: regularExpression(re), subject(subject),
+ subjectStart(subjectStart), subjectLength(subjectLength),
matchType(matchType), matchOptions(matchOptions),
capturedCount(0),
hasMatch(false), hasPartialMatch(false), isValid(false)
@@ -1412,6 +1437,8 @@ QRegularExpressionMatch QRegularExpressionMatchPrivate::nextMatch() const
// then that subject was already checked at least once (when this object
// was created, or when the object that created this one was created, etc.)
QRegularExpressionMatchPrivate *nextPrivate = regularExpression.d->doMatch(subject,
+ subjectStart,
+ subjectLength,
capturedOffsets.at(1),
matchType,
matchOptions,
@@ -1684,7 +1711,33 @@ QRegularExpressionMatch QRegularExpression::match(const QString &subject,
{
d.data()->compilePattern();
- QRegularExpressionMatchPrivate *priv = d->doMatch(subject, offset, matchType, matchOptions);
+ QRegularExpressionMatchPrivate *priv = d->doMatch(subject, 0, subject.length(), offset, matchType, matchOptions);
+ return QRegularExpressionMatch(*priv);
+}
+
+/*!
+ \since 5.5
+ \overload
+
+ Attempts to match the regular expression against the given \a subjectRef
+ string reference, starting at the position \a offset inside the subject, using a
+ match of type \a matchType and honoring the given \a matchOptions.
+
+ The returned QRegularExpressionMatch object contains the results of the
+ match.
+
+ \sa QRegularExpressionMatch, {normal matching}
+*/
+QRegularExpressionMatch QRegularExpression::match(const QStringRef &subjectRef,
+ int offset,
+ MatchType matchType,
+ MatchOptions matchOptions) const
+{
+ d.data()->compilePattern();
+
+ const QString subject = subjectRef.string() ? *subjectRef.string() : QString();
+
+ QRegularExpressionMatchPrivate *priv = d->doMatch(subject, subjectRef.position(), subjectRef.length(), offset, matchType, matchOptions);
return QRegularExpressionMatch(*priv);
}
@@ -1714,6 +1767,34 @@ QRegularExpressionMatchIterator QRegularExpression::globalMatch(const QString &s
}
/*!
+ \since 5.5
+ \overload
+
+ Attempts to perform a global match of the regular expression against the
+ given \a subjectRef string reference, starting at the position \a offset inside the
+ subject, using a match of type \a matchType and honoring the given \a
+ matchOptions.
+
+ The returned QRegularExpressionMatchIterator is positioned before the
+ first match result (if any).
+
+ \sa QRegularExpressionMatchIterator, {global matching}
+*/
+QRegularExpressionMatchIterator QRegularExpression::globalMatch(const QStringRef &subjectRef,
+ int offset,
+ MatchType matchType,
+ MatchOptions matchOptions) const
+{
+ QRegularExpressionMatchIteratorPrivate *priv =
+ new QRegularExpressionMatchIteratorPrivate(*this,
+ matchType,
+ matchOptions,
+ match(subjectRef, offset, matchType, matchOptions));
+
+ return QRegularExpressionMatchIterator(*priv);
+}
+
+/*!
\since 5.4
Forces an immediate optimization of the pattern, including
@@ -1823,6 +1904,8 @@ QString QRegularExpression::escape(const QString &str)
QRegularExpressionMatch::QRegularExpressionMatch()
: d(new QRegularExpressionMatchPrivate(QRegularExpression(),
QString(),
+ 0,
+ 0,
QRegularExpression::NoMatch,
QRegularExpression::NoMatchOption))
{
diff --git a/src/corelib/tools/qregularexpression.h b/src/corelib/tools/qregularexpression.h
index 66538f22b3..8e19a53142 100644
--- a/src/corelib/tools/qregularexpression.h
+++ b/src/corelib/tools/qregularexpression.h
@@ -77,11 +77,11 @@ public:
QRegularExpression &operator=(const QRegularExpression &re);
#ifdef Q_COMPILER_RVALUE_REFS
- inline QRegularExpression &operator=(QRegularExpression &&re)
+ QRegularExpression &operator=(QRegularExpression &&re) Q_DECL_NOTHROW
{ d.swap(re.d); return *this; }
#endif
- inline void swap(QRegularExpression &re) { d.swap(re.d); }
+ void swap(QRegularExpression &other) Q_DECL_NOTHROW { d.swap(other.d); }
QString pattern() const;
void setPattern(const QString &pattern);
@@ -112,11 +112,21 @@ public:
MatchType matchType = NormalMatch,
MatchOptions matchOptions = NoMatchOption) const;
+ QRegularExpressionMatch match(const QStringRef &subjectRef,
+ int offset = 0,
+ MatchType matchType = NormalMatch,
+ MatchOptions matchOptions = NoMatchOption) const;
+
QRegularExpressionMatchIterator globalMatch(const QString &subject,
int offset = 0,
MatchType matchType = NormalMatch,
MatchOptions matchOptions = NoMatchOption) const;
+ QRegularExpressionMatchIterator globalMatch(const QStringRef &subjectRef,
+ int offset = 0,
+ MatchType matchType = NormalMatch,
+ MatchOptions matchOptions = NoMatchOption) const;
+
void optimize() const;
static QString escape(const QString &str);
@@ -159,10 +169,10 @@ public:
QRegularExpressionMatch &operator=(const QRegularExpressionMatch &match);
#ifdef Q_COMPILER_RVALUE_REFS
- inline QRegularExpressionMatch &operator=(QRegularExpressionMatch &&match)
+ QRegularExpressionMatch &operator=(QRegularExpressionMatch &&match) Q_DECL_NOTHROW
{ d.swap(match.d); return *this; }
#endif
- inline void swap(QRegularExpressionMatch &match) { d.swap(match.d); }
+ void swap(QRegularExpressionMatch &other) Q_DECL_NOTHROW { d.swap(other.d); }
QRegularExpression regularExpression() const;
QRegularExpression::MatchType matchType() const;
@@ -216,10 +226,10 @@ public:
QRegularExpressionMatchIterator(const QRegularExpressionMatchIterator &iterator);
QRegularExpressionMatchIterator &operator=(const QRegularExpressionMatchIterator &iterator);
#ifdef Q_COMPILER_RVALUE_REFS
- inline QRegularExpressionMatchIterator &operator=(QRegularExpressionMatchIterator &&iterator)
+ QRegularExpressionMatchIterator &operator=(QRegularExpressionMatchIterator &&iterator) Q_DECL_NOTHROW
{ d.swap(iterator.d); return *this; }
#endif
- void swap(QRegularExpressionMatchIterator &iterator) { d.swap(iterator.d); }
+ void swap(QRegularExpressionMatchIterator &other) Q_DECL_NOTHROW { d.swap(other.d); }
bool isValid() const;
diff --git a/src/corelib/tools/qringbuffer_p.h b/src/corelib/tools/qringbuffer_p.h
index 2279f1bc2a..610c099733 100644
--- a/src/corelib/tools/qringbuffer_p.h
+++ b/src/corelib/tools/qringbuffer_p.h
@@ -63,7 +63,7 @@ public:
}
inline const char *readPointer() const {
- return buffers.isEmpty() ? 0 : (buffers.first().constData() + head);
+ return bufferSize == 0 ? Q_NULLPTR : (buffers.first().constData() + head);
}
// access the bytes at a specified position
@@ -91,11 +91,20 @@ public:
int blockSize = buffers.first().size() - head;
if (tailBuffer == 0 || blockSize > bytes) {
- bufferSize -= bytes;
- if (bufferSize <= 0)
- clear(); // try to minify/squeeze us
- else
+ // keep a single block around if it does not exceed
+ // the basic block size, to avoid repeated allocations
+ // between uses of the buffer
+ if (bufferSize <= bytes) {
+ if (buffers.first().size() <= basicBlockSize) {
+ bufferSize = 0;
+ head = tail = 0;
+ } else {
+ clear(); // try to minify/squeeze us
+ }
+ } else {
head += bytes;
+ bufferSize -= bytes;
+ }
return;
}
@@ -113,7 +122,7 @@ public:
// if need buffer reallocation
if (tail + bytes > buffers.last().size()) {
- if (tail >= basicBlockSize) {
+ if (tail + bytes > buffers.last().capacity() && tail >= basicBlockSize) {
// shrink this buffer to its current size
buffers.last().resize(tail);
@@ -139,11 +148,20 @@ public:
inline void chop(int bytes) {
while (bytes > 0) {
if (tailBuffer == 0 || tail > bytes) {
- bufferSize -= bytes;
- if (bufferSize <= 0)
- clear(); // try to minify/squeeze us
- else
+ // keep a single block around if it does not exceed
+ // the basic block size, to avoid repeated allocations
+ // between uses of the buffer
+ if (bufferSize <= bytes) {
+ if (buffers.first().size() <= basicBlockSize) {
+ bufferSize = 0;
+ head = tail = 0;
+ } else {
+ clear(); // try to minify/squeeze us
+ }
+ } else {
tail -= bytes;
+ bufferSize -= bytes;
+ }
return;
}
@@ -156,7 +174,7 @@ public:
}
inline bool isEmpty() const {
- return tailBuffer == 0 && tail == 0;
+ return bufferSize == 0;
}
inline int getChar() {
@@ -175,10 +193,14 @@ public:
inline void ungetChar(char c) {
--head;
if (head < 0) {
- buffers.prepend(QByteArray());
+ if (bufferSize != 0) {
+ buffers.prepend(QByteArray());
+ ++tailBuffer;
+ } else {
+ tail = basicBlockSize;
+ }
buffers.first().resize(basicBlockSize);
head = basicBlockSize - 1;
- ++tailBuffer;
}
buffers.first()[head] = c;
++bufferSize;
diff --git a/src/corelib/tools/qset.h b/src/corelib/tools/qset.h
index 662afbf84a..baa412a550 100644
--- a/src/corelib/tools/qset.h
+++ b/src/corelib/tools/qset.h
@@ -237,6 +237,15 @@ private:
}
};
+template <typename T>
+uint qHash(const QSet<T> &key, uint seed = 0)
+Q_DECL_NOEXCEPT_EXPR(noexcept(qHashRangeCommutative(key.begin(), key.end(), seed)))
+{
+ return qHashRangeCommutative(key.begin(), key.end(), seed);
+}
+
+// inline function implementations
+
template <class T>
Q_INLINE_TEMPLATE void QSet<T>::reserve(int asize) { q_hash.reserve(asize); }
diff --git a/src/corelib/tools/qset.qdoc b/src/corelib/tools/qset.qdoc
index ab7d72611e..73599a2a72 100644
--- a/src/corelib/tools/qset.qdoc
+++ b/src/corelib/tools/qset.qdoc
@@ -968,3 +968,14 @@
\sa{Serializing Qt Data Types}{Format of the QDataStream operators}
*/
+
+/*!
+ \fn uint qHash(const QSet<T> &key, uint seed = 0)
+ \relates QHash
+ \since 5.5
+
+ Returns the hash value for the \a key, using \a seed to seed the calculation.
+
+ The hash value is independent of the order of elements in \a key, that is, sets
+ that contain the same elements hash to the same value.
+*/
diff --git a/src/corelib/tools/qshareddata.h b/src/corelib/tools/qshareddata.h
index 53f51b7f2e..183b9ff238 100644
--- a/src/corelib/tools/qshareddata.h
+++ b/src/corelib/tools/qshareddata.h
@@ -79,7 +79,7 @@ public:
inline QSharedDataPointer() { d = 0; }
inline ~QSharedDataPointer() { if (d && !d->ref.deref()) delete d; }
- explicit QSharedDataPointer(T *data);
+ explicit QSharedDataPointer(T *data) Q_DECL_NOTHROW;
inline QSharedDataPointer(const QSharedDataPointer<T> &o) : d(o.d) { if (d) d->ref.ref(); }
inline QSharedDataPointer<T> & operator=(const QSharedDataPointer<T> &o) {
if (o.d != d) {
@@ -104,14 +104,14 @@ public:
return *this;
}
#ifdef Q_COMPILER_RVALUE_REFS
- QSharedDataPointer(QSharedDataPointer &&o) : d(o.d) { o.d = 0; }
- inline QSharedDataPointer<T> &operator=(QSharedDataPointer<T> &&other)
+ QSharedDataPointer(QSharedDataPointer &&o) Q_DECL_NOTHROW : d(o.d) { o.d = Q_NULLPTR; }
+ inline QSharedDataPointer<T> &operator=(QSharedDataPointer<T> &&other) Q_DECL_NOTHROW
{ qSwap(d, other.d); return *this; }
#endif
inline bool operator!() const { return !d; }
- inline void swap(QSharedDataPointer &other)
+ inline void swap(QSharedDataPointer &other) Q_DECL_NOTHROW
{ qSwap(d, other.d); }
protected:
@@ -155,7 +155,7 @@ public:
inline QExplicitlySharedDataPointer() { d = 0; }
inline ~QExplicitlySharedDataPointer() { if (d && !d->ref.deref()) delete d; }
- explicit QExplicitlySharedDataPointer(T *data);
+ explicit QExplicitlySharedDataPointer(T *data) Q_DECL_NOTHROW;
inline QExplicitlySharedDataPointer(const QExplicitlySharedDataPointer<T> &o) : d(o.d) { if (d) d->ref.ref(); }
template<class X>
@@ -193,14 +193,14 @@ public:
return *this;
}
#ifdef Q_COMPILER_RVALUE_REFS
- inline QExplicitlySharedDataPointer(QExplicitlySharedDataPointer &&o) : d(o.d) { o.d = 0; }
- inline QExplicitlySharedDataPointer<T> &operator=(QExplicitlySharedDataPointer<T> &&other)
+ inline QExplicitlySharedDataPointer(QExplicitlySharedDataPointer &&o) Q_DECL_NOTHROW : d(o.d) { o.d = Q_NULLPTR; }
+ inline QExplicitlySharedDataPointer<T> &operator=(QExplicitlySharedDataPointer<T> &&other) Q_DECL_NOTHROW
{ qSwap(d, other.d); return *this; }
#endif
inline bool operator!() const { return !d; }
- inline void swap(QExplicitlySharedDataPointer &other)
+ inline void swap(QExplicitlySharedDataPointer &other) Q_DECL_NOTHROW
{ qSwap(d, other.d); }
protected:
@@ -213,7 +213,8 @@ private:
};
template <class T>
-Q_INLINE_TEMPLATE QSharedDataPointer<T>::QSharedDataPointer(T *adata) : d(adata)
+Q_INLINE_TEMPLATE QSharedDataPointer<T>::QSharedDataPointer(T *adata) Q_DECL_NOTHROW
+ : d(adata)
{ if (d) d->ref.ref(); }
template <class T>
@@ -249,7 +250,8 @@ Q_OUTOFLINE_TEMPLATE void QExplicitlySharedDataPointer<T>::detach_helper()
}
template <class T>
-Q_INLINE_TEMPLATE QExplicitlySharedDataPointer<T>::QExplicitlySharedDataPointer(T *adata) : d(adata)
+Q_INLINE_TEMPLATE QExplicitlySharedDataPointer<T>::QExplicitlySharedDataPointer(T *adata) Q_DECL_NOTHROW
+ : d(adata)
{ if (d) d->ref.ref(); }
template <class T>
@@ -273,12 +275,12 @@ namespace std {
QT_BEGIN_NAMESPACE
template <class T>
-Q_INLINE_TEMPLATE uint qHash(const QSharedDataPointer<T> &ptr, uint seed = 0)
+Q_INLINE_TEMPLATE uint qHash(const QSharedDataPointer<T> &ptr, uint seed = 0) Q_DECL_NOTHROW
{
return qHash(ptr.data(), seed);
}
template <class T>
-Q_INLINE_TEMPLATE uint qHash(const QExplicitlySharedDataPointer<T> &ptr, uint seed = 0)
+Q_INLINE_TEMPLATE uint qHash(const QExplicitlySharedDataPointer<T> &ptr, uint seed = 0) Q_DECL_NOTHROW
{
return qHash(ptr.data(), seed);
}
diff --git a/src/corelib/tools/qsize.cpp b/src/corelib/tools/qsize.cpp
index 4c124162a1..12673ccd0c 100644
--- a/src/corelib/tools/qsize.cpp
+++ b/src/corelib/tools/qsize.cpp
@@ -156,7 +156,7 @@ QT_BEGIN_NAMESPACE
\sa setWidth(), setHeight(), transposed()
*/
-void QSize::transpose()
+void QSize::transpose() Q_DECL_NOTHROW
{
int tmp = wd;
wd = ht;
@@ -217,7 +217,7 @@ void QSize::transpose()
Return a size scaled to a rectangle with the given size \a s,
according to the specified \a mode.
*/
-QSize QSize::scaled(const QSize &s, Qt::AspectRatioMode mode) const
+QSize QSize::scaled(const QSize &s, Qt::AspectRatioMode mode) const Q_DECL_NOTHROW
{
if (mode == Qt::IgnoreAspectRatio || wd == 0 || ht == 0) {
return s;
@@ -590,7 +590,7 @@ QDebug operator<<(QDebug dbg, const QSize &s)
\sa setWidth(), setHeight(), transposed()
*/
-void QSizeF::transpose()
+void QSizeF::transpose() Q_DECL_NOTHROW
{
qreal tmp = wd;
wd = ht;
@@ -651,7 +651,7 @@ void QSizeF::transpose()
Returns a size scaled to a rectangle with the given size \a s,
according to the specified \a mode.
*/
-QSizeF QSizeF::scaled(const QSizeF &s, Qt::AspectRatioMode mode) const
+QSizeF QSizeF::scaled(const QSizeF &s, Qt::AspectRatioMode mode) const Q_DECL_NOTHROW
{
if (mode == Qt::IgnoreAspectRatio || qIsNull(wd) || qIsNull(ht)) {
return s;
diff --git a/src/corelib/tools/qsize.h b/src/corelib/tools/qsize.h
index 6b5cf2dd7d..037b532f37 100644
--- a/src/corelib/tools/qsize.h
+++ b/src/corelib/tools/qsize.h
@@ -42,42 +42,42 @@ QT_BEGIN_NAMESPACE
class Q_CORE_EXPORT QSize
{
public:
- Q_DECL_CONSTEXPR QSize();
- Q_DECL_CONSTEXPR QSize(int w, int h);
-
- Q_DECL_CONSTEXPR inline bool isNull() const;
- Q_DECL_CONSTEXPR inline bool isEmpty() const;
- Q_DECL_CONSTEXPR inline bool isValid() const;
-
- Q_DECL_CONSTEXPR inline int width() const;
- Q_DECL_CONSTEXPR inline int height() const;
- inline void setWidth(int w);
- inline void setHeight(int h);
- void transpose();
- Q_DECL_CONSTEXPR inline QSize transposed() const;
-
- inline void scale(int w, int h, Qt::AspectRatioMode mode);
- inline void scale(const QSize &s, Qt::AspectRatioMode mode);
- QSize scaled(int w, int h, Qt::AspectRatioMode mode) const;
- QSize scaled(const QSize &s, Qt::AspectRatioMode mode) const;
-
- Q_DECL_CONSTEXPR inline QSize expandedTo(const QSize &) const;
- Q_DECL_CONSTEXPR inline QSize boundedTo(const QSize &) const;
-
- inline int &rwidth();
- inline int &rheight();
-
- inline QSize &operator+=(const QSize &);
- inline QSize &operator-=(const QSize &);
- inline QSize &operator*=(qreal c);
+ Q_DECL_CONSTEXPR QSize() Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR QSize(int w, int h) Q_DECL_NOTHROW;
+
+ Q_DECL_CONSTEXPR inline bool isNull() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline bool isEmpty() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline bool isValid() const Q_DECL_NOTHROW;
+
+ Q_DECL_CONSTEXPR inline int width() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline int height() const Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setWidth(int w) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setHeight(int h) Q_DECL_NOTHROW;
+ void transpose() Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline QSize transposed() const Q_DECL_NOTHROW;
+
+ inline void scale(int w, int h, Qt::AspectRatioMode mode) Q_DECL_NOTHROW;
+ inline void scale(const QSize &s, Qt::AspectRatioMode mode) Q_DECL_NOTHROW;
+ QSize scaled(int w, int h, Qt::AspectRatioMode mode) const Q_DECL_NOTHROW;
+ QSize scaled(const QSize &s, Qt::AspectRatioMode mode) const Q_DECL_NOTHROW;
+
+ Q_DECL_CONSTEXPR inline QSize expandedTo(const QSize &) const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline QSize boundedTo(const QSize &) const Q_DECL_NOTHROW;
+
+ Q_DECL_RELAXED_CONSTEXPR inline int &rwidth() Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline int &rheight() Q_DECL_NOTHROW;
+
+ Q_DECL_RELAXED_CONSTEXPR inline QSize &operator+=(const QSize &) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline QSize &operator-=(const QSize &) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline QSize &operator*=(qreal c) Q_DECL_NOTHROW;
inline QSize &operator/=(qreal c);
- friend inline Q_DECL_CONSTEXPR bool operator==(const QSize &, const QSize &);
- friend inline Q_DECL_CONSTEXPR bool operator!=(const QSize &, const QSize &);
- friend inline Q_DECL_CONSTEXPR const QSize operator+(const QSize &, const QSize &);
- friend inline Q_DECL_CONSTEXPR const QSize operator-(const QSize &, const QSize &);
- friend inline Q_DECL_CONSTEXPR const QSize operator*(const QSize &, qreal);
- friend inline Q_DECL_CONSTEXPR const QSize operator*(qreal, const QSize &);
+ friend inline Q_DECL_CONSTEXPR bool operator==(const QSize &, const QSize &) Q_DECL_NOTHROW;
+ friend inline Q_DECL_CONSTEXPR bool operator!=(const QSize &, const QSize &) Q_DECL_NOTHROW;
+ friend inline Q_DECL_CONSTEXPR const QSize operator+(const QSize &, const QSize &) Q_DECL_NOTHROW;
+ friend inline Q_DECL_CONSTEXPR const QSize operator-(const QSize &, const QSize &) Q_DECL_NOTHROW;
+ friend inline Q_DECL_CONSTEXPR const QSize operator*(const QSize &, qreal) Q_DECL_NOTHROW;
+ friend inline Q_DECL_CONSTEXPR const QSize operator*(qreal, const QSize &) Q_DECL_NOTHROW;
friend inline const QSize operator/(const QSize &, qreal);
private:
@@ -100,74 +100,74 @@ Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QSize &);
QSize inline functions
*****************************************************************************/
-Q_DECL_CONSTEXPR inline QSize::QSize() : wd(-1), ht(-1) {}
+Q_DECL_CONSTEXPR inline QSize::QSize() Q_DECL_NOTHROW : wd(-1), ht(-1) {}
-Q_DECL_CONSTEXPR inline QSize::QSize(int w, int h) : wd(w), ht(h) {}
+Q_DECL_CONSTEXPR inline QSize::QSize(int w, int h) Q_DECL_NOTHROW : wd(w), ht(h) {}
-Q_DECL_CONSTEXPR inline bool QSize::isNull() const
+Q_DECL_CONSTEXPR inline bool QSize::isNull() const Q_DECL_NOTHROW
{ return wd==0 && ht==0; }
-Q_DECL_CONSTEXPR inline bool QSize::isEmpty() const
+Q_DECL_CONSTEXPR inline bool QSize::isEmpty() const Q_DECL_NOTHROW
{ return wd<1 || ht<1; }
-Q_DECL_CONSTEXPR inline bool QSize::isValid() const
+Q_DECL_CONSTEXPR inline bool QSize::isValid() const Q_DECL_NOTHROW
{ return wd>=0 && ht>=0; }
-Q_DECL_CONSTEXPR inline int QSize::width() const
+Q_DECL_CONSTEXPR inline int QSize::width() const Q_DECL_NOTHROW
{ return wd; }
-Q_DECL_CONSTEXPR inline int QSize::height() const
+Q_DECL_CONSTEXPR inline int QSize::height() const Q_DECL_NOTHROW
{ return ht; }
-inline void QSize::setWidth(int w)
+Q_DECL_RELAXED_CONSTEXPR inline void QSize::setWidth(int w) Q_DECL_NOTHROW
{ wd = w; }
-inline void QSize::setHeight(int h)
+Q_DECL_RELAXED_CONSTEXPR inline void QSize::setHeight(int h) Q_DECL_NOTHROW
{ ht = h; }
-Q_DECL_CONSTEXPR inline QSize QSize::transposed() const
+Q_DECL_CONSTEXPR inline QSize QSize::transposed() const Q_DECL_NOTHROW
{ return QSize(ht, wd); }
-inline void QSize::scale(int w, int h, Qt::AspectRatioMode mode)
+inline void QSize::scale(int w, int h, Qt::AspectRatioMode mode) Q_DECL_NOTHROW
{ scale(QSize(w, h), mode); }
-inline void QSize::scale(const QSize &s, Qt::AspectRatioMode mode)
+inline void QSize::scale(const QSize &s, Qt::AspectRatioMode mode) Q_DECL_NOTHROW
{ *this = scaled(s, mode); }
-inline QSize QSize::scaled(int w, int h, Qt::AspectRatioMode mode) const
+inline QSize QSize::scaled(int w, int h, Qt::AspectRatioMode mode) const Q_DECL_NOTHROW
{ return scaled(QSize(w, h), mode); }
-inline int &QSize::rwidth()
+Q_DECL_RELAXED_CONSTEXPR inline int &QSize::rwidth() Q_DECL_NOTHROW
{ return wd; }
-inline int &QSize::rheight()
+Q_DECL_RELAXED_CONSTEXPR inline int &QSize::rheight() Q_DECL_NOTHROW
{ return ht; }
-inline QSize &QSize::operator+=(const QSize &s)
+Q_DECL_RELAXED_CONSTEXPR inline QSize &QSize::operator+=(const QSize &s) Q_DECL_NOTHROW
{ wd+=s.wd; ht+=s.ht; return *this; }
-inline QSize &QSize::operator-=(const QSize &s)
+Q_DECL_RELAXED_CONSTEXPR inline QSize &QSize::operator-=(const QSize &s) Q_DECL_NOTHROW
{ wd-=s.wd; ht-=s.ht; return *this; }
-inline QSize &QSize::operator*=(qreal c)
+Q_DECL_RELAXED_CONSTEXPR inline QSize &QSize::operator*=(qreal c) Q_DECL_NOTHROW
{ wd = qRound(wd*c); ht = qRound(ht*c); return *this; }
-Q_DECL_CONSTEXPR inline bool operator==(const QSize &s1, const QSize &s2)
+Q_DECL_CONSTEXPR inline bool operator==(const QSize &s1, const QSize &s2) Q_DECL_NOTHROW
{ return s1.wd == s2.wd && s1.ht == s2.ht; }
-Q_DECL_CONSTEXPR inline bool operator!=(const QSize &s1, const QSize &s2)
+Q_DECL_CONSTEXPR inline bool operator!=(const QSize &s1, const QSize &s2) Q_DECL_NOTHROW
{ return s1.wd != s2.wd || s1.ht != s2.ht; }
-Q_DECL_CONSTEXPR inline const QSize operator+(const QSize & s1, const QSize & s2)
+Q_DECL_CONSTEXPR inline const QSize operator+(const QSize & s1, const QSize & s2) Q_DECL_NOTHROW
{ return QSize(s1.wd+s2.wd, s1.ht+s2.ht); }
-Q_DECL_CONSTEXPR inline const QSize operator-(const QSize &s1, const QSize &s2)
+Q_DECL_CONSTEXPR inline const QSize operator-(const QSize &s1, const QSize &s2) Q_DECL_NOTHROW
{ return QSize(s1.wd-s2.wd, s1.ht-s2.ht); }
-Q_DECL_CONSTEXPR inline const QSize operator*(const QSize &s, qreal c)
+Q_DECL_CONSTEXPR inline const QSize operator*(const QSize &s, qreal c) Q_DECL_NOTHROW
{ return QSize(qRound(s.wd*c), qRound(s.ht*c)); }
-Q_DECL_CONSTEXPR inline const QSize operator*(qreal c, const QSize &s)
+Q_DECL_CONSTEXPR inline const QSize operator*(qreal c, const QSize &s) Q_DECL_NOTHROW
{ return QSize(qRound(s.wd*c), qRound(s.ht*c)); }
inline QSize &QSize::operator/=(qreal c)
@@ -183,12 +183,12 @@ inline const QSize operator/(const QSize &s, qreal c)
return QSize(qRound(s.wd/c), qRound(s.ht/c));
}
-Q_DECL_CONSTEXPR inline QSize QSize::expandedTo(const QSize & otherSize) const
+Q_DECL_CONSTEXPR inline QSize QSize::expandedTo(const QSize & otherSize) const Q_DECL_NOTHROW
{
return QSize(qMax(wd,otherSize.wd), qMax(ht,otherSize.ht));
}
-Q_DECL_CONSTEXPR inline QSize QSize::boundedTo(const QSize & otherSize) const
+Q_DECL_CONSTEXPR inline QSize QSize::boundedTo(const QSize & otherSize) const Q_DECL_NOTHROW
{
return QSize(qMin(wd,otherSize.wd), qMin(ht,otherSize.ht));
}
@@ -201,46 +201,46 @@ Q_CORE_EXPORT QDebug operator<<(QDebug, const QSize &);
class Q_CORE_EXPORT QSizeF
{
public:
- Q_DECL_CONSTEXPR QSizeF();
- Q_DECL_CONSTEXPR QSizeF(const QSize &sz);
- Q_DECL_CONSTEXPR QSizeF(qreal w, qreal h);
-
- inline bool isNull() const;
- Q_DECL_CONSTEXPR inline bool isEmpty() const;
- Q_DECL_CONSTEXPR inline bool isValid() const;
-
- Q_DECL_CONSTEXPR inline qreal width() const;
- Q_DECL_CONSTEXPR inline qreal height() const;
- inline void setWidth(qreal w);
- inline void setHeight(qreal h);
- void transpose();
- Q_DECL_CONSTEXPR inline QSizeF transposed() const;
-
- inline void scale(qreal w, qreal h, Qt::AspectRatioMode mode);
- inline void scale(const QSizeF &s, Qt::AspectRatioMode mode);
- QSizeF scaled(qreal w, qreal h, Qt::AspectRatioMode mode) const;
- QSizeF scaled(const QSizeF &s, Qt::AspectRatioMode mode) const;
-
- Q_DECL_CONSTEXPR inline QSizeF expandedTo(const QSizeF &) const;
- Q_DECL_CONSTEXPR inline QSizeF boundedTo(const QSizeF &) const;
-
- inline qreal &rwidth();
- inline qreal &rheight();
-
- inline QSizeF &operator+=(const QSizeF &);
- inline QSizeF &operator-=(const QSizeF &);
- inline QSizeF &operator*=(qreal c);
+ Q_DECL_CONSTEXPR QSizeF() Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR QSizeF(const QSize &sz) Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR QSizeF(qreal w, qreal h) Q_DECL_NOTHROW;
+
+ inline bool isNull() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline bool isEmpty() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline bool isValid() const Q_DECL_NOTHROW;
+
+ Q_DECL_CONSTEXPR inline qreal width() const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline qreal height() const Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setWidth(qreal w) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline void setHeight(qreal h) Q_DECL_NOTHROW;
+ void transpose() Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline QSizeF transposed() const Q_DECL_NOTHROW;
+
+ inline void scale(qreal w, qreal h, Qt::AspectRatioMode mode) Q_DECL_NOTHROW;
+ inline void scale(const QSizeF &s, Qt::AspectRatioMode mode) Q_DECL_NOTHROW;
+ QSizeF scaled(qreal w, qreal h, Qt::AspectRatioMode mode) const Q_DECL_NOTHROW;
+ QSizeF scaled(const QSizeF &s, Qt::AspectRatioMode mode) const Q_DECL_NOTHROW;
+
+ Q_DECL_CONSTEXPR inline QSizeF expandedTo(const QSizeF &) const Q_DECL_NOTHROW;
+ Q_DECL_CONSTEXPR inline QSizeF boundedTo(const QSizeF &) const Q_DECL_NOTHROW;
+
+ Q_DECL_RELAXED_CONSTEXPR inline qreal &rwidth() Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline qreal &rheight() Q_DECL_NOTHROW;
+
+ Q_DECL_RELAXED_CONSTEXPR inline QSizeF &operator+=(const QSizeF &) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline QSizeF &operator-=(const QSizeF &) Q_DECL_NOTHROW;
+ Q_DECL_RELAXED_CONSTEXPR inline QSizeF &operator*=(qreal c) Q_DECL_NOTHROW;
inline QSizeF &operator/=(qreal c);
- friend Q_DECL_CONSTEXPR inline bool operator==(const QSizeF &, const QSizeF &);
- friend Q_DECL_CONSTEXPR inline bool operator!=(const QSizeF &, const QSizeF &);
- friend Q_DECL_CONSTEXPR inline const QSizeF operator+(const QSizeF &, const QSizeF &);
- friend Q_DECL_CONSTEXPR inline const QSizeF operator-(const QSizeF &, const QSizeF &);
- friend Q_DECL_CONSTEXPR inline const QSizeF operator*(const QSizeF &, qreal);
- friend Q_DECL_CONSTEXPR inline const QSizeF operator*(qreal, const QSizeF &);
+ friend Q_DECL_CONSTEXPR inline bool operator==(const QSizeF &, const QSizeF &) Q_DECL_NOTHROW;
+ friend Q_DECL_CONSTEXPR inline bool operator!=(const QSizeF &, const QSizeF &) Q_DECL_NOTHROW;
+ friend Q_DECL_CONSTEXPR inline const QSizeF operator+(const QSizeF &, const QSizeF &) Q_DECL_NOTHROW;
+ friend Q_DECL_CONSTEXPR inline const QSizeF operator-(const QSizeF &, const QSizeF &) Q_DECL_NOTHROW;
+ friend Q_DECL_CONSTEXPR inline const QSizeF operator*(const QSizeF &, qreal) Q_DECL_NOTHROW;
+ friend Q_DECL_CONSTEXPR inline const QSizeF operator*(qreal, const QSizeF &) Q_DECL_NOTHROW;
friend inline const QSizeF operator/(const QSizeF &, qreal);
- Q_DECL_CONSTEXPR inline QSize toSize() const;
+ Q_DECL_CONSTEXPR inline QSize toSize() const Q_DECL_NOTHROW;
private:
qreal wd;
@@ -263,76 +263,76 @@ Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QSizeF &);
QSizeF inline functions
*****************************************************************************/
-Q_DECL_CONSTEXPR inline QSizeF::QSizeF() : wd(-1.), ht(-1.) {}
+Q_DECL_CONSTEXPR inline QSizeF::QSizeF() Q_DECL_NOTHROW : wd(-1.), ht(-1.) {}
-Q_DECL_CONSTEXPR inline QSizeF::QSizeF(const QSize &sz) : wd(sz.width()), ht(sz.height()) {}
+Q_DECL_CONSTEXPR inline QSizeF::QSizeF(const QSize &sz) Q_DECL_NOTHROW : wd(sz.width()), ht(sz.height()) {}
-Q_DECL_CONSTEXPR inline QSizeF::QSizeF(qreal w, qreal h) : wd(w), ht(h) {}
+Q_DECL_CONSTEXPR inline QSizeF::QSizeF(qreal w, qreal h) Q_DECL_NOTHROW : wd(w), ht(h) {}
-inline bool QSizeF::isNull() const
+inline bool QSizeF::isNull() const Q_DECL_NOTHROW
{ return qIsNull(wd) && qIsNull(ht); }
-Q_DECL_CONSTEXPR inline bool QSizeF::isEmpty() const
+Q_DECL_CONSTEXPR inline bool QSizeF::isEmpty() const Q_DECL_NOTHROW
{ return wd <= 0. || ht <= 0.; }
-Q_DECL_CONSTEXPR inline bool QSizeF::isValid() const
+Q_DECL_CONSTEXPR inline bool QSizeF::isValid() const Q_DECL_NOTHROW
{ return wd >= 0. && ht >= 0.; }
-Q_DECL_CONSTEXPR inline qreal QSizeF::width() const
+Q_DECL_CONSTEXPR inline qreal QSizeF::width() const Q_DECL_NOTHROW
{ return wd; }
-Q_DECL_CONSTEXPR inline qreal QSizeF::height() const
+Q_DECL_CONSTEXPR inline qreal QSizeF::height() const Q_DECL_NOTHROW
{ return ht; }
-inline void QSizeF::setWidth(qreal w)
+Q_DECL_RELAXED_CONSTEXPR inline void QSizeF::setWidth(qreal w) Q_DECL_NOTHROW
{ wd = w; }
-inline void QSizeF::setHeight(qreal h)
+Q_DECL_RELAXED_CONSTEXPR inline void QSizeF::setHeight(qreal h) Q_DECL_NOTHROW
{ ht = h; }
-Q_DECL_CONSTEXPR inline QSizeF QSizeF::transposed() const
+Q_DECL_CONSTEXPR inline QSizeF QSizeF::transposed() const Q_DECL_NOTHROW
{ return QSizeF(ht, wd); }
-inline void QSizeF::scale(qreal w, qreal h, Qt::AspectRatioMode mode)
+inline void QSizeF::scale(qreal w, qreal h, Qt::AspectRatioMode mode) Q_DECL_NOTHROW
{ scale(QSizeF(w, h), mode); }
-inline void QSizeF::scale(const QSizeF &s, Qt::AspectRatioMode mode)
+inline void QSizeF::scale(const QSizeF &s, Qt::AspectRatioMode mode) Q_DECL_NOTHROW
{ *this = scaled(s, mode); }
-inline QSizeF QSizeF::scaled(qreal w, qreal h, Qt::AspectRatioMode mode) const
+inline QSizeF QSizeF::scaled(qreal w, qreal h, Qt::AspectRatioMode mode) const Q_DECL_NOTHROW
{ return scaled(QSizeF(w, h), mode); }
-inline qreal &QSizeF::rwidth()
+Q_DECL_RELAXED_CONSTEXPR inline qreal &QSizeF::rwidth() Q_DECL_NOTHROW
{ return wd; }
-inline qreal &QSizeF::rheight()
+Q_DECL_RELAXED_CONSTEXPR inline qreal &QSizeF::rheight() Q_DECL_NOTHROW
{ return ht; }
-inline QSizeF &QSizeF::operator+=(const QSizeF &s)
+Q_DECL_RELAXED_CONSTEXPR inline QSizeF &QSizeF::operator+=(const QSizeF &s) Q_DECL_NOTHROW
{ wd += s.wd; ht += s.ht; return *this; }
-inline QSizeF &QSizeF::operator-=(const QSizeF &s)
+Q_DECL_RELAXED_CONSTEXPR inline QSizeF &QSizeF::operator-=(const QSizeF &s) Q_DECL_NOTHROW
{ wd -= s.wd; ht -= s.ht; return *this; }
-inline QSizeF &QSizeF::operator*=(qreal c)
+Q_DECL_RELAXED_CONSTEXPR inline QSizeF &QSizeF::operator*=(qreal c) Q_DECL_NOTHROW
{ wd *= c; ht *= c; return *this; }
-Q_DECL_CONSTEXPR inline bool operator==(const QSizeF &s1, const QSizeF &s2)
+Q_DECL_CONSTEXPR inline bool operator==(const QSizeF &s1, const QSizeF &s2) Q_DECL_NOTHROW
{ return qFuzzyCompare(s1.wd, s2.wd) && qFuzzyCompare(s1.ht, s2.ht); }
-Q_DECL_CONSTEXPR inline bool operator!=(const QSizeF &s1, const QSizeF &s2)
+Q_DECL_CONSTEXPR inline bool operator!=(const QSizeF &s1, const QSizeF &s2) Q_DECL_NOTHROW
{ return !qFuzzyCompare(s1.wd, s2.wd) || !qFuzzyCompare(s1.ht, s2.ht); }
-Q_DECL_CONSTEXPR inline const QSizeF operator+(const QSizeF & s1, const QSizeF & s2)
+Q_DECL_CONSTEXPR inline const QSizeF operator+(const QSizeF & s1, const QSizeF & s2) Q_DECL_NOTHROW
{ return QSizeF(s1.wd+s2.wd, s1.ht+s2.ht); }
-Q_DECL_CONSTEXPR inline const QSizeF operator-(const QSizeF &s1, const QSizeF &s2)
+Q_DECL_CONSTEXPR inline const QSizeF operator-(const QSizeF &s1, const QSizeF &s2) Q_DECL_NOTHROW
{ return QSizeF(s1.wd-s2.wd, s1.ht-s2.ht); }
-Q_DECL_CONSTEXPR inline const QSizeF operator*(const QSizeF &s, qreal c)
+Q_DECL_CONSTEXPR inline const QSizeF operator*(const QSizeF &s, qreal c) Q_DECL_NOTHROW
{ return QSizeF(s.wd*c, s.ht*c); }
-Q_DECL_CONSTEXPR inline const QSizeF operator*(qreal c, const QSizeF &s)
+Q_DECL_CONSTEXPR inline const QSizeF operator*(qreal c, const QSizeF &s) Q_DECL_NOTHROW
{ return QSizeF(s.wd*c, s.ht*c); }
inline QSizeF &QSizeF::operator/=(qreal c)
@@ -348,17 +348,17 @@ inline const QSizeF operator/(const QSizeF &s, qreal c)
return QSizeF(s.wd/c, s.ht/c);
}
-Q_DECL_CONSTEXPR inline QSizeF QSizeF::expandedTo(const QSizeF & otherSize) const
+Q_DECL_CONSTEXPR inline QSizeF QSizeF::expandedTo(const QSizeF & otherSize) const Q_DECL_NOTHROW
{
return QSizeF(qMax(wd,otherSize.wd), qMax(ht,otherSize.ht));
}
-Q_DECL_CONSTEXPR inline QSizeF QSizeF::boundedTo(const QSizeF & otherSize) const
+Q_DECL_CONSTEXPR inline QSizeF QSizeF::boundedTo(const QSizeF & otherSize) const Q_DECL_NOTHROW
{
return QSizeF(qMin(wd,otherSize.wd), qMin(ht,otherSize.ht));
}
-Q_DECL_CONSTEXPR inline QSize QSizeF::toSize() const
+Q_DECL_CONSTEXPR inline QSize QSizeF::toSize() const Q_DECL_NOTHROW
{
return QSize(qRound(wd), qRound(ht));
}
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index 9921d5cfbb..50184f4696 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -70,6 +70,7 @@
#include "qchar.cpp"
#include "qstringmatcher.cpp"
#include "qstringiterator_p.h"
+#include "qstringalgorithms_p.h"
#include "qthreadstorage.h"
#ifdef Q_OS_WIN
@@ -731,12 +732,30 @@ inline char qToLower(char ch)
const QString::Null QString::null = { };
/*!
+ \macro QT_RESTRICTED_CAST_FROM_ASCII
+ \relates QString
+
+ Defining this macro disables most automatic conversions from source
+ literals and 8-bit data to unicode QStrings, but allows the use of
+ the \c{QChar(char)} and \c{QString(const char (&ch)[N]} constructors,
+ and the \c{QString::operator=(const char (&ch)[N])} assignment operator
+ giving most of the type-safety benefits of QT_NO_CAST_FROM_ASCII
+ but does not require user code to wrap character and string literals
+ with QLatin1Char, QLatin1String or similar.
+
+ Using this macro together with source strings outside the 7-bit range,
+ non-literals, or literals with embedded NUL characters is undefined.
+
+ \sa QT_NO_CAST_FROM_ASCII, QT_NO_CAST_TO_ASCII
+*/
+
+/*!
\macro QT_NO_CAST_FROM_ASCII
\relates QString
Disables automatic conversions from 8-bit strings (char *) to unicode QStrings
- \sa QT_NO_CAST_TO_ASCII, QT_NO_CAST_FROM_BYTEARRAY
+ \sa QT_NO_CAST_TO_ASCII, QT_RESTRICTED_CAST_FROM_ASCII, QT_NO_CAST_FROM_BYTEARRAY
*/
/*!
@@ -745,7 +764,7 @@ const QString::Null QString::null = { };
disables automatic conversion from QString to 8-bit strings (char *)
- \sa QT_NO_CAST_FROM_ASCII, QT_NO_CAST_FROM_BYTEARRAY
+ \sa QT_NO_CAST_FROM_ASCII, QT_RESTRICTED_CAST_FROM_ASCII, QT_NO_CAST_FROM_BYTEARRAY
*/
/*!
@@ -759,7 +778,7 @@ const QString::Null QString::null = { };
Note: This only works for compilers that support warnings for
deprecated API.
- \sa QT_NO_CAST_TO_ASCII, QT_NO_CAST_FROM_ASCII
+ \sa QT_NO_CAST_TO_ASCII, QT_NO_CAST_FROM_ASCII, QT_RESTRICTED_CAST_FROM_ASCII
*/
/*!
@@ -993,6 +1012,9 @@ const QString::Null QString::null = { };
\list
\li \c QT_NO_CAST_FROM_ASCII disables automatic conversions from
C string literals and pointers to Unicode.
+ \li \c QT_RESTRICTED_CAST_FROM_ASCII allows automatic conversions
+ from C characters and character arrays, but disables automatic
+ conversions from character pointers to Unicode.
\li \c QT_NO_CAST_TO_ASCII disables automatic conversion from QString
to C strings.
\endlist
@@ -1310,6 +1332,12 @@ const QString::Null QString::null = { };
can be useful if you want to ensure that all user-visible strings
go through QObject::tr(), for example.
+ \note Defining QT_RESTRICTED_CAST_FROM_ASCII also disables
+ this constructor, but enables a \c{QString(const char (&ch)[N])}
+ constructor instead. Using non-literal input, or input with
+ embedded NUL characters, or non-7-bit characters is undefined
+ in this case.
+
\sa fromLatin1(), fromLocal8Bit(), fromUtf8()
*/
@@ -1328,7 +1356,7 @@ const QString::Null QString::null = { };
windows) and ucs4 if the size of wchar_t is 4 bytes (most Unix
systems).
- \sa fromUtf16(), fromLatin1(), fromLocal8Bit(), fromUtf8(), fromUcs4()
+ \sa fromUtf16(), fromLatin1(), fromLocal8Bit(), fromUtf8(), fromUcs4(), fromStdU16String(), fromStdU32String()
*/
/*! \fn QString QString::fromWCharArray(const wchar_t *string, int size)
@@ -1353,7 +1381,7 @@ const QString::Null QString::null = { };
This method is mostly useful to pass a QString to a function
that accepts a std::wstring object.
- \sa utf16(), toLatin1(), toUtf8(), toLocal8Bit()
+ \sa utf16(), toLatin1(), toUtf8(), toLocal8Bit(), toStdU16String(), toStdU32String()
*/
int QString::toUcs4_helper(const ushort *uc, int length, uint *out)
@@ -1656,8 +1684,11 @@ void QString::resize(int size)
void QString::reallocData(uint alloc, bool grow)
{
- if (grow)
+ if (grow) {
+ if (alloc > (uint(MaxAllocSize) - sizeof(Data)) / sizeof(QChar))
+ qBadAlloc();
alloc = qAllocMore(alloc * sizeof(QChar), sizeof(Data)) / sizeof(QChar);
+ }
if (d->ref.isShared() || IS_RAW_DATA(d)) {
Data::AllocationOptions allocOptions(d->capacityReserved ? Data::CapacityReserved : 0);
@@ -1703,7 +1734,7 @@ void QString::expand(int i)
string.
*/
-QString &QString::operator=(const QString &other)
+QString &QString::operator=(const QString &other) Q_DECL_NOTHROW
{
other.d->ref.ref();
if (!d->ref.deref())
@@ -1748,10 +1779,11 @@ QString &QString::operator=(const QString &other)
Assigns \a str to this string. The const char pointer is converted
to Unicode using the fromUtf8() function.
- You can disable this operator by defining \c
- QT_NO_CAST_FROM_ASCII when you compile your applications. This
- can be useful if you want to ensure that all user-visible strings
+ You can disable this operator by defining \c QT_NO_CAST_FROM_ASCII
+ or \c QT_RESTRICTED_CAST_FROM_ASCII when you compile your applications.
+ This can be useful if you want to ensure that all user-visible strings
go through QObject::tr(), for example.
+
*/
/*! \fn QString &QString::operator=(char ch)
@@ -3664,14 +3696,39 @@ int QString::count(const QRegExp& rx) const
*/
int QString::indexOf(const QRegularExpression& re, int from) const
{
+ return indexOf(re, from, Q_NULLPTR);
+}
+
+/*!
+ \overload
+ \since 5.5
+
+ Returns the index position of the first match of the regular
+ expression \a re in the string, searching forward from index
+ position \a from. Returns -1 if \a re didn't match anywhere.
+
+ If the match is successful and \a rmatch is not a null pointer, it also
+ writes the results of the match into the QRegularExpressionMatch object
+ pointed to by \a rmatch.
+
+ Example:
+
+ \snippet qstring/main.cpp 97
+*/
+int QString::indexOf(const QRegularExpression &re, int from, QRegularExpressionMatch *rmatch) const
+{
if (!re.isValid()) {
qWarning("QString::indexOf: invalid QRegularExpression object");
return -1;
}
QRegularExpressionMatch match = re.match(*this, from);
- if (match.hasMatch())
- return match.capturedStart();
+ if (match.hasMatch()) {
+ const int ret = match.capturedStart();
+ if (rmatch)
+ *rmatch = qMove(match);
+ return ret;
+ }
return -1;
}
@@ -3690,22 +3747,45 @@ int QString::indexOf(const QRegularExpression& re, int from) const
*/
int QString::lastIndexOf(const QRegularExpression &re, int from) const
{
+ return lastIndexOf(re, from, Q_NULLPTR);
+}
+
+/*!
+ \overload
+ \since 5.5
+
+ Returns the index position of the last match of the regular
+ expression \a re in the string, which starts before the index
+ position \a from. Returns -1 if \a re didn't match anywhere.
+
+ If the match is successful and \a rmatch is not a null pointer, it also
+ writes the results of the match into the QRegularExpressionMatch object
+ pointed to by \a rmatch.
+
+ Example:
+
+ \snippet qstring/main.cpp 98
+*/
+int QString::lastIndexOf(const QRegularExpression &re, int from, QRegularExpressionMatch *rmatch) const
+{
if (!re.isValid()) {
qWarning("QString::lastIndexOf: invalid QRegularExpression object");
return -1;
}
int endpos = (from < 0) ? (size() + from + 1) : (from + 1);
-
QRegularExpressionMatchIterator iterator = re.globalMatch(*this);
int lastIndex = -1;
while (iterator.hasNext()) {
QRegularExpressionMatch match = iterator.next();
int start = match.capturedStart();
- if (start < endpos)
+ if (start < endpos) {
lastIndex = start;
- else
+ if (rmatch)
+ *rmatch = qMove(match);
+ } else {
break;
+ }
}
return lastIndex;
@@ -3719,12 +3799,7 @@ int QString::lastIndexOf(const QRegularExpression &re, int from) const
*/
bool QString::contains(const QRegularExpression &re) const
{
- if (!re.isValid()) {
- qWarning("QString::contains: invalid QRegularExpression object");
- return false;
- }
- QRegularExpressionMatch match = re.match(*this);
- return match.hasMatch();
+ return contains(re, Q_NULLPTR);
}
/*!
@@ -3744,13 +3819,13 @@ bool QString::contains(const QRegularExpression &re) const
bool QString::contains(const QRegularExpression &re, QRegularExpressionMatch *match) const
{
if (!re.isValid()) {
- qWarning("QString::contains: invalid QRegularExpresssion object");
+ qWarning("QString::contains: invalid QRegularExpression object");
return false;
}
QRegularExpressionMatch m = re.match(*this);
bool hasMatch = m.hasMatch();
if (hasMatch && match)
- *match = m;
+ *match = qMove(m);
return hasMatch;
}
@@ -3912,12 +3987,14 @@ QString QString::section(const QString &sep, int start, int end, SectionFlags fl
#if !(defined(QT_NO_REGEXP) && defined(QT_NO_REGULAREXPRESSION))
class qt_section_chunk {
public:
- qt_section_chunk(int l, QString s) { length = l; string = s; }
+ qt_section_chunk() {}
+ qt_section_chunk(int l, QString s) : length(l), string(qMove(s)) {}
int length;
QString string;
};
+Q_DECLARE_TYPEINFO(qt_section_chunk, Q_MOVABLE_TYPE);
-static QString extractSections(const QList<qt_section_chunk> &sections,
+static QString extractSections(const QVector<qt_section_chunk> &sections,
int start,
int end,
QString::SectionFlags flags)
@@ -4003,7 +4080,7 @@ QString QString::section(const QRegExp &reg, int start, int end, SectionFlags fl
sep.setCaseSensitivity((flags & SectionCaseInsensitiveSeps) ? Qt::CaseInsensitive
: Qt::CaseSensitive);
- QList<qt_section_chunk> sections;
+ QVector<qt_section_chunk> sections;
int n = length(), m = 0, last_m = 0, last_len = 0;
while ((m = sep.indexIn(*this, m)) != -1) {
sections.append(qt_section_chunk(last_len, QString(uc + last_m, m - last_m)));
@@ -4048,7 +4125,7 @@ QString QString::section(const QRegularExpression &re, int start, int end, Secti
if (flags & SectionCaseInsensitiveSeps)
sep.setPatternOptions(sep.patternOptions() | QRegularExpression::CaseInsensitiveOption);
- QList<qt_section_chunk> sections;
+ QVector<qt_section_chunk> sections;
int n = length(), m = 0, last_m = 0, last_len = 0;
QRegularExpressionMatchIterator iterator = sep.globalMatch(*this);
while (iterator.hasNext()) {
@@ -4555,7 +4632,7 @@ QString QString::fromUtf8_helper(const char *str, int size)
QString makes a deep copy of the Unicode data.
- \sa utf16(), setUtf16()
+ \sa utf16(), setUtf16(), fromStdU16String()
*/
QString QString::fromUtf16(const ushort *unicode, int size)
{
@@ -4579,7 +4656,7 @@ QString QString::fromUtf16(const ushort *unicode, int size)
If \a size is -1 (default), \a unicode must be terminated
with a 0.
- \sa toUcs4(), fromUtf16(), utf16(), setUtf16(), fromWCharArray()
+ \sa toUcs4(), fromUtf16(), utf16(), setUtf16(), fromWCharArray(), fromStdU32String()
*/
QString QString::fromUcs4(const uint *unicode, int size)
{
@@ -4626,6 +4703,8 @@ QString& QString::setUnicode(const QChar *unicode, int size)
*/
/*!
+ \fn QString QString::simplified() const
+
Returns a string that has whitespace removed from the start
and the end, and that has each sequence of internal whitespace
replaced with a single space.
@@ -4640,83 +4719,19 @@ QString& QString::setUnicode(const QChar *unicode, int size)
\sa trimmed()
*/
-QString QString::simplified() const
+QString QString::simplified_helper(const QString &str)
{
- if (d->size == 0)
- return *this;
-
- const QChar * const start = reinterpret_cast<QChar *>(d->data());
- const QChar *from = start;
- const QChar *fromEnd = start + d->size;
- forever {
- QChar ch = *from;
- if (!ch.isSpace())
- break;
- if (++from == fromEnd) {
- // All-whitespace string
- QStringDataPtr empty = { Data::allocate(0) };
- return QString(empty);
- }
- }
- // This loop needs no underflow check, as we already determined that
- // the string contains non-whitespace. If the string has exactly one
- // non-whitespace, it will be checked twice - we can live with that.
- while (fromEnd[-1].isSpace())
- fromEnd--;
- // The rest of the function depends on the fact that we already know
- // that the last character in the source is no whitespace.
- const QChar *copyFrom = from;
- int copyCount;
- forever {
- if (++from == fromEnd) {
- // Only leading and/or trailing whitespace, if any at all
- return mid(copyFrom - start, from - copyFrom);
- }
- QChar ch = *from;
- if (!ch.isSpace())
- continue;
- if (ch != QLatin1Char(' ')) {
- copyCount = from - copyFrom;
- break;
- }
- ch = *++from;
- if (ch.isSpace()) {
- copyCount = from - copyFrom - 1;
- break;
- }
- }
- // 'from' now points at the non-trailing whitespace which made the
- // string not simplified in the first place. 'copyCount' is the number
- // of already simplified characters - at least one, obviously -
- // without a trailing space.
- QString result((fromEnd - from) + copyCount, Qt::Uninitialized);
- QChar *to = reinterpret_cast<QChar *>(result.d->data());
- ::memcpy(to, copyFrom, copyCount * 2);
- to += copyCount;
- fromEnd--;
- QChar ch;
- forever {
- *to++ = QLatin1Char(' ');
- do {
- ch = *++from;
- } while (ch.isSpace());
- if (from == fromEnd)
- break;
- do {
- *to++ = ch;
- ch = *++from;
- if (from == fromEnd)
- goto done;
- } while (!ch.isSpace());
+ return QStringAlgorithms<const QString>::simplified_helper(str);
+}
- }
- done:
- *to++ = ch;
- result.truncate(to - reinterpret_cast<QChar *>(result.d->data()));
- return result;
+QString QString::simplified_helper(QString &str)
+{
+ return QStringAlgorithms<QString>::simplified_helper(str);
}
/*!
+ \fn QString QString::trimmed() const
+
Returns a string that has whitespace removed from the start and
the end.
@@ -4732,27 +4747,14 @@ QString QString::simplified() const
\sa simplified()
*/
-QString QString::trimmed() const
+QString QString::trimmed_helper(const QString &str)
{
- if (d->size == 0)
- return *this;
- const QChar *s = (const QChar*)d->data();
- if (!s->isSpace() && !s[d->size-1].isSpace())
- return *this;
- int start = 0;
- int end = d->size - 1;
- while (start<=end && s[start].isSpace()) // skip white space from start
- start++;
- if (start <= end) { // only white space
- while (end && s[end].isSpace()) // skip white space from end
- end--;
- }
- int l = end - start + 1;
- if (l <= 0) {
- QStringDataPtr empty = { Data::allocate(0) };
- return QString(empty);
- }
- return QString(s + start, l);
+ return QStringAlgorithms<const QString>::trimmed_helper(str);
+}
+
+QString QString::trimmed_helper(QString &str)
+{
+ return QStringAlgorithms<QString>::trimmed_helper(str);
}
/*! \fn const QChar QString::at(int position) const
@@ -5519,6 +5521,8 @@ QString QString::rightJustified(int width, QChar fill, bool truncate) const
}
/*!
+ \fn QString QString::toLower() const
+
Returns a lowercase copy of the string.
\snippet qstring/main.cpp 75
@@ -5529,132 +5533,114 @@ QString QString::rightJustified(int width, QChar fill, bool truncate) const
\sa toUpper(), QLocale::toLower()
*/
-QString QString::toLower() const
+namespace QUnicodeTables {
+struct LowercaseTraits
{
- const ushort *p = d->data();
- if (!p)
- return *this;
+ static signed short caseDiff(const Properties *prop)
+ { return prop->lowerCaseDiff; }
+ static bool caseSpecial(const Properties *prop)
+ { return prop->lowerCaseSpecial; }
+};
- const ushort *e = p + d->size;
- // this avoids out of bounds check in the loop
- while (e != p && QChar::isHighSurrogate(*(e - 1)))
- --e;
+struct UppercaseTraits
+{
+ static signed short caseDiff(const Properties *prop)
+ { return prop->upperCaseDiff; }
+ static bool caseSpecial(const Properties *prop)
+ { return prop->upperCaseSpecial; }
+};
- const QUnicodeTables::Properties *prop;
- while (p != e) {
- if (QChar::isHighSurrogate(*p) && QChar::isLowSurrogate(p[1])) {
- ushort high = *p++;
- prop = qGetProp(QChar::surrogateToUcs4(high, *p));
+struct CasefoldTraits
+{
+ static signed short caseDiff(const Properties *prop)
+ { return prop->caseFoldDiff; }
+ static bool caseSpecial(const Properties *prop)
+ { return prop->caseFoldSpecial; }
+};
+
+template <typename Traits, typename T>
+Q_NEVER_INLINE
+static QString detachAndConvertCase(T &str, QStringIterator it)
+{
+ QString s = qMove(str); // will copy if T is const QString
+ QChar *pp = s.begin() + it.index(); // will detach if necessary
+ uint uc = it.nextUnchecked();
+ forever {
+ const QUnicodeTables::Properties *prop = qGetProp(uc);
+ signed short caseDiff = Traits::caseDiff(prop);
+
+ if (Q_UNLIKELY(Traits::caseSpecial(prop))) {
+ // slow path
+ const ushort *specialCase = specialCaseMap + caseDiff;
+ ushort length = *specialCase++;
+ int pos = pp - s.constBegin();
+ s.replace(pos, 1, reinterpret_cast<const QChar *>(specialCase), length);
+ pp = const_cast<QChar *>(s.constBegin()) + pos + length;
+ } else if (QChar::requiresSurrogates(uc)) {
+ *pp++ = QChar::highSurrogate(uc + caseDiff);
+ *pp++ = QChar::lowSurrogate(uc + caseDiff);
} else {
- prop = qGetProp(*p);
+ *pp++ = QChar(uc + caseDiff);
}
- if (prop->lowerCaseDiff) {
- if (QChar::isLowSurrogate(*p))
- --p; // safe; diff is 0 for surrogates
- QString s(d->size, Qt::Uninitialized);
- memcpy(s.d->data(), d->data(), (p - d->data())*sizeof(ushort));
- ushort *pp = s.d->data() + (p - d->data());
- while (p != e) {
- if (QChar::isHighSurrogate(*p) && QChar::isLowSurrogate(p[1])) {
- *pp = *p++;
- prop = qGetProp(QChar::surrogateToUcs4(*pp++, *p));
- } else {
- prop = qGetProp(*p);
- }
- if (prop->lowerCaseSpecial) {
- const ushort *specialCase = specialCaseMap + prop->lowerCaseDiff;
- ushort length = *specialCase++;
- int pos = pp - s.d->data();
- s.resize(s.d->size + length - 1);
- pp = s.d->data() + pos;
- while (length--)
- *pp++ = *specialCase++;
- } else {
- *pp++ = *p + prop->lowerCaseDiff;
- }
- ++p;
- }
-
- // this restores high surrogate parts eaten above, if any
- while (e != d->data() + d->size)
- *pp++ = *e++;
+ if (!it.hasNext())
return s;
- }
- ++p;
+
+ uc = it.nextUnchecked();
}
- return *this;
}
-/*!
- Returns the case folded equivalent of the string. For most Unicode
- characters this is the same as toLower().
-*/
-QString QString::toCaseFolded() const
+template <typename Traits, typename T>
+static QString convertCase(T &str)
{
- const ushort *p = d->data();
- if (!p)
- return *this;
+ const QChar *p = str.constBegin();
+ const QChar *e = p + str.size();
- const ushort *e = p + d->size;
// this avoids out of bounds check in the loop
- while (e != p && QChar::isHighSurrogate(*(e - 1)))
+ while (e != p && e[-1].isHighSurrogate())
--e;
const QUnicodeTables::Properties *prop;
- while (p != e) {
- if (QChar::isHighSurrogate(*p) && QChar::isLowSurrogate(p[1])) {
- ushort high = *p++;
- prop = qGetProp(QChar::surrogateToUcs4(high, *p));
- } else {
- prop = qGetProp(*p);
- }
- if (prop->caseFoldDiff) {
- if (QChar::isLowSurrogate(*p))
- --p; // safe; diff is 0 for surrogates
- QString s(d->size, Qt::Uninitialized);
- memcpy(s.d->data(), d->data(), (p - d->data())*sizeof(ushort));
- ushort *pp = s.d->data() + (p - d->data());
- while (p != e) {
- if (QChar::isHighSurrogate(*p) && QChar::isLowSurrogate(p[1])) {
- *pp = *p++;
- prop = qGetProp(QChar::surrogateToUcs4(*pp++, *p));
- } else {
- prop = qGetProp(*p);
- }
- if (prop->caseFoldSpecial) {
- const ushort *specialCase = specialCaseMap + prop->caseFoldDiff;
- ushort length = *specialCase++;
-#if 0
- int pos = pp - s.d->data;
- s.resize(s.d->size + length - 1);
- pp = s.d->data + pos;
- while (length--)
- *pp++ = *specialCase++;
-#else
- //### we currently don't support full case foldings
- Q_ASSERT(length == 1);
- Q_UNUSED(length)
- *pp++ = *specialCase;
-#endif
- } else {
- *pp++ = *p + prop->caseFoldDiff;
- }
- ++p;
- }
+ QStringIterator it(p, e);
+ for ( ; it.hasNext(); it.advanceUnchecked()) {
+ prop = qGetProp(it.peekNextUnchecked());
+ if (Traits::caseDiff(prop))
+ return detachAndConvertCase<Traits>(str, it);
+ }
+ return qMove(str);
+}
+} // namespace QUnicodeTables
- // this restores high surrogate parts eaten above, if any
- while (e != d->data() + d->size)
- *pp++ = *e++;
+QString QString::toLower_helper(const QString &str)
+{
+ return QUnicodeTables::convertCase<QUnicodeTables::LowercaseTraits>(str);
+}
- return s;
- }
- ++p;
- }
- return *this;
+QString QString::toLower_helper(QString &str)
+{
+ return QUnicodeTables::convertCase<QUnicodeTables::LowercaseTraits>(str);
+}
+
+/*!
+ \fn QString QString::toCaseFolded() const
+
+ Returns the case folded equivalent of the string. For most Unicode
+ characters this is the same as toLower().
+*/
+
+QString QString::toCaseFolded_helper(const QString &str)
+{
+ return QUnicodeTables::convertCase<QUnicodeTables::CasefoldTraits>(str);
+}
+
+QString QString::toCaseFolded_helper(QString &str)
+{
+ return QUnicodeTables::convertCase<QUnicodeTables::CasefoldTraits>(str);
}
/*!
+ \fn QString QString::toUpper() const
+
Returns an uppercase copy of the string.
\snippet qstring/main.cpp 81
@@ -5664,63 +5650,18 @@ QString QString::toCaseFolded() const
\sa toLower(), QLocale::toLower()
*/
-QString QString::toUpper() const
-{
- const ushort *p = d->data();
- if (!p)
- return *this;
- const ushort *e = p + d->size;
- // this avoids out of bounds check in the loop
- while (e != p && QChar::isHighSurrogate(*(e - 1)))
- --e;
-
- const QUnicodeTables::Properties *prop;
- while (p != e) {
- if (QChar::isHighSurrogate(*p) && QChar::isLowSurrogate(p[1])) {
- ushort high = *p++;
- prop = qGetProp(QChar::surrogateToUcs4(high, *p));
- } else {
- prop = qGetProp(*p);
- }
- if (prop->upperCaseDiff) {
- if (QChar::isLowSurrogate(*p))
- --p; // safe; diff is 0 for surrogates
- QString s(d->size, Qt::Uninitialized);
- memcpy(s.d->data(), d->data(), (p - d->data())*sizeof(ushort));
- ushort *pp = s.d->data() + (p - d->data());
- while (p != e) {
- if (QChar::isHighSurrogate(*p) && QChar::isLowSurrogate(p[1])) {
- *pp = *p++;
- prop = qGetProp(QChar::surrogateToUcs4(*pp++, *p));
- } else {
- prop = qGetProp(*p);
- }
- if (prop->upperCaseSpecial) {
- const ushort *specialCase = specialCaseMap + prop->upperCaseDiff;
- ushort length = *specialCase++;
- int pos = pp - s.d->data();
- s.resize(s.d->size + length - 1);
- pp = s.d->data() + pos;
- while (length--)
- *pp++ = *specialCase++;
- } else {
- *pp++ = *p + prop->upperCaseDiff;
- }
- ++p;
- }
-
- // this restores high surrogate parts eaten above, if any
- while (e != d->data() + d->size)
- *pp++ = *e++;
+QString QString::toUpper_helper(const QString &str)
+{
+ return QUnicodeTables::convertCase<QUnicodeTables::UppercaseTraits>(str);
+}
- return s;
- }
- ++p;
- }
- return *this;
+QString QString::toUpper_helper(QString &str)
+{
+ return QUnicodeTables::convertCase<QUnicodeTables::UppercaseTraits>(str);
}
+
// ### Qt 6: Consider whether this function shouldn't be removed See task 202871.
/*!
Safely builds a formatted string from the format string \a cformat
@@ -6630,24 +6571,25 @@ QString QString::number(double n, char f, int prec)
}
namespace {
-template<class ResultList, class StringSource, typename MidMethod, typename Separtor>
-static ResultList splitString(const StringSource &source, MidMethod mid, const Separtor &sep,
+template<class ResultList, class StringSource>
+static ResultList splitString(const StringSource &source, const QChar *sep,
QString::SplitBehavior behavior, Qt::CaseSensitivity cs, const int separatorSize)
{
ResultList list;
int start = 0;
int end;
int extra = 0;
- while ((end = source.indexOf(sep, start + extra, cs)) != -1) {
+ while ((end = qFindString(source.constData(), source.size(), start + extra, sep, separatorSize, cs)) != -1) {
if (start != end || behavior == QString::KeepEmptyParts)
- list.append((source.*mid)(start, end - start));
+ list.append(source.mid(start, end - start));
start = end + separatorSize;
extra = (separatorSize == 0 ? 1 : 0);
}
if (start != source.size() || behavior == QString::KeepEmptyParts)
- list.append((source.*mid)(start, -1));
+ list.append(source.mid(start, -1));
return list;
}
+
} // namespace
/*!
@@ -6670,7 +6612,7 @@ static ResultList splitString(const StringSource &source, MidMethod mid, const S
*/
QStringList QString::split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
{
- return splitString<QStringList>(*this, &QString::mid, sep, behavior, cs, sep.size());
+ return splitString<QStringList>(*this, sep.constData(), behavior, cs, sep.size());
}
/*!
@@ -6693,14 +6635,14 @@ QStringList QString::split(const QString &sep, SplitBehavior behavior, Qt::CaseS
*/
QVector<QStringRef> QString::splitRef(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
{
- return splitString<QVector<QStringRef> >(*this, &QString::midRef, sep, behavior, cs, sep.size());
+ return splitString<QVector<QStringRef> >(QStringRef(this), sep.constData(), behavior, cs, sep.size());
}
/*!
\overload
*/
QStringList QString::split(QChar sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
{
- return splitString<QStringList>(*this, &QString::mid, sep, behavior, cs, 1);
+ return splitString<QStringList>(*this, &sep, behavior, cs, 1);
}
/*!
@@ -6709,7 +6651,7 @@ QStringList QString::split(QChar sep, SplitBehavior behavior, Qt::CaseSensitivit
*/
QVector<QStringRef> QString::splitRef(QChar sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
{
- return splitString<QVector<QStringRef> >(*this, &QString::midRef, sep, behavior, cs, 1);
+ return splitString<QVector<QStringRef> >(QStringRef(this), &sep, behavior, cs, 1);
}
/*!
@@ -6731,7 +6673,7 @@ QVector<QStringRef> QString::splitRef(QChar sep, SplitBehavior behavior, Qt::Cas
*/
QVector<QStringRef> QStringRef::split(const QString &sep, QString::SplitBehavior behavior, Qt::CaseSensitivity cs) const
{
- return splitString<QVector<QStringRef> >(*this, &QStringRef::mid, sep, behavior, cs, sep.size());
+ return splitString<QVector<QStringRef> >(*this, sep.constData(), behavior, cs, sep.size());
}
/*!
@@ -6740,7 +6682,7 @@ QVector<QStringRef> QStringRef::split(const QString &sep, QString::SplitBehavior
*/
QVector<QStringRef> QStringRef::split(QChar sep, QString::SplitBehavior behavior, Qt::CaseSensitivity cs) const
{
- return splitString<QVector<QStringRef> >(*this, &QStringRef::mid, sep, behavior, cs, 1);
+ return splitString<QVector<QStringRef> >(*this, &sep, behavior, cs, 1);
}
#ifndef QT_NO_REGEXP
@@ -7654,49 +7596,79 @@ static int getEscape(const QChar *uc, int *pos, int len, int maxNumber = 999)
return -1;
}
+namespace {
+class ArgMapper {
+ QVarLengthArray<int, 16> argPosToNumberMap; // maps from argument position to number
+public:
+ void found(int n) { argPosToNumberMap.push_back(n); }
+
+ struct AssignmentResult {
+ int numArgs;
+ int lastNumber;
+ };
+
+ AssignmentResult assignArgumentNumberToEachOfTheNs(int numArgs)
+ {
+ std::sort(argPosToNumberMap.begin(), argPosToNumberMap.end());
+ argPosToNumberMap.erase(std::unique(argPosToNumberMap.begin(), argPosToNumberMap.end()),
+ argPosToNumberMap.end());
+
+ if (argPosToNumberMap.size() > numArgs)
+ argPosToNumberMap.resize(numArgs);
+
+ int lastNumber = argPosToNumberMap.empty() ? -1 : argPosToNumberMap.back();
+ int arg = argPosToNumberMap.size();
+
+ const AssignmentResult result = {arg, lastNumber};
+ return result;
+ }
+
+ int numberToArgsIndex(int number) const
+ {
+ if (number != -1) {
+ const int * const it = std::find(argPosToNumberMap.begin(), argPosToNumberMap.end(), number);
+ return it == argPosToNumberMap.end() ? -1 : it - argPosToNumberMap.begin();
+ } else {
+ return -1;
+ }
+ }
+};
+} // unnamed namespace
+
QString QString::multiArg(int numArgs, const QString **args) const
{
QString result;
- QMap<int, int> numbersUsed;
+ ArgMapper mapper;
const QChar *uc = (const QChar *) d->data();
const int len = d->size;
const int end = len - 1;
- int lastNumber = -1;
int i = 0;
- // populate the numbersUsed map with the %n's that actually occur in the string
+ // populate the arg-mapper with the %n's that actually occur in the string
while (i < end) {
if (uc[i] == QLatin1Char('%')) {
int number = getEscape(uc, &i, len);
if (number != -1) {
- numbersUsed.insert(number, -1);
+ mapper.found(number);
continue;
}
}
++i;
}
- // assign an argument number to each of the %n's
- QMap<int, int>::iterator j = numbersUsed.begin();
- QMap<int, int>::iterator jend = numbersUsed.end();
- int arg = 0;
- while (j != jend && arg < numArgs) {
- *j = arg++;
- lastNumber = j.key();
- ++j;
- }
+ const ArgMapper::AssignmentResult r = mapper.assignArgumentNumberToEachOfTheNs(numArgs);
// sanity
- if (numArgs > arg) {
- qWarning("QString::arg: %d argument(s) missing in %s", numArgs - arg, toLocal8Bit().data());
- numArgs = arg;
+ if (numArgs > r.numArgs) {
+ qWarning("QString::arg: %d argument(s) missing in %s", numArgs - r.numArgs, toLocal8Bit().data());
+ numArgs = r.numArgs;
}
i = 0;
while (i < len) {
if (uc[i] == QLatin1Char('%') && i != end) {
- int number = getEscape(uc, &i, len, lastNumber);
- int arg = numbersUsed[number];
+ int number = getEscape(uc, &i, len, r.lastNumber);
+ int arg = mapper.numberToArgsIndex(number);
if (number != -1 && arg != -1) {
result += *args[arg];
continue;
@@ -7942,6 +7914,46 @@ QString &QString::setRawData(const QChar *unicode, int size)
return *this;
}
+/*! \fn QString QString::fromStdU16String(const std::u16string &str)
+ \since 5.5
+
+ Returns a copy of the \a str string. The given string is assumed
+ to be encoded in UTF-16.
+
+ \sa fromUtf16(), fromStdWString(), fromStdU32String()
+*/
+
+/*!
+ \fn std::u16string QString::toStdU16String() const
+ \since 5.5
+
+ Returns a std::u16string object with the data contained in this
+ QString. The Unicode data is the same as returned by the utf16()
+ method.
+
+ \sa utf16(), toStdWString(), toStdU32String()
+*/
+
+/*! \fn QString QString::fromStdU32String(const std::u32string &str)
+ \since 5.5
+
+ Returns a copy of the \a str string. The given string is assumed
+ to be encoded in UCS-4.
+
+ \sa fromUcs4(), fromStdWString(), fromStdU16String()
+*/
+
+/*!
+ \fn std::u32string QString::toStdU32String() const
+ \since 5.5
+
+ Returns a std::u32string object with the data contained in this
+ QString. The Unicode data is the same as returned by the toUcs4()
+ method.
+
+ \sa toUcs4(), toStdWString(), toStdU16String()
+*/
+
/*! \class QLatin1String
\inmodule QtCore
\brief The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal.
@@ -9843,20 +9855,15 @@ QVector<uint> QStringRef::toUcs4() const
*/
QStringRef QStringRef::trimmed() const
{
- if (m_size == 0 || m_string == 0)
+ const QChar *begin = cbegin();
+ const QChar *end = cend();
+ QStringAlgorithms<const QStringRef>::trimmed_helper_positions(begin, end);
+ if (begin == cbegin() && end == cend())
return *this;
- const QChar *s = m_string->constData() + m_position;
- int start = 0;
- int end = m_size - 1;
- while (start <= end && s[start].isSpace()) // skip white space from start
- start++;
- if (start <= end) { // only white space
- while (end && s[end].isSpace()) // skip white space from end
- end--;
- }
- int l = end - start + 1;
- Q_ASSERT(l >= 0);
- return QStringRef(m_string, m_position + start, l);
+ if (begin == end)
+ return QStringRef();
+ int position = m_position + (begin - cbegin());
+ return QStringRef(m_string, position, end - begin);
}
/*!
diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h
index a12946e23c..0deb664dc7 100644
--- a/src/corelib/tools/qstring.h
+++ b/src/corelib/tools/qstring.h
@@ -34,6 +34,10 @@
#ifndef QSTRING_H
#define QSTRING_H
+#if defined(QT_NO_CAST_FROM_ASCII) && defined(QT_RESTRICTED_CAST_FROM_ASCII)
+#error QT_NO_CAST_FROM_ASCII and QT_RESTRICTED_CAST_FROM_ASCII must not be defined at the same time
+#endif
+
#include <QtCore/qchar.h>
#include <QtCore/qbytearray.h>
#include <QtCore/qrefcount.h>
@@ -93,7 +97,7 @@ public:
inline bool operator>=(const QString &s) const;
inline bool operator<=(const QString &s) const;
-#ifndef QT_NO_CAST_FROM_ASCII
+#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
inline QT_ASCII_CAST_WARN bool operator==(const char *s) const;
inline QT_ASCII_CAST_WARN bool operator!=(const char *s) const;
inline QT_ASCII_CAST_WARN bool operator<(const char *s) const;
@@ -107,7 +111,7 @@ public:
inline QT_ASCII_CAST_WARN bool operator>(const QByteArray &s) const;
inline QT_ASCII_CAST_WARN bool operator<=(const QByteArray &s) const;
inline QT_ASCII_CAST_WARN bool operator>=(const QByteArray &s) const;
-#endif // QT_NO_CAST_FROM_ASCII
+#endif // !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
private:
int m_size;
@@ -206,22 +210,22 @@ class Q_CORE_EXPORT QString
public:
typedef QStringData Data;
- inline QString();
+ inline QString() Q_DECL_NOTHROW;
explicit QString(const QChar *unicode, int size = -1);
QString(QChar c);
QString(int size, QChar c);
inline QString(QLatin1String latin1);
- inline QString(const QString &);
+ inline QString(const QString &) Q_DECL_NOTHROW;
inline ~QString();
QString &operator=(QChar c);
- QString &operator=(const QString &);
+ QString &operator=(const QString &) Q_DECL_NOTHROW;
inline QString &operator=(QLatin1String latin1);
#ifdef Q_COMPILER_RVALUE_REFS
- inline QString(QString && other) : d(other.d) { other.d = Data::sharedNull(); }
- inline QString &operator=(QString &&other)
+ inline QString(QString && other) Q_DECL_NOTHROW : d(other.d) { other.d = Data::sharedNull(); }
+ inline QString &operator=(QString &&other) Q_DECL_NOTHROW
{ qSwap(d, other.d); return *this; }
#endif
- inline void swap(QString &other) { qSwap(d, other.d); }
+ inline void swap(QString &other) Q_DECL_NOTHROW { qSwap(d, other.d); }
inline int size() const { return d->size; }
inline int count() const { return d->size; }
inline int length() const;
@@ -327,7 +331,9 @@ public:
#ifndef QT_NO_REGULAREXPRESSION
int indexOf(const QRegularExpression &re, int from = 0) const;
+ int indexOf(const QRegularExpression &re, int from, QRegularExpressionMatch *rmatch) const; // ### Qt 6: merge overloads
int lastIndexOf(const QRegularExpression &re, int from = -1) const;
+ int lastIndexOf(const QRegularExpression &re, int from, QRegularExpressionMatch *rmatch) const; // ### Qt 6: merge overloads
bool contains(const QRegularExpression &re) const;
bool contains(const QRegularExpression &re, QRegularExpressionMatch *match) const; // ### Qt 6: merge overloads
int count(const QRegularExpression &re) const;
@@ -369,12 +375,44 @@ public:
QString leftJustified(int width, QChar fill = QLatin1Char(' '), bool trunc = false) const Q_REQUIRED_RESULT;
QString rightJustified(int width, QChar fill = QLatin1Char(' '), bool trunc = false) const Q_REQUIRED_RESULT;
+#if defined(Q_COMPILER_REF_QUALIFIERS) && !defined(QT_COMPILING_QSTRING_COMPAT_CPP)
+# if defined(Q_CC_GNU)
+ // required due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61941
+# pragma push_macro("Q_REQUIRED_RESULT")
+# undef Q_REQUIRED_RESULT
+# define Q_REQUIRED_RESULT
+# define Q_REQUIRED_RESULT_pushed
+# endif
+ QString toLower() const & Q_REQUIRED_RESULT
+ { return toLower_helper(*this); }
+ QString toLower() && Q_REQUIRED_RESULT
+ { return toLower_helper(*this); }
+ QString toUpper() const & Q_REQUIRED_RESULT
+ { return toUpper_helper(*this); }
+ QString toUpper() && Q_REQUIRED_RESULT
+ { return toUpper_helper(*this); }
+ QString toCaseFolded() const & Q_REQUIRED_RESULT
+ { return toCaseFolded_helper(*this); }
+ QString toCaseFolded() && Q_REQUIRED_RESULT
+ { return toCaseFolded_helper(*this); }
+ QString trimmed() const & Q_REQUIRED_RESULT
+ { return trimmed_helper(*this); }
+ QString trimmed() && Q_REQUIRED_RESULT
+ { return trimmed_helper(*this); }
+ QString simplified() const & Q_REQUIRED_RESULT
+ { return simplified_helper(*this); }
+ QString simplified() && Q_REQUIRED_RESULT
+ { return simplified_helper(*this); }
+# ifdef Q_REQUIRED_RESULT_pushed
+# pragma pop_macro("Q_REQUIRED_RESULT")
+# endif
+#else
QString toLower() const Q_REQUIRED_RESULT;
QString toUpper() const Q_REQUIRED_RESULT;
QString toCaseFolded() const Q_REQUIRED_RESULT;
-
QString trimmed() const Q_REQUIRED_RESULT;
QString simplified() const Q_REQUIRED_RESULT;
+#endif
QString toHtmlEscaped() const Q_REQUIRED_RESULT;
QString &insert(int i, QChar c);
@@ -596,7 +634,16 @@ public:
inline bool operator>=(QLatin1String s) const { return !operator<(s); }
// ASCII compatibility
-#ifndef QT_NO_CAST_FROM_ASCII
+#if defined(QT_RESTRICTED_CAST_FROM_ASCII)
+ template <int N>
+ inline QString(const char (&ch)[N])
+ : d(fromAscii_helper(ch, N - 1))
+ {}
+ template <int N>
+ inline QString &operator=(const char (&ch)[N])
+ { return (*this = fromLatin1(ch, N - 1)); }
+#endif
+#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
inline QT_ASCII_CAST_WARN QString(const char *ch)
: d(fromAscii_helper(ch, ch ? int(strlen(ch)) : -1))
{}
@@ -686,6 +733,13 @@ public:
static inline QString fromStdWString(const std::wstring &s);
inline std::wstring toStdWString() const;
+#if defined(Q_COMPILER_UNICODE_STRINGS) || defined(Q_QDOC)
+ static inline QString fromStdU16String(const std::u16string &s);
+ inline std::u16string toStdU16String() const;
+ static inline QString fromStdU32String(const std::u32string &s);
+ inline std::u32string toStdU32String() const;
+#endif
+
#if defined(Q_OS_MAC) || defined(Q_QDOC)
static QString fromCFString(CFStringRef string);
CFStringRef toCFString() const Q_DECL_CF_RETURNS_RETAINED;
@@ -734,6 +788,16 @@ private:
Qt::CaseSensitivity cs = Qt::CaseSensitive);
static int localeAwareCompare_helper(const QChar *data1, int length1,
const QChar *data2, int length2);
+ static QString toLower_helper(const QString &str);
+ static QString toLower_helper(QString &str);
+ static QString toUpper_helper(const QString &str);
+ static QString toUpper_helper(QString &str);
+ static QString toCaseFolded_helper(const QString &str);
+ static QString toCaseFolded_helper(QString &str);
+ static QString trimmed_helper(const QString &str);
+ static QString trimmed_helper(QString &str);
+ static QString simplified_helper(const QString &str);
+ static QString simplified_helper(QString &str);
static Data *fromLatin1_helper(const char *str, int size = -1);
static Data *fromAscii_helper(const char *str, int size = -1);
static QString fromUtf8_helper(const char *str, int size);
@@ -808,7 +872,7 @@ inline QString &QString::operator=(QLatin1String s)
}
inline void QString::clear()
{ if (!isNull()) *this = QString(); }
-inline QString::QString(const QString &other) : d(other.d)
+inline QString::QString(const QString &other) Q_DECL_NOTHROW : d(other.d)
{ Q_ASSERT(&other != this); d->ref.ref(); }
inline int QString::capacity() const
{ return d->alloc ? d->alloc - 1 : 0; }
@@ -867,11 +931,8 @@ inline QString QString::arg(const QString &a1, const QString &a2, const QString
inline QString QString::section(QChar asep, int astart, int aend, SectionFlags aflags) const
{ return section(QString(asep), astart, aend, aflags); }
-#ifdef Q_CC_MSVC
-// "conditional expression is constant"
-#pragma warning(push)
-#pragma warning(disable : 4127)
-#endif
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_MSVC(4127) // "conditional expression is constant"
inline int QString::toWCharArray(wchar_t *array) const
{
@@ -882,9 +943,7 @@ inline int QString::toWCharArray(wchar_t *array) const
return toUcs4_helper(d->data(), size(), reinterpret_cast<uint *>(array));
}
-#ifdef Q_CC_MSVC
-#pragma warning(pop)
-#endif
+QT_WARNING_POP
inline QString QString::fromWCharArray(const wchar_t *string, int size)
{
@@ -988,7 +1047,7 @@ inline void QCharRef::setRow(uchar arow) { QChar(*this).setRow(arow); }
inline void QCharRef::setCell(uchar acell) { QChar(*this).setCell(acell); }
-inline QString::QString() : d(Data::sharedNull()) {}
+inline QString::QString() Q_DECL_NOTHROW : d(Data::sharedNull()) {}
inline QString::~QString() { if (!d->ref.deref()) Data::deallocate(d); }
inline void QString::reserve(int asize)
@@ -1083,7 +1142,7 @@ inline bool QLatin1String::operator>=(const QString &s) const
inline bool QLatin1String::operator<=(const QString &s) const
{ return s >= *this; }
-#ifndef QT_NO_CAST_FROM_ASCII
+#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
inline bool QString::operator==(const char *s) const
{ return QString::compare_helper(constData(), size(), s, -1) == 0; }
inline bool QString::operator!=(const char *s) const
@@ -1174,7 +1233,7 @@ inline bool QByteArray::operator<=(const QString &s) const
{ return QString::compare_helper(s.constData(), s.size(), constData(), qstrnlen(constData(), size())) <= 0; }
inline bool QByteArray::operator>=(const QString &s) const
{ return QString::compare_helper(s.constData(), s.size(), constData(), qstrnlen(constData(), size())) >= 0; }
-#endif // QT_NO_CAST_FROM_ASCII
+#endif // !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
#ifndef QT_NO_CAST_TO_ASCII
inline QByteArray &QByteArray::append(const QString &s)
@@ -1202,7 +1261,7 @@ inline const QString operator+(const QString &s1, QChar s2)
{ QString t(s1); t += s2; return t; }
inline const QString operator+(QChar s1, const QString &s2)
{ QString t(s1); t += s2; return t; }
-# ifndef QT_NO_CAST_FROM_ASCII
+# if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
inline QT_ASCII_CAST_WARN const QString operator+(const QString &s1, const char *s2)
{ QString t(s1); t += QString::fromUtf8(s2); return t; }
inline QT_ASCII_CAST_WARN const QString operator+(const char *s1, const QString &s2)
@@ -1242,6 +1301,25 @@ inline std::wstring QString::toStdWString() const
inline QString QString::fromStdWString(const std::wstring &s)
{ return fromWCharArray(s.data(), int(s.size())); }
+#if defined(Q_COMPILER_UNICODE_STRINGS)
+inline QString QString::fromStdU16String(const std::u16string &s)
+{ return fromUtf16(s.data(), int(s.size())); }
+
+inline std::u16string QString::toStdU16String() const
+{ return std::u16string(reinterpret_cast<const char16_t*>(utf16()), length()); }
+
+inline QString QString::fromStdU32String(const std::u32string &s)
+{ return fromUcs4(s.data(), int(s.size())); }
+
+inline std::u32string QString::toStdU32String() const
+{
+ std::u32string u32str(length(), char32_t(0));
+ int len = toUcs4_helper(d->data(), length(), reinterpret_cast<uint*>(&u32str[0]));
+ u32str.resize(len);
+ return u32str;
+}
+#endif
+
#if !defined(QT_NO_DATASTREAM) || (defined(QT_BOOTSTRAPPED) && !defined(QT_BUILD_QMAKE))
Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QString &);
Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QString &);
@@ -1355,7 +1433,7 @@ public:
inline const QChar at(int i) const
{ Q_ASSERT(uint(i) < uint(size())); return m_string->at(i + m_position); }
-#ifndef QT_NO_CAST_FROM_ASCII
+#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
// ASCII compatibility
inline QT_ASCII_CAST_WARN bool operator==(const char *s) const;
inline QT_ASCII_CAST_WARN bool operator!=(const char *s) const;
@@ -1429,7 +1507,7 @@ inline bool operator<=(const QStringRef &s1, const QStringRef &s2)
inline bool operator>=(const QStringRef &s1, const QStringRef &s2)
{ return !(s1 < s2); }
-#ifndef QT_NO_CAST_FROM_ASCII
+#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
inline QT_ASCII_CAST_WARN bool QStringRef::operator==(const char *s) const
{ return QString::compare_helper(constData(), size(), s, -1) == 0; }
inline QT_ASCII_CAST_WARN bool QStringRef::operator!=(const char *s) const
@@ -1455,7 +1533,7 @@ inline QT_ASCII_CAST_WARN bool operator>(const char *s1, const QStringRef &s2)
{ return QString::compare_helper(s2.constData(), s2.size(), s1, -1) <= 0; }
inline QT_ASCII_CAST_WARN bool operator>=(const char *s1, const QStringRef &s2)
{ return QString::compare_helper(s2.constData(), s2.size(), s1, -1) >= 0; }
-#endif // QT_NO_CAST_FROM_ASCII
+#endif // !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
inline int QString::compare(const QStringRef &s, Qt::CaseSensitivity cs) const
{ return QString::compare_helper(constData(), length(), s.constData(), s.length(), cs); }
diff --git a/src/corelib/tools/qstring_compat.cpp b/src/corelib/tools/qstring_compat.cpp
index c776092569..d4f21e483a 100644
--- a/src/corelib/tools/qstring_compat.cpp
+++ b/src/corelib/tools/qstring_compat.cpp
@@ -31,16 +31,42 @@
**
****************************************************************************/
-#if defined(QSTRING_H)
+#if defined(QSTRING_H) || defined(QBYTEARRAY_H)
# error "This file cannot be compiled with pre-compiled headers"
#endif
#define QT_COMPILING_QSTRING_COMPAT_CPP
+#include "qbytearray.h"
#include "qstring.h"
QT_BEGIN_NAMESPACE
// all these implementations must be the same as the inline versions in qstring.h
+QString QString::trimmed() const
+{
+ return trimmed_helper(*this);
+}
+
+QString QString::simplified() const
+{
+ return simplified_helper(*this);
+}
+
+QString QString::toLower() const
+{
+ return toLower_helper(*this);
+}
+
+QString QString::toCaseFolded() const
+{
+ return toCaseFolded_helper(*this);
+}
+
+QString QString::toUpper() const
+{
+ return toUpper_helper(*this);
+}
+
QByteArray QString::toLatin1() const
{
return toLatin1_helper(*this);
@@ -56,4 +82,25 @@ QByteArray QString::toUtf8() const
return toUtf8_helper(*this);
}
+// ditto, for qbytearray.h (because we're lazy)
+QByteArray QByteArray::toLower() const
+{
+ return toLower_helper(*this);
+}
+
+QByteArray QByteArray::toUpper() const
+{
+ return toUpper_helper(*this);
+}
+
+QByteArray QByteArray::trimmed() const
+{
+ return trimmed_helper(*this);
+}
+
+QByteArray QByteArray::simplified() const
+{
+ return simplified_helper(*this);
+}
+
QT_END_NAMESPACE
diff --git a/src/corelib/tools/qstringalgorithms_p.h b/src/corelib/tools/qstringalgorithms_p.h
new file mode 100644
index 0000000000..2911055f6a
--- /dev/null
+++ b/src/corelib/tools/qstringalgorithms_p.h
@@ -0,0 +1,156 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Intel Corporation.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSTRINGALGORITHMS_P_H
+#define QSTRINGALGORITHMS_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of internal files. This header file may change from version to version
+// without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qstring.h"
+#include "qlocale_p.h" // for ascii_isspace
+
+QT_BEGIN_NAMESPACE
+
+template <typename StringType> struct QStringAlgorithms
+{
+ typedef typename StringType::value_type Char;
+ typedef typename StringType::size_type size_type;
+ typedef typename QtPrivate::remove_cv<StringType>::type NakedStringType;
+ static const bool isConst = QtPrivate::is_const<StringType>::value;
+
+ static inline bool isSpace(char ch) { return ascii_isspace(ch); }
+ static inline bool isSpace(QChar ch) { return ch.isSpace(); }
+
+ // Surrogate pairs are not handled in either of the functions below. That is
+ // not a problem because there are no space characters (Zs, Zl, Zp) outside the
+ // Basic Multilingual Plane.
+
+ static inline StringType trimmed_helper_inplace(NakedStringType &str, const Char *begin, const Char *end)
+ {
+ // in-place trimming:
+ Char *data = const_cast<Char *>(str.cbegin());
+ if (begin != data)
+ memmove(data, begin, (end - begin) * sizeof(Char));
+ str.resize(end - begin);
+ return qMove(str);
+ }
+
+ static inline StringType trimmed_helper_inplace(const NakedStringType &, const Char *, const Char *)
+ {
+ // can't happen
+ Q_UNREACHABLE();
+ return StringType();
+ }
+
+ static inline void trimmed_helper_positions(const Char *&begin, const Char *&end)
+ {
+ // skip white space from start
+ while (begin < end && isSpace(*begin))
+ begin++;
+ // skip white space from end
+ if (begin < end) {
+ while (begin < end && isSpace(end[-1]))
+ end--;
+ }
+ }
+
+ static inline StringType trimmed_helper(StringType &str)
+ {
+ const Char *begin = str.cbegin();
+ const Char *end = str.cend();
+ trimmed_helper_positions(begin, end);
+
+ if (begin == str.cbegin() && end == str.cend())
+ return str;
+ if (begin == end)
+ return StringType();
+ if (!isConst && str.isDetached())
+ return trimmed_helper_inplace(str, begin, end);
+ return StringType(begin, end - begin);
+ }
+
+ static inline StringType simplified_helper(StringType &str)
+ {
+ if (str.isEmpty())
+ return str;
+ const Char *src = str.cbegin();
+ const Char *end = str.cend();
+ NakedStringType result = isConst ?
+ StringType(str.size(), Qt::Uninitialized) :
+ qMove(str);
+
+ Char *dst = const_cast<Char *>(result.cbegin());
+ Char *ptr = dst;
+ forever {
+ while (src != end && isSpace(*src))
+ ++src;
+ while (src != end && !isSpace(*src))
+ *ptr++ = *src++;
+ if (src != end)
+ *ptr++ = QChar::Space;
+ else
+ break;
+ }
+ if (ptr != dst && ptr[-1] == QChar::Space)
+ --ptr;
+
+ int newlen = ptr - dst;
+ if (isConst && newlen == str.size()) {
+ // nothing happened, return the original
+ return str;
+ }
+ result.resize(newlen);
+ return result;
+ }
+};
+
+QT_END_NAMESPACE
+
+#endif // QSTRINGALGORITHMS_P_H
diff --git a/src/corelib/tools/qstringiterator_p.h b/src/corelib/tools/qstringiterator_p.h
index b80193b790..3f431daf6f 100644
--- a/src/corelib/tools/qstringiterator_p.h
+++ b/src/corelib/tools/qstringiterator_p.h
@@ -74,6 +74,11 @@ public:
return pos;
}
+ inline int index() const
+ {
+ return pos - i;
+ }
+
inline void setPosition(QString::const_iterator position)
{
Q_ASSERT_X(i <= position && position <= e, Q_FUNC_INFO, "position out of bounds");
diff --git a/src/corelib/tools/qstringlist.cpp b/src/corelib/tools/qstringlist.cpp
index 4e5393e0b0..192306c059 100644
--- a/src/corelib/tools/qstringlist.cpp
+++ b/src/corelib/tools/qstringlist.cpp
@@ -516,28 +516,6 @@ QString QtPrivate::QStringList_join(const QStringList *that, const QChar *sep, i
the latter string list.
*/
-#ifndef QT_NO_DATASTREAM
-/*!
- \fn QDataStream &operator>>(QDataStream &in, QStringList &list)
- \relates QStringList
-
- Reads a string list from the given \a in stream into the specified
- \a list.
-
- \sa {Serializing Qt Data Types}
-*/
-
-/*!
- \fn QDataStream &operator<<(QDataStream &out, const QStringList &list)
- \relates QStringList
-
- Writes the given string \a list to the specified \a out stream.
-
- \sa {Serializing Qt Data Types}
-*/
-#endif // QT_NO_DATASTREAM
-
-
#ifndef QT_NO_REGEXP
static int indexOfMutating(const QStringList *that, QRegExp &rx, int from)
{
@@ -704,29 +682,6 @@ int QtPrivate::QStringList_lastIndexOf(const QStringList *that, const QRegularEx
#endif // QT_BOOTSTRAPPED
/*!
- \fn int QStringList::indexOf(const QString &value, int from = 0) const
-
- Returns the index position of the first occurrence of \a value in
- the list, searching forward from index position \a from. Returns
- -1 if no item matched.
-
- \sa lastIndexOf(), contains(), QList::indexOf()
-*/
-
-/*!
- \fn int QStringList::lastIndexOf(const QString &value, int from = -1) const
-
- Returns the index position of the last occurrence of \a value in
- the list, searching backward from index position \a from. If \a
- from is -1 (the default), the search starts at the last item.
- Returns -1 if no item matched.
-
- By default, this function is case sensitive.
-
- \sa indexOf(), QList::lastIndexOf()
-*/
-
-/*!
\fn int QStringList::removeDuplicates()
\since 4.5
diff --git a/src/corelib/tools/qstringlist.h b/src/corelib/tools/qstringlist.h
index b24a261a7c..f82981b9dc 100644
--- a/src/corelib/tools/qstringlist.h
+++ b/src/corelib/tools/qstringlist.h
@@ -31,33 +31,70 @@
**
****************************************************************************/
+#include <QtCore/qlist.h>
+
#ifndef QSTRINGLIST_H
#define QSTRINGLIST_H
#include <QtCore/qalgorithms.h>
-#include <QtCore/qdatastream.h>
-#include <QtCore/qlist.h>
#include <QtCore/qregexp.h>
#include <QtCore/qstring.h>
#include <QtCore/qstringmatcher.h>
QT_BEGIN_NAMESPACE
-
class QRegExp;
class QRegularExpression;
typedef QListIterator<QString> QStringListIterator;
typedef QMutableListIterator<QString> QMutableStringListIterator;
+class QStringList;
+
+#ifdef Q_QDOC
+class QStringList : public QList<QString>
+#else
+template <> struct QListSpecialMethods<QString>
+#endif
+{
+public:
+ inline void sort(Qt::CaseSensitivity cs = Qt::CaseSensitive);
+ inline int removeDuplicates();
+
+ inline QString join(const QString &sep) const;
+ inline QString join(QChar sep) const;
+
+ inline QStringList filter(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
+ inline QStringList &replaceInStrings(const QString &before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive);
+
+#ifndef QT_NO_REGEXP
+ inline QStringList filter(const QRegExp &rx) const;
+ inline QStringList &replaceInStrings(const QRegExp &rx, const QString &after);
+#endif
+
+#ifndef QT_BOOTSTRAPPED
+#ifndef QT_NO_REGULAREXPRESSION
+ inline QStringList filter(const QRegularExpression &re) const;
+ inline QStringList &replaceInStrings(const QRegularExpression &re, const QString &after);
+#endif // QT_NO_REGULAREXPRESSION
+#endif // QT_BOOTSTRAPPED
+
+#ifndef Q_QDOC
+private:
+ inline QStringList *self();
+ inline const QStringList *self() const;
+};
+
+// ### Qt6: check if there's a better way
class QStringList : public QList<QString>
{
+#endif
public:
- inline QStringList() { }
+ inline QStringList() Q_DECL_NOTHROW { }
inline explicit QStringList(const QString &i) { append(i); }
inline QStringList(const QList<QString> &l) : QList<QString>(l) { }
#ifdef Q_COMPILER_RVALUE_REFS
- inline QStringList(QList<QString> &&l) : QList<QString>(std::move(l)) { }
+ inline QStringList(QList<QString> &&l) Q_DECL_NOTHROW : QList<QString>(std::move(l)) { }
#endif
#ifdef Q_COMPILER_INITIALIZER_LISTS
inline QStringList(std::initializer_list<QString> args) : QList<QString>(args) { }
@@ -66,21 +103,12 @@ public:
QStringList &operator=(const QList<QString> &other)
{ QList<QString>::operator=(other); return *this; }
#ifdef Q_COMPILER_RVALUE_REFS
- QStringList &operator=(QList<QString> &&other)
+ QStringList &operator=(QList<QString> &&other) Q_DECL_NOTHROW
{ QList<QString>::operator=(std::move(other)); return *this; }
#endif
- inline void sort(Qt::CaseSensitivity cs = Qt::CaseSensitive);
- inline int removeDuplicates();
-
- inline QString join(const QString &sep) const;
- inline QString join(QChar sep) const;
-
- inline QStringList filter(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
inline bool contains(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
- inline QStringList &replaceInStrings(const QString &before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive);
-
inline QStringList operator+(const QStringList &other) const
{ QStringList n = *this; n += other; return n; }
inline QStringList &operator<<(const QString &str)
@@ -91,8 +119,6 @@ public:
{ *this += l; return *this; }
#ifndef QT_NO_REGEXP
- inline QStringList filter(const QRegExp &rx) const;
- inline QStringList &replaceInStrings(const QRegExp &rx, const QString &after);
inline int indexOf(const QRegExp &rx, int from = 0) const;
inline int lastIndexOf(const QRegExp &rx, int from = -1) const;
inline int indexOf(QRegExp &rx, int from = 0) const;
@@ -101,26 +127,22 @@ public:
#ifndef QT_BOOTSTRAPPED
#ifndef QT_NO_REGULAREXPRESSION
- inline QStringList filter(const QRegularExpression &re) const;
- inline QStringList &replaceInStrings(const QRegularExpression &re, const QString &after);
inline int indexOf(const QRegularExpression &re, int from = 0) const;
inline int lastIndexOf(const QRegularExpression &re, int from = -1) const;
#endif // QT_NO_REGULAREXPRESSION
#endif // QT_BOOTSTRAPPED
-#if !defined(Q_NO_USING_KEYWORD)
using QList<QString>::indexOf;
using QList<QString>::lastIndexOf;
-#else
- inline int indexOf(const QString &str, int from = 0) const
- { return QList<QString>::indexOf(str, from); }
- inline int lastIndexOf(const QString &str, int from = -1) const
- { return QList<QString>::lastIndexOf(str, from); }
-#endif
};
Q_DECLARE_TYPEINFO(QStringList, Q_MOVABLE_TYPE);
+inline QStringList *QListSpecialMethods<QString>::self()
+{ return static_cast<QStringList *>(this); }
+inline const QStringList *QListSpecialMethods<QString>::self() const
+{ return static_cast<const QStringList *>(this); }
+
namespace QtPrivate {
void Q_CORE_EXPORT QStringList_sort(QStringList *that, Qt::CaseSensitivity cs);
int Q_CORE_EXPORT QStringList_removeDuplicates(QStringList *that);
@@ -151,29 +173,29 @@ namespace QtPrivate {
#endif // QT_BOOTSTRAPPED
}
-inline void QStringList::sort(Qt::CaseSensitivity cs)
+inline void QListSpecialMethods<QString>::sort(Qt::CaseSensitivity cs)
{
- QtPrivate::QStringList_sort(this, cs);
+ QtPrivate::QStringList_sort(self(), cs);
}
-inline int QStringList::removeDuplicates()
+inline int QListSpecialMethods<QString>::removeDuplicates()
{
- return QtPrivate::QStringList_removeDuplicates(this);
+ return QtPrivate::QStringList_removeDuplicates(self());
}
-inline QString QStringList::join(const QString &sep) const
+inline QString QListSpecialMethods<QString>::join(const QString &sep) const
{
- return QtPrivate::QStringList_join(this, sep.constData(), sep.length());
+ return QtPrivate::QStringList_join(self(), sep.constData(), sep.length());
}
-inline QString QStringList::join(QChar sep) const
+inline QString QListSpecialMethods<QString>::join(QChar sep) const
{
- return QtPrivate::QStringList_join(this, &sep, 1);
+ return QtPrivate::QStringList_join(self(), &sep, 1);
}
-inline QStringList QStringList::filter(const QString &str, Qt::CaseSensitivity cs) const
+inline QStringList QListSpecialMethods<QString>::filter(const QString &str, Qt::CaseSensitivity cs) const
{
- return QtPrivate::QStringList_filter(this, str, cs);
+ return QtPrivate::QStringList_filter(self(), str, cs);
}
inline bool QStringList::contains(const QString &str, Qt::CaseSensitivity cs) const
@@ -181,22 +203,29 @@ inline bool QStringList::contains(const QString &str, Qt::CaseSensitivity cs) co
return QtPrivate::QStringList_contains(this, str, cs);
}
-inline QStringList &QStringList::replaceInStrings(const QString &before, const QString &after, Qt::CaseSensitivity cs)
+inline QStringList &QListSpecialMethods<QString>::replaceInStrings(const QString &before, const QString &after, Qt::CaseSensitivity cs)
+{
+ QtPrivate::QStringList_replaceInStrings(self(), before, after, cs);
+ return *self();
+}
+
+inline QStringList operator+(const QList<QString> &one, const QStringList &other)
{
- QtPrivate::QStringList_replaceInStrings(this, before, after, cs);
- return *this;
+ QStringList n = one;
+ n += other;
+ return n;
}
#ifndef QT_NO_REGEXP
-inline QStringList &QStringList::replaceInStrings(const QRegExp &rx, const QString &after)
+inline QStringList &QListSpecialMethods<QString>::replaceInStrings(const QRegExp &rx, const QString &after)
{
- QtPrivate::QStringList_replaceInStrings(this, rx, after);
- return *this;
+ QtPrivate::QStringList_replaceInStrings(self(), rx, after);
+ return *self();
}
-inline QStringList QStringList::filter(const QRegExp &rx) const
+inline QStringList QListSpecialMethods<QString>::filter(const QRegExp &rx) const
{
- return QtPrivate::QStringList_filter(this, rx);
+ return QtPrivate::QStringList_filter(self(), rx);
}
inline int QStringList::indexOf(const QRegExp &rx, int from) const
@@ -222,15 +251,15 @@ inline int QStringList::lastIndexOf(QRegExp &rx, int from) const
#ifndef QT_BOOTSTRAPPED
#ifndef QT_NO_REGULAREXPRESSION
-inline QStringList &QStringList::replaceInStrings(const QRegularExpression &rx, const QString &after)
+inline QStringList &QListSpecialMethods<QString>::replaceInStrings(const QRegularExpression &rx, const QString &after)
{
- QtPrivate::QStringList_replaceInStrings(this, rx, after);
- return *this;
+ QtPrivate::QStringList_replaceInStrings(self(), rx, after);
+ return *self();
}
-inline QStringList QStringList::filter(const QRegularExpression &rx) const
+inline QStringList QListSpecialMethods<QString>::filter(const QRegularExpression &rx) const
{
- return QtPrivate::QStringList_filter(this, rx);
+ return QtPrivate::QStringList_filter(self(), rx);
}
inline int QStringList::indexOf(const QRegularExpression &rx, int from) const
@@ -245,17 +274,6 @@ inline int QStringList::lastIndexOf(const QRegularExpression &rx, int from) cons
#endif // QT_NO_REGULAREXPRESSION
#endif // QT_BOOTSTRAPPED
-#ifndef QT_NO_DATASTREAM
-inline QDataStream &operator>>(QDataStream &in, QStringList &list)
-{
- return operator>>(in, static_cast<QList<QString> &>(list));
-}
-inline QDataStream &operator<<(QDataStream &out, const QStringList &list)
-{
- return operator<<(out, static_cast<const QList<QString> &>(list));
-}
-#endif // QT_NO_DATASTREAM
-
QT_END_NAMESPACE
#endif // QSTRINGLIST_H
diff --git a/src/corelib/tools/qstringmatcher.h b/src/corelib/tools/qstringmatcher.h
index 00e5fc1587..d416831434 100644
--- a/src/corelib/tools/qstringmatcher.h
+++ b/src/corelib/tools/qstringmatcher.h
@@ -66,11 +66,6 @@ private:
QStringMatcherPrivate *d_ptr;
QString q_pattern;
Qt::CaseSensitivity q_cs;
-#ifdef Q_CC_RVCT
-// explicitly allow anonymous unions for RVCT to prevent compiler warnings
-# pragma push
-# pragma anon_unions
-#endif
struct Data {
uchar q_skiptable[256];
const QChar *uc;
@@ -80,9 +75,6 @@ private:
uint q_data[256];
Data p;
};
-#ifdef Q_CC_RVCT
-# pragma pop
-#endif
};
QT_END_NAMESPACE
diff --git a/src/corelib/tools/qtimeline.h b/src/corelib/tools/qtimeline.h
index 8e577c2651..c0b245ed8d 100644
--- a/src/corelib/tools/qtimeline.h
+++ b/src/corelib/tools/qtimeline.h
@@ -137,7 +137,7 @@ Q_SIGNALS:
);
protected:
- void timerEvent(QTimerEvent *event);
+ void timerEvent(QTimerEvent *event) Q_DECL_OVERRIDE;
private:
Q_DISABLE_COPY(QTimeLine)
diff --git a/src/corelib/tools/qtimezone.cpp b/src/corelib/tools/qtimezone.cpp
index 8f3db74131..30c4c60167 100644
--- a/src/corelib/tools/qtimezone.cpp
+++ b/src/corelib/tools/qtimezone.cpp
@@ -56,6 +56,8 @@ static QTimeZonePrivate *newBackendTimeZone()
#else
#if defined Q_OS_MAC
return new QMacTimeZonePrivate();
+#elif defined Q_OS_ANDROID
+ return new QAndroidTimeZonePrivate();
#elif defined Q_OS_UNIX
return new QTzTimeZonePrivate();
// Registry based timezone backend not available on WinRT
@@ -81,6 +83,8 @@ static QTimeZonePrivate *newBackendTimeZone(const QByteArray &ianaId)
#else
#if defined Q_OS_MAC
return new QMacTimeZonePrivate(ianaId);
+#elif defined Q_OS_ANDROID
+ return new QAndroidTimeZonePrivate(ianaId);
#elif defined Q_OS_UNIX
return new QTzTimeZonePrivate(ianaId);
// Registry based timezone backend not available on WinRT
@@ -785,6 +789,29 @@ QByteArray QTimeZone::systemTimeZoneId()
}
/*!
+ \since 5.5
+ Returns a QTimeZone object that refers to the local system time, as
+ specified by systemTimeZoneId().
+
+ \sa utc()
+*/
+QTimeZone QTimeZone::systemTimeZone()
+{
+ return QTimeZone(QTimeZone::systemTimeZoneId());
+}
+
+/*!
+ \since 5.5
+ Returns a QTimeZone object that refers to UTC (Universal Time Coordinated).
+
+ \sa systemTimeZone()
+*/
+QTimeZone QTimeZone::utc()
+{
+ return QTimeZone(QTimeZonePrivate::utcQByteArray());
+}
+
+/*!
Returns \c true if a given time zone \a ianaId is available on this system.
\sa availableTimeZoneIds()
diff --git a/src/corelib/tools/qtimezone.h b/src/corelib/tools/qtimezone.h
index ffc2316b5f..e35cee6bbe 100644
--- a/src/corelib/tools/qtimezone.h
+++ b/src/corelib/tools/qtimezone.h
@@ -79,10 +79,10 @@ public:
QTimeZone &operator=(const QTimeZone &other);
#ifdef Q_COMPILER_RVALUE_REFS
- QTimeZone &operator=(QTimeZone &&other) { swap(other); return *this; }
+ QTimeZone &operator=(QTimeZone &&other) Q_DECL_NOTHROW { swap(other); return *this; }
#endif
- void swap(QTimeZone &other)
+ void swap(QTimeZone &other) Q_DECL_NOTHROW
{ d.swap(other.d); }
bool operator==(const QTimeZone &other) const;
@@ -117,6 +117,8 @@ public:
OffsetDataList transitions(const QDateTime &fromDateTime, const QDateTime &toDateTime) const;
static QByteArray systemTimeZoneId();
+ static QTimeZone systemTimeZone();
+ static QTimeZone utc();
static bool isTimeZoneIdAvailable(const QByteArray &ianaId);
diff --git a/src/corelib/tools/qtimezoneprivate_android.cpp b/src/corelib/tools/qtimezoneprivate_android.cpp
new file mode 100644
index 0000000000..9d9bfc612d
--- /dev/null
+++ b/src/corelib/tools/qtimezoneprivate_android.cpp
@@ -0,0 +1,287 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Drew Parsons <dparsons@emerall.com>
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore/QSet>
+#include "qtimezone.h"
+#include "qtimezoneprivate_p.h"
+
+QT_BEGIN_NAMESPACE
+
+/*
+ Private
+
+ Android implementation
+*/
+
+// Create the system default time zone
+QAndroidTimeZonePrivate::QAndroidTimeZonePrivate()
+ : QTimeZonePrivate()
+{
+ // start with system time zone
+ androidTimeZone = QJNIObjectPrivate::callStaticObjectMethod("java.util.TimeZone", "getDefault", "()Ljava/util/TimeZone;");
+ init("UTC");
+}
+
+// Create a named time zone
+QAndroidTimeZonePrivate::QAndroidTimeZonePrivate(const QByteArray &ianaId)
+ : QTimeZonePrivate()
+{
+ init(ianaId);
+}
+
+QAndroidTimeZonePrivate::QAndroidTimeZonePrivate(const QAndroidTimeZonePrivate &other)
+ : QTimeZonePrivate(other)
+{
+ androidTimeZone = other.androidTimeZone;
+ m_id = other.id();
+}
+
+QAndroidTimeZonePrivate::~QAndroidTimeZonePrivate()
+{
+}
+
+
+void QAndroidTimeZonePrivate::init(const QByteArray &ianaId)
+{
+ QJNIObjectPrivate jo_ianaId = QJNIObjectPrivate::fromString( QString::fromUtf8(ianaId) );
+ androidTimeZone = QJNIObjectPrivate::callStaticObjectMethod( "java.util.TimeZone", "getTimeZone", "(Ljava/lang/String;)Ljava/util/TimeZone;", static_cast<jstring>(jo_ianaId.object()) );
+
+ if (ianaId.isEmpty())
+ m_id = systemTimeZoneId();
+ else
+ m_id = ianaId;
+}
+
+QTimeZonePrivate *QAndroidTimeZonePrivate::clone()
+{
+ return new QAndroidTimeZonePrivate(*this);
+}
+
+
+QString QAndroidTimeZonePrivate::displayName(QTimeZone::TimeType timeType, QTimeZone::NameType nameType,
+ const QLocale &locale) const
+{
+ QString name;
+
+ if (androidTimeZone.isValid()) {
+ jboolean daylightTime = (timeType == QTimeZone::DaylightTime); // treat QTimeZone::GenericTime as QTimeZone::StandardTime
+
+ // treat all NameTypes as java TimeZone style LONG (value 1), except of course QTimeZone::ShortName which is style SHORT (value 0);
+ jint style = (nameType == QTimeZone::ShortName ? 0 : 1);
+
+ QJNIObjectPrivate jlanguage = QJNIObjectPrivate::fromString(QLocale::languageToString(locale.language()));
+ QJNIObjectPrivate jcountry = QJNIObjectPrivate::fromString(QLocale::countryToString(locale.country()));
+ QJNIObjectPrivate jvariant = QJNIObjectPrivate::fromString(QLocale::scriptToString(locale.script()));
+ QJNIObjectPrivate jlocale("java.util.Locale", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", static_cast<jstring>(jlanguage.object()), static_cast<jstring>(jcountry.object()), static_cast<jstring>(jvariant.object()));
+
+ QJNIObjectPrivate jname = androidTimeZone.callObjectMethod("getDisplayName", "(ZILjava/util/Locale;)Ljava/lang/String;", daylightTime, style, jlocale.object());
+
+ name = jname.toString();
+ }
+
+ return name;
+}
+
+QString QAndroidTimeZonePrivate::abbreviation(qint64 atMSecsSinceEpoch) const
+{
+ if ( isDaylightTime( atMSecsSinceEpoch ) )
+ return displayName(QTimeZone::DaylightTime, QTimeZone::ShortName, QLocale() );
+ else
+ return displayName(QTimeZone::StandardTime, QTimeZone::ShortName, QLocale() );
+}
+
+int QAndroidTimeZonePrivate::offsetFromUtc(qint64 atMSecsSinceEpoch) const
+{
+ // offsetFromUtc( ) is invoked when androidTimeZone may not yet be set at startup,
+ // so a validity test is needed here
+ if ( androidTimeZone.isValid() )
+ // the java method getOffset() returns milliseconds, but QTimeZone returns seconds
+ return androidTimeZone.callMethod<jint>( "getOffset", "(J)I", static_cast<jlong>(atMSecsSinceEpoch) ) / 1000;
+ else
+ return 0;
+}
+
+int QAndroidTimeZonePrivate::standardTimeOffset(qint64 atMSecsSinceEpoch) const
+{
+ // the java method does not use a reference time
+ Q_UNUSED( atMSecsSinceEpoch );
+ if ( androidTimeZone.isValid() )
+ // the java method getRawOffset() returns milliseconds, but QTimeZone returns seconds
+ return androidTimeZone.callMethod<jint>( "getRawOffset" ) / 1000;
+ else
+ return 0;
+}
+
+int QAndroidTimeZonePrivate::daylightTimeOffset(qint64 atMSecsSinceEpoch) const
+{
+ return ( offsetFromUtc(atMSecsSinceEpoch) - standardTimeOffset(atMSecsSinceEpoch) );
+}
+
+bool QAndroidTimeZonePrivate::hasDaylightTime() const
+{
+ if ( androidTimeZone.isValid() )
+ /* note: the Java function only tests for future daylight transtions, not past */
+ return androidTimeZone.callMethod<jboolean>("useDaylightTime" );
+ else
+ return false;
+}
+
+bool QAndroidTimeZonePrivate::isDaylightTime(qint64 atMSecsSinceEpoch) const
+{
+ if ( androidTimeZone.isValid() ) {
+ QJNIObjectPrivate jDate( "java/util/Date", "(J)V", static_cast<jlong>(atMSecsSinceEpoch) );
+ return androidTimeZone.callMethod<jboolean>("inDaylightTime", "(Ljava/util/Date;)Z", jDate.object() );
+ }
+ else
+ return false;
+}
+
+QTimeZonePrivate::Data QAndroidTimeZonePrivate::data(qint64 forMSecsSinceEpoch) const
+{
+ if (androidTimeZone.isValid()) {
+ Data data;
+ data.atMSecsSinceEpoch = forMSecsSinceEpoch;
+ data.standardTimeOffset = standardTimeOffset(forMSecsSinceEpoch);
+ data.offsetFromUtc = offsetFromUtc(forMSecsSinceEpoch);
+ data.daylightTimeOffset = data.offsetFromUtc - data.standardTimeOffset;
+ data.abbreviation = abbreviation(forMSecsSinceEpoch);
+ return data;
+ } else {
+ return invalidData();
+ }
+}
+
+bool QAndroidTimeZonePrivate::hasTransitions() const
+{
+ // java.util.TimeZone does not directly provide transitions
+ return false;
+}
+
+QTimeZonePrivate::Data QAndroidTimeZonePrivate::nextTransition(qint64 afterMSecsSinceEpoch) const
+{
+ // transitions not available on Android, so return an invalid data object
+ Q_UNUSED( afterMSecsSinceEpoch );
+ return invalidData();
+}
+
+QTimeZonePrivate::Data QAndroidTimeZonePrivate::previousTransition(qint64 beforeMSecsSinceEpoch) const
+{
+ // transitions not available on Android, so return an invalid data object
+ Q_UNUSED( beforeMSecsSinceEpoch );
+ return invalidData();
+}
+
+// Since Android does not provide an API to access transitions,
+// dataForLocalTime needs to be reimplemented without direct use of transitions
+QTimeZonePrivate::Data QAndroidTimeZonePrivate::dataForLocalTime(qint64 forLocalMSecs) const
+{
+ if (!androidTimeZone.isValid()) {
+ return invalidData();
+ } else {
+ qint64 UTCepochMSecs;
+
+ // compare the UTC time with standard offset against normal daylight offset of one hour
+ qint64 standardUTCMSecs(forLocalMSecs - (standardTimeOffset(forLocalMSecs) * 1000));
+ qint64 daylightUTCMsecs;
+
+ // Check if daylight time does apply,
+ // checking also for daylight time boundaries
+ if (isDaylightTime(standardUTCMSecs)) {
+ // If daylight does apply, then standardUTCMSecs will be an hour or so ahead of the real epoch time
+ // so check that time
+ daylightUTCMsecs = standardUTCMSecs - daylightTimeOffset(standardUTCMSecs)*1000;
+ if (isDaylightTime(daylightUTCMsecs)) {
+ // daylight time confirmed
+ UTCepochMSecs = daylightUTCMsecs;
+ } else {
+ // daylight time has just finished
+ UTCepochMSecs = standardUTCMSecs;
+ }
+ } else {
+ // Standard time indicated, but check for a false negative.
+ // Would a standard one-hour daylight offset indicate daylight time?
+ daylightUTCMsecs = standardUTCMSecs - 3600000; // 3600000 MSECS_PER_HOUR
+ if (isDaylightTime(daylightUTCMsecs)) {
+ // daylight time may have just started,
+ // but double check against timezone's own daylight offset
+ // (don't necessarily assume a one-hour offset)
+ daylightUTCMsecs = standardUTCMSecs - daylightTimeOffset(daylightUTCMsecs)*1000;
+ if (isDaylightTime(daylightUTCMsecs)) {
+ // daylight time confirmed
+ UTCepochMSecs = daylightUTCMsecs;
+ } else {
+ // false positive, apply standard time after all
+ UTCepochMSecs = standardUTCMSecs;
+ }
+ } else {
+ // confirmed standard time
+ UTCepochMSecs = standardUTCMSecs;
+ }
+ }
+
+ return data(UTCepochMSecs);
+ }
+}
+
+QByteArray QAndroidTimeZonePrivate::systemTimeZoneId() const
+{
+ QJNIObjectPrivate androidSystemTimeZone = QJNIObjectPrivate::callStaticObjectMethod("java.util.TimeZone", "getDefault", "()Ljava/util/TimeZone;");
+ QJNIObjectPrivate systemTZIdAndroid = androidSystemTimeZone.callObjectMethod<jstring>("getID");
+ QByteArray systemTZid = systemTZIdAndroid.toString().toUtf8();
+
+ return systemTZid;
+}
+
+QSet<QByteArray> QAndroidTimeZonePrivate::availableTimeZoneIds() const
+{
+ QSet<QByteArray> availableTimeZoneIdList;
+ QJNIObjectPrivate androidAvailableIdList = QJNIObjectPrivate::callStaticObjectMethod("java.util.TimeZone", "getAvailableIDs", "()[Ljava/lang/String;");
+
+ QJNIEnvironmentPrivate jniEnv;
+ int androidTZcount = jniEnv->GetArrayLength( static_cast<jarray>(androidAvailableIdList.object()) );
+
+ // need separate jobject and QAndroidJniObject here so that we can delete (DeleteLocalRef) the reference to the jobject
+ // (or else the JNI reference table fills after 512 entries from GetObjectArrayElement)
+ jobject androidTZobject;
+ QJNIObjectPrivate androidTZ;
+ for (int i=0; i<androidTZcount; i++ ) {
+ androidTZobject = jniEnv->GetObjectArrayElement( static_cast<jobjectArray>( androidAvailableIdList.object() ), i );
+ androidTZ = androidTZobject;
+ availableTimeZoneIdList.insert( androidTZ.toString().toUtf8() );
+ jniEnv->DeleteLocalRef(androidTZobject);
+ }
+
+ return availableTimeZoneIdList;
+}
+
+QT_END_NAMESPACE
diff --git a/src/corelib/tools/qtimezoneprivate_p.h b/src/corelib/tools/qtimezoneprivate_p.h
index 5ba42de560..4b44c6a262 100644
--- a/src/corelib/tools/qtimezoneprivate_p.h
+++ b/src/corelib/tools/qtimezoneprivate_p.h
@@ -65,6 +65,10 @@ class NSTimeZone;
#include <qt_windows.h>
#endif // Q_OS_WIN
+#ifdef Q_OS_ANDROID
+#include <QtCore/private/qjni_p.h>
+#endif
+
QT_BEGIN_NAMESPACE
class Q_CORE_EXPORT QTimeZonePrivate : public QSharedData
@@ -179,7 +183,7 @@ public:
QUtcTimeZonePrivate(const QUtcTimeZonePrivate &other);
virtual ~QUtcTimeZonePrivate();
- QTimeZonePrivate *clone();
+ QTimeZonePrivate *clone() Q_DECL_OVERRIDE;
QLocale::Country country() const Q_DECL_OVERRIDE;
QString comment() const Q_DECL_OVERRIDE;
@@ -224,7 +228,7 @@ public:
QIcuTimeZonePrivate(const QIcuTimeZonePrivate &other);
~QIcuTimeZonePrivate();
- QTimeZonePrivate *clone();
+ QTimeZonePrivate *clone() Q_DECL_OVERRIDE;
QString displayName(QTimeZone::TimeType timeType, QTimeZone::NameType nameType,
const QLocale &locale) const Q_DECL_OVERRIDE;
@@ -256,7 +260,7 @@ private:
};
#endif // QT_USE_ICU
-#if defined Q_OS_UNIX && !defined Q_OS_MAC
+#if defined Q_OS_UNIX && !defined Q_OS_MAC && !defined Q_OS_ANDROID
class Q_AUTOTEST_EXPORT QTzTimeZonePrivate Q_DECL_FINAL : public QTimeZonePrivate
{
public:
@@ -267,7 +271,7 @@ public:
QTzTimeZonePrivate(const QTzTimeZonePrivate &other);
~QTzTimeZonePrivate();
- QTimeZonePrivate *clone();
+ QTimeZonePrivate *clone() Q_DECL_OVERRIDE;
QLocale::Country country() const Q_DECL_OVERRIDE;
QString comment() const Q_DECL_OVERRIDE;
@@ -334,7 +338,7 @@ public:
QMacTimeZonePrivate(const QMacTimeZonePrivate &other);
~QMacTimeZonePrivate();
- QTimeZonePrivate *clone();
+ QTimeZonePrivate *clone() Q_DECL_OVERRIDE;
QString comment() const Q_DECL_OVERRIDE;
@@ -385,7 +389,7 @@ public:
QWinTimeZonePrivate(const QWinTimeZonePrivate &other);
~QWinTimeZonePrivate();
- QTimeZonePrivate *clone();
+ QTimeZonePrivate *clone() Q_DECL_OVERRIDE;
QString comment() const Q_DECL_OVERRIDE;
@@ -424,6 +428,50 @@ private:
};
#endif // Q_OS_WIN
+#ifdef Q_OS_ANDROID
+class QAndroidTimeZonePrivate Q_DECL_FINAL : public QTimeZonePrivate
+{
+public:
+ // Create default time zone
+ QAndroidTimeZonePrivate();
+ // Create named time zone
+ QAndroidTimeZonePrivate(const QByteArray &ianaId);
+ QAndroidTimeZonePrivate(const QAndroidTimeZonePrivate &other);
+ ~QAndroidTimeZonePrivate();
+
+ QTimeZonePrivate *clone() Q_DECL_OVERRIDE;
+
+ QString displayName(QTimeZone::TimeType timeType, QTimeZone::NameType nameType,
+ const QLocale &locale) const Q_DECL_OVERRIDE;
+ QString abbreviation(qint64 atMSecsSinceEpoch) const Q_DECL_OVERRIDE;
+
+ int offsetFromUtc(qint64 atMSecsSinceEpoch) const Q_DECL_OVERRIDE;
+ int standardTimeOffset(qint64 atMSecsSinceEpoch) const Q_DECL_OVERRIDE;
+ int daylightTimeOffset(qint64 atMSecsSinceEpoch) const Q_DECL_OVERRIDE;
+
+ bool hasDaylightTime() const Q_DECL_OVERRIDE;
+ bool isDaylightTime(qint64 atMSecsSinceEpoch) const Q_DECL_OVERRIDE;
+
+ Data data(qint64 forMSecsSinceEpoch) const Q_DECL_OVERRIDE;
+
+ bool hasTransitions() const Q_DECL_OVERRIDE;
+ Data nextTransition(qint64 afterMSecsSinceEpoch) const Q_DECL_OVERRIDE;
+ Data previousTransition(qint64 beforeMSecsSinceEpoch) const Q_DECL_OVERRIDE;
+
+ Data dataForLocalTime(qint64 forLocalMSecs) const Q_DECL_OVERRIDE;
+
+ QByteArray systemTimeZoneId() const Q_DECL_OVERRIDE;
+
+ QSet<QByteArray> availableTimeZoneIds() const Q_DECL_OVERRIDE;
+
+private:
+ void init(const QByteArray &zoneId);
+
+ QJNIObjectPrivate androidTimeZone;
+
+};
+#endif // Q_OS_ANDROID
+
QT_END_NAMESPACE
#endif // QTIMEZONEPRIVATE_P_H
diff --git a/src/corelib/tools/qtools_p.h b/src/corelib/tools/qtools_p.h
index 3876d3822c..53d5228c3b 100644
--- a/src/corelib/tools/qtools_p.h
+++ b/src/corelib/tools/qtools_p.h
@@ -46,9 +46,40 @@
//
#include "QtCore/qglobal.h"
+#include <limits>
QT_BEGIN_NAMESPACE
+namespace QtMiscUtils {
+inline char toHexUpper(uint value)
+{
+ static const char hexdigits[] = "0123456789ABCDEF";
+ return hexdigits[value & 0xF];
+}
+
+inline char toHexLower(uint value)
+{
+ static const char hexdigits[] = "0123456789abcdef";
+ return hexdigits[value & 0xF];
+}
+
+inline int fromHex(uint c)
+{
+ if ((c >= '0') && (c <= '9'))
+ return c - '0';
+ if ((c >= 'A') && (c <= 'F'))
+ return c - 'A' + 10;
+ if ((c >= 'a') && (c <= 'f'))
+ return c - 'a' + 10;
+ return -1;
+}
+}
+
+// We typically need an extra bit for qNextPowerOfTwo when determining the next allocation size.
+enum {
+ MaxAllocSize = (1 << (std::numeric_limits<int>::digits - 1)) - 1
+};
+
// implemented in qbytearray.cpp
int Q_CORE_EXPORT qAllocMore(int alloc, int extra) Q_DECL_NOTHROW;
diff --git a/src/corelib/tools/qunicodetables.cpp b/src/corelib/tools/qunicodetables.cpp
index 072e8ad920..477a0441b0 100644
--- a/src/corelib/tools/qunicodetables.cpp
+++ b/src/corelib/tools/qunicodetables.cpp
@@ -6912,44 +6912,44 @@ static const Properties uc_properties[] = {
{ 12, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 12, 0 }
};
-Q_DECL_CONST_FUNCTION static inline const Properties *qGetProp(uint ucs4)
+Q_DECL_CONST_FUNCTION static inline const Properties *qGetProp(uint ucs4) Q_DECL_NOTHROW
{
const int index = GET_PROP_INDEX(ucs4);
return uc_properties + index;
}
-Q_DECL_CONST_FUNCTION static inline const Properties *qGetProp(ushort ucs2)
+Q_DECL_CONST_FUNCTION static inline const Properties *qGetProp(ushort ucs2) Q_DECL_NOTHROW
{
const int index = GET_PROP_INDEX_UCS2(ucs2);
return uc_properties + index;
}
-Q_DECL_CONST_FUNCTION Q_CORE_EXPORT const Properties * QT_FASTCALL properties(uint ucs4)
+Q_DECL_CONST_FUNCTION Q_CORE_EXPORT const Properties * QT_FASTCALL properties(uint ucs4) Q_DECL_NOTHROW
{
return qGetProp(ucs4);
}
-Q_DECL_CONST_FUNCTION Q_CORE_EXPORT const Properties * QT_FASTCALL properties(ushort ucs2)
+Q_DECL_CONST_FUNCTION Q_CORE_EXPORT const Properties * QT_FASTCALL properties(ushort ucs2) Q_DECL_NOTHROW
{
return qGetProp(ucs2);
}
-Q_CORE_EXPORT GraphemeBreakClass QT_FASTCALL graphemeBreakClass(uint ucs4)
+Q_CORE_EXPORT GraphemeBreakClass QT_FASTCALL graphemeBreakClass(uint ucs4) Q_DECL_NOTHROW
{
return (GraphemeBreakClass)qGetProp(ucs4)->graphemeBreakClass;
}
-Q_CORE_EXPORT WordBreakClass QT_FASTCALL wordBreakClass(uint ucs4)
+Q_CORE_EXPORT WordBreakClass QT_FASTCALL wordBreakClass(uint ucs4) Q_DECL_NOTHROW
{
return (WordBreakClass)qGetProp(ucs4)->wordBreakClass;
}
-Q_CORE_EXPORT SentenceBreakClass QT_FASTCALL sentenceBreakClass(uint ucs4)
+Q_CORE_EXPORT SentenceBreakClass QT_FASTCALL sentenceBreakClass(uint ucs4) Q_DECL_NOTHROW
{
return (SentenceBreakClass)qGetProp(ucs4)->sentenceBreakClass;
}
-Q_CORE_EXPORT LineBreakClass QT_FASTCALL lineBreakClass(uint ucs4)
+Q_CORE_EXPORT LineBreakClass QT_FASTCALL lineBreakClass(uint ucs4) Q_DECL_NOTHROW
{
return (LineBreakClass)qGetProp(ucs4)->lineBreakClass;
}
diff --git a/src/corelib/tools/qunicodetables_p.h b/src/corelib/tools/qunicodetables_p.h
index 64e1ad12b5..34da53ac58 100644
--- a/src/corelib/tools/qunicodetables_p.h
+++ b/src/corelib/tools/qunicodetables_p.h
@@ -79,8 +79,8 @@ struct Properties {
ushort script : 8; /* 7 used */
};
-Q_CORE_EXPORT const Properties * QT_FASTCALL properties(uint ucs4);
-Q_CORE_EXPORT const Properties * QT_FASTCALL properties(ushort ucs2);
+Q_CORE_EXPORT const Properties * QT_FASTCALL properties(uint ucs4) Q_DECL_NOTHROW;
+Q_CORE_EXPORT const Properties * QT_FASTCALL properties(ushort ucs2) Q_DECL_NOTHROW;
enum GraphemeBreakClass {
GraphemeBreak_Other,
@@ -147,20 +147,20 @@ enum LineBreakClass {
LineBreak_BK
};
-Q_CORE_EXPORT GraphemeBreakClass QT_FASTCALL graphemeBreakClass(uint ucs4);
-inline GraphemeBreakClass graphemeBreakClass(QChar ch)
+Q_CORE_EXPORT GraphemeBreakClass QT_FASTCALL graphemeBreakClass(uint ucs4) Q_DECL_NOTHROW;
+inline GraphemeBreakClass graphemeBreakClass(QChar ch) Q_DECL_NOTHROW
{ return graphemeBreakClass(ch.unicode()); }
-Q_CORE_EXPORT WordBreakClass QT_FASTCALL wordBreakClass(uint ucs4);
-inline WordBreakClass wordBreakClass(QChar ch)
+Q_CORE_EXPORT WordBreakClass QT_FASTCALL wordBreakClass(uint ucs4) Q_DECL_NOTHROW;
+inline WordBreakClass wordBreakClass(QChar ch) Q_DECL_NOTHROW
{ return wordBreakClass(ch.unicode()); }
-Q_CORE_EXPORT SentenceBreakClass QT_FASTCALL sentenceBreakClass(uint ucs4);
-inline SentenceBreakClass sentenceBreakClass(QChar ch)
+Q_CORE_EXPORT SentenceBreakClass QT_FASTCALL sentenceBreakClass(uint ucs4) Q_DECL_NOTHROW;
+inline SentenceBreakClass sentenceBreakClass(QChar ch) Q_DECL_NOTHROW
{ return sentenceBreakClass(ch.unicode()); }
-Q_CORE_EXPORT LineBreakClass QT_FASTCALL lineBreakClass(uint ucs4);
-inline LineBreakClass lineBreakClass(QChar ch)
+Q_CORE_EXPORT LineBreakClass QT_FASTCALL lineBreakClass(uint ucs4) Q_DECL_NOTHROW;
+inline LineBreakClass lineBreakClass(QChar ch) Q_DECL_NOTHROW
{ return lineBreakClass(ch.unicode()); }
} // namespace QUnicodeTables
diff --git a/src/corelib/tools/qvector.cpp b/src/corelib/tools/qvector.cpp
index 99e1db1cab..50c90ad746 100644
--- a/src/corelib/tools/qvector.cpp
+++ b/src/corelib/tools/qvector.cpp
@@ -463,6 +463,18 @@
\sa operator<<(), prepend(), insert()
*/
+/*! \fn void QVector::append(const QVector<T> &value)
+
+ \overload
+
+ \since 5.5
+
+ Appends the items of the \a value vector to this vector.
+
+ \sa operator<<(), operator+=()
+*/
+
+
/*! \fn void QVector::prepend(const T &value)
Inserts \a value at the beginning of the vector.
diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h
index 07c66bc393..c3d65b7d51 100644
--- a/src/corelib/tools/qvector.h
+++ b/src/corelib/tools/qvector.h
@@ -61,7 +61,7 @@ class QVector
Data *d;
public:
- inline QVector() : d(Data::sharedNull()) { }
+ inline QVector() Q_DECL_NOTHROW : d(Data::sharedNull()) { }
explicit QVector(int size);
QVector(int size, const T &t);
inline QVector(const QVector<T> &v);
@@ -128,6 +128,7 @@ public:
T &operator[](int i);
const T &operator[](int i) const;
void append(const T &t);
+ inline void append(const QVector<T> &l) { *this += l; }
void prepend(const T &t);
void insert(int i, const T &t);
void insert(int i, int n, const T &t);
@@ -327,9 +328,11 @@ inline QVector<T>::QVector(const QVector<T> &v)
} else {
if (v.d->capacityReserved) {
d = Data::allocate(v.d->alloc);
+ Q_CHECK_PTR(d);
d->capacityReserved = true;
} else {
d = Data::allocate(v.d->size);
+ Q_CHECK_PTR(d);
}
if (d->alloc) {
copyConstruct(v.d->begin(), v.d->end(), d->begin());
@@ -439,6 +442,7 @@ QVector<T>::QVector(int asize)
Q_ASSERT_X(asize >= 0, "QVector::QVector", "Size must be greater than or equal to 0.");
if (Q_LIKELY(asize > 0)) {
d = Data::allocate(asize);
+ Q_CHECK_PTR(d);
d->size = asize;
defaultConstruct(d->begin(), d->end());
} else {
@@ -452,6 +456,7 @@ QVector<T>::QVector(int asize, const T &t)
Q_ASSERT_X(asize >= 0, "QVector::QVector", "Size must be greater than or equal to 0.");
if (asize > 0) {
d = Data::allocate(asize);
+ Q_CHECK_PTR(d);
d->size = asize;
T* i = d->end();
while (i != d->begin())
@@ -467,6 +472,7 @@ QVector<T>::QVector(std::initializer_list<T> args)
{
if (args.size() > 0) {
d = Data::allocate(args.size());
+ Q_CHECK_PTR(d);
// std::initializer_list<T>::iterator is guaranteed to be
// const T* ([support.initlist]/1), so can be memcpy'ed away from by copyConstruct
copyConstruct(args.begin(), args.end(), d->begin());
@@ -707,13 +713,10 @@ bool QVector<T>::operator==(const QVector<T> &v) const
return true;
if (d->size != v.d->size)
return false;
- T* b = d->begin();
- T* i = b + d->size;
- T* j = v.d->end();
- while (i != b)
- if (!(*--i == *--j))
- return false;
- return true;
+ const T *vb = v.d->begin();
+ const T *b = d->begin();
+ const T *e = d->end();
+ return std::equal(b, e, vb);
}
template <typename T>
@@ -791,12 +794,9 @@ int QVector<T>::lastIndexOf(const T &t, int from) const
template <typename T>
bool QVector<T>::contains(const T &t) const
{
- T* b = d->begin();
- T* i = d->end();
- while (i != b)
- if (*--i == t)
- return true;
- return false;
+ const T *b = d->begin();
+ const T *e = d->end();
+ return std::find(b, e, t) != e;
}
template <typename T>
diff --git a/src/corelib/tools/qversionnumber.cpp b/src/corelib/tools/qversionnumber.cpp
index 3c8a9db086..7817cabe33 100644
--- a/src/corelib/tools/qversionnumber.cpp
+++ b/src/corelib/tools/qversionnumber.cpp
@@ -473,13 +473,7 @@ QDebug operator<<(QDebug debug, const QVersionNumber &version)
*/
uint qHash(const QVersionNumber &key, uint seed)
{
- uint hash = seed;
- for (QVector<int>::const_iterator it = key.m_segments.begin(), end = key.m_segments.end(); it != end; ++it) {
- // used to preserve order
- // see N3876 for more information
- hash ^= qHash(*it) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
- }
- return hash;
+ return qHashRange(key.m_segments.begin(), key.m_segments.end(), seed);
}
QT_END_NAMESPACE
diff --git a/src/corelib/tools/qversionnumber_p.h b/src/corelib/tools/qversionnumber_p.h
index a951b2f1a0..883aae11ff 100644
--- a/src/corelib/tools/qversionnumber_p.h
+++ b/src/corelib/tools/qversionnumber_p.h
@@ -59,7 +59,7 @@ Q_CORE_EXPORT QDataStream& operator<<(QDataStream &out, const QVersionNumber &ve
Q_CORE_EXPORT QDataStream& operator>>(QDataStream &in, QVersionNumber &version);
#endif
-class Q_CORE_EXPORT QVersionNumber
+class QVersionNumber
{
public:
inline QVersionNumber() Q_DECL_NOTHROW
@@ -150,17 +150,17 @@ public:
inline int segmentCount() const Q_DECL_NOTHROW Q_REQUIRED_RESULT
{ return m_segments.size(); }
- bool isPrefixOf(const QVersionNumber &other) const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+ Q_CORE_EXPORT bool isPrefixOf(const QVersionNumber &other) const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
- static int compare(const QVersionNumber &v1, const QVersionNumber &v2) Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+ Q_CORE_EXPORT static int compare(const QVersionNumber &v1, const QVersionNumber &v2) Q_DECL_NOTHROW Q_REQUIRED_RESULT;
- static Q_DECL_PURE_FUNCTION QVersionNumber commonPrefix(const QVersionNumber &v1, const QVersionNumber &v2) Q_REQUIRED_RESULT;
+ Q_CORE_EXPORT static Q_DECL_PURE_FUNCTION QVersionNumber commonPrefix(const QVersionNumber &v1, const QVersionNumber &v2) Q_REQUIRED_RESULT;
- QString toString() const Q_REQUIRED_RESULT;
- static Q_DECL_PURE_FUNCTION QVersionNumber fromString(const QString &string, int *suffixIndex = 0) Q_REQUIRED_RESULT;
+ Q_CORE_EXPORT QString toString() const Q_REQUIRED_RESULT;
+ Q_CORE_EXPORT static Q_DECL_PURE_FUNCTION QVersionNumber fromString(const QString &string, int *suffixIndex = 0) Q_REQUIRED_RESULT;
private:
- static QVersionNumber normalizedImpl(QVector<int> &segs) Q_REQUIRED_RESULT;
+ Q_CORE_EXPORT static QVersionNumber normalizedImpl(QVector<int> &segs) Q_REQUIRED_RESULT;
#ifndef QT_NO_DATASTREAM
friend Q_CORE_EXPORT QDataStream& operator>>(QDataStream &in, QVersionNumber &version);
diff --git a/src/corelib/tools/tools.pri b/src/corelib/tools/tools.pri
index cef802fa76..c4c347d6ff 100644
--- a/src/corelib/tools/tools.pri
+++ b/src/corelib/tools/tools.pri
@@ -57,6 +57,7 @@ HEADERS += \
tools/qsize.h \
tools/qstack.h \
tools/qstring.h \
+ tools/qstringalgorithms_p.h \
tools/qstringbuilder.h \
tools/qstringiterator_p.h \
tools/qstringlist.h \
@@ -66,6 +67,7 @@ HEADERS += \
tools/qtimezone.h \
tools/qtimezoneprivate_p.h \
tools/qtimezoneprivate_data_p.h \
+ tools/qtools_p.h \
tools/qelapsedtimer.h \
tools/qunicodetables_p.h \
tools/qunicodetools_p.h \
@@ -128,13 +130,19 @@ false: SOURCES += $$NO_PCH_SOURCES # Hack for QtCreator
OBJECTIVE_SOURCES += tools/qlocale_mac.mm \
tools/qtimezoneprivate_mac.mm \
tools/qstring_mac.mm \
- tools/qbytearray_mac.mm
+ tools/qbytearray_mac.mm \
+ tools/qdatetime_mac.mm
}
else:blackberry {
SOURCES += tools/qelapsedtimer_unix.cpp tools/qlocale_blackberry.cpp tools/qtimezoneprivate_tz.cpp
HEADERS += tools/qlocale_blackberry.h
}
-else:unix:SOURCES += tools/qelapsedtimer_unix.cpp tools/qlocale_unix.cpp tools/qtimezoneprivate_tz.cpp
+else:android {
+ SOURCES += tools/qelapsedtimer_unix.cpp tools/qlocale_unix.cpp tools/qtimezoneprivate_android.cpp
+}
+else:unix {
+ SOURCES += tools/qelapsedtimer_unix.cpp tools/qlocale_unix.cpp tools/qtimezoneprivate_tz.cpp
+}
else:win32 {
SOURCES += tools/qelapsedtimer_win.cpp tools/qlocale_win.cpp
!winrt: SOURCES += tools/qtimezoneprivate_win.cpp
@@ -207,7 +215,7 @@ INCLUDEPATH += ../3rdparty/md5 \
../3rdparty/sha3
# Note: libm should be present by default becaue this is C++
-!macx-icc:!vxworks:unix:LIBS_PRIVATE += -lm
+!macx-icc:!vxworks:!haiku:unix:LIBS_PRIVATE += -lm
TR_EXCLUDE += ../3rdparty/*