ReFRACtor
environment_substitute.cc
Go to the documentation of this file.
2 #include <boost/regex.hpp>
3 #include <cstdlib>
4 
5 std::string replace_env(boost::smatch const &what)
6 {
7  char* t = getenv(what[1].str().c_str());
8  if(t)
9  return t;
10  else
11  return "";
12 }
13 
14 
15 //-----------------------------------------------------------------------
21 //-----------------------------------------------------------------------
22 
23 std::string FullPhysics::environment_substitute(const std::string& In)
24 {
25  // It turns out the regex_replace is a bit slow, so don't use the
26  // full regex unless we find at least one "$(" in the string.
27  if(In.find("$(") == std::string::npos)
28  return In;
29  return boost::regex_replace(In, boost::regex("\\$\\((\\w+)\\)"),
30  replace_env);
31 }
std::string replace_env(boost::smatch const &what)
std::string environment_substitute(const std::string &In)
This routine takes a string that may have one or more strings in it like .

Copyright © 2017, California Institute of Technology.
ALL RIGHTS RESERVED.
U.S. Government Sponsorship acknowledged.
Generated Fri Aug 24 2018 15:44:11