X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FVariables.C;h=3b3f6d4f9d25d2c4bf31272349b5139564d13997;hb=3f8fa07c6ed38218d6a4048f2993a512aa942c96;hp=dd178f29d197c2d06a477f3ea4a465860d2fdb92;hpb=83acbbd5237373926c629855379e1df9a04209b2;p=lyx.git diff --git a/src/Variables.C b/src/Variables.C index dd178f29d1..3b3f6d4f9d 100644 --- a/src/Variables.C +++ b/src/Variables.C @@ -1,19 +1,16 @@ -/* This file is part of -* ====================================================== -* -* LyX, The Document Processor -* -* Copyright 1995 Matthias Ettrich -* Copyright 1995-2001 the LyX Team. -* -* ====================================================== */ +/** + * \file Variables.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Lars Gullik Bjønnes + * \author Jean-Marc Lasgouttes + * + * Full author contact details are available in file CREDITS. + */ #include -#ifdef __GNUG__ -#pragma implementation "Variables.h" -#endif - #include "Variables.h" #include "support/LRegex.h" @@ -22,7 +19,7 @@ void Variables::set(string const & var, string const & val) { // We want to use const_iterator (Lgb) Vars::iterator cit = vars_.find(var); - if (cit != vars_.end()) + if (cit != vars_.end()) vars_.erase(var); vars_[var] = val;; } @@ -30,54 +27,59 @@ 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("\\$\\{\\(.*\\)\\}"); - - 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)); - - return str; + string str(s); + LRegex reg("\\$\\{\\(.*\\)\\}"); + + 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)); + + return str; } #ifdef TEST #include + + +namespace lyx { 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 + +} // namespace lyx