From da4931ab2f871b32f1b96e2cfa6518a4f57711f0 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 19 May 2019 19:04:18 +0200 Subject: [PATCH] Made tag-sorting locale-aware. --- CMakeLists.txt | 2 +- src/adoc.cpp | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 26dcb12..671f525 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.2) project(remwharead - VERSION 0.2.0 + VERSION 0.2.1 LANGUAGES CXX ) diff --git a/src/adoc.cpp b/src/adoc.cpp index 20b6ecd..f193cb8 100644 --- a/src/adoc.cpp +++ b/src/adoc.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include "version.hpp" #include "time.hpp" @@ -116,16 +117,27 @@ void export_adoc(const vector &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 &coll = + std::use_facet>(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; + } } });