mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
variables.diff
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2157 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
f87b93ec65
commit
65c6e5bed3
@ -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>
|
2001-06-29 Lars Gullik Bjønnes <larsbj@birdstep.com>
|
||||||
|
|
||||||
* lyxfunc.C (Dispatch): fix typo
|
* lyxfunc.C (Dispatch): fix typo
|
||||||
|
@ -30,40 +30,40 @@ void Variables::set(string const & var, string const & val)
|
|||||||
|
|
||||||
string const Variables::get(string const & var) const
|
string const Variables::get(string const & var) const
|
||||||
{
|
{
|
||||||
Vars::const_iterator cit = vars_.find(var);
|
Vars::const_iterator cit = vars_.find(var);
|
||||||
if (cit != vars_.end())
|
if (cit != vars_.end())
|
||||||
return (*cit).second;
|
return (*cit).second;
|
||||||
else
|
else
|
||||||
return string();
|
return string();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Variables::set(string const & var) const
|
bool Variables::isSet(string const & var) const
|
||||||
{
|
{
|
||||||
Vars::const_iterator cit = vars_.find(var);
|
Vars::const_iterator cit = vars_.find(var);
|
||||||
return (cit != vars_.end());
|
return (cit != vars_.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
string const Variables::expand(string const & s) const
|
string const Variables::expand(string const & s) const
|
||||||
{
|
{
|
||||||
string str(s);
|
string str(s);
|
||||||
LRegex reg("\\$\\{\\(.*\\)\\}");
|
LRegex reg("\\$\\{\\(.*\\)\\}");
|
||||||
|
|
||||||
if (!reg.exact_match(str))
|
if (!reg.exact_match(str))
|
||||||
return str;
|
return str;
|
||||||
|
|
||||||
LRegex::MatchPair match;
|
LRegex::MatchPair match;
|
||||||
string var;
|
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));
|
|
||||||
|
|
||||||
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
|
#ifdef TEST
|
||||||
@ -73,10 +73,10 @@ using std::endl;
|
|||||||
using std::cout;
|
using std::cout;
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
Variables vars;
|
Variables vars;
|
||||||
vars.set("x", "hello");
|
vars.set("x", "hello");
|
||||||
vars.set("y", "world");
|
vars.set("y", "world");
|
||||||
cout << vars.expand("${x}") << endl;
|
cout << vars.expand("${x}") << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -23,19 +23,19 @@
|
|||||||
///
|
///
|
||||||
class Variables {
|
class Variables {
|
||||||
public:
|
public:
|
||||||
///
|
///
|
||||||
void set(string const &, string const &);
|
void set(string const &, string const &);
|
||||||
///
|
///
|
||||||
string const get(string const &) const;
|
string const get(string const &) const;
|
||||||
///
|
///
|
||||||
bool set(string const & var) const;
|
bool isSet(string const & var) const;
|
||||||
///
|
///
|
||||||
string const expand(string const &) const;
|
string const expand(string const &) const;
|
||||||
private:
|
private:
|
||||||
///
|
///
|
||||||
typedef std::map<string, string> Vars;
|
typedef std::map<string, string> Vars;
|
||||||
///
|
///
|
||||||
Vars vars_;
|
Vars vars_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user