Skip to content
Permalink
Browse files

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 9cf99389bbb85b99a5d0444281be4dd2419070a9
Showing with 20 additions and 3 deletions.
  1. +20 −3 src/core/qgsexpressionsorter.h
@@ -16,6 +16,8 @@
#ifndef QGSEXPRESSIONSORTER_H
#define QGSEXPRESSIONSORTER_H

#include <QLocale>

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

@@ -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
@@ -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;
}
}
}

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

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

/// @endcond

0 comments on commit 9cf9938

Please sign in to comment.