Use gstring to build suggestions script in formhistory

This commit is contained in:
Alexander Butenko 2011-12-09 21:29:16 +01:00 committed by Christian Dywan
parent a57850e533
commit b41367b735

View file

@ -101,27 +101,22 @@ formhistory_fixup_value (char* value)
static gchar* static gchar*
formhistory_build_js () formhistory_build_js ()
{ {
gchar* suggestions = g_strdup (""); GString* suggestions;
GHashTableIter iter; GHashTableIter iter;
gpointer key, value; gpointer key, value;
gchar* script;
suggestions = g_string_new (
"function FormSuggestions(eid) { "
"arr = new Array();");
g_hash_table_iter_init (&iter, global_keys); g_hash_table_iter_init (&iter, global_keys);
while (g_hash_table_iter_next (&iter, &key, &value)) while (g_hash_table_iter_next (&iter, &key, &value))
{ {
gchar* _suggestions = g_strdup_printf ("%s arr[\"%s\"] = [%s]; ", g_string_append_printf (suggestions, " arr[\"%s\"] = [%s]; ",
suggestions, (char*)key, (char*)value); (gchar*)key, (gchar*)value);
katze_assign (suggestions, _suggestions);
} }
script = g_strdup_printf ("function FormSuggestions(eid) { " g_string_append (suggestions, "this.suggestions = arr[eid]; }");
"arr = new Array();" g_string_append (suggestions, jsforms);
"%s" return g_string_free (suggestions, FALSE);
"this.suggestions = arr[eid]; }"
"%s",
suggestions,
jsforms);
g_free (suggestions);
return script;
} }
static void static void