diff --git a/src/Format.cpp b/src/Format.cpp index 4045d80d35..0bbd3fc144 100644 --- a/src/Format.cpp +++ b/src/Format.cpp @@ -104,12 +104,12 @@ private: bool Format::formatSorter(Format const * lhs, Format const * rhs) { - return _(lhs->prettyname()) < _(rhs->prettyname()); + return compare_locale(_(lhs->prettyname()), _(rhs->prettyname())) < 0; } bool operator<(Format const & a, Format const & b) { - return _(a.prettyname()) < _(b.prettyname()); + return compare_locale(_(a.prettyname()), _(b.prettyname())) < 0; } diff --git a/src/support/lstrings.cpp b/src/support/lstrings.cpp index 656f82ee11..a2487f8844 100644 --- a/src/support/lstrings.cpp +++ b/src/support/lstrings.cpp @@ -15,6 +15,7 @@ #include "support/lstrings.h" #include "support/convert.h" +#include "support/debug.h" #include "support/qstring_helpers.h" #include "support/lassert.h" @@ -22,6 +23,7 @@ #include #include +#include #include using namespace std; @@ -200,6 +202,29 @@ int compare_no_case(docstring const & s, docstring const & s2) } +int compare_locale(docstring const & s, docstring const & s2) +{ + // FIXME We have a report that this does not work on windows (bug 9030) + try + { + string const l = to_local8bit(s); + string const r = to_local8bit(s2); + return strcoll(l.c_str(), r.c_str()); + } + catch (bad_cast & e) + { + // fall back to builtin sorting + LYXERR0("Could not compare using the current locale: " + << e.what() << ", using fallback."); + if (s < s2) + return -1; + if (s > s2) + return 1; + return 0; + } +} + + namespace { template diff --git a/src/support/lstrings.h b/src/support/lstrings.h index 576a5b921d..02b5cf2f2b 100644 --- a/src/support/lstrings.h +++ b/src/support/lstrings.h @@ -28,6 +28,9 @@ namespace support { /// Does not depend on the locale. int compare_no_case(docstring const & s, docstring const & s2); +/// Compare \p s and \p s2 using the collating rules of the current locale. +int compare_locale(docstring const & s, docstring const & s2); + /// Compare \p s and \p s2, ignoring the case of ASCII characters only. int compare_ascii_no_case(std::string const & s, std::string const & s2);