aboutsummaryrefslogtreecommitdiffstats
path: root/e-util
diff options
context:
space:
mode:
Diffstat (limited to 'e-util')
-rw-r--r--e-util/ChangeLog5
-rw-r--r--e-util/e-util.c54
-rw-r--r--e-util/e-util.c-861154
-rw-r--r--e-util/e-util.h4
-rw-r--r--e-util/e-util.h-290024
5 files changed, 121 insertions, 0 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog
index 4a19bb7207..582155a13f 100644
--- a/e-util/ChangeLog
+++ b/e-util/ChangeLog
@@ -1,5 +1,10 @@
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.
+
+2000-07-07 Christopher James Lahey <clahey@helixcode.com>
+
* e-iterator.c, e-iterator.h, e-list-iterator.c,
e-list-iterator.h: Added last and insert functions.
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 <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;
+}
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;
+}
diff --git a/e-util/e-util.h b/e-util/e-util.h
index 3df503f2d9..ab5325806b 100644
--- a/e-util/e-util.h
+++ b/e-util/e-util.h
@@ -42,6 +42,10 @@ void e_free_string_list (GList *list);
char *e_read_file (const char *filename);
gint e_write_file(const char *filename, const char *data, int flags);
+gchar **e_strsplit (const gchar *string,
+ const gchar *delimiter,
+ gint max_tokens);
+
void e_marshal_INT__INT_INT_POINTER (GtkObject * object,
GtkSignalFunc func,
gpointer func_data, GtkArg * args);
diff --git a/e-util/e-util.h-29002 b/e-util/e-util.h-29002
index 3df503f2d9..ab5325806b 100644
--- a/e-util/e-util.h-29002
+++ b/e-util/e-util.h-29002
@@ -42,6 +42,10 @@ void e_free_string_list (GList *list);
char *e_read_file (const char *filename);
gint e_write_file(const char *filename, const char *data, int flags);
+gchar **e_strsplit (const gchar *string,
+ const gchar *delimiter,
+ gint max_tokens);
+
void e_marshal_INT__INT_INT_POINTER (GtkObject * object,
GtkSignalFunc func,
gpointer func_data, GtkArg * args);