From b41367b7357898923a9dbcc4166af2c67a0a4057 Mon Sep 17 00:00:00 2001 From: Alexander Butenko Date: Fri, 9 Dec 2011 21:29:16 +0100 Subject: [PATCH] Use gstring to build suggestions script in formhistory --- extensions/formhistory.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/extensions/formhistory.c b/extensions/formhistory.c index d7a0c6e9..00e9ea72 100644 --- a/extensions/formhistory.c +++ b/extensions/formhistory.c @@ -101,27 +101,22 @@ formhistory_fixup_value (char* value) static gchar* formhistory_build_js () { - gchar* suggestions = g_strdup (""); + GString* suggestions; GHashTableIter iter; gpointer key, value; - gchar* script; + suggestions = g_string_new ( + "function FormSuggestions(eid) { " + "arr = new Array();"); g_hash_table_iter_init (&iter, global_keys); while (g_hash_table_iter_next (&iter, &key, &value)) { - gchar* _suggestions = g_strdup_printf ("%s arr[\"%s\"] = [%s]; ", - suggestions, (char*)key, (char*)value); - katze_assign (suggestions, _suggestions); + g_string_append_printf (suggestions, " arr[\"%s\"] = [%s]; ", + (gchar*)key, (gchar*)value); } - script = g_strdup_printf ("function FormSuggestions(eid) { " - "arr = new Array();" - "%s" - "this.suggestions = arr[eid]; }" - "%s", - suggestions, - jsforms); - g_free (suggestions); - return script; + g_string_append (suggestions, "this.suggestions = arr[eid]; }"); + g_string_append (suggestions, jsforms); + return g_string_free (suggestions, FALSE); } static void -- 2.39.5