Implement katze_array_find_uri for finding duplicates

This commit is contained in:
Christian Dywan 2009-10-02 21:27:31 +02:00
parent a6ee2320e8
commit 41385a9e5e
2 changed files with 48 additions and 1 deletions

View file

@ -375,13 +375,56 @@ katze_array_find_token (KatzeArray* array,
i = 0; i = 0;
while ((item = g_list_nth_data (array->items, i++))) 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)) if (!g_strcmp0 (found_token, token))
return item; return item;
} }
return NULL; 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: * katze_array_get_length:
* @array: a #KatzeArray * @array: a #KatzeArray

View file

@ -65,6 +65,10 @@ gpointer
katze_array_find_token (KatzeArray* array, katze_array_find_token (KatzeArray* array,
const gchar* token); const gchar* token);
gpointer
katze_array_find_uri (KatzeArray* array,
const gchar* uri);
guint guint
katze_array_get_length (KatzeArray* array); katze_array_get_length (KatzeArray* array);