From: stephan b. <sg...@us...> - 2004-12-26 11:10:12
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3367/include/pclasses/Util Modified Files: StringTool.h Log Message: Added expandVars() and expandVarsInline(), to expand a map<string,string> as a set of ${vars} in an input string. Index: StringTool.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Util/StringTool.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- StringTool.h 26 Dec 2004 10:42:05 -0000 1.1 +++ StringTool.h 26 Dec 2004 11:10:00 -0000 1.2 @@ -288,6 +288,32 @@ return quote + to( v ) + quote; } + /** + Parsed env vars out of text, replacing them with their + values. Accepts variable tokens in the format ${VAR}. + + e.g., ${foo} corresponds to the value set in src["foo"]. + + Referencing a variable which is not set does not + expand the variable to an empty value: it is left + as-is. Thus expanding ${FOO} when "FOO" is not set + will result in "${FOO}". + + To get a dollar sign into the resulting string, escape + it with a single backslash: this keeps it from being + parsed as a ${variable}. + */ + std::string expandVars( const EntityMap & src, const std::string & text ); + + /** + Exactly like expandVars() but directly modifies + the input string. Returns the number of variables + expanded. + */ + size_t expandVarsInline( const EntityMap & src, std::string & text ); + + + }} // namespace P::StringTool |