All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Utils.cpp
Go to the documentation of this file.
1 // $Id:$
2 // ===========================================================================
3 // Include files
4 // ===========================================================================
5 #include "Utils.h"
6 // ===========================================================================
7 // STD & STL
8 // ===========================================================================
9 // ===========================================================================
10 // Boost
11 // ===========================================================================
12 #include <boost/tokenizer.hpp>
13 #include <boost/regex.hpp>
14 #include <boost/algorithm/string.hpp>
15 // ===========================================================================
16 // Gaudi
17 // ===========================================================================
18 #include "GaudiKernel/System.h"
19 // ===========================================================================
20 // Local
21 // ===========================================================================
22 // ===========================================================================
23 
24 namespace gpu=Gaudi::Parsers::Utils;
25 
26 std::string gpu::replaceEnvironments(const std::string& input) {
27  std::string result=input;// result
28 
29  const char* re = "\\$(([A-Za-z0-9_]+)|\\(([A-Za-z0-9_]+)\\))";
30  std::string::const_iterator start, end;
31  boost::regex expression(re);
32  start = input.begin();
33  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  {
38  std::string var,env;
39  std::string matched(what[0].first,what[0].second);
40  std::string v1(what[2].first,what[2].second);
41  std::string v2(what[3].first,what[3].second);
42 
43  if ( v1.length()>0){ var = v1; }
44  else { var = v2; }
45 
46  System::getEnv(var, env);
47  if(var != "UNKNOWN") {
48  boost::algorithm::replace_first(result,matched, env);
49  }
50  start = what[0].second;
51  // update flags:
52  flags |= boost::match_prev_avail;
53  flags |= boost::match_not_bob;
54  }
55  return result;
56 }
57 
58 
59 // ===========================================================================
60 
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
Definition: System.cpp:608
std::string replaceEnvironments(const std::string &input)
Definition: Utils.cpp:26
tuple end
Definition: IOTest.py:101
tuple start
Definition: IOTest.py:88