Skip to content

Commit 9cf9938

Browse files
rouaultm-kuhn
authored andcommitted
Fix shapefile test failures if locale is C (#3523)
QString::localeAwareCompare() is case insensitive for common locales, but case sensitive for the C locale. So use an explicit case insensitive comparison in that later case to avoid test failures.
1 parent 6b7d7b0 commit 9cf9938

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/core/qgsexpressionsorter.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#ifndef QGSEXPRESSIONSORTER_H
1717
#define QGSEXPRESSIONSORTER_H
1818

19+
#include <QLocale>
20+
1921
#include "qgsfeaturerequest.h"
2022
#include "qgsindexedfeature.h"
2123

@@ -25,6 +27,10 @@ class QgsExpressionSorter
2527
public:
2628
explicit QgsExpressionSorter( const QList<QgsFeatureRequest::OrderByClause>& preparedOrderBys )
2729
: mPreparedOrderBys( preparedOrderBys )
30+
// QString::localeAwareCompare() is case insensitive for common locales,
31+
// but case sensitive for the C locale. So use an explicit case
32+
// insensitive comparison in that later case to avoid test failures.
33+
, mUseCaseInsensitiveComparison( QLocale::system().name() == QLocale::c().name() )
2834
{}
2935

3036
bool operator()( const QgsIndexedFeature& f1, const QgsIndexedFeature& f2 ) const
@@ -106,10 +112,20 @@ class QgsExpressionSorter
106112
default:
107113
if ( 0 == v1.toString().localeAwareCompare( v2.toString() ) )
108114
continue;
109-
if ( orderBy.ascending() )
110-
return v1.toString().localeAwareCompare( v2.toString() ) < 0;
115+
if ( mUseCaseInsensitiveComparison )
116+
{
117+
if ( orderBy.ascending() )
118+
return v1.toString().compare( v2.toString(), Qt::CaseInsensitive ) < 0;
119+
else
120+
return v1.toString().compare( v2.toString(), Qt::CaseInsensitive ) > 0;
121+
}
111122
else
112-
return v1.toString().localeAwareCompare( v2.toString() ) > 0;
123+
{
124+
if ( orderBy.ascending() )
125+
return v1.toString().localeAwareCompare( v2.toString() ) < 0;
126+
else
127+
return v1.toString().localeAwareCompare( v2.toString() ) > 0;
128+
}
113129
}
114130
}
115131

@@ -154,6 +170,7 @@ class QgsExpressionSorter
154170

155171
private:
156172
QList<QgsFeatureRequest::OrderByClause> mPreparedOrderBys;
173+
bool mUseCaseInsensitiveComparison;
157174
};
158175

159176
/// @endcond

0 commit comments

Comments
 (0)