[vlc-devel] [PATCH] playlist/directory: ignore case when sorting files

Thomas Guillem thomas at gllm.fr
Thu Aug 20 14:48:36 CEST 2015


4 differents cases when sorting files:

- "collate" option with HAVE_STRCOLL: the case is ignored depending of the
  program's LOCAL.

- "collate" option without HAVE_STRCOLL: use strcasecmp instead of strcmp to
  ignore the case.

- "version" option with HAVE_STRCOLL: use strxfrm to transform two strings into
  a form such that the result of strcmp (or strverscmp for our case) on these
  strings is the same result than strcoll. Therefore, the case is ignored
  depending of the program's LOCAL.

- "version" option without HAVE_STRCOLL: the case is not ignored.
---
 modules/demux/playlist/directory.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/modules/demux/playlist/directory.c b/modules/demux/playlist/directory.c
index 5c835bb..0ad5913 100644
--- a/modules/demux/playlist/directory.c
+++ b/modules/demux/playlist/directory.c
@@ -129,9 +129,10 @@ static int compar_collate( input_item_t *p1, input_item_t *p2 )
         return i_ret;
 
 #ifdef HAVE_STRCOLL
+    /* The program's LOCAL defines if case is ignored */
     return strcoll( p1->psz_name, p2->psz_name );
 #else
-    return strcmp( p1->psz_name, p2->psz_name );
+    return strcasecmp( p1->psz_name, p2->psz_name );
 #endif
 }
 
@@ -142,7 +143,25 @@ static int compar_version( input_item_t *p1, input_item_t *p2 )
     if( i_ret != 0 )
         return i_ret;
 
+#ifdef HAVE_STRCOLL
+    /* The program's LOCAL defines if case is ignored */
+
+    /* strxfrm(NULL, src, 0) returns the number of bytes required for the
+     * transformation */
+    char *psz_name1 = malloc( strxfrm( NULL, p1->psz_name, 0 ) + 1 );
+    char *psz_name2 = malloc( strxfrm( NULL, p2->psz_name, 0 ) + 1 );
+    if( !psz_name1 || !psz_name2 )
+        return 0;
+
+    strxfrm( psz_name1, p1->psz_name, sizeof(psz_name1) );
+    strxfrm( psz_name2, p2->psz_name, sizeof(psz_name2) );
+    i_ret = strverscmp( psz_name1, psz_name2 );
+    free( psz_name1 );
+    free( psz_name2 );
+    return i_ret;
+#else
     return strverscmp( p1->psz_name, p2->psz_name );
+#endif
 }
 
 static int Demux( demux_t *p_demux )
-- 
2.1.4



More information about the vlc-devel mailing list