Fix max_tokens == 1 case to match documentation. Add tests.
authorDarin Adler <darin@src.gnome.org>
Tue, 13 Nov 2001 00:02:30 +0000 (00:02 +0000)
committerDarin Adler <darin@src.gnome.org>
Tue, 13 Nov 2001 00:02:30 +0000 (00:02 +0000)
* glib/gstrfuncs.c: (g_strsplit): Fix max_tokens == 1 case to
match documentation.
* tests/strfunc-test.c: (main): Add tests.

* tests/.cvsignore: Recently-added test.

ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
glib/gstrfuncs.c
tests/.cvsignore
tests/strfunc-test.c

index d239df3..f2bdada 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2001-11-12  Darin Adler  <darin@bentspoon.com>
+
+       * glib/gstrfuncs.c: (g_strsplit): Fix max_tokens == 1 case to
+       match documentation.
+       * tests/strfunc-test.c: (main): Add tests.
+
+       * tests/.cvsignore: Recently-added test.
+
 Mon Nov 12 03:01:28 2001  Tim Janik  <timj@gtk.org>
 
        * glib/gscanner.c (g_scanner_eof): G_TOKEN_ERROR is also an end
index d239df3..f2bdada 100644 (file)
@@ -1,3 +1,11 @@
+2001-11-12  Darin Adler  <darin@bentspoon.com>
+
+       * glib/gstrfuncs.c: (g_strsplit): Fix max_tokens == 1 case to
+       match documentation.
+       * tests/strfunc-test.c: (main): Add tests.
+
+       * tests/.cvsignore: Recently-added test.
+
 Mon Nov 12 03:01:28 2001  Tim Janik  <timj@gtk.org>
 
        * glib/gscanner.c (g_scanner_eof): G_TOKEN_ERROR is also an end
index d239df3..f2bdada 100644 (file)
@@ -1,3 +1,11 @@
+2001-11-12  Darin Adler  <darin@bentspoon.com>
+
+       * glib/gstrfuncs.c: (g_strsplit): Fix max_tokens == 1 case to
+       match documentation.
+       * tests/strfunc-test.c: (main): Add tests.
+
+       * tests/.cvsignore: Recently-added test.
+
 Mon Nov 12 03:01:28 2001  Tim Janik  <timj@gtk.org>
 
        * glib/gscanner.c (g_scanner_eof): G_TOKEN_ERROR is also an end
index d239df3..f2bdada 100644 (file)
@@ -1,3 +1,11 @@
+2001-11-12  Darin Adler  <darin@bentspoon.com>
+
+       * glib/gstrfuncs.c: (g_strsplit): Fix max_tokens == 1 case to
+       match documentation.
+       * tests/strfunc-test.c: (main): Add tests.
+
+       * tests/.cvsignore: Recently-added test.
+
 Mon Nov 12 03:01:28 2001  Tim Janik  <timj@gtk.org>
 
        * glib/gscanner.c (g_scanner_eof): G_TOKEN_ERROR is also an end
index d239df3..f2bdada 100644 (file)
@@ -1,3 +1,11 @@
+2001-11-12  Darin Adler  <darin@bentspoon.com>
+
+       * glib/gstrfuncs.c: (g_strsplit): Fix max_tokens == 1 case to
+       match documentation.
+       * tests/strfunc-test.c: (main): Add tests.
+
+       * tests/.cvsignore: Recently-added test.
+
 Mon Nov 12 03:01:28 2001  Tim Janik  <timj@gtk.org>
 
        * glib/gscanner.c (g_scanner_eof): G_TOKEN_ERROR is also an end
index d239df3..f2bdada 100644 (file)
@@ -1,3 +1,11 @@
+2001-11-12  Darin Adler  <darin@bentspoon.com>
+
+       * glib/gstrfuncs.c: (g_strsplit): Fix max_tokens == 1 case to
+       match documentation.
+       * tests/strfunc-test.c: (main): Add tests.
+
+       * tests/.cvsignore: Recently-added test.
+
 Mon Nov 12 03:01:28 2001  Tim Janik  <timj@gtk.org>
 
        * glib/gscanner.c (g_scanner_eof): G_TOKEN_ERROR is also an end
index d239df3..f2bdada 100644 (file)
@@ -1,3 +1,11 @@
+2001-11-12  Darin Adler  <darin@bentspoon.com>
+
+       * glib/gstrfuncs.c: (g_strsplit): Fix max_tokens == 1 case to
+       match documentation.
+       * tests/strfunc-test.c: (main): Add tests.
+
+       * tests/.cvsignore: Recently-added test.
+
 Mon Nov 12 03:01:28 2001  Tim Janik  <timj@gtk.org>
 
        * glib/gscanner.c (g_scanner_eof): G_TOKEN_ERROR is also an end
index d239df3..f2bdada 100644 (file)
@@ -1,3 +1,11 @@
+2001-11-12  Darin Adler  <darin@bentspoon.com>
+
+       * glib/gstrfuncs.c: (g_strsplit): Fix max_tokens == 1 case to
+       match documentation.
+       * tests/strfunc-test.c: (main): Add tests.
+
+       * tests/.cvsignore: Recently-added test.
+
 Mon Nov 12 03:01:28 2001  Tim Janik  <timj@gtk.org>
 
        * glib/gscanner.c (g_scanner_eof): G_TOKEN_ERROR is also an end
index e53f59d..704d14a 100644 (file)
@@ -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 37cd77c..5c95c79 100644 (file)
@@ -35,6 +35,7 @@ stamp-gc-h
 stamp-h
 strfunc-test
 string-test
+strtod-test
 thread-test
 threadpool-test
 timeloop-closure
index 5e361b9..0c7b5c2 100644 (file)
@@ -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));