11 #include <mrpt/core/exceptions.h> 19 using namespace mvsim;
25 const auto start = text.find(
"$env{");
26 if (start == std::string::npos)
return text;
28 const std::string pre = text.substr(0, start);
29 const std::string post = text.substr(start + 5);
31 const auto post_end = post.find(
'}');
32 if (post_end == std::string::npos)
35 "Column=%u: Cannot find matching `}` for `$env{` in: `%s`",
36 static_cast<unsigned int>(start), text.c_str());
39 const auto varname = post.substr(0, post_end);
41 const char*
v = ::getenv(varname.c_str());
43 varvalue = std::string(v);
47 "parseEnvVars(): Undefined environment variable found: $env{%s}",
51 return parseEnvVars(pre + varvalue + post.substr(post_end + 1));
56 const std::string& text,
57 const std::map<std::string, std::string>& variableNamesValues)
61 const auto start = text.find(
"${");
62 if (start == std::string::npos)
return text;
64 const std::string pre = text.substr(0, start);
65 const std::string post = text.substr(start + 2);
67 const auto post_end = post.find(
'}');
68 if (post_end == std::string::npos)
71 "Column=%u: Cannot find matching `}` for `${` in: `%s`",
72 static_cast<unsigned int>(start), text.c_str());
75 const auto varname = post.substr(0, post_end);
77 if (
const auto it = variableNamesValues.find(varname);
78 it != variableNamesValues.end())
80 varvalue = it->second;
85 "parseEnvVars(): Undefined variable found: $env{%s}",
89 return parseEnvVars(pre + varvalue + post.substr(post_end + 1));
97 const auto start = text.find(
"$(");
98 if (start == std::string::npos)
return text;
100 const std::string pre = text.substr(0, start);
101 const std::string post = text.substr(start + 2);
103 const auto post_end = post.find(
')');
104 if (post_end == std::string::npos)
107 "Column=%u: Cannot find matching `)` for `$(` in: `%s`",
108 static_cast<unsigned int>(start), text.c_str());
111 const auto cmd = post.substr(0, post_end);
120 "Error (retval=%i) executing external command: `%s`", ret,
125 cmdOut.erase(std::remove(cmdOut.begin(), cmdOut.end(),
'\r'), cmdOut.end());
126 cmdOut.erase(std::remove(cmdOut.begin(), cmdOut.end(),
'\n'), cmdOut.end());
128 return parseCmdRuns(pre + cmdOut + post.substr(post_end + 1));
133 const std::string&
input,
134 const std::map<std::string, std::string>& variableNamesValues)
136 std::string
s = input;
138 std::string prevValue = s;
139 for (
int iter = 0; iter < 10; iter++)
146 if (s == prevValue)
break;
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
GLenum GLenum GLenum input
static std::string parseCmdRuns(const std::string &text)
int BASE_IMPEXP executeCommand(const std::string &command, std::string *output=NULL, const std::string &mode="r")
static std::string parseVars(const std::string &text, const std::map< std::string, std::string > &variableNamesValues)
std::string parse(const std::string &input, const std::map< std::string, std::string > &variableNamesValues={})
static std::string parseEnvVars(const std::string &text)
TCLAP::CmdLine cmd("mvsim", ' ',"version", false)
std::string BASE_IMPEXP trim(const std::string &str)