Correct qcollator_posix.cpp's check against system locale

The check was made against the default locale but the code calls the
system functions (wcscoll, wcsxfrm, wcscmp) for locale-specific
collation, so should be comparing to the system locale's collation
locale (i.e. LC_COLLATE). Also correct the Android-only check in
tst_QCollator::compare() which duplicated the check but neglected the
C locale, which is also supported (via QString::compare).

Pick-to: 6.2
Change-Id: I48c3237dd6825e2070272ab88d95bdb8cbb9fc37
Reviewed-by: Aleix Pol Gonzalez <aleixpol@kde.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Edward Welbourne 2021-10-29 12:36:19 +02:00
parent 48856934ec
commit 25d807f629
2 changed files with 8 additions and 5 deletions

View File

@ -1,6 +1,7 @@
/**************************************************************************** /****************************************************************************
** **
** Copyright (C) 2020 Aleix Pol Gonzalez <aleixpol@kde.org> ** Copyright (C) 2021 The Qt Company Ltd.
** Copyright (C) 2013 Aleix Pol Gonzalez <aleixpol@kde.org>
** Contact: https://www.qt.io/licensing/ ** Contact: https://www.qt.io/licensing/
** **
** This file is part of the QtCore module of the Qt Toolkit. ** This file is part of the QtCore module of the Qt Toolkit.
@ -49,8 +50,10 @@ QT_BEGIN_NAMESPACE
void QCollatorPrivate::init() void QCollatorPrivate::init()
{ {
if (!isC()) { if (!isC()) {
if (locale != QLocale()) if (locale != QLocale::system().collation()) {
qWarning("Only C and default locale supported with the posix collation implementation"); qWarning("Only the C and system collation locales are supported "
"with the POSIX collation implementation");
}
if (caseSensitivity != Qt::CaseSensitive) if (caseSensitivity != Qt::CaseSensitive)
qWarning("Case insensitive sorting unsupported in the posix collation implementation"); qWarning("Case insensitive sorting unsupported in the posix collation implementation");
} }

View File

@ -282,8 +282,8 @@ void tst_QCollator::compare()
}; };
#ifdef Q_OS_ANDROID #ifdef Q_OS_ANDROID
if (collator.locale() != QLocale()) if (collator.locale() != QLocale::c() && collator.locale() != QLocale::system().collation())
QSKIP("Posix implementation of collation only supports default locale"); QSKIP("POSIX implementation of collation only supports C and system collation locales");
#endif #endif
if (numericMode) if (numericMode)