From 69b2e6d8eee098cf070e9797dd9d9bfde933d21f Mon Sep 17 00:00:00 2001 From: Christopher James Lahey Date: Thu, 11 Oct 2001 16:17:41 +0000 Subject: Use e_strdup_append_strings here instead of g_strdup_printf because 2001-10-11 Christopher James Lahey * gal/e-text/e-table-text-model.c (e_table_text_model_insert, e_table_text_model_insert_length, e_table_text_model_delete), gal/e-text/e-text-model.c (e_text_model_real_insert, e_text_model_real_insert_length): Use e_strdup_append_strings here instead of g_strdup_printf because printf("%.*s") is locale dependent on some systems. * gal/util/e-util.c (e_strdup_append_strings): New function to append a bunch of strings with optional lengths. svn path=/trunk/; revision=13581 --- e-util/e-util.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ e-util/e-util.h | 4 ++++ 2 files changed, 57 insertions(+) (limited to 'e-util') diff --git a/e-util/e-util.c b/e-util/e-util.c index 345fd39bf4..b8fab82b25 100644 --- a/e-util/e-util.c +++ b/e-util/e-util.c @@ -1402,3 +1402,56 @@ e_ascii_dtostr (gchar *buffer, return buffer; } + +gchar * +e_strdup_append_strings (gchar *first_string, ...) +{ + gchar *buffer; + gchar *current; + gint length; + va_list args1; + va_list args2; + char *v_string; + int v_int; + + va_start (args1, first_string); + G_VA_COPY (args2, args1); + + length = 0; + + v_string = first_string; + while (v_string) { + v_int = va_arg (args1, int); + if (v_int >= 0) + length += v_int; + else + length += strlen (v_string); + v_string = va_arg (args1, char *); + } + + buffer = g_new (char, length + 1); + current = buffer; + + v_string = first_string; + while (v_string) { + v_int = va_arg (args2, int); + if (v_int < 0) { + int i; + for (i = 0; v_string[i]; i++) { + *(current++) = v_string[i]; + } + } else { + int i; + for (i = 0; v_string[i] && i < v_int; i++) { + *(current++) = v_string[i]; + } + } + v_string = va_arg (args2, char *); + } + *(current++) = 0; + + va_end (args1); + va_end (args2); + + return buffer; +} diff --git a/e-util/e-util.h b/e-util/e-util.h index e9eb07ffa8..f7b2bf7a3c 100644 --- a/e-util/e-util.h +++ b/e-util/e-util.h @@ -129,6 +129,10 @@ gchar *e_ascii_dtostr (gcha const gchar *format, gdouble d); +/* Alternating char * and int arguments with a NULL char * to end. + Less than 0 for the int means copy the whole string. */ +gchar *e_strdup_append_strings (gchar *first_string, + ...); /* Marshallers */ void e_marshal_INT__INT_INT_POINTER (GtkObject *object, -- cgit v1.2.3