Author: duncan
Date: 2006-08-21 00:15:35 -0400 (Mon, 21 Aug 2006)
New Revision: 64119

Modified:
   trunk/mono/eglib/COPYING
   trunk/mono/eglib/src/glist.c
   trunk/mono/eglib/test/list.c
Log:
Implment g_list_insert_before.


Modified: trunk/mono/eglib/COPYING
===================================================================
--- trunk/mono/eglib/COPYING    2006-08-21 00:00:00 UTC (rev 64118)
+++ trunk/mono/eglib/COPYING    2006-08-21 04:15:35 UTC (rev 64119)
@@ -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.

Modified: trunk/mono/eglib/src/glist.c
===================================================================
--- trunk/mono/eglib/src/glist.c        2006-08-21 00:00:00 UTC (rev 64118)
+++ trunk/mono/eglib/src/glist.c        2006-08-21 04:15:35 UTC (rev 64119)
@@ -276,23 +276,17 @@
        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

Modified: trunk/mono/eglib/test/list.c
===================================================================
--- trunk/mono/eglib/test/list.c        2006-08-21 00:00:00 UTC (rev 64118)
+++ trunk/mono/eglib/test/list.c        2006-08-21 04:15:35 UTC (rev 64119)
@@ -279,6 +279,26 @@
        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 @@
        {"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},

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to