From fc43959180e0ab748ba68fa4834e6913f2aba74e Mon Sep 17 00:00:00 2001 From: Christopher James Lahey Date: Fri, 7 Jul 2000 18:29:26 +0000 Subject: Added e_strsplit to work around a bug in g_strsplit. 2000-07-07 Christopher James Lahey * e-util.c, e-util.h: Added e_strsplit to work around a bug in g_strsplit. svn path=/trunk/; revision=3953 --- e-util/e-util.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'e-util/e-util.c') diff --git a/e-util/e-util.c b/e-util/e-util.c index 6cb261410d..3dea9282c3 100644 --- a/e-util/e-util.c +++ b/e-util/e-util.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "e-util.h" @@ -251,3 +252,56 @@ e_marshal_BOOL__OBJECT_DOUBLE_DOUBLE_BOOL (GtkObject * object, GTK_VALUE_BOOL (args[3]), func_data); } + +gchar** +e_strsplit (const gchar *string, + const gchar *delimiter, + gint max_tokens) +{ + GSList *string_list = NULL, *slist; + gchar **str_array, *s; + guint i, n = 1; + + g_return_val_if_fail (string != NULL, NULL); + g_return_val_if_fail (delimiter != NULL, NULL); + + if (max_tokens < 1) + max_tokens = G_MAXINT; + + s = strstr (string, delimiter); + if (s) + { + guint delimiter_len = strlen (delimiter); + + do + { + guint len; + gchar *new_string; + + len = s - string; + new_string = g_new (gchar, len + 1); + strncpy (new_string, string, len); + new_string[len] = 0; + string_list = g_slist_prepend (string_list, new_string); + n++; + string = s + delimiter_len; + s = strstr (string, delimiter); + } + while (--max_tokens && s); + } + + n++; + string_list = g_slist_prepend (string_list, g_strdup (string)); + + str_array = g_new (gchar*, n); + + i = n - 1; + + str_array[i--] = NULL; + for (slist = string_list; slist; slist = slist->next) + str_array[i--] = slist->data; + + g_slist_free (string_list); + + return str_array; +} -- cgit