Go to the documentation of this file.00001
00002
00003
00004
00005 #include "Utils.h"
00006
00007
00008
00009
00010
00011
00012 #include <boost/tokenizer.hpp>
00013 #include <boost/regex.hpp>
00014 #include <boost/algorithm/string.hpp>
00015
00016
00017
00018 #include "GaudiKernel/System.h"
00019
00020
00021
00022
00023
00024 namespace gpu=Gaudi::Parsers::Utils;
00025
00026 std::string gpu::replaceEnvironments(const std::string& input) {
00027 std::string result=input;
00028
00029 const char* re = "\\$(([A-Za-z0-9_]+)|\\(([A-Za-z0-9_]+)\\))";
00030 std::string::const_iterator start, end;
00031 boost::regex expression(re);
00032 start = input.begin();
00033 end = input.end();
00034 boost::match_results<std::string::const_iterator> what;
00035 boost::match_flag_type flags = boost::match_default;
00036 while ( boost::regex_search(start, end, what, expression, flags ) )
00037 {
00038 std::string var,env;
00039 std::string matched(what[0].first,what[0].second);
00040 std::string v1(what[2].first,what[2].second);
00041 std::string v2(what[3].first,what[3].second);
00042
00043 if ( v1.length()>0){ var = v1; }
00044 else { var = v2; }
00045
00046 System::getEnv(var, env);
00047 if(var != "UNKNOWN") {
00048 boost::algorithm::replace_first(result,matched, env);
00049 }
00050 start = what[0].second;
00051
00052 flags |= boost::match_prev_avail;
00053 flags |= boost::match_not_bob;
00054 }
00055 return result;
00056 }
00057
00058
00059
00060