[vlc-commits] [Git][videolan/vlc][master] playlist: sort title and album by filename order
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Fri Jul 9 16:56:56 UTC 2021
Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC
Commits:
0635abe2 by Christian Christiansen at 2021-07-09T16:43:55+00:00
playlist: sort title and album by filename order
When sorting a playlist by title or album, use the filename sort order
(i.e. 2-title should come before 10-title). strcasecmp would previously
sort 10-title to come before 2-title. strverscmp would also solve the issue
but we use vlc_filenamecmp for the increased accuracy as
vlc_filenamecmp takes user locale into consideration.
We use strverscmp for the sort order of URLs, as URLs are generally
in ASCII and not locale-dependent.
Fixes #14548 #23200 #23611
- - - - -
1 changed file:
- src/playlist/sort.c
Changes:
=====================================
src/playlist/sort.c
=====================================
@@ -25,6 +25,7 @@
#include <vlc_common.h>
#include <vlc_rand.h>
#include <vlc_sort.h>
+#include <vlc_strings.h>
#include "control.h"
#include "item.h"
#include "notify.h"
@@ -229,6 +230,26 @@ CompareStrings(const char *a, const char *b)
return a ? 1 : -1;
}
+static inline int
+CompareFilenameStrings(const char *a, const char *b)
+{
+ if (a && b)
+ return vlc_filenamecmp(a, b);
+ if (!a && !b)
+ return 0;
+ return a ? 1 : -1;
+}
+
+static inline int
+CompareVersionStrings(const char *a, const char *b)
+{
+ if (a && b)
+ return strverscmp(a, b);
+ if (!a && !b)
+ return 0;
+ return a ? 1 : -1;
+}
+
static inline int
CompareIntegers(int64_t a, int64_t b)
{
@@ -259,13 +280,13 @@ CompareMetaByKey(const struct vlc_playlist_item_meta *a,
switch (key)
{
case VLC_PLAYLIST_SORT_KEY_TITLE:
- return CompareStrings(a->title_or_name, b->title_or_name);
+ return CompareFilenameStrings(a->title_or_name, b->title_or_name);
case VLC_PLAYLIST_SORT_KEY_DURATION:
return CompareIntegers(a->duration, b->duration);
case VLC_PLAYLIST_SORT_KEY_ARTIST:
return CompareStrings(a->artist, b->artist);
case VLC_PLAYLIST_SORT_KEY_ALBUM:
- return CompareStrings(a->album, b->album);
+ return CompareFilenameStrings(a->album, b->album);
case VLC_PLAYLIST_SORT_KEY_ALBUM_ARTIST:
return CompareStrings(a->album_artist, b->album_artist);
case VLC_PLAYLIST_SORT_KEY_GENRE:
@@ -280,7 +301,7 @@ CompareMetaByKey(const struct vlc_playlist_item_meta *a,
return CompareOptionalIntegers(a->has_disc_number, a->disc_number,
b->has_disc_number, b->disc_number);
case VLC_PLAYLIST_SORT_KEY_URL:
- return CompareStrings(a->url, b->url);
+ return CompareVersionStrings(a->url, b->url);
case VLC_PLAYLIST_SORT_KEY_RATING:
return CompareOptionalIntegers(a->has_rating, a->rating,
b->has_rating, b->rating);
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/0635abe236b1306bb4aaa83ebdbbc0d953ab5e5e
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/0635abe236b1306bb4aaa83ebdbbc0d953ab5e5e
You're receiving this email because of your account on code.videolan.org.
More information about the vlc-commits
mailing list