smart playlists: case sensitivity of string comparisons

James Burton <[email protected]>
Newsgroups gmane.comp.ipod.gtkpod
Message-ID <[email protected]>
Hello all,

I've noticed that smart playlists on iPods with string comparisons (artist name etc) created with libgpod behave differently to those created in iTunes. Playlists created in and evaluated with libgpod do a case sensitive string comparison, iTunes does a case-insensitive one. This means if you create a playlist with libgpod then access the device in iTunes, the contents of the smart playlist will often change (iTunes seems to re-evaluate smart playlist rules every time a device is first attached).

I think case insensitive matching would be preferable: it's more likely to be what the user expects, and matches iTunes behaviour. As far as I can tell all the string comparison rules in iTunes are case-insensitive (contains/does not contain/is/is not/starts with/ends with).

This would be a trivial change (using strcasecmp/strcasestr/strncasecmp in itdb_splr_eval in itdb_playlist.c), but I don't know if this issue has come up before and the current behaviour was deemed preferable.

Thoughts?

James Burton

------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store 
http://p.sf.net/sfu/nokia-dev2dev

_______________________________________________
Gtkpod-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gtkpod-devel
0001-make-smart-playlist-string-comparisons-case-insensit.patch (application/octet-stream, 1.9 KB)
From bfe47488639db52b64e842ee0a8b364d35f055a3 Mon Sep 17 00:00:00 2001
From: James Burton <[email protected]>
Date: Sat, 30 Oct 2010 20:09:53 +0100
Subject: [PATCH 1/1] make smart playlist string comparisons case-insensitive

bring behaviour in line with iTunes by making
smart playlist string comparisons case-insensitive

diff --git a/src/itdb_playlist.c b/src/itdb_playlist.c
index fbb4aac..441d769 100644
--- a/src/itdb_playlist.c
+++ b/src/itdb_playlist.c
@@ -514,25 +514,25 @@ gboolean itdb_splr_eval (Itdb_SPLRule *splr, Itdb_Track *track)
 	    switch (splr->action)
 	    {
 	    case ITDB_SPLACTION_IS_STRING:
-		return (strcmp (strcomp, splr->string) == 0);
+		return (strcasecmp (strcomp, splr->string) == 0);
 	    case ITDB_SPLACTION_IS_NOT:
-		return (strcmp (strcomp, splr->string) != 0);
+		return (strcasecmp (strcomp, splr->string) != 0);
 	    case ITDB_SPLACTION_CONTAINS:
-		return (strstr (strcomp, splr->string) != NULL);
+		return (strcasestr (strcomp, splr->string) != NULL);
 	    case ITDB_SPLACTION_DOES_NOT_CONTAIN:
-		return (strstr (strcomp, splr->string) == NULL);
+		return (strcasestr (strcomp, splr->string) == NULL);
 	    case ITDB_SPLACTION_STARTS_WITH:
-		return (strncmp (strcomp, splr->string, len2) == 0);
+		return (strncasecmp (strcomp, splr->string, len2) == 0);
 	    case ITDB_SPLACTION_ENDS_WITH:
 	    if (len2 > len1)  return FALSE;
-	    return (strncmp (strcomp+len1-len2,
+	    return (strncasecmp (strcomp+len1-len2,
 			     splr->string, len2) == 0);
 	    case ITDB_SPLACTION_DOES_NOT_START_WITH:
-		return (strncmp (strcomp, splr->string,
+		return (strncasecmp (strcomp, splr->string,
 				 strlen (splr->string)) != 0);
 	    case ITDB_SPLACTION_DOES_NOT_END_WITH:
 		if (len2 > len1)  return TRUE;
-		return (strncmp (strcomp+len1-len2,
+		return (strncasecmp (strcomp+len1-len2,
 				 splr->string, len2) != 0);
 	    };
 	}
-- 
1.7.2.3
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.