|
|
|
@ -1247,6 +1247,41 @@ std::string joinArguments(const std::vector<std::string> &args)
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string escapeArgument(const std::string &arg)
|
|
|
|
|
{
|
|
|
|
|
#ifdef NL_OS_WINDOWS
|
|
|
|
|
// we can't escape %VARIABLE% on command-line under Windows
|
|
|
|
|
return arg;
|
|
|
|
|
#else
|
|
|
|
|
// characters to escapce, only " and $ (to prevent a $something replaced by an environment variable)
|
|
|
|
|
static const char s_charsToEscape[] = "\"$";
|
|
|
|
|
|
|
|
|
|
std::string res;
|
|
|
|
|
std::string::size_type pos = 0, lastPos = 0;
|
|
|
|
|
|
|
|
|
|
// to avoid reallocations
|
|
|
|
|
res.reserve(arg.size() * 2);
|
|
|
|
|
|
|
|
|
|
while ((pos = arg.find_first_of(s_charsToEscape, lastPos)) != std::string::npos)
|
|
|
|
|
{
|
|
|
|
|
// add previous part
|
|
|
|
|
res += arg.substr(lastPos, pos - lastPos);
|
|
|
|
|
|
|
|
|
|
// not already escaped
|
|
|
|
|
if (!pos || arg[pos - 1] != '\\') res += '\\';
|
|
|
|
|
|
|
|
|
|
// add escaped character
|
|
|
|
|
res += arg[pos];
|
|
|
|
|
|
|
|
|
|
lastPos = pos+1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res += arg.substr(lastPos);
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Display the bits (with 0 and 1) composing a byte (from right to left)
|
|
|
|
|
*/
|
|
|
|
|