Author: dick
Date: 2007-11-21 11:12:05 -0500 (Wed, 21 Nov 2007)
New Revision: 90089
Modified:
trunk/mono/eglib/ChangeLog
trunk/mono/eglib/src/glib.h
trunk/mono/eglib/src/glist.c
trunk/mono/eglib/src/gslist.c
trunk/mono/eglib/test/list.c
trunk/mono/eglib/test/slist.c
Log:
2007-11-21 Dick Porter <[EMAIL PROTECTED]>
* src/gslist.c (g_slist_find_custom): Implement
* src/glist.c (g_list_find_custom): Implement
* test/list.c: Test g_list_find_custom()
* test/slist.c: Test g_slist_find_custom()
Modified: trunk/mono/eglib/ChangeLog
===================================================================
--- trunk/mono/eglib/ChangeLog 2007-11-21 16:11:41 UTC (rev 90088)
+++ trunk/mono/eglib/ChangeLog 2007-11-21 16:12:05 UTC (rev 90089)
@@ -1,3 +1,13 @@
+2007-11-21 Dick Porter <[EMAIL PROTECTED]>
+
+ * src/gslist.c (g_slist_find_custom): Implement
+
+ * src/glist.c (g_list_find_custom): Implement
+
+ * test/list.c: Test g_list_find_custom()
+
+ * test/slist.c: Test g_slist_find_custom()
+
2007-11-20 Dick Porter <[EMAIL PROTECTED]>
* src/gstr.c: Implement g_strsplit_set() and re-implement
Modified: trunk/mono/eglib/src/glib.h
===================================================================
--- trunk/mono/eglib/src/glib.h 2007-11-21 16:11:41 UTC (rev 90088)
+++ trunk/mono/eglib/src/glib.h 2007-11-21 16:12:05 UTC (rev 90089)
@@ -315,6 +315,9 @@
GSList *g_slist_last (GSList *list);
GSList *g_slist_find (GSList *list,
gconstpointer data);
+GSList *g_slist_find_custom (GSList *list,
+ gconstpointer data,
+ GCompareFunc func);
GSList *g_slist_remove (GSList *list,
gconstpointer data);
GSList *g_slist_remove_all (GSList *list,
@@ -376,6 +379,9 @@
GList *g_list_first (GList *list);
GList *g_list_find (GList *list,
gconstpointer data);
+GList *g_list_find_custom (GList *list,
+ gconstpointer data,
+ GCompareFunc func);
GList *g_list_remove (GList *list,
gconstpointer data);
GList *g_list_reverse (GList *list);
Modified: trunk/mono/eglib/src/glist.c
===================================================================
--- trunk/mono/eglib/src/glist.c 2007-11-21 16:11:41 UTC (rev 90088)
+++ trunk/mono/eglib/src/glist.c 2007-11-21 16:12:05 UTC (rev 90089)
@@ -161,6 +161,22 @@
}
GList*
+g_list_find_custom (GList *list, gconstpointer data, GCompareFunc func)
+{
+ if (!func)
+ return NULL;
+
+ while (list) {
+ if (func (list->data, data) == 0)
+ return list;
+
+ list = list->next;
+ }
+
+ return NULL;
+}
+
+GList*
g_list_reverse (GList *list)
{
GList *reverse = NULL;
Modified: trunk/mono/eglib/src/gslist.c
===================================================================
--- trunk/mono/eglib/src/gslist.c 2007-11-21 16:11:41 UTC (rev 90088)
+++ trunk/mono/eglib/src/gslist.c 2007-11-21 16:12:05 UTC (rev 90089)
@@ -181,6 +181,22 @@
return list;
}
+GSList *
+g_slist_find_custom (GSList *list, gconstpointer data, GCompareFunc func)
+{
+ if (!func)
+ return NULL;
+
+ while (list) {
+ if (func (list->data, data) == 0)
+ return list;
+
+ list = list->next;
+ }
+
+ return NULL;
+}
+
guint
g_slist_length (GSList *list)
{
Modified: trunk/mono/eglib/test/list.c
===================================================================
--- trunk/mono/eglib/test/list.c 2007-11-21 16:11:41 UTC (rev 90088)
+++ trunk/mono/eglib/test/list.c 2007-11-21 16:12:05 UTC (rev 90089)
@@ -388,6 +388,34 @@
return OK;
}
+static gint
+find_custom (gconstpointer a, gconstpointer b)
+{
+ return(strcmp (a, b));
+}
+
+RESULT
+test_list_find_custom ()
+{
+ GList *list = NULL, *found;
+ char *foo = "foo";
+ char *bar = "bar";
+ char *baz = "baz";
+
+ list = g_list_prepend (list, baz);
+ list = g_list_prepend (list, bar);
+ list = g_list_prepend (list, foo);
+
+ found = g_list_find_custom (list, baz, find_custom);
+
+ if (found == NULL)
+ return FAILED ("Find failed");
+
+ g_list_free (list);
+
+ return OK;
+}
+
static Test list_tests [] = {
{ "length", test_list_length},
{ "nth", test_list_nth},
@@ -403,6 +431,7 @@
{ "remove_link", test_list_remove_link},
{ "remove_link", test_list_remove_link},
{ "sort", test_list_sort},
+ { "find_custom", test_list_find_custom},
{NULL, NULL}
};
Modified: trunk/mono/eglib/test/slist.c
===================================================================
--- trunk/mono/eglib/test/slist.c 2007-11-21 16:11:41 UTC (rev 90088)
+++ trunk/mono/eglib/test/slist.c 2007-11-21 16:12:05 UTC (rev 90089)
@@ -119,7 +119,35 @@
return OK;
}
+static gint
+find_custom (gconstpointer a, gconstpointer b)
+{
+ return(strcmp (a, b));
+}
+
RESULT
+test_slist_find_custom ()
+{
+ GSList *list = NULL, *found;
+ char *foo = "foo";
+ char *bar = "bar";
+ char *baz = "baz";
+
+ list = g_slist_prepend (list, baz);
+ list = g_slist_prepend (list, bar);
+ list = g_slist_prepend (list, foo);
+
+ found = g_slist_find_custom (list, baz, find_custom);
+
+ if (found == NULL)
+ return FAILED ("Find failed");
+
+ g_slist_free (list);
+
+ return OK;
+}
+
+RESULT
test_slist_remove ()
{
GSList *list = g_slist_prepend (NULL, "three");
@@ -304,6 +332,7 @@
{"append", test_slist_append},
{"concat", test_slist_concat},
{"find", test_slist_find},
+ {"find_custom", test_slist_find_custom},
{"remove", test_slist_remove},
{"remove_link", test_slist_remove_link},
{"insert_sorted", test_slist_insert_sorted},
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches