Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  master (d98a2936)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 <regex>
14 
15 namespace gpu = Gaudi::Parsers::Utils;
16 
17 std::string gpu::replaceEnvironments( std::string_view input ) {
18  static const std::regex expression( "\\$(([A-Za-z0-9_]+)|\\(([A-Za-z0-9_]+)\\))" );
19 
20  std::string result = std::string{ input };
21  auto start = input.begin();
22  auto end = input.end();
23  std::match_results<std::string_view::const_iterator> what;
24  auto flags = std::regex_constants::match_default;
25  std::size_t from = 0;
26  while ( std::regex_search( start, end, what, expression, flags ) ) {
27  if ( std::string env; System::getEnv( what[what[2].matched ? 2 : 3].str(), env ) ) {
28  auto pos = result.find( what[0].first, from, what[0].length() );
29  result.replace( pos, what[0].length(), env );
30  from = pos + env.size();
31  }
32  start = what[0].second;
33  // update flags:
34  flags |= std::regex_constants::match_prev_avail;
35  }
36  return result;
37 }
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:329
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:17
IOTest.end
end
Definition: IOTest.py:125