Mercurial > hg > svcore
changeset 1546:9c14dee72329
Use locale-aware comparators for user-visible string sorting
author | Chris Cannam |
---|---|
date | Mon, 01 Oct 2018 14:37:30 +0100 |
parents | b89705af7a60 |
children | 32400727bcbd 51d6551d5244 |
files | transform/TransformDescription.h transform/TransformFactory.cpp transform/TransformFactory.h |
diffstat | 3 files changed, 36 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- 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); + } }; };
--- 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 <iostream> #include <set> +#include <functional> #include <QRegExp> #include <QTextStream> @@ -111,19 +112,17 @@ populateTransforms(); std::set<TransformDescription> 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<TransformDescription>::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<TransformDescription> 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<TransformDescription>::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<TransformDescription::Type> 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<TransformDescription::Type> rv; - for (std::set<TransformDescription::Type>::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<QString> categories; - for (TransformDescriptionMap::const_iterator i = m_transforms.begin(); - i != m_transforms.end(); ++i) { + std::set<QString, std::function<bool(QString, QString)>> + 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<QString> rv; - for (std::set<QString>::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<QString> makers; - for (TransformDescriptionMap::const_iterator i = m_transforms.begin(); - i != m_transforms.end(); ++i) { + std::set<QString, std::function<bool(QString, QString)>> + 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<QString> rv; - for (std::set<QString>::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];
--- 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"