diff options
Diffstat (limited to 'src/corelib')
31 files changed, 249 insertions, 71 deletions
diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index 520f98b18f..d043b3aea5 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -2001,7 +2001,7 @@ QString QDir::homePath() Returns the system's temporary directory. - The directory is constructed using the absolute path of the temporary directory, + The directory is constructed using the absolute canonical path of the temporary directory, ensuring that its path() will be the same as its absolutePath(). See tempPath() for details. @@ -2010,7 +2010,7 @@ QString QDir::homePath() */ /*! - Returns the absolute path of the system's temporary directory. + Returns the absolute canonical path of the system's temporary directory. On Unix/Linux systems this is the path in the \c TMPDIR environment variable or \c{/tmp} if \c TMPDIR is not defined. On Windows this is diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index b974af80dc..2a42ad42f9 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -1523,7 +1523,7 @@ QString QFileSystemEngine::tempPath() temp = QLatin1String(_PATH_TMP); } } - return QDir::cleanPath(temp); + return QDir(QDir::cleanPath(temp)).canonicalPath(); #endif } diff --git a/src/corelib/io/qfilesystemwatcher_fsevents.mm b/src/corelib/io/qfilesystemwatcher_fsevents.mm index 792ea387ac..844aa9daa7 100644 --- a/src/corelib/io/qfilesystemwatcher_fsevents.mm +++ b/src/corelib/io/qfilesystemwatcher_fsevents.mm @@ -499,7 +499,7 @@ bool QFseventsFileSystemWatcherEngine::startStream() DEBUG() << "Starting stream with paths" << watchingState.watchedPaths.keys(); - NSMutableArray *pathsToWatch = [NSMutableArray arrayWithCapacity:watchingState.watchedPaths.size()]; + NSMutableArray<NSString *> *pathsToWatch = [NSMutableArray<NSString *> arrayWithCapacity:watchingState.watchedPaths.size()]; for (PathRefCounts::const_iterator i = watchingState.watchedPaths.begin(), ei = watchingState.watchedPaths.end(); i != ei; ++i) [pathsToWatch addObject:i.key().toNSString()]; diff --git a/src/corelib/kernel/qcore_mac_objc.mm b/src/corelib/kernel/qcore_mac_objc.mm index 24d73fa8be..b91b5e76be 100644 --- a/src/corelib/kernel/qcore_mac_objc.mm +++ b/src/corelib/kernel/qcore_mac_objc.mm @@ -87,19 +87,20 @@ QT_FOR_EACH_MUTABLE_CORE_GRAPHICS_TYPE(QT_DECLARE_WEAK_QDEBUG_OPERATOR_FOR_CF_TY QT_END_NAMESPACE QT_USE_NAMESPACE @interface QT_MANGLE_NAMESPACE(QMacAutoReleasePoolTracker) : NSObject -{ +@end + +@implementation QT_MANGLE_NAMESPACE(QMacAutoReleasePoolTracker) { NSAutoreleasePool **m_pool; } --(id)initWithPool:(NSAutoreleasePool**)pool; -@end -@implementation QT_MANGLE_NAMESPACE(QMacAutoReleasePoolTracker) --(id)initWithPool:(NSAutoreleasePool**)pool + +- (instancetype)initWithPool:(NSAutoreleasePool **)pool { - if (self = [super init]) + if ((self = [self init])) m_pool = pool; return self; } --(void)dealloc + +- (void)dealloc { if (*m_pool) { // The pool is still valid, which means we're not being drained from diff --git a/src/corelib/kernel/qdeadlinetimer.cpp b/src/corelib/kernel/qdeadlinetimer.cpp index d8a670310b..97b98a1376 100644 --- a/src/corelib/kernel/qdeadlinetimer.cpp +++ b/src/corelib/kernel/qdeadlinetimer.cpp @@ -39,7 +39,6 @@ #include "qdeadlinetimer.h" #include "qdeadlinetimer_p.h" -#include <qpair.h> QT_BEGIN_NAMESPACE diff --git a/src/corelib/kernel/qdeadlinetimer.h b/src/corelib/kernel/qdeadlinetimer.h index 6c10e1025e..1a4ee04a96 100644 --- a/src/corelib/kernel/qdeadlinetimer.h +++ b/src/corelib/kernel/qdeadlinetimer.h @@ -43,6 +43,7 @@ #include <QtCore/qelapsedtimer.h> #include <QtCore/qmetatype.h> #include <QtCore/qnamespace.h> +#include <QtCore/qpair.h> #ifdef max // un-pollute the namespace. We need std::numeric_limits::max() and std::chrono::duration::max() @@ -186,6 +187,10 @@ private: unsigned type; qint64 rawRemainingTimeNSecs() const Q_DECL_NOTHROW; + +public: + // This is not a public function, it's here only for Qt's internal convenience... + QPair<qint64, unsigned> _q_data() const { return qMakePair(t1, t2); } }; Q_DECLARE_SHARED(QDeadlineTimer) diff --git a/src/corelib/kernel/qeventdispatcher_cf.mm b/src/corelib/kernel/qeventdispatcher_cf.mm index 8499b3fd57..35b2390c6d 100644 --- a/src/corelib/kernel/qeventdispatcher_cf.mm +++ b/src/corelib/kernel/qeventdispatcher_cf.mm @@ -58,18 +58,18 @@ QT_USE_NAMESPACE -@interface QT_MANGLE_NAMESPACE(RunLoopModeTracker) : NSObject { - QStack<CFStringRef> m_runLoopModes; -} +@interface QT_MANGLE_NAMESPACE(RunLoopModeTracker) : NSObject @end QT_NAMESPACE_ALIAS_OBJC_CLASS(RunLoopModeTracker); -@implementation RunLoopModeTracker +@implementation RunLoopModeTracker { + QStack<CFStringRef> m_runLoopModes; +} -- (id) init +- (instancetype)init { - if (self = [super init]) { + if ((self = [super init])) { m_runLoopModes.push(kCFRunLoopDefaultMode); [[NSNotificationCenter defaultCenter] @@ -77,21 +77,21 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(RunLoopModeTracker); selector:@selector(receivedNotification:) name:nil #ifdef Q_OS_OSX - object:[NSApplication sharedApplication]]; + object:NSApplication.sharedApplication]; #elif defined(Q_OS_WATCHOS) - object:[WKExtension sharedExtension]]; + object:WKExtension.sharedExtension]; #else // Use performSelector so this can work in an App Extension - object:[[UIApplication class] performSelector:@selector(sharedApplication)]]; + object:[UIApplication.class performSelector:@selector(sharedApplication)]]; #endif } return self; } -- (void) dealloc +- (void)dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; + [NSNotificationCenter.defaultCenter removeObserver:self]; [super dealloc]; } @@ -100,13 +100,13 @@ static CFStringRef runLoopMode(NSDictionary *dictionary) { for (NSString *key in dictionary) { if (CFStringHasSuffix((CFStringRef)key, CFSTR("RunLoopMode"))) - return (CFStringRef)[dictionary objectForKey: key]; + return (CFStringRef)dictionary[key]; } return nil; } -- (void) receivedNotification:(NSNotification *) notification +- (void)receivedNotification:(NSNotification *)notification { if (CFStringHasSuffix((CFStringRef)notification.name, CFSTR("RunLoopModePushNotification"))) { if (CFStringRef mode = runLoopMode(notification.userInfo)) @@ -116,7 +116,7 @@ static CFStringRef runLoopMode(NSDictionary *dictionary) } else if (CFStringHasSuffix((CFStringRef)notification.name, CFSTR("RunLoopModePopNotification"))) { CFStringRef mode = runLoopMode(notification.userInfo); - if (CFStringCompare(mode, [self currentMode], 0) == kCFCompareEqualTo) + if (CFStringCompare(mode, self.currentMode, 0) == kCFCompareEqualTo) m_runLoopModes.pop(); else qCWarning(lcEventDispatcher) << "Tried to pop run loop mode" @@ -126,7 +126,7 @@ static CFStringRef runLoopMode(NSDictionary *dictionary) } } -- (CFStringRef) currentMode +- (CFStringRef)currentMode { return m_runLoopModes.top(); } diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index fe1ef1bdfc..b515dfa099 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -627,6 +627,7 @@ public: const_iterator &operator-=(int j); const_iterator operator+(int j) const; const_iterator operator-(int j) const; + friend inline const_iterator operator+(int j, const_iterator k) { return k + j; } }; friend struct const_iterator; @@ -684,6 +685,7 @@ public: const_iterator &operator-=(int j); const_iterator operator+(int j) const; const_iterator operator-(int j) const; + friend inline const_iterator operator+(int j, const_iterator k) { return k + j; } }; friend struct const_iterator; diff --git a/src/corelib/serialization/qdatastream.cpp b/src/corelib/serialization/qdatastream.cpp index 8f419a4a46..54d1ae816b 100644 --- a/src/corelib/serialization/qdatastream.cpp +++ b/src/corelib/serialization/qdatastream.cpp @@ -564,6 +564,7 @@ void QDataStream::setByteOrder(ByteOrder bo) \value Qt_5_9 Same as Qt_5_6 \value Qt_5_10 Same as Qt_5_6 \value Qt_5_11 Same as Qt_5_6 + \value Qt_5_12 Same as Qt_5_6 \omitvalue Qt_DefaultCompiledVersion \sa setVersion(), version() diff --git a/src/corelib/serialization/qdatastream.h b/src/corelib/serialization/qdatastream.h index 1f1b13686c..85a2177652 100644 --- a/src/corelib/serialization/qdatastream.h +++ b/src/corelib/serialization/qdatastream.h @@ -98,10 +98,11 @@ public: Qt_5_9 = Qt_5_8, Qt_5_10 = Qt_5_9, Qt_5_11 = Qt_5_10, -#if QT_VERSION >= 0x050c00 + Qt_5_12 = Qt_5_11, +#if QT_VERSION >= 0x050d00 #error Add the datastream version for this Qt version and update Qt_DefaultCompiledVersion #endif - Qt_DefaultCompiledVersion = Qt_5_11 + Qt_DefaultCompiledVersion = Qt_5_12 }; enum ByteOrder { diff --git a/src/corelib/thread/qfuture.h b/src/corelib/thread/qfuture.h index af599c26db..a456dd9139 100644 --- a/src/corelib/thread/qfuture.h +++ b/src/corelib/thread/qfuture.h @@ -136,6 +136,7 @@ public: inline const_iterator operator-(int j) const { return const_iterator(future, index - j); } inline const_iterator &operator+=(int j) { index += j; return *this; } inline const_iterator &operator-=(int j) { index -= j; return *this; } + friend inline const_iterator operator+(int j, const_iterator k) { return k + j; } private: QFuture const * future; int index; diff --git a/src/corelib/thread/qmutex_p.h b/src/corelib/thread/qmutex_p.h index 4e6f522a37..ec9bfc1152 100644 --- a/src/corelib/thread/qmutex_p.h +++ b/src/corelib/thread/qmutex_p.h @@ -58,6 +58,7 @@ #include <QtCore/qnamespace.h> #include <QtCore/qmutex.h> #include <QtCore/qatomic.h> +#include <QtCore/qdeadlinetimer.h> #if defined(Q_OS_MAC) # include <mach/semaphore.h> @@ -146,7 +147,7 @@ public: // helper functions for qmutex_unix.cpp and qwaitcondition_unix.cpp // they are in qwaitcondition_unix.cpp actually void qt_initialize_pthread_cond(pthread_cond_t *cond, const char *where); -void qt_abstime_for_timeout(struct timespec *ts, int timeout); +void qt_abstime_for_timeout(struct timespec *ts, QDeadlineTimer deadline); #endif QT_END_NAMESPACE diff --git a/src/corelib/thread/qmutex_unix.cpp b/src/corelib/thread/qmutex_unix.cpp index 3e1e531be4..91f02ba3ec 100644 --- a/src/corelib/thread/qmutex_unix.cpp +++ b/src/corelib/thread/qmutex_unix.cpp @@ -130,7 +130,7 @@ bool QMutexPrivate::wait(int timeout) errorCode = pthread_cond_wait(&cond, &mutex); } else { timespec ti; - qt_abstime_for_timeout(&ti, timeout); + qt_abstime_for_timeout(&ti, QDeadlineTimer(timeout)); errorCode = pthread_cond_timedwait(&cond, &mutex, &ti); } if (errorCode) { diff --git a/src/corelib/thread/qsemaphore.cpp b/src/corelib/thread/qsemaphore.cpp index 012628ef63..6497792bf5 100644 --- a/src/corelib/thread/qsemaphore.cpp +++ b/src/corelib/thread/qsemaphore.cpp @@ -424,11 +424,9 @@ bool QSemaphore::tryAcquire(int n, int timeout) QDeadlineTimer timer(timeout); QMutexLocker locker(&d->mutex); - qint64 remainingTime = timer.remainingTime(); - while (n > d->avail && remainingTime != 0) { - if (!d->cond.wait(locker.mutex(), remainingTime)) + while (n > d->avail && !timer.hasExpired()) { + if (!d->cond.wait(locker.mutex(), timer)) return false; - remainingTime = timer.remainingTime(); } if (n > d->avail) return false; diff --git a/src/corelib/thread/qwaitcondition.h b/src/corelib/thread/qwaitcondition.h index a0c6766833..e42efbdfca 100644 --- a/src/corelib/thread/qwaitcondition.h +++ b/src/corelib/thread/qwaitcondition.h @@ -49,6 +49,7 @@ QT_BEGIN_NAMESPACE #ifndef QT_NO_THREAD +class QDeadlineTimer; class QWaitConditionPrivate; class QMutex; class QReadWriteLock; @@ -59,8 +60,11 @@ public: QWaitCondition(); ~QWaitCondition(); + // ### Qt 6: remove unsigned long overloads bool wait(QMutex *lockedMutex, unsigned long time = ULONG_MAX); + bool wait(QMutex *lockedMutex, QDeadlineTimer deadline); bool wait(QReadWriteLock *lockedReadWriteLock, unsigned long time = ULONG_MAX); + bool wait(QReadWriteLock *lockedReadWriteLock, QDeadlineTimer deadline); void wakeOne(); void wakeAll(); diff --git a/src/corelib/thread/qwaitcondition_unix.cpp b/src/corelib/thread/qwaitcondition_unix.cpp index 6adee5412e..1628ede3a2 100644 --- a/src/corelib/thread/qwaitcondition_unix.cpp +++ b/src/corelib/thread/qwaitcondition_unix.cpp @@ -44,6 +44,8 @@ #include "qreadwritelock.h" #include "qatomic.h" #include "qstring.h" +#include "qdeadlinetimer.h" +#include "private/qdeadlinetimer_p.h" #include "qelapsedtimer.h" #include "private/qcore_unix_p.h" @@ -93,23 +95,25 @@ void qt_initialize_pthread_cond(pthread_cond_t *cond, const char *where) pthread_condattr_destroy(&condattr); } -void qt_abstime_for_timeout(timespec *ts, int timeout) +void qt_abstime_for_timeout(timespec *ts, QDeadlineTimer deadline) { #ifdef Q_OS_MAC // on Mac, qt_gettime() (on qelapsedtimer_mac.cpp) returns ticks related to the Mach absolute time // that doesn't work with pthread // Mac also doesn't have clock_gettime struct timeval tv; + qint64 nsec = deadline.remainingTimeNSecs(); gettimeofday(&tv, 0); - ts->tv_sec = tv.tv_sec; - ts->tv_nsec = tv.tv_usec * 1000; -#else - *ts = qt_gettime(); -#endif + ts->tv_sec = tv.tv_sec + nsec / (1000 * 1000 * 1000); + ts->tv_nsec = tv.tv_usec * 1000 + nsec % (1000 * 1000 * 1000); - ts->tv_sec += timeout / 1000; - ts->tv_nsec += timeout % 1000 * Q_UINT64_C(1000) * 1000; normalizedTimespec(*ts); +#else + // depends on QDeadlineTimer's internals!! + Q_STATIC_ASSERT(QDeadlineTimerNanosecondsInT2); + ts->tv_sec = deadline._q_data().first; + ts->tv_nsec = deadline._q_data().second; +#endif } class QWaitConditionPrivate { @@ -119,26 +123,27 @@ public: int waiters; int wakeups; - int wait_relative(unsigned long time) + int wait_relative(QDeadlineTimer deadline) { timespec ti; #ifdef Q_OS_ANDROID - if (local_cond_timedwait_relative) { - ti.tv_sec = time / 1000; - ti.tv_nsec = time % 1000 * Q_UINT64_C(1000) * 1000; + if (!local_condattr_setclock && local_cond_timedwait_relative) { + qint64 nsec = deadline.remainingTimeNSecs(); + ti.tv_sec = nsec / (1000 * 1000 * 1000); + ti.tv_nsec = nsec - ti.tv_sec * 1000 * 1000 * 1000; return local_cond_timedwait_relative(&cond, &mutex, &ti); } #endif - qt_abstime_for_timeout(&ti, time); + qt_abstime_for_timeout(&ti, deadline); return pthread_cond_timedwait(&cond, &mutex, &ti); } - bool wait(unsigned long time) + bool wait(QDeadlineTimer deadline) { int code; forever { - if (time != ULONG_MAX) { - code = wait_relative(time); + if (!deadline.isForever()) { + code = wait_relative(deadline); } else { code = pthread_cond_wait(&cond, &mutex); } @@ -201,6 +206,13 @@ void QWaitCondition::wakeAll() bool QWaitCondition::wait(QMutex *mutex, unsigned long time) { + if (time > std::numeric_limits<qint64>::max()) + return wait(mutex, QDeadlineTimer(QDeadlineTimer::Forever)); + return wait(mutex, QDeadlineTimer(time)); +} + +bool QWaitCondition::wait(QMutex *mutex, QDeadlineTimer deadline) +{ if (! mutex) return false; if (mutex->isRecursive()) { @@ -212,7 +224,7 @@ bool QWaitCondition::wait(QMutex *mutex, unsigned long time) ++d->waiters; mutex->unlock(); - bool returnValue = d->wait(time); + bool returnValue = d->wait(deadline); mutex->lock(); @@ -221,6 +233,11 @@ bool QWaitCondition::wait(QMutex *mutex, unsigned long time) bool QWaitCondition::wait(QReadWriteLock *readWriteLock, unsigned long time) { + return wait(readWriteLock, QDeadlineTimer(time)); +} + +bool QWaitCondition::wait(QReadWriteLock *readWriteLock, QDeadlineTimer deadline) +{ if (!readWriteLock) return false; auto previousState = readWriteLock->stateForWaitCondition(); @@ -236,7 +253,7 @@ bool QWaitCondition::wait(QReadWriteLock *readWriteLock, unsigned long time) readWriteLock->unlock(); - bool returnValue = d->wait(time); + bool returnValue = d->wait(deadline); if (previousState == QReadWriteLock::LockedForWrite) readWriteLock->lockForWrite(); diff --git a/src/corelib/thread/qwaitcondition_win.cpp b/src/corelib/thread/qwaitcondition_win.cpp index e6610f18c8..61e4c2bcb1 100644 --- a/src/corelib/thread/qwaitcondition_win.cpp +++ b/src/corelib/thread/qwaitcondition_win.cpp @@ -38,6 +38,7 @@ ****************************************************************************/ #include "qwaitcondition.h" +#include "qdeadlinetimer.h" #include "qnamespace.h" #include "qmutex.h" #include "qreadwritelock.h" @@ -184,6 +185,11 @@ bool QWaitCondition::wait(QMutex *mutex, unsigned long time) return returnValue; } +bool QWaitCondition::wait(QMutex *mutex, QDeadlineTimer deadline) +{ + return wait(mutex, deadline.remainingTime()); +} + bool QWaitCondition::wait(QReadWriteLock *readWriteLock, unsigned long time) { if (!readWriteLock) @@ -210,6 +216,11 @@ bool QWaitCondition::wait(QReadWriteLock *readWriteLock, unsigned long time) return returnValue; } +bool QWaitCondition::wait(QReadWriteLock *readWriteLock, QDeadlineTimer deadline) +{ + return wait(readWriteLock, deadline.remainingTime()); +} + void QWaitCondition::wakeOne() { // wake up the first waiting thread in the queue diff --git a/src/corelib/tools/qarraydata.h b/src/corelib/tools/qarraydata.h index f0cc56e899..a642fb9b39 100644 --- a/src/corelib/tools/qarraydata.h +++ b/src/corelib/tools/qarraydata.h @@ -159,6 +159,7 @@ struct QTypedArrayData inline iterator &operator-=(int j) { i-=j; return *this; } inline iterator operator+(int j) const { return iterator(i+j); } inline iterator operator-(int j) const { return iterator(i-j); } + friend inline iterator operator+(int j, iterator k) { return k + j; } inline int operator-(iterator j) const { return i - j.i; } inline operator T*() const { return i; } }; @@ -194,6 +195,7 @@ struct QTypedArrayData inline const_iterator &operator-=(int j) { i-=j; return *this; } inline const_iterator operator+(int j) const { return const_iterator(i+j); } inline const_iterator operator-(int j) const { return const_iterator(i-j); } + friend inline const_iterator operator+(int j, const_iterator k) { return k + j; } inline int operator-(const_iterator j) const { return i - j.i; } inline operator const T*() const { return i; } }; diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp index adfa939cc6..4ae4e687a0 100644 --- a/src/corelib/tools/qbytearray.cpp +++ b/src/corelib/tools/qbytearray.cpp @@ -958,7 +958,7 @@ static inline char qToLower(char c) $LC_CTYPE is set, most Unix systems do "the right thing".) Functions that this affects include contains(), indexOf(), lastIndexOf(), operator<(), operator<=(), operator>(), - operator>=(), toLower() and toUpper(). + operator>=(), isLower(), isUpper(), toLower() and toUpper(). This issue does not apply to \l{QString}s since they represent characters using Unicode. @@ -2949,6 +2949,78 @@ bool QByteArray::endsWith(const char *str) const return qstrncmp(d->data() + d->size - len, str, len) == 0; } +/*! + Returns true if \a c is an uppercase Latin1 letter. + \note The multiplication sign 0xD7 and the sz ligature 0xDF are not + treated as uppercase Latin1. + */ +static inline bool isUpperCaseLatin1(char c) +{ + if (c >= 'A' && c <= 'Z') + return true; + + return (uchar(c) >= 0xC0 && uchar(c) <= 0xDE && uchar(c) != 0xD7); +} + +/*! + Returns \c true if this byte array contains only uppercase letters, + otherwise returns \c false. The byte array is interpreted as a Latin-1 + encoded string. + \since 5.12 + + \sa isLower(), toUpper() +*/ +bool QByteArray::isUpper() const +{ + if (isEmpty()) + return false; + + const char *d = data(); + + for (int i = 0, max = size(); i < max; ++i) { + if (!isUpperCaseLatin1(d[i])) + return false; + } + + return true; +} + +/*! + Returns true if \a c is an lowercase Latin1 letter. + \note The division sign 0xF7 is not treated as lowercase Latin1, + but the small y dieresis 0xFF is. + */ +static inline bool isLowerCaseLatin1(char c) +{ + if (c >= 'a' && c <= 'z') + return true; + + return (uchar(c) >= 0xD0 && uchar(c) != 0xF7); +} + +/*! + Returns \c true if this byte array contains only lowercase letters, + otherwise returns \c false. The byte array is interpreted as a Latin-1 + encoded string. + \since 5.12 + + \sa isUpper(), toLower() + */ +bool QByteArray::isLower() const +{ + if (isEmpty()) + return false; + + const char *d = data(); + + for (int i = 0, max = size(); i < max; ++i) { + if (!isLowerCaseLatin1(d[i])) + return false; + } + + return true; +} + /*! \overload Returns \c true if this byte array ends with character \a ch; @@ -3060,7 +3132,7 @@ QByteArray QByteArray::mid(int pos, int len) const Example: \snippet code/src_corelib_tools_qbytearray.cpp 30 - \sa toUpper(), {8-bit Character Comparisons} + \sa isLower(), toUpper(), {8-bit Character Comparisons} */ // prevent the compiler from inlining the function in each of @@ -3114,7 +3186,7 @@ QByteArray QByteArray::toLower_helper(QByteArray &a) Example: \snippet code/src_corelib_tools_qbytearray.cpp 31 - \sa toLower(), {8-bit Character Comparisons} + \sa isUpper(), toLower(), {8-bit Character Comparisons} */ QByteArray QByteArray::toUpper_helper(const QByteArray &a) diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h index 300f795469..bed710c597 100644 --- a/src/corelib/tools/qbytearray.h +++ b/src/corelib/tools/qbytearray.h @@ -245,6 +245,9 @@ public: bool endsWith(char c) const; bool endsWith(const char *c) const; + bool isUpper() const; + bool isLower() const; + void truncate(int pos); void chop(int n); diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index ce663ce2ca..a586ca5671 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -348,6 +348,7 @@ public: inline iterator operator-(int j) const { return operator+(-j); } inline iterator &operator+=(int j) { return *this = *this + j; } inline iterator &operator-=(int j) { return *this = *this - j; } + friend inline iterator operator+(int j, iterator k) { return k + j; } #ifndef QT_STRICT_ITERATORS public: @@ -413,6 +414,7 @@ public: inline const_iterator operator-(int j) const { return operator+(-j); } inline const_iterator &operator+=(int j) { return *this = *this + j; } inline const_iterator &operator-=(int j) { return *this = *this - j; } + friend inline const_iterator operator+(int j, const_iterator k) { return k + j; } // ### Qt 5: not sure this is necessary anymore #ifdef QT_STRICT_ITERATORS diff --git a/src/corelib/tools/qlinkedlist.h b/src/corelib/tools/qlinkedlist.h index c8f3f4c8c3..1e6d4df474 100644 --- a/src/corelib/tools/qlinkedlist.h +++ b/src/corelib/tools/qlinkedlist.h @@ -159,6 +159,7 @@ public: inline iterator operator-(int j) const { return operator+(-j); } inline iterator &operator+=(int j) { return *this = *this + j; } inline iterator &operator-=(int j) { return *this = *this - j; } + friend inline iterator operator+(int j, iterator k) { return k + j; } }; friend class iterator; @@ -193,6 +194,7 @@ public: inline const_iterator operator-(int j) const { return operator+(-j); } inline const_iterator &operator+=(int j) { return *this = *this + j; } inline const_iterator &operator-=(int j) { return *this = *this - j; } + friend inline const_iterator operator+(int j, const_iterator k) { return k + j; } }; friend class const_iterator; diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index af7659e995..c00220ad3a 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -269,6 +269,7 @@ public: inline iterator &operator-=(difference_type j) { i-=j; return *this; } inline iterator operator+(difference_type j) const { return iterator(i+j); } inline iterator operator-(difference_type j) const { return iterator(i-j); } + friend inline iterator operator+(difference_type j, iterator k) { return k + j; } inline int operator-(iterator j) const { return int(i - j.i); } }; friend class iterator; @@ -312,6 +313,7 @@ public: inline const_iterator &operator-=(difference_type j) { i-=j; return *this; } inline const_iterator operator+(difference_type j) const { return const_iterator(i+j); } inline const_iterator operator-(difference_type j) const { return const_iterator(i-j); } + friend inline const_iterator operator+(difference_type j, const_iterator k) { return k + j; } inline int operator-(const_iterator j) const { return int(i - j.i); } }; friend class const_iterator; diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h index a5b9096835..1cf9299e26 100644 --- a/src/corelib/tools/qmap.h +++ b/src/corelib/tools/qmap.h @@ -449,6 +449,7 @@ public: inline iterator operator-(int j) const { return operator+(-j); } inline iterator &operator+=(int j) { return *this = *this + j; } inline iterator &operator-=(int j) { return *this = *this - j; } + friend inline iterator operator+(int j, iterator k) { return k + j; } #ifndef QT_STRICT_ITERATORS public: @@ -512,6 +513,7 @@ public: inline const_iterator operator-(int j) const { return operator+(-j); } inline const_iterator &operator+=(int j) { return *this = *this + j; } inline const_iterator &operator-=(int j) { return *this = *this - j; } + friend inline const_iterator operator+(int j, const_iterator k) { return k + j; } #ifdef QT_STRICT_ITERATORS private: diff --git a/src/corelib/tools/qringbuffer.cpp b/src/corelib/tools/qringbuffer.cpp index eb7bdfe95c..59650ed2f7 100644 --- a/src/corelib/tools/qringbuffer.cpp +++ b/src/corelib/tools/qringbuffer.cpp @@ -312,12 +312,14 @@ qint64 QRingBuffer::peek(char *data, qint64 maxLength, qint64 pos) const Q_ASSERT(maxLength >= 0 && pos >= 0); qint64 readSoFar = 0; - for (int i = 0; readSoFar < maxLength && i < buffers.size(); ++i) { - qint64 blockLength = buffers[i].size(); + for (const QRingChunk &chunk : buffers) { + if (readSoFar == maxLength) + break; + qint64 blockLength = chunk.size(); if (pos < blockLength) { blockLength = qMin(blockLength - pos, maxLength - readSoFar); - memcpy(data + readSoFar, buffers[i].data() + pos, blockLength); + memcpy(data + readSoFar, chunk.data() + pos, blockLength); readSoFar += blockLength; pos = 0; } else { diff --git a/src/corelib/tools/qset.h b/src/corelib/tools/qset.h index 7ded120ab7..6640c8486d 100644 --- a/src/corelib/tools/qset.h +++ b/src/corelib/tools/qset.h @@ -131,6 +131,7 @@ public: inline iterator operator--(int) { iterator r = *this; --i; return r; } inline iterator operator+(int j) const { return i + j; } inline iterator operator-(int j) const { return i - j; } + friend inline iterator operator+(int j, iterator k) { return k + j; } inline iterator &operator+=(int j) { i += j; return *this; } inline iterator &operator-=(int j) { i -= j; return *this; } }; @@ -165,6 +166,7 @@ public: inline const_iterator operator--(int) { const_iterator r = *this; --i; return r; } inline const_iterator operator+(int j) const { return i + j; } inline const_iterator operator-(int j) const { return i - j; } + friend inline const_iterator operator+(int j, const_iterator k) { return k + j; } inline const_iterator &operator+=(int j) { i += j; return *this; } inline const_iterator &operator-=(int j) { i -= j; return *this; } }; diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index b56ad34546..ed56f99771 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -4887,6 +4887,50 @@ bool QString::endsWith(QChar c, Qt::CaseSensitivity cs) const return qt_ends_with(*this, c, cs); } +/*! + Returns \c true if the string only contains uppercase letters, + otherwise returns \c false. + \since 5.12 + + \sa QChar::isUpper(), isLower() +*/ +bool QString::isUpper() const +{ + if (isEmpty()) + return false; + + const QChar *d = data(); + + for (int i = 0, max = size(); i < max; ++i) { + if (!d[i].isUpper()) + return false; + } + + return true; +} + +/*! + Returns \c true if the string only contains lowercase letters, + otherwise returns \c false. + \since 5.12 + + \sa QChar::isLower(), isUpper() + */ +bool QString::isLower() const +{ + if (isEmpty()) + return false; + + const QChar *d = data(); + + for (int i = 0, max = size(); i < max; ++i) { + if (!d[i].isLower()) + return false; + } + + return true; +} + static QByteArray qt_convert_to_latin1(QStringView string); QByteArray QString::toLatin1_helper(const QString &string) diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index 0138ae4098..d93891248f 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -409,6 +409,9 @@ public: bool endsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; bool endsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + bool isUpper() const; + bool isLower() const; + Q_REQUIRED_RESULT 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; diff --git a/src/corelib/tools/qtimezone.cpp b/src/corelib/tools/qtimezone.cpp index daa7dc1531..445ddeb31d 100644 --- a/src/corelib/tools/qtimezone.cpp +++ b/src/corelib/tools/qtimezone.cpp @@ -66,11 +66,10 @@ static QTimeZonePrivate *newBackendTimeZone() return new QAndroidTimeZonePrivate(); #elif defined(Q_OS_UNIX) || defined(Q_OS_ANDROID_EMBEDDED) return new QTzTimeZonePrivate(); - // Registry based timezone backend not available on WinRT -#elif defined Q_OS_WIN - return new QWinTimeZonePrivate(); #elif QT_CONFIG(icu) return new QIcuTimeZonePrivate(); +#elif defined Q_OS_WIN + return new QWinTimeZonePrivate(); #else return new QUtcTimeZonePrivate(); #endif // System Locales @@ -93,11 +92,10 @@ static QTimeZonePrivate *newBackendTimeZone(const QByteArray &ianaId) return new QAndroidTimeZonePrivate(ianaId); #elif defined(Q_OS_UNIX) || defined(Q_OS_ANDROID_EMBEDDED) return new QTzTimeZonePrivate(ianaId); - // Registry based timezone backend not available on WinRT -#elif defined Q_OS_WIN - return new QWinTimeZonePrivate(ianaId); #elif QT_CONFIG(icu) return new QIcuTimeZonePrivate(ianaId); +#elif defined Q_OS_WIN + return new QWinTimeZonePrivate(ianaId); #else return new QUtcTimeZonePrivate(ianaId); #endif // System Locales diff --git a/src/corelib/tools/qtimezoneprivate_win.cpp b/src/corelib/tools/qtimezoneprivate_win.cpp index 8bde07c710..ec91b7e8a8 100644 --- a/src/corelib/tools/qtimezoneprivate_win.cpp +++ b/src/corelib/tools/qtimezoneprivate_win.cpp @@ -49,6 +49,7 @@ QT_BEGIN_NAMESPACE #ifndef Q_OS_WINRT +// The registry-based timezone backend is not available on WinRT, which falls back to equivalent APIs. #define QT_USE_REGISTRY_TIMEZONE 1 #endif diff --git a/src/corelib/tools/tools.pri b/src/corelib/tools/tools.pri index 72224f280d..88708851d7 100644 --- a/src/corelib/tools/tools.pri +++ b/src/corelib/tools/tools.pri @@ -159,16 +159,18 @@ qtConfig(timezone) { SOURCES += \ tools/qtimezone.cpp \ tools/qtimezoneprivate.cpp - !nacl:darwin: \ + !nacl:darwin: { SOURCES += tools/qtimezoneprivate_mac.mm - else: android:!android-embedded: \ + } else: android:!android-embedded: { SOURCES += tools/qtimezoneprivate_android.cpp - else: unix: \ + } else: unix: { SOURCES += tools/qtimezoneprivate_tz.cpp - else: win32: \ - SOURCES += tools/qtimezoneprivate_win.cpp - qtConfig(icu): \ + qtConfig(icu): SOURCES += tools/qtimezoneprivate_icu.cpp + } else: qtConfig(icu): { SOURCES += tools/qtimezoneprivate_icu.cpp + } else: win32: { + SOURCES += tools/qtimezoneprivate_win.cpp + } } qtConfig(datetimeparser) { |