diff options
author | Christopher James Lahey <clahey@helixcode.com> | 2000-07-08 02:29:26 +0800 |
---|---|---|
committer | Chris Lahey <clahey@src.gnome.org> | 2000-07-08 02:29:26 +0800 |
commit | fc43959180e0ab748ba68fa4834e6913f2aba74e (patch) | |
tree | d3656b3e13170a0c86008a4d690227dbc47054ef /e-util/e-util.c-8611 | |
parent | 7eaa10884a75068e6e6032455363f57f79718f00 (diff) | |
download | gsoc2013-evolution-fc43959180e0ab748ba68fa4834e6913f2aba74e.tar gsoc2013-evolution-fc43959180e0ab748ba68fa4834e6913f2aba74e.tar.gz gsoc2013-evolution-fc43959180e0ab748ba68fa4834e6913f2aba74e.tar.bz2 gsoc2013-evolution-fc43959180e0ab748ba68fa4834e6913f2aba74e.tar.lz gsoc2013-evolution-fc43959180e0ab748ba68fa4834e6913f2aba74e.tar.xz gsoc2013-evolution-fc43959180e0ab748ba68fa4834e6913f2aba74e.tar.zst gsoc2013-evolution-fc43959180e0ab748ba68fa4834e6913f2aba74e.zip |
Added e_strsplit to work around a bug in g_strsplit.
2000-07-07 Christopher James Lahey <clahey@helixcode.com>
* e-util.c, e-util.h: Added e_strsplit to work around a bug in
g_strsplit.
svn path=/trunk/; revision=3953
Diffstat (limited to 'e-util/e-util.c-8611')
-rw-r--r-- | e-util/e-util.c-8611 | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/e-util/e-util.c-8611 b/e-util/e-util.c-8611 index 6cb261410d..3dea9282c3 100644 --- a/e-util/e-util.c-8611 +++ b/e-util/e-util.c-8611 @@ -26,6 +26,7 @@ #include <fcntl.h> #include <unistd.h> #include <ctype.h> +#include <string.h> #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; +} |