From fb4ada538119ae94b118691301d59f0ad90fc33f Mon Sep 17 00:00:00 2001 From: mquinson Date: Wed, 1 Oct 2008 14:54:32 +0000 Subject: [PATCH] new function: xbt_str_varsubst(), which call xbt_strbuff_varsubst() do do variable value expansion git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@5952 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/xbt/xbt_str.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/xbt/xbt_str.c b/src/xbt/xbt_str.c index 2b225bfa0b..6cd5a2da64 100644 --- a/src/xbt/xbt_str.c +++ b/src/xbt/xbt_str.c @@ -12,6 +12,7 @@ #include "xbt/misc.h" #include "xbt/sysdep.h" #include "xbt/str.h" /* headers of these functions */ +#include "xbt/strbuff.h" #include "portable.h" #include "xbt/matrix.h" /* for the diff */ @@ -191,6 +192,24 @@ void xbt_str_subst(char *str, char from, char to, int occurence) { p++; } } +/** @brief Replaces a set of variables by their values + * + * @param str where to apply the change + * @param patterns what to change + * @return The string modified + * + * Check xbt_strbuff_varsubst() for more details, and remember that the string may be reallocated (moved) in the process. + */ + +char *xbt_str_varsubst(char *str, xbt_dict_t patterns) { + xbt_strbuff_t buff = xbt_strbuff_new_from(str); + char * res; + xbt_strbuff_varsubst(buff,patterns); + res = buff->data; + xbt_strbuff_free_container(buff); + return res; +} + /** @brief Splits a string into a dynar of strings * -- 2.20.1