Made tag-sorting locale-aware.
continuous-integration/drone/push Build is failing Details

This commit is contained in:
tastytea 2019-05-19 19:04:18 +02:00
parent 963f62fb1b
commit da4931ab2f
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
2 changed files with 17 additions and 5 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.2)
project(remwharead
VERSION 0.2.0
VERSION 0.2.1
LANGUAGES CXX
)

View File

@ -18,6 +18,7 @@
#include <regex>
#include <algorithm>
#include <utility>
#include <locale>
#include <curlpp/cURLpp.hpp>
#include "version.hpp"
#include "time.hpp"
@ -116,16 +117,27 @@ void export_adoc(const vector<Database::entry> &entries, ostream &out)
std::sort(sortedtags.begin(), sortedtags.end(),
[](const tagpair &a, tagpair &b)
{
// return a.second.size() > b.second.size();
if (a.second.size() != b.second.size())
{ // Sort by number of occurrences if they are
// different.
return a.second.size() > b.second.size();
}
else
{ // Sort alphabetically otherwise.
// TODO: Does this work with non-latin languages?
return a.first < b.first;
{ // Sort by tag names otherwise.
std::locale loc("");
const std::collate<char> &coll =
std::use_facet<std::collate<char>>(loc);
if (coll.compare(a.first.data(), a.first.data()
+ a.first.length(),
b.first.data(), b.first.data()
+ b.first.length()) == -1)
{ // -1 == less than
return true;
}
else
{
return false;
}
}
});