commit afc34c7a60faaceb5fba9463aba44e3c4062f6cb
Author: Georg Baum <[email protected]>
Date: Mon May 19 22:37:14 2014 +0200
Fix bug 9030 except for windows
The format entries should be sorted according to the culture selected for
the
UI. This was not the case previously, resulting in unexpected sorting of
small
and capital letters. This is now fixed by using the standard C function
strcoll(). Qt does only offer similar functionality in Qt5, and this is not
mature enough yet to depend on it.
Unfortunately we have a report that strcoll() does not work on MSVC, however
this partial fix is better than nothing. The MSVC issue might also be a
configuration problem, since MS claims that strcoll() is supported. This
still needs to be checked.
diff --git a/src/Format.cpp b/src/Format.cpp
index 4045d80..0bbd3fc 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 656f82e..a2487f8 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 <QString>
#include <cstdio>
+#include <cstring>
#include <algorithm>
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<typename Char>
diff --git a/src/support/lstrings.h b/src/support/lstrings.h
index 576a5b9..02b5cf2 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);