From: Christian Dywan Date: Fri, 2 Oct 2009 19:27:31 +0000 (+0200) Subject: Implement katze_array_find_uri for finding duplicates X-Git-Url: https://spindle.queued.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=41385a9e5ee638777fdb0a23610c4ca9aabef76a;p=midori Implement katze_array_find_uri for finding duplicates --- diff --git a/katze/katze-array.c b/katze/katze-array.c index 5df9291f..93a3f569 100644 --- a/katze/katze-array.c +++ b/katze/katze-array.c @@ -375,13 +375,56 @@ katze_array_find_token (KatzeArray* array, i = 0; while ((item = g_list_nth_data (array->items, i++))) { - const gchar* found_token = katze_item_get_token ((KatzeItem*)item); + const gchar* found_token; + + if (!KATZE_IS_ITEM (item)) + continue; + found_token = ((KatzeItem*)item)->token; if (!g_strcmp0 (found_token, token)) return item; } return NULL; } +/** + * katze_array_find_uri: + * @array: a #KatzeArray + * @uri: an URI + * + * Looks up an item in the array which has the specified URI. + * + * This function will silently fail if the type of the list + * is not based on #GObject and only #KatzeItem children + * are checked for their token, any other objects are skipped. + * + * Return value: an item, or %NULL + * + * Since: 0.2.0 + **/ +gpointer +katze_array_find_uri (KatzeArray* array, + const gchar* uri) +{ + guint i; + gpointer item; + + if (!katze_array_is_a (array, G_TYPE_OBJECT)) + return NULL; + + i = 0; + while ((item = g_list_nth_data (array->items, i++))) + { + const gchar* found_uri; + + if (!KATZE_IS_ITEM (item)) + continue; + found_uri = ((KatzeItem*)item)->uri; + if (!g_strcmp0 (found_uri, uri)) + return item; + } + return NULL; +} + /** * katze_array_get_length: * @array: a #KatzeArray diff --git a/katze/katze-array.h b/katze/katze-array.h index 89bfea9c..af3370d5 100644 --- a/katze/katze-array.h +++ b/katze/katze-array.h @@ -65,6 +65,10 @@ gpointer katze_array_find_token (KatzeArray* array, const gchar* token); +gpointer +katze_array_find_uri (KatzeArray* array, + const gchar* uri); + guint katze_array_get_length (KatzeArray* array);