Hi, Sorry for the multiple posts but I've attached a better version of the patch :) It doesn't ignore special characters and also the memory leak has been fixed. Cheers,
On Sun, Mar 22, 2009 at 10:29 PM, Surya Kiran (Virus) < suryaoruga...@gmail.com> wrote: > > > On Sun, Mar 22, 2009 at 10:12 PM, Jud Craft <craft...@gmail.com> wrote: > >> 2009/3/19 Surya Kiran (Virus): >> > Expected behaviour: No case-sesntivity. All 3 artists must be grouped >> into >> > one, >> > as *never* is an artist differentiated by case. >> >> Are you sure no one has ever tried to remix an existing author's name >> with different case for "originality?" >> >> I mean, I think you're almost right here...but I'm not completely >> sure. If some artist did re-case an existing name and call it >> "creativity" I wouldn't be surprised. But even if so, it may still be >> so rare that this patch wouldn't be a problem at all. >> > > > Hi Jud, > This patch is in no way complete. It is just a workaround that will be > useful in a majority of the cases. I wrote this one just for my convenience > and thought that it might be useful to some other people too! > As this bug discussion shows ( > http://bugzilla.gnome.org/show_bug.cgi?id=144283 ) , there are a lot of > flaws and this cannot be accepted into the rhythmbox source, but it was > worth a try. Also, I need to add a little free statement at the end to clear > up the memory. > Cheers, > -- > Surya Kiran Oruganti > -- Surya Kiran Oruganti
Index: rhythmdb/rb-refstring.c =================================================================== --- rhythmdb/rb-refstring.c (revision 6240) +++ rhythmdb/rb-refstring.c (working copy) @@ -145,6 +145,18 @@ } const char * +rb_refstring_get_titlecase (const RBRefString *val) +{ + const char *val_lower; + if (val) { + val_lower = rb_search_fold_titlecase (rb_refstring_get (val)); + return val_lower; + } + else + return NULL; +} + +const char * rb_refstring_get (const RBRefString *val) { return val ? val->value : NULL; Index: rhythmdb/rb-refstring.h =================================================================== --- rhythmdb/rb-refstring.h (revision 6240) +++ rhythmdb/rb-refstring.h (working copy) @@ -46,9 +46,12 @@ void rb_refstring_unref (RBRefString *val); const char * rb_refstring_get (const RBRefString *val); +const char * rb_refstring_get_titlecase (const RBRefString *val); const char * rb_refstring_get_folded (RBRefString *val); const char * rb_refstring_get_sort_key (RBRefString *val); +gchar* rb_search_fold_titlecase (const char *original); + guint rb_refstring_hash (gconstpointer p); gboolean rb_refstring_equal (gconstpointer ap, gconstpointer bp); Index: rhythmdb/rhythmdb.c =================================================================== --- rhythmdb/rhythmdb.c (revision 6240) +++ rhythmdb/rhythmdb.c (working copy) @@ -1489,6 +1489,7 @@ * * Returns: the newly allocated #RhythmDBEntry **/ + RhythmDBEntry * rhythmdb_entry_allocate (RhythmDB *db, RhythmDBEntryType type) @@ -4907,13 +4908,13 @@ switch (propid) { case RHYTHMDB_PROP_TITLE: - return rb_refstring_get (entry->title); + return rb_refstring_get_titlecase (entry->title); case RHYTHMDB_PROP_ALBUM: - return rb_refstring_get (entry->album); + return rb_refstring_get_titlecase (entry->album); case RHYTHMDB_PROP_ARTIST: - return rb_refstring_get (entry->artist); + return rb_refstring_get_titlecase (entry->artist); case RHYTHMDB_PROP_GENRE: - return rb_refstring_get (entry->genre); + return rb_refstring_get_titlecase (entry->genre); case RHYTHMDB_PROP_MUSICBRAINZ_TRACKID: return rb_refstring_get (entry->musicbrainz_trackid); case RHYTHMDB_PROP_MUSICBRAINZ_ARTISTID: Index: lib/rb-util.c =================================================================== --- lib/rb-util.c (revision 6240) +++ lib/rb-util.c (working copy) @@ -497,6 +497,78 @@ } gchar* +rb_search_fold_titlecase (const char *original) +{ + GString *string; + gchar *normalized; + gunichar *unicode, *cur, prev = 0x0020; + + g_return_val_if_fail (original != NULL, NULL); + + /* old behaviour is equivalent to: return g_utf8_casefold (original, -1); */ + + string = g_string_new (NULL); + normalized = g_utf8_normalize(original, -1, G_NORMALIZE_DEFAULT); + unicode = g_utf8_to_ucs4_fast (normalized, -1, NULL); + cur = unicode; + + for (cur = unicode; *cur != 0; cur++) { + if (*cur == 0x005f) //underscore + *cur = 0x0020; + switch (g_unichar_type (*cur)) { + case G_UNICODE_COMBINING_MARK: + case G_UNICODE_ENCLOSING_MARK: + case G_UNICODE_NON_SPACING_MARK: + case G_UNICODE_CONNECT_PUNCTUATION: + case G_UNICODE_DASH_PUNCTUATION: + case G_UNICODE_CLOSE_PUNCTUATION: + case G_UNICODE_FINAL_PUNCTUATION: + case G_UNICODE_INITIAL_PUNCTUATION: + case G_UNICODE_OTHER_PUNCTUATION: + case G_UNICODE_OPEN_PUNCTUATION: + + case G_UNICODE_LOWERCASE_LETTER: + case G_UNICODE_MODIFIER_LETTER: + case G_UNICODE_OTHER_LETTER: + case G_UNICODE_TITLECASE_LETTER: + case G_UNICODE_UPPERCASE_LETTER: + /* convert to title case */ + if (prev == 0x0020) + *cur = g_unichar_toupper (*cur); + else + *cur = g_unichar_tolower (*cur); + /* ... and fall through */\ + case G_UNICODE_DECIMAL_NUMBER: + case G_UNICODE_LETTER_NUMBER: + case G_UNICODE_OTHER_NUMBER: + /* should be keep symbols? */ + case G_UNICODE_CURRENCY_SYMBOL: + case G_UNICODE_MODIFIER_SYMBOL: + case G_UNICODE_MATH_SYMBOL: + case G_UNICODE_OTHER_SYMBOL: + g_string_append_unichar (string, *cur); + break; + + case G_UNICODE_UNASSIGNED: + rb_debug ("unassigned unicode character type found"); + /* fall through */ + + default: + /* leave these in */ + g_string_append_unichar (string, *cur); + } + prev = *cur; + } + + g_free (unicode); + g_free (normalized); + + return g_string_free (string, FALSE); +} + + + +gchar* rb_search_fold (const char *original) { GString *string; Index: lib/rb-util.h =================================================================== --- lib/rb-util.h (revision 6240) +++ lib/rb-util.h (working copy) @@ -60,6 +60,7 @@ gboolean rb_is_main_thread (void); gchar* rb_search_fold (const char *original); +gchar* rb_search_fold_titlecase (const char *original); gchar** rb_string_split_words (const gchar *string); gboolean rb_string_list_equal (GList *a, GList *b);
_______________________________________________ rhythmbox-devel mailing list rhythmbox-devel@gnome.org http://mail.gnome.org/mailman/listinfo/rhythmbox-devel