refactor: Simplify CoreProcess::QuoteArgs, use QString::Simplify and simplify logic in the loop

This commit is contained in:
sithlord48 2025-10-05 08:48:52 -04:00 committed by Chris Rizzitello
parent bb1e2ecc78
commit e3f940c70a

View file

@ -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);
} }
/** /**