mirror of
https://github.com/NixOS/nix
synced 2025-07-03 22:51:47 +02:00
nix: Reserve shebang line syntax and only parse double backtick quotes
Being restrictive about syntax leaves opportunity to improve the syntax and functionality later.
This commit is contained in:
parent
cc68ed8ff7
commit
20ff61ab25
6 changed files with 177 additions and 58 deletions
|
@ -138,49 +138,6 @@ std::string shellEscape(const std::string_view s)
|
|||
return r;
|
||||
}
|
||||
|
||||
/* Recreate the effect of the perl shellwords function, breaking up a
|
||||
* string into arguments like a shell word, including escapes
|
||||
*/
|
||||
std::vector<std::string> shellwords2(const std::string & s)
|
||||
{
|
||||
std::regex whitespace("^(\\s+).*");
|
||||
auto begin = s.cbegin();
|
||||
std::vector<std::string> res;
|
||||
std::string cur;
|
||||
enum state {
|
||||
sBegin,
|
||||
sQuote
|
||||
};
|
||||
state st = sBegin;
|
||||
auto it = begin;
|
||||
for (; it != s.cend(); ++it) {
|
||||
if (st == sBegin) {
|
||||
std::smatch match;
|
||||
if (regex_search(it, s.cend(), match, whitespace)) {
|
||||
cur.append(begin, it);
|
||||
res.push_back(cur);
|
||||
cur.clear();
|
||||
it = match[1].second;
|
||||
begin = it;
|
||||
}
|
||||
}
|
||||
switch (*it) {
|
||||
case '"':
|
||||
cur.append(begin, it);
|
||||
begin = it + 1;
|
||||
st = st == sBegin ? sQuote : sBegin;
|
||||
break;
|
||||
case '\\':
|
||||
/* perl shellwords mostly just treats the next char as part of the string with no special processing */
|
||||
cur.append(begin, it);
|
||||
begin = ++it;
|
||||
break;
|
||||
}
|
||||
}
|
||||
cur.append(begin, it);
|
||||
if (!cur.empty()) res.push_back(cur);
|
||||
return res;
|
||||
}
|
||||
|
||||
void ignoreException(Verbosity lvl)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue