Add sokoke_replace_variables
This commit is contained in:
parent
d6721f09b0
commit
7d0d2d60bc
2 changed files with 29 additions and 0 deletions
|
@ -1018,3 +1018,28 @@ sokoke_get_res_server (void)
|
||||||
|
|
||||||
return res_server;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -157,4 +157,8 @@ sokoke_remove_path (const gchar* path,
|
||||||
SoupServer*
|
SoupServer*
|
||||||
sokoke_get_res_server (void);
|
sokoke_get_res_server (void);
|
||||||
|
|
||||||
|
gchar*
|
||||||
|
sokoke_replace_variables (const gchar* template,
|
||||||
|
const gchar* variable_first, ...);
|
||||||
|
|
||||||
#endif /* !__SOKOKE_H__ */
|
#endif /* !__SOKOKE_H__ */
|
||||||
|
|
Loading…
Reference in a new issue