Fix for g_strsplit when passed 1
- From: Darin Adler <darin bentspoon com>
- To: Owen Taylor <otaylor redhat com>
- Cc: Gtk Developers <gtk-devel-list gnome org>
- Subject: Fix for g_strsplit when passed 1
- Date: Wed, 07 Nov 2001 08:32:08 -0800
g_strsplit was treating a value of 1 the same as a value of 0, but 1 should
mean "put it all in a single string" as the documentation says.
OK to commit?
Index: glib/gstrfuncs.c
===================================================================
RCS file: /cvs/gnome/glib/glib/gstrfuncs.c,v
retrieving revision 1.77
diff -p -u -r1.77 gstrfuncs.c
--- glib/gstrfuncs.c 2001/10/24 18:00:10 1.77
+++ glib/gstrfuncs.c 2001/11/07 16:27:30
@@ -1888,8 +1888,6 @@ g_strsplit (const gchar *string,
if (max_tokens < 1)
max_tokens = G_MAXINT;
- else
- --max_tokens;
remainder = string;
s = strstr (remainder, delimiter);
@@ -1897,7 +1895,7 @@ g_strsplit (const gchar *string,
{
gsize delimiter_len = strlen (delimiter);
- do
+ while (--max_tokens && s)
{
gsize len;
gchar *new_string;
@@ -1911,7 +1909,6 @@ g_strsplit (const gchar *string,
remainder = s + delimiter_len;
s = strstr (remainder, delimiter);
}
- while (--max_tokens && s);
}
if (*string)
{
Index: tests/strfunc-test.c
===================================================================
RCS file: /cvs/gnome/glib/tests/strfunc-test.c,v
retrieving revision 1.14
diff -p -u -r1.14 strfunc-test.c
--- tests/strfunc-test.c 2001/09/17 15:27:04 1.14
+++ tests/strfunc-test.c 2001/11/07 16:27:30
@@ -284,6 +284,19 @@ main (int argc,
TEST (NULL, strv_check (g_strsplit (",,x,,y,,z,,", ",", 0), "", "", "x",
"", "y", "", "z", "", "", NULL));
TEST (NULL, strv_check (g_strsplit (",,x,,y,,z,,", ",,", 0), "", "x",
"y", "z", "", NULL));
+ TEST (NULL, strv_check (g_strsplit ("", ",", 1), NULL));
+ TEST (NULL, strv_check (g_strsplit ("x", ",", 1), "x", NULL));
+ TEST (NULL, strv_check (g_strsplit ("x,y", ",", 1), "x,y", NULL));
+ TEST (NULL, strv_check (g_strsplit ("x,y,", ",", 1), "x,y,", NULL));
+ TEST (NULL, strv_check (g_strsplit (",x,y", ",", 1), ",x,y", NULL));
+ TEST (NULL, strv_check (g_strsplit (",x,y,", ",", 1), ",x,y,", NULL));
+ TEST (NULL, strv_check (g_strsplit ("x,y,z", ",", 1), "x,y,z", NULL));
+ TEST (NULL, strv_check (g_strsplit ("x,y,z,", ",", 1), "x,y,z,", NULL));
+ TEST (NULL, strv_check (g_strsplit (",x,y,z", ",", 1), ",x,y,z", NULL));
+ TEST (NULL, strv_check (g_strsplit (",x,y,z,", ",", 1), ",x,y,z,",
NULL));
+ TEST (NULL, strv_check (g_strsplit (",,x,,y,,z,,", ",", 1),
",,x,,y,,z,,", NULL));
+ TEST (NULL, strv_check (g_strsplit (",,x,,y,,z,,", ",,", 1),
",,x,,y,,z,,", NULL));
+
TEST (NULL, strv_check (g_strsplit ("", ",", 2), NULL));
TEST (NULL, strv_check (g_strsplit ("x", ",", 2), "x", NULL));
TEST (NULL, strv_check (g_strsplit ("x,y", ",", 2), "x", "y", NULL));
===================================================================
-- Darin
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]