variables.diff

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2157 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2001-06-29 06:40:08 +00:00
parent f87b93ec65
commit 65c6e5bed3
3 changed files with 42 additions and 38 deletions

View File

@ -1,3 +1,7 @@
2001-06-29 John Levon <moz@compsoc.man.ac.uk>
* Variables.[Ch]: fix indentation, rename set to isSet
2001-06-29 Lars Gullik Bjønnes <larsbj@birdstep.com>
* lyxfunc.C (Dispatch): fix typo

View File

@ -30,40 +30,40 @@ void Variables::set(string const & var, string const & val)
string const Variables::get(string const & var) const
{
Vars::const_iterator cit = vars_.find(var);
if (cit != vars_.end())
return (*cit).second;
else
return string();
Vars::const_iterator cit = vars_.find(var);
if (cit != vars_.end())
return (*cit).second;
else
return string();
}
bool Variables::set(string const & var) const
bool Variables::isSet(string const & var) const
{
Vars::const_iterator cit = vars_.find(var);
return (cit != vars_.end());
Vars::const_iterator cit = vars_.find(var);
return (cit != vars_.end());
}
string const Variables::expand(string const & s) const
{
string str(s);
LRegex reg("\\$\\{\\(.*\\)\\}");
string str(s);
LRegex reg("\\$\\{\\(.*\\)\\}");
if (!reg.exact_match(str))
return str;
if (!reg.exact_match(str))
return str;
LRegex::MatchPair match;
string var;
do {
match = reg.first_match(str);
var = str.substr(match.first,match.second);
// we correct the match to take ${} in account.
str.replace(match.first - 2, match.second + 3, get(var));
} while (reg.exact_match(str));
LRegex::MatchPair match;
string var;
return str;
do {
match = reg.first_match(str);
var = str.substr(match.first,match.second);
// we correct the match to take ${} in account.
str.replace(match.first - 2, match.second + 3, get(var));
} while (reg.exact_match(str));
return str;
}
#ifdef TEST
@ -73,10 +73,10 @@ using std::endl;
using std::cout;
int main() {
Variables vars;
vars.set("x", "hello");
vars.set("y", "world");
cout << vars.expand("${x}") << endl;
Variables vars;
vars.set("x", "hello");
vars.set("y", "world");
cout << vars.expand("${x}") << endl;
}
#endif

View File

@ -23,19 +23,19 @@
///
class Variables {
public:
///
void set(string const &, string const &);
///
string const get(string const &) const;
///
bool set(string const & var) const;
///
string const expand(string const &) const;
///
void set(string const &, string const &);
///
string const get(string const &) const;
///
bool isSet(string const & var) const;
///
string const expand(string const &) const;
private:
///
typedef std::map<string, string> Vars;
///
Vars vars_;
///
typedef std::map<string, string> Vars;
///
Vars vars_;
};
#endif