1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Roman Artiukhin 2025-05-10 11:44:11 +03:00 committed by Solomon Peachy
parent e08b8fcc74
commit 3cb4e63253

View file

@ -154,6 +154,15 @@ static int strnatcmp0(char const *a, char const *b,
return cmp_fn(a,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) { if (cmp_fn == &strcasecmp) {
ca = nat_unify_case(ca); ca = nat_unify_case(ca);
cb = nat_unify_case(cb); cb = nat_unify_case(cb);