The Gaudi Framework  v33r1 (b1225454)
Gaudi::Parsers::Utils Namespace Reference

Functions

std::string replaceEnvironments (const std::string &input)
 

Function Documentation

◆ replaceEnvironments()

std::string Gaudi::Parsers::Utils::replaceEnvironments ( const std::string input)

Definition at line 28 of file Utils.cpp.

28  {
29  static const boost::regex expression( "\\$(([A-Za-z0-9_]+)|\\(([A-Za-z0-9_]+)\\))" );
30 
31  std::string result = input;
32  auto start = input.begin();
33  auto end = input.end();
34  boost::match_results<std::string::const_iterator> what;
35  boost::match_flag_type flags = boost::match_default;
36  while ( boost::regex_search( start, end, what, expression, flags ) ) {
37  std::string var{what[2].first, what[2].second};
38  if ( var.empty() ) var = std::string{what[3].first, what[3].second};
39  std::string env;
40  if ( System::getEnv( var, env ) ) {
41  boost::algorithm::replace_first( result, std::string{what[0].first, what[0].second}, env );
42  }
43  start = what[0].second;
44  // update flags:
45  flags |= boost::match_prev_avail;
46  flags |= boost::match_not_bob;
47  }
48  return result;
49 }
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
Definition: System.cpp:379
T end(T... args)
def start
Definition: IOTest.py:108
STL class.
def end
Definition: IOTest.py:123
T begin(T... args)