mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-25 13:11:13 +00:00
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! :)
This commit is contained in:
parent
8725269e0d
commit
a0d3a674d0
@ -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,
|
||||
|
15
glib/glist.c
15
glib/glist.c
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user