mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 10:00:33 +00:00
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.
This commit is contained in:
parent
2acd00fc17
commit
afc34c7a60
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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>
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user