Add a function to calculate the length of a NULL-terminated string array.

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().
This commit is contained in:
Matthias Clasen 2004-09-09 04:12:19 +00:00 committed by Matthias Clasen
parent cbadee0812
commit 6ec4724399
10 changed files with 79 additions and 0 deletions

View 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> 2004-09-08 Tor Lillqvist <tml@iki.fi>
* glib/gutils.c (guess_category_value): On Win32, as last resort * glib/gutils.c (guess_category_value): On Win32, as last resort

View 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> 2004-09-08 Tor Lillqvist <tml@iki.fi>
* glib/gutils.c (guess_category_value): On Win32, as last resort * glib/gutils.c (guess_category_value): On Win32, as last resort

View 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> 2004-09-08 Tor Lillqvist <tml@iki.fi>
* glib/gutils.c (guess_category_value): On Win32, as last resort * glib/gutils.c (guess_category_value): On Win32, as last resort

View 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> 2004-09-08 Tor Lillqvist <tml@iki.fi>
* glib/gutils.c (guess_category_value): On Win32, as last resort * glib/gutils.c (guess_category_value): On Win32, as last resort

View 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> 2004-09-08 Tor Lillqvist <tml@iki.fi>
* glib/gutils.c (guess_category_value): On Win32, as last resort * glib/gutils.c (guess_category_value): On Win32, as last resort

View 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> 2004-09-07 Matthias Clasen <mclasen@redhat.com>
* glib/glib-sections.txt: Add g_get_language_names(). * glib/glib-sections.txt: Add g_get_language_names().

View File

@ -1085,6 +1085,7 @@ g_strfreev
g_strconcat g_strconcat
g_strjoin g_strjoin
g_strjoinv g_strjoinv
g_strv_length
<SUBSECTION> <SUBSECTION>
g_strerror g_strerror

View File

@ -2696,3 +2696,28 @@ g_strip_context (const gchar *msgid,
return msgval; 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;
}

View File

@ -219,6 +219,7 @@ gpointer g_memdup (gconstpointer mem,
* optional separator, the returned string is newly allocated. * optional separator, the returned string is newly allocated.
* g_strfreev() frees the array itself and all of its strings. * g_strfreev() frees the array itself and all of its strings.
* g_strdupv() copies a NULL-terminated array of 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, gchar** g_strsplit (const gchar *string,
const gchar *delimiter, const gchar *delimiter,
@ -230,6 +231,7 @@ gchar* g_strjoinv (const gchar *separator,
gchar **str_array); gchar **str_array);
void g_strfreev (gchar **str_array); void g_strfreev (gchar **str_array);
gchar** g_strdupv (gchar **str_array); gchar** g_strdupv (gchar **str_array);
guint g_strv_length (gchar **str_array);
gchar* g_stpcpy (gchar *dest, gchar* g_stpcpy (gchar *dest,
const char *src); const char *src);

View File

@ -551,5 +551,7 @@ main (int argc,
TEST (NULL, 9 == g_snprintf (buf, 5, "%s", "abcdefghi")); 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; return any_failed;
} }