1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 the LyX Team.
9 * ====================================================== */
13 #include "Variables.h"
14 #include "support/LRegex.h"
17 void Variables::set(string const & var, string const & val)
19 // We want to use const_iterator (Lgb)
20 Vars::iterator cit = vars_.find(var);
21 if (cit != vars_.end())
27 string const Variables::get(string const & var) const
29 Vars::const_iterator cit = vars_.find(var);
30 if (cit != vars_.end())
37 bool Variables::isSet(string const & var) const
39 Vars::const_iterator cit = vars_.find(var);
40 return (cit != vars_.end());
44 string const Variables::expand(string const & s) const
47 LRegex reg("\\$\\{\\(.*\\)\\}");
49 if (!reg.exact_match(str))
52 LRegex::MatchPair match;
56 match = reg.first_match(str);
57 var = str.substr(match.first,match.second);
58 // we correct the match to take ${} in account.
59 str.replace(match.first - 2, match.second + 3, get(var));
60 } while (reg.exact_match(str));
73 vars.set("x", "hello");
74 vars.set("y", "world");
75 cout << vars.expand("${x}") << endl;