| The Gaudi Framework v30r0 (c919700c)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

Utils.cpp
Go to the documentation of this file.
1 // ===========================================================================
2 // Include files
3 // ===========================================================================
4 #include "Utils.h"
5 // ===========================================================================
6 // Boost
7 // ===========================================================================
8 #include <boost/algorithm/string.hpp>
9 #include <boost/regex.hpp>
10 // ===========================================================================
11 // Gaudi
12 // ===========================================================================
13 #include "GaudiKernel/System.h"
14 // ===========================================================================
15
16 namespace gpu = Gaudi::Parsers::Utils;
17
18 std::string gpu::replaceEnvironments( const std::string& input )
19 {
20 static const boost::regex expression( "\\$(([A-Za-z0-9_]+)|\\(([A-Za-z0-9_]+)\\))" );
21
22 std::string result = input;
23 auto start = input.begin();
24 auto end = input.end();
25 boost::match_results<std::string::const_iterator> what;
26 boost::match_flag_type flags = boost::match_default;
27 while ( boost::regex_search( start, end, what, expression, flags ) ) {
28 std::string var{what[2].first, what[2].second};
29 if ( var.empty() ) var = std::string{what[3].first, what[3].second};
30 std::string env;
31 if ( System::getEnv( var, env ) ) {
32 boost::algorithm::replace_first( result, std::string{what[0].first, what[0].second}, env );
33 }
34 start = what[0].second;
35 // update flags:
36 flags |= boost::match_prev_avail;
37 flags |= boost::match_not_bob;
38 }
39 return result;
40 }
41 // ===========================================================================
System::getEnv
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
Definition: System.cpp:415
System.h
std::string::end
T end(T...args)
Gaudi::Parsers::Utils::replaceEnvironments
std::string replaceEnvironments(const std::string &input)
Definition: Utils.cpp:18
std::string
STL class.
Utils.h
Gaudi::Parsers::Utils
Definition: Utils.h:13
IOTest.start
start
Definition: IOTest.py:99
end
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:64
std::string::begin
T begin(T...args)