]> spindle.queued.net Git - midori/commitdiff
Add sokoke_replace_variables
authorChristian Dywan <christian@twotoasts.de>
Sat, 2 May 2009 19:38:43 +0000 (21:38 +0200)
committerChristian Dywan <christian@twotoasts.de>
Sat, 2 May 2009 19:38:43 +0000 (21:38 +0200)
midori/sokoke.c
midori/sokoke.h

index 69f2d675af289d27b7d792f5a0ae1ab8e04b76fa..1af7289de3fe9af3e748e115352493f016431e87 100644 (file)
@@ -1018,3 +1018,28 @@ sokoke_get_res_server (void)
 
     return res_server;
 }
+
+gchar*
+sokoke_replace_variables (const gchar* template,
+                          const gchar* variable_first, ...)
+{
+    gchar* result = g_strdup (template);
+    const gchar* variable;
+
+    va_list args;
+    va_start (args, variable_first);
+
+    for (variable = variable_first; variable; variable = va_arg (args, const gchar*))
+    {
+        const gchar* value = va_arg (args, const gchar*);
+        GRegex* regex = g_regex_new (variable, 0, 0, NULL);
+        gchar* replaced = result;
+        result = g_regex_replace (regex, replaced, -1, 0, value, 0, NULL);
+        g_free (replaced);
+        g_regex_unref (regex);
+    }
+
+    va_end (args);
+
+    return result;
+}
index e960e08723a301385db277a68cc5b02195a2eb09..56a766155c4d72f040b61a28dd55e242b9de1eb8 100644 (file)
@@ -157,4 +157,8 @@ sokoke_remove_path                      (const gchar*    path,
 SoupServer*
 sokoke_get_res_server                   (void);
 
+gchar*
+sokoke_replace_variables                (const gchar* template,
+                                         const gchar* variable_first, ...);
+
 #endif /* !__SOKOKE_H__ */