3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
7 * \author Jean-Marc Lasgouttes
9 * Full author contact details are available in file CREDITS.
14 #include "Variables.h"
15 #include "support/LRegex.h"
18 void Variables::set(string const & var, string const & val)
20 // We want to use const_iterator (Lgb)
21 Vars::iterator cit = vars_.find(var);
22 if (cit != vars_.end())
28 string const Variables::get(string const & var) const
30 Vars::const_iterator cit = vars_.find(var);
31 if (cit != vars_.end())
38 bool Variables::isSet(string const & var) const
40 Vars::const_iterator cit = vars_.find(var);
41 return (cit != vars_.end());
45 string const Variables::expand(string const & s) const
48 LRegex reg("\\$\\{\\(.*\\)\\}");
50 if (!reg.exact_match(str))
53 LRegex::MatchPair match;
57 match = reg.first_match(str);
58 var = str.substr(match.first,match.second);
59 // we correct the match to take ${} in account.
60 str.replace(match.first - 2, match.second + 3, get(var));
61 } while (reg.exact_match(str));
74 vars.set("x", "hello");
75 vars.set("y", "world");
76 cout << vars.expand("${x}") << endl;