commit bbc7c59563b13d49cbfd3fca0390829dbfca7f93
parent b122d3b8e5c787e8c1c6d0d4b438fa0f32554b17
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Thu, 3 Sep 2020 16:17:45 +0200
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.
Diffstat:
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/src/files.c b/src/files.c
@@ -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