Commit a0d3a674 authored by Elliot Lee's avatar Elliot Lee
Browse files

Added g_s?list_find_custom functions to allow user to specify a



Added g_s?list_find_custom functions to allow user to specify a
GCompareFunc to determine whether a node matches or not.

If you have a better idea for naming the functions, please, make it so! :)
parent 8725269e
......@@ -531,6 +531,9 @@ GList* g_list_nth (GList *list,
guint n);
GList* g_list_find (GList *list,
gpointer data);
GList *g_list_find_custom (GList *list,
gpointer data,
GCompareFunc func);
gint g_list_position (GList *list,
GList *link);
gint g_list_index (GList *list,
......@@ -574,6 +577,9 @@ GSList* g_slist_nth (GSList *list,
guint n);
GSList* g_slist_find (GSList *list,
gpointer data);
GSList *g_slist_find_custom (GSList *list,
gpointer data,
GCompareFunc func);
gint g_slist_position (GSList *list,
GSList *link);
gint g_slist_index (GSList *list,
......
......@@ -324,6 +324,21 @@ g_list_find (GList *list,
return list;
}
GList *
g_list_find_custom(GList *list, gpointer data, GCompareFunc func)
{
if(!func) return g_list_find(list, data);
while (list)
{
if ( !((*func)(list->data, data)) ) break;
list = list->next;
}
return list;
}
gint
g_list_position (GList *list,
GList *link)
......
......@@ -313,6 +313,20 @@ g_slist_find (GSList *list,
return list;
}
GSList *
g_slist_find_custom(GSList *list, gpointer data, GCompareFunc func)
{
if(!func) return g_slist_find(list, data);
while (list)
{
if ( !((*func)(list->data, data)) ) break;
list = list->next;
}
return list;
}
gint
g_slist_position (GSList *list,
GSList *link)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment