# HG changeset patch # User Chris Cannam # Date 1538401050 -3600 # Node ID 9c14dee723292a4f126eb66174fee1c6d5ee4d54 # Parent b89705af7a609fbac4ab8df394594f41ac3e3180 Use locale-aware comparators for user-visible string sorting diff -r b89705af7a60 -r 9c14dee72329 transform/TransformDescription.h --- a/transform/TransformDescription.h Mon Oct 01 14:37:11 2018 +0100 +++ b/transform/TransformDescription.h Mon Oct 01 14:37:30 2018 +0100 @@ -13,8 +13,8 @@ COPYING included with this distribution for more information. */ -#ifndef _TRANSFORM_DESCRIPTION_H_ -#define _TRANSFORM_DESCRIPTION_H_ +#ifndef SV_TRANSFORM_DESCRIPTION_H +#define SV_TRANSFORM_DESCRIPTION_H #include "Transform.h" @@ -77,11 +77,19 @@ QString infoUrl; QString units; bool configurable; + + // User-visible strings (name, maker etc) should be sorted in a + // locale-aware way + static bool compareUserStrings(QString s1, QString s2) { + return QString::localeAwareCompare(s1, s2) < 0; + }; bool operator<(const TransformDescription &od) const { - return - (name < od.name) || - (name == od.name && identifier < od.identifier); + if (name == od.name) { + return identifier < od.identifier; + } else { + return compareUserStrings(name, od.name); + } }; }; diff -r b89705af7a60 -r 9c14dee72329 transform/TransformFactory.cpp --- a/transform/TransformFactory.cpp Mon Oct 01 14:37:11 2018 +0100 +++ b/transform/TransformFactory.cpp Mon Oct 01 14:37:30 2018 +0100 @@ -32,6 +32,7 @@ #include #include +#include #include #include @@ -111,19 +112,17 @@ populateTransforms(); std::set dset; - for (TransformDescriptionMap::const_iterator i = m_transforms.begin(); - i != m_transforms.end(); ++i) { + for (auto i = m_transforms.begin(); i != m_transforms.end(); ++i) { #ifdef DEBUG_TRANSFORM_FACTORY - cerr << "inserting transform into set: id = " << i->second.identifier << endl; + cerr << "inserting transform into set: id = " << i->second.identifier << " (" << i->second.name << ")" << endl; #endif dset.insert(i->second); } TransformList list; - for (std::set::const_iterator i = dset.begin(); - i != dset.end(); ++i) { + for (auto i = dset.begin(); i != dset.end(); ++i) { #ifdef DEBUG_TRANSFORM_FACTORY - cerr << "inserting transform into list: id = " << i->identifier << endl; + cerr << "inserting transform into list: id = " << i->identifier << " (" << i->name << ")" << endl; #endif list.push_back(*i); } @@ -157,7 +156,7 @@ populateUninstalledTransforms(); std::set dset; - for (TransformDescriptionMap::const_iterator i = m_uninstalledTransforms.begin(); + for (auto i = m_uninstalledTransforms.begin(); i != m_uninstalledTransforms.end(); ++i) { #ifdef DEBUG_TRANSFORM_FACTORY cerr << "inserting transform into set: id = " << i->second.identifier << endl; @@ -166,8 +165,7 @@ } TransformList list; - for (std::set::const_iterator i = dset.begin(); - i != dset.end(); ++i) { + for (auto i = dset.begin(); i != dset.end(); ++i) { #ifdef DEBUG_TRANSFORM_FACTORY cerr << "inserting transform into uninstalled list: id = " << i->identifier << endl; #endif @@ -247,13 +245,12 @@ populateTransforms(); std::set types; - for (TransformDescriptionMap::const_iterator i = m_transforms.begin(); - i != m_transforms.end(); ++i) { + for (auto i = m_transforms.begin(); i != m_transforms.end(); ++i) { types.insert(i->second.type); } std::vector rv; - for (std::set::iterator i = types.begin(); i != types.end(); ++i) { + for (auto i = types.begin(); i != types.end(); ++i) { rv.push_back(*i); } @@ -265,9 +262,10 @@ { populateTransforms(); - std::set categories; - for (TransformDescriptionMap::const_iterator i = m_transforms.begin(); - i != m_transforms.end(); ++i) { + std::set> + categories(TransformDescription::compareUserStrings); + + for (auto i = m_transforms.begin(); i != m_transforms.end(); ++i) { if (i->second.type == transformType) { categories.insert(i->second.category); } @@ -276,8 +274,7 @@ bool haveEmpty = false; std::vector rv; - for (std::set::iterator i = categories.begin(); - i != categories.end(); ++i) { + for (auto i = categories.begin(); i != categories.end(); ++i) { if (*i != "") rv.push_back(*i); else haveEmpty = true; } @@ -292,9 +289,10 @@ { populateTransforms(); - std::set makers; - for (TransformDescriptionMap::const_iterator i = m_transforms.begin(); - i != m_transforms.end(); ++i) { + std::set> + makers(TransformDescription::compareUserStrings); + + for (auto i = m_transforms.begin(); i != m_transforms.end(); ++i) { if (i->second.type == transformType) { makers.insert(i->second.maker); } @@ -303,8 +301,7 @@ bool haveEmpty = false; std::vector rv; - for (std::set::iterator i = makers.begin(); - i != makers.end(); ++i) { + for (auto i = makers.begin(); i != makers.end(); ++i) { if (*i != "") rv.push_back(*i); else haveEmpty = true; } @@ -414,7 +411,7 @@ if (m_exiting) return; - for (int i = 0; i < (int)plugs.size(); ++i) { + for (int i = 0; in_range_for(plugs, i); ++i) { QString pluginId = plugs[i]; @@ -504,7 +501,7 @@ static QRegExp unitRE("[\\[\\(]([A-Za-z0-9/]+)[\\)\\]]$"); - for (int i = 0; i < (int)plugs.size(); ++i) { + for (int i = 0; in_range_for(plugs, i); ++i) { QString pluginId = plugs[i]; diff -r b89705af7a60 -r 9c14dee72329 transform/TransformFactory.h --- a/transform/TransformFactory.h Mon Oct 01 14:37:11 2018 +0100 +++ b/transform/TransformFactory.h Mon Oct 01 14:37:30 2018 +0100 @@ -13,8 +13,8 @@ COPYING included with this distribution for more information. */ -#ifndef _TRANSFORM_FACTORY_H_ -#define _TRANSFORM_FACTORY_H_ +#ifndef SV_TRANSFORM_FACTORY_H +#define SV_TRANSFORM_FACTORY_H #include "TransformDescription.h"