refactor: Simplify CoreProcess::QuoteArgs, use QString::Simplify and simplify logic in the loop
This commit is contained in:
parent
bb1e2ecc78
commit
e3f940c70a
1 changed files with 10 additions and 9 deletions
|
|
@ -79,20 +79,21 @@ QString processStateToString(CoreProcess::ProcessState state)
|
||||||
*/
|
*/
|
||||||
QString CoreProcess::makeQuotedArgs(const QString &app, const QStringList &args)
|
QString CoreProcess::makeQuotedArgs(const QString &app, const QStringList &args)
|
||||||
{
|
{
|
||||||
QStringList command;
|
QStringList command = {app};
|
||||||
command << app;
|
command.append(args);
|
||||||
command << args;
|
|
||||||
|
|
||||||
|
static const auto quote = QStringLiteral("\"");
|
||||||
|
static const auto space = QStringLiteral(" ");
|
||||||
QStringList quoted;
|
QStringList quoted;
|
||||||
for (const auto &arg : std::as_const(command)) {
|
for (const auto &item : std::as_const(command)) {
|
||||||
if (arg.contains(' ')) {
|
auto temp = item.simplified();
|
||||||
quoted << QString("\"%1\"").arg(arg);
|
if (const auto wrapped = (temp.startsWith(quote) && temp.endsWith(quote)); temp.contains(space) && !wrapped) {
|
||||||
} else {
|
temp = QStringLiteral("%1%2%1").arg(quote, temp);
|
||||||
quoted << arg;
|
|
||||||
}
|
}
|
||||||
|
quoted.append(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
return quoted.join(" ");
|
return quoted.join(space);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue