aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--e-util/e-util.c53
-rw-r--r--e-util/e-util.h4
-rw-r--r--widgets/text/e-table-text-model.c21
-rw-r--r--widgets/text/e-text-model.c14
4 files changed, 87 insertions, 5 deletions
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,
diff --git a/widgets/text/e-table-text-model.c b/widgets/text/e-table-text-model.c
index daf0456110..f7b7dc1400 100644
--- a/widgets/text/e-table-text-model.c
+++ b/widgets/text/e-table-text-model.c
@@ -19,6 +19,7 @@
#include <config.h>
#include <ctype.h>
#include <gtk/gtksignal.h>
+#include <gal/util/e-util.h>
#include "e-table-text-model.h"
static void e_table_text_model_class_init (ETableTextModelClass *class);
@@ -151,7 +152,12 @@ e_table_text_model_insert (ETextModel *text_model, gint position, const gchar *t
ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model);
if (model->model){
gchar *temp = (gchar *)e_table_model_value_at (model->model, model->model_col, model->row);
- temp = g_strdup_printf ("%.*s%s%s", position, temp, text, temp + position);
+ /* Can't use g_strdup_printf here because on some
+ systems printf ("%.*s"); is locale dependent. */
+ temp = e_strdup_append_strings (temp, position,
+ text, -1,
+ temp + position, -1,
+ NULL);
e_table_model_set_value_at (model->model, model->model_col, model->row, temp);
g_free (temp);
}
@@ -163,7 +169,12 @@ e_table_text_model_insert_length (ETextModel *text_model, gint position, const g
ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model);
if (model->model){
gchar *temp = (gchar *)e_table_model_value_at (model->model, model->model_col, model->row);
- temp = g_strdup_printf ("%.*s%.*s%s", position, temp, length, text, temp + position);
+ /* Can't use g_strdup_printf here because on some
+ systems printf ("%.*s"); is locale dependent. */
+ temp = e_strdup_append_strings (temp, position,
+ text, length,
+ temp + position, -1,
+ NULL);
e_table_model_set_value_at (model->model, model->model_col, model->row, temp);
g_free (temp);
}
@@ -175,7 +186,11 @@ e_table_text_model_delete (ETextModel *text_model, gint position, gint length)
ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model);
if (model->model){
gchar *temp = (gchar *)e_table_model_value_at (model->model, model->model_col, model->row);
- temp = g_strdup_printf ("%.*s%s", position, temp, temp + position + length);
+ /* Can't use g_strdup_printf here because on some
+ systems printf ("%.*s"); is locale dependent. */
+ temp = e_strdup_append_strings (temp, position,
+ temp + position + length, -1,
+ NULL);
e_table_model_set_value_at (model->model, model->model_col, model->row, temp);
g_free (temp);
}
diff --git a/widgets/text/e-text-model.c b/widgets/text/e-text-model.c
index 97eb2a9a86..929247ed4e 100644
--- a/widgets/text/e-text-model.c
+++ b/widgets/text/e-text-model.c
@@ -268,7 +268,12 @@ e_text_model_real_insert (ETextModel *model, gint position, const gchar *text)
if (length <= 0)
return;
- new_text = g_strdup_printf ("%.*s%.*s%s", position, model->priv->text, length, text, model->priv->text + position);
+ /* Can't use g_strdup_printf here because on some systems
+ printf ("%.*s"); is locale dependent. */
+ new_text = e_strdup_append_strings (model->priv->text, position,
+ text, length,
+ model->priv->text + position, -1,
+ NULL);
if (model->priv->text)
g_free (model->priv->text);
@@ -301,7 +306,12 @@ e_text_model_real_insert_length (ETextModel *model, gint position, const gchar *
if (length <= 0)
return;
- new_text = g_strdup_printf ("%.*s%.*s%s", position, model->priv->text, length, text, model->priv->text + position);
+ /* Can't use g_strdup_printf here because on some systems
+ printf ("%.*s"); is locale dependent. */
+ new_text = e_strdup_append_strings (model->priv->text, position,
+ text, length,
+ model->priv->text + position, -1,
+ NULL);
if (model->priv->text)
g_free (model->priv->text);