Re: Bug#15026: g_strsplit inconsistency



Hi Dan,

> g_strsplit behaves inconsistently with empty strings:
> 
>         g_strsplit (":x:x", ":", 0) -> "", "x", "x", NULL
> 
>         g_strsplit ("x::x", ":", 0) -> "x", "", "x", NULL
> 
>         g_strsplit ("x:x:", ":", 0) -> "x", "x", NULL
> 
> (I think this is a bug, but if you disagree, I think it should at
> least be documented.)

I tend to agree, that this is a bug. Unless noone objects, I'm going to commit
the attached patch, that solves that.

Bye,
Sebastian
-- 
Sebastian Wilhelmi                   |            här ovanför alla molnen
mailto:wilhelmi ira uka de           |     är himmlen så förunderligt blå
http://goethe.ira.uka.de/~wilhelmi   |
Index: gstrfuncs.c
===================================================================
RCS file: /cvs/gnome/glib/gstrfuncs.c,v
retrieving revision 1.45
diff -u -b -B -r1.45 gstrfuncs.c
--- gstrfuncs.c	2000/09/29 13:37:01	1.45
+++ gstrfuncs.c	2000/10/26 12:37:18
@@ -1487,7 +1487,7 @@
 {
   GSList *string_list = NULL, *slist;
   gchar **str_array, *s;
-  guint i, n = 1;
+  guint n = 1;
 
   g_return_val_if_fail (string != NULL, NULL);
   g_return_val_if_fail (delimiter != NULL, NULL);
@@ -1516,19 +1516,13 @@
 	}
       while (--max_tokens && s);
     }
-  if (*string)
-    {
-      n++;
       string_list = g_slist_prepend (string_list, g_strdup (string));
-    }
-
-  str_array = g_new (gchar*, n);
 
-  i = n - 1;
+  str_array = g_new (gchar*, n + 1);
 
-  str_array[i--] = NULL;
+  str_array[n--] = NULL;
   for (slist = string_list; slist; slist = slist->next)
-    str_array[i--] = slist->data;
+    str_array[n--] = slist->data;
 
   g_slist_free (string_list);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]