The Gaudi Framework  v40r0 (475e45c1)
Utils.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2025 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 #include "Utils.h"
12 #include <GaudiKernel/System.h>
13 #include <boost/algorithm/string.hpp>
14 #include <regex>
15 
16 namespace gpu = Gaudi::Parsers::Utils;
17 
18 std::string gpu::replaceEnvironments( std::string_view input ) {
19  static const std::regex expression( "\\$(([A-Za-z0-9_]+)|\\(([A-Za-z0-9_]+)\\))" );
20 
21  std::string result = std::string{ input };
22  auto start = input.begin();
23  auto end = input.end();
24  std::match_results<std::string_view::const_iterator> what;
25  auto flags = std::regex_constants::match_default;
26  while ( std::regex_search( start, end, what, expression, flags ) ) {
27  std::string var{ what[2].first, what[2].second };
28  if ( var.empty() ) var = std::string{ what[3].first, what[3].second };
29  std::string env;
30  if ( System::getEnv( var, env ) ) {
31  boost::algorithm::replace_first( result, std::string{ what[0].first, what[0].second }, env );
32  }
33  start = what[0].second;
34  // update flags:
35  flags |= std::regex_constants::match_prev_avail;
36  }
37  return result;
38 }
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:376
IOTest.start
start
Definition: IOTest.py:110
Utils.h
Gaudi::Parsers::Utils
Definition: Utils.h:17
Gaudi::Parsers::Utils::replaceEnvironments
std::string replaceEnvironments(std::string_view input)
Definition: Utils.cpp:18
IOTest.end
end
Definition: IOTest.py:125