Add a function to calculate the length of a NULL-terminated string array.
authorMatthias Clasen <maclas@gmx.de>
Thu, 9 Sep 2004 04:12:19 +0000 (04:12 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Thu, 9 Sep 2004 04:12:19 +0000 (04:12 +0000)
Thu Sep  9 00:10:40 2004  Matthias Clasen  <maclas@gmx.de>

* glib/gstrfuncs.h:
* glib/gstrfuncs.c (g_strv_length): Add a function to
calculate the length of a NULL-terminated string
array.  (#150455, Tim-Philipp Müller)

* tests/strfunc-test.c (main): Add a test for g_strv_length().

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-6
ChangeLog.pre-2-8
docs/reference/ChangeLog
docs/reference/glib/glib-sections.txt
glib/gstrfuncs.c
glib/gstrfuncs.h
tests/strfunc-test.c

index 1afdcd7..eb0458b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Thu Sep  9 00:10:40 2004  Matthias Clasen  <maclas@gmx.de>
+
+       * glib/gstrfuncs.h: 
+       * glib/gstrfuncs.c (g_strv_length): Add a function to 
+       calculate the length of a NULL-terminated string 
+       array.  (#150455, Tim-Philipp Müller)
+
+       * tests/strfunc-test.c (main): Add a test for g_strv_length().
+
 2004-09-08  Tor Lillqvist  <tml@iki.fi>
 
        * glib/gutils.c (guess_category_value): On Win32, as last resort
index 1afdcd7..eb0458b 100644 (file)
@@ -1,3 +1,12 @@
+Thu Sep  9 00:10:40 2004  Matthias Clasen  <maclas@gmx.de>
+
+       * glib/gstrfuncs.h: 
+       * glib/gstrfuncs.c (g_strv_length): Add a function to 
+       calculate the length of a NULL-terminated string 
+       array.  (#150455, Tim-Philipp Müller)
+
+       * tests/strfunc-test.c (main): Add a test for g_strv_length().
+
 2004-09-08  Tor Lillqvist  <tml@iki.fi>
 
        * glib/gutils.c (guess_category_value): On Win32, as last resort
index 1afdcd7..eb0458b 100644 (file)
@@ -1,3 +1,12 @@
+Thu Sep  9 00:10:40 2004  Matthias Clasen  <maclas@gmx.de>
+
+       * glib/gstrfuncs.h: 
+       * glib/gstrfuncs.c (g_strv_length): Add a function to 
+       calculate the length of a NULL-terminated string 
+       array.  (#150455, Tim-Philipp Müller)
+
+       * tests/strfunc-test.c (main): Add a test for g_strv_length().
+
 2004-09-08  Tor Lillqvist  <tml@iki.fi>
 
        * glib/gutils.c (guess_category_value): On Win32, as last resort
index 1afdcd7..eb0458b 100644 (file)
@@ -1,3 +1,12 @@
+Thu Sep  9 00:10:40 2004  Matthias Clasen  <maclas@gmx.de>
+
+       * glib/gstrfuncs.h: 
+       * glib/gstrfuncs.c (g_strv_length): Add a function to 
+       calculate the length of a NULL-terminated string 
+       array.  (#150455, Tim-Philipp Müller)
+
+       * tests/strfunc-test.c (main): Add a test for g_strv_length().
+
 2004-09-08  Tor Lillqvist  <tml@iki.fi>
 
        * glib/gutils.c (guess_category_value): On Win32, as last resort
index 1afdcd7..eb0458b 100644 (file)
@@ -1,3 +1,12 @@
+Thu Sep  9 00:10:40 2004  Matthias Clasen  <maclas@gmx.de>
+
+       * glib/gstrfuncs.h: 
+       * glib/gstrfuncs.c (g_strv_length): Add a function to 
+       calculate the length of a NULL-terminated string 
+       array.  (#150455, Tim-Philipp Müller)
+
+       * tests/strfunc-test.c (main): Add a test for g_strv_length().
+
 2004-09-08  Tor Lillqvist  <tml@iki.fi>
 
        * glib/gutils.c (guess_category_value): On Win32, as last resort
index 43f7cbd..f66d1be 100644 (file)
@@ -1,3 +1,7 @@
+Thu Sep  9 00:11:19 2004  Matthias Clasen  <maclas@gmx.de>
+
+       * glib/glib-sections.txt: Add g_strv_length().
+
 2004-09-07  Matthias Clasen  <mclasen@redhat.com>
 
        * glib/glib-sections.txt: Add g_get_language_names().
index 89557b7..0b83b81 100644 (file)
@@ -1085,6 +1085,7 @@ g_strfreev
 g_strconcat
 g_strjoin
 g_strjoinv
+g_strv_length
 
 <SUBSECTION>
 g_strerror
index ececffa..f551145 100644 (file)
@@ -2696,3 +2696,28 @@ g_strip_context  (const gchar *msgid,
   
   return msgval;
 }
+
+
+/**
+ * g_strv_length:
+ * @str_array: a %NULL-terminated array of strings.
+ * 
+ * Returns the length of the given %NULL-terminated 
+ * string array @str_array.
+ * 
+ * Return value: length of @str_array.
+ *
+ * Since: 2.6
+ **/
+guint
+g_strv_length (gchar **str_array)
+{
+  guint i = 0;
+
+  g_return_val_if_fail (str_array != NULL, 0);
+
+  while (str_array[i])
+    ++i;
+
+  return i;
+}
index 9281068..c5a7522 100644 (file)
@@ -219,6 +219,7 @@ gpointer              g_memdup             (gconstpointer mem,
  * optional separator, the returned string is newly allocated.
  * g_strfreev() frees the array itself and all of its strings.
  * g_strdupv() copies a NULL-terminated array of strings
+ * g_strv_length() returns the length of a NULL-terminated array of strings
  */
 gchar**                      g_strsplit       (const gchar  *string,
                                        const gchar  *delimiter,
@@ -230,6 +231,7 @@ gchar*                g_strjoinv       (const gchar  *separator,
                                        gchar       **str_array);
 void                  g_strfreev       (gchar       **str_array);
 gchar**               g_strdupv        (gchar       **str_array);
+guint                 g_strv_length    (gchar       **str_array);
 
 gchar*                g_stpcpy         (gchar        *dest,
                                         const char   *src);
index eab248f..09fb1c5 100644 (file)
@@ -551,5 +551,7 @@ main (int   argc,
     TEST (NULL, 9 == g_snprintf (buf, 5, "%s", "abcdefghi"));
   }
 
+  TEST (NULL, g_strv_length (g_strsplit ("1,2,3,4", ",", -1)) == 4);
+
   return any_failed;
 }