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"
19 void Variables::set(string
const & var
, string
const & val
)
21 // We want to use const_iterator (Lgb)
22 Vars::iterator cit
= vars_
.find(var
);
23 if (cit
!= vars_
.end())
29 string
const Variables::get(string
const & var
) const
31 Vars::const_iterator cit
= vars_
.find(var
);
32 if (cit
!= vars_
.end())
39 bool Variables::isSet(string
const & var
) const
41 Vars::const_iterator cit
= vars_
.find(var
);
42 return (cit
!= vars_
.end());
46 string
const Variables::expand(string
const & s
) const
49 LRegex
reg("\\$\\{\\(.*\\)\\}");
51 if (!reg
.exact_match(str
))
54 LRegex::MatchPair match
;
58 match
= reg
.first_match(str
);
59 var
= str
.substr(match
.first
,match
.second
);
60 // we correct the match to take ${} in account.
61 str
.replace(match
.first
- 2, match
.second
+ 3, get(var
));
62 } while (reg
.exact_match(str
));
75 vars
.set("x", "hello");
76 vars
.set("y", "world");
77 cout
<< vars
.expand("${x}") << endl
;