From 6694065148e5222df2c4cac7bfbf1e36251acde8 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 11 Jul 2018 18:25:33 +0200 Subject: [PATCH] Use suitable abstraction for the null value of CollatorType QCollatorPrivate defines a back-end-specific CollatorType and sets a member of this type to 0; but ICU's version really wants a nullptr not 0. So provide a named constant of the type, that's the NoCollator value for use there. Change-Id: Iad4d2f803ff4807ea568755efe00b9a92f1a8eeb Reviewed-by: Thiago Macieira --- src/corelib/tools/qcollator_icu.cpp | 4 ++-- src/corelib/tools/qcollator_p.h | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/corelib/tools/qcollator_icu.cpp b/src/corelib/tools/qcollator_icu.cpp index 43bbe0ea794..fd621983d34 100644 --- a/src/corelib/tools/qcollator_icu.cpp +++ b/src/corelib/tools/qcollator_icu.cpp @@ -61,7 +61,7 @@ void QCollatorPrivate::init() collator = ucol_open(name.constData(), &status); if (U_FAILURE(status)) { qWarning("Could not create collator: %d", status); - collator = 0; + collator = nullptr; dirty = false; return; } @@ -100,7 +100,7 @@ void QCollatorPrivate::cleanup() { if (collator) ucol_close(collator); - collator = 0; + collator = nullptr; } int QCollator::compare(const QChar *s1, int len1, const QChar *s2, int len2) const diff --git a/src/corelib/tools/qcollator_p.h b/src/corelib/tools/qcollator_p.h index 18a43f0de6b..f244a7721a4 100644 --- a/src/corelib/tools/qcollator_p.h +++ b/src/corelib/tools/qcollator_p.h @@ -68,21 +68,25 @@ QT_BEGIN_NAMESPACE #if QT_CONFIG(icu) typedef UCollator *CollatorType; typedef QByteArray CollatorKeyType; +const CollatorType NoCollator = nullptr; #elif defined(Q_OS_OSX) typedef CollatorRef CollatorType; typedef QVector CollatorKeyType; +const CollatorType NoCollator = 0; #elif defined(Q_OS_WIN) typedef QString CollatorKeyType; typedef int CollatorType; +const CollatorType NoCollator = 0; # ifdef Q_OS_WINRT # define USE_COMPARESTRINGEX # endif -#else //posix +#else // posix - ignores CollatorType collator, only handles system locale typedef QVector CollatorKeyType; typedef int CollatorType; +const CollatorType NoCollator = 0; #endif class QCollatorPrivate @@ -102,14 +106,14 @@ public: bool ignorePunctuation = false; bool dirty = true; - CollatorType collator = 0; + CollatorType collator = NoCollator; QCollatorPrivate(const QLocale &locale) : locale(locale) {} ~QCollatorPrivate() { cleanup(); } void clear() { cleanup(); - collator = 0; + collator = NoCollator; } // Implemented by each back-end, in its own way: