The Gaudi Framework  master (37c0b60a)
Utils.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 // ===========================================================================
12 // Include files
13 // ===========================================================================
14 #include "Utils.h"
15 // ===========================================================================
16 // Boost
17 // ===========================================================================
18 #include <boost/algorithm/string.hpp>
19 #include <regex>
20 // ===========================================================================
21 // Gaudi
22 // ===========================================================================
23 #include <GaudiKernel/System.h>
24 // ===========================================================================
25 
26 namespace gpu = Gaudi::Parsers::Utils;
27 
28 std::string gpu::replaceEnvironments( std::string_view input ) {
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 }
49 // ===========================================================================
std::string
STL class.
System.h
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
Utils.h
Gaudi::Parsers::Utils
Definition: Utils.h:21
Gaudi::Parsers::Utils::replaceEnvironments
std::string replaceEnvironments(std::string_view input)
Definition: Utils.cpp:28
std::regex
std::regex_search
T regex_search(T... args)
std::match_results
IOTest.end
end
Definition: IOTest.py:125