browser: sort names that differ only in case with uppercase first

This is the opposite of what 'ls' does in a UTF-8 locale, but nano
has never followed the collating rules of Unicode (uppercase after
lowercase, ignoring punctuation, and so on) -- it would be strange
to change that now.

Until now, nano left such equivalent names unsorted, in a seemingly
random order.

This fixes https://savannah.gnu.org/bugs/?59059.

Bug existed since before version 2.0.6.
master
Benno Schulenberg 2020-09-03 16:17:45 +02:00
parent b122d3b8e5
commit bbc7c59563
1 changed files with 7 additions and 5 deletions

View File

@ -2354,11 +2354,13 @@ int diralphasort(const void *va, const void *vb)
if (!aisdir && bisdir)
return 1;
/* Standard function brain damage: We should be sorting
* alphabetically and case-insensitively according to the current
* locale, but there's no standard strcasecoll() function, so we
* have to use multibyte strcasecmp() instead. */
return mbstrcasecmp(a, b);
int difference = mbstrcasecmp(a, b);
/* If two names are equivalent when ignoring case, compare them bytewise. */
if (difference == 0)
return strcmp(a, b);
else
return difference;
}
#endif