Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rouault authored and m-kuhn committed Sep 27, 2016
1 parent 6b7d7b0 commit 9cf9938
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/core/qgsexpressionsorter.h
Expand Up @@ -16,6 +16,8 @@
#ifndef QGSEXPRESSIONSORTER_H
#define QGSEXPRESSIONSORTER_H

#include <QLocale>

#include "qgsfeaturerequest.h"
#include "qgsindexedfeature.h"

Expand All @@ -25,6 +27,10 @@ class QgsExpressionSorter
public:
explicit QgsExpressionSorter( const QList<QgsFeatureRequest::OrderByClause>& preparedOrderBys )
: mPreparedOrderBys( preparedOrderBys )
// 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.
, mUseCaseInsensitiveComparison( QLocale::system().name() == QLocale::c().name() )
{}

bool operator()( const QgsIndexedFeature& f1, const QgsIndexedFeature& f2 ) const
Expand Down Expand Up @@ -106,10 +112,20 @@ class QgsExpressionSorter
default:
if ( 0 == v1.toString().localeAwareCompare( v2.toString() ) )
continue;
if ( orderBy.ascending() )
return v1.toString().localeAwareCompare( v2.toString() ) < 0;
if ( mUseCaseInsensitiveComparison )
{
if ( orderBy.ascending() )
return v1.toString().compare( v2.toString(), Qt::CaseInsensitive ) < 0;
else
return v1.toString().compare( v2.toString(), Qt::CaseInsensitive ) > 0;
}
else
return v1.toString().localeAwareCompare( v2.toString() ) > 0;
{
if ( orderBy.ascending() )
return v1.toString().localeAwareCompare( v2.toString() ) < 0;
else
return v1.toString().localeAwareCompare( v2.toString() ) > 0;
}
}
}

Expand Down Expand Up @@ -154,6 +170,7 @@ class QgsExpressionSorter

private:
QList<QgsFeatureRequest::OrderByClause> mPreparedOrderBys;
bool mUseCaseInsensitiveComparison;
};

/// @endcond
Expand Down

0 comments on commit 9cf9938

Please sign in to comment.