From 3cb4e63253b929cc3447fa99b3e1c48a6031a03e Mon Sep 17 00:00:00 2001 From: Roman Artiukhin Date: Sat, 10 May 2025 11:44:11 +0300 Subject: [PATCH] strnatcmp: Sort dots first Moves special folders (like .rockbox) on top and makes filenames sorting look more consistent with folders sorting. See https://forums.rockbox.org/index.php/topic,55303 Change-Id: I6ffd9b3ea0acfcbab69f09415f4e9f53737e7769 --- firmware/common/strnatcmp.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/firmware/common/strnatcmp.c b/firmware/common/strnatcmp.c index d77f7e995e..7a116c519d 100644 --- a/firmware/common/strnatcmp.c +++ b/firmware/common/strnatcmp.c @@ -154,6 +154,15 @@ static int strnatcmp0(char const *a, char const *b, return cmp_fn(a,b); } + // Place dots before any chars (but after end of line '\0') + // It makes filenames sorting more natural by placing shorter names before longer ones. + // Without fix: Song (Live).mp3, Song.mp3 + // With fix: Song.mp3, Song (Live).mp3 + if (ca == '.') + ca = 1; + if (cb == '.') + cb = 1; + if (cmp_fn == &strcasecmp) { ca = nat_unify_case(ca); cb = nat_unify_case(cb);