The Gaudi Framework  master (37c0b60a)
Gaudi::Parsers::Utils Namespace Reference

Functions

std::string replaceEnvironments (std::string_view input)
 

Function Documentation

◆ replaceEnvironments()

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

Definition at line 28 of file Utils.cpp.

28  {
29  static const std::regex expression( "\\$(([A-Za-z0-9_]+)|\\(([A-Za-z0-9_]+)\\))" );
30 
31  std::string result = std::string{ input };
32  auto start = input.begin();
33  auto end = input.end();
35  auto flags = std::regex_constants::match_default;
36  while ( std::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 |= std::regex_constants::match_prev_avail;
46  }
47  return result;
48 }
std::string
STL class.
System::getEnv
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
Definition: System.cpp:390
IOTest.start
start
Definition: IOTest.py:110
std::regex
std::regex_search
T regex_search(T... args)
std::match_results
IOTest.end
end
Definition: IOTest.py:125