From: Duncan Mak Date: Mon, 21 Aug 2006 04:15:35 +0000 (-0000) Subject: Implment g_list_insert_before. X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=6621b257cbbb59d40589d1cec3577666fe4b6e9c;p=mono.git Implment g_list_insert_before. svn path=/trunk/mono/; revision=64119 --- diff --git a/eglib/COPYING b/eglib/COPYING index 1f95d26c5ac..1bb5a44356f 100644 --- a/eglib/COPYING +++ b/eglib/COPYING @@ -1,5 +1,17 @@ -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +IN THE SOFTWARE. diff --git a/eglib/src/glist.c b/eglib/src/glist.c index 0fd6c37dba2..cf135231036 100644 --- a/eglib/src/glist.c +++ b/eglib/src/glist.c @@ -276,23 +276,17 @@ g_list_insert_sorted (GList *list, gpointer data, GCompareFunc func) return list; } -/* TODO */ GList* g_list_insert_before (GList *list, GList *sibling, gpointer data) { + if (!list) + return g_list_prepend (NULL, data); + if (!sibling) - return g_list_append (list, g_list_prepend (NULL, data)); - - while (list){ - if (list->next == sibling){ - g_list_prepend (sibling, g_list_prepend (NULL, data)); - break; - } - - list = list->next; - } + return g_list_append (list, data); - return list; + else + return g_list_prepend (sibling, data); } void diff --git a/eglib/test/list.c b/eglib/test/list.c index 1ab8d0ea7b3..7460ec7b53e 100644 --- a/eglib/test/list.c +++ b/eglib/test/list.c @@ -279,6 +279,26 @@ test_list_remove_link () return OK; } +RESULT +test_list_insert_before () +{ + GList *foo, *bar; + + foo = g_list_prepend (NULL, "foo"); + foo = g_list_insert_before (foo, NULL, "bar"); + bar = g_list_last (foo); + + if (strcmp (bar->data, "bar")) + return FAILED ("1"); + + g_list_insert_before (foo, bar, "baz"); + + if (strcmp (g_list_nth (foo, 1)->data, "baz")) + return FAILED ("2"); + + return OK; +} + static Test list_tests [] = { {"list_length", test_list_length}, {"list_nth", test_list_nth}, @@ -287,6 +307,7 @@ static Test list_tests [] = { {"list_append", test_list_append}, {"list_concat", test_list_concat}, {"list_insert_sorted", test_list_insert_sorted}, + {"list_insert_before", test_list_insert_before}, {"list_copy", test_list_copy}, {"list_reverse", test_list_reverse}, {"list_remove", test_list_remove},