Fix empty string parameter was omitted

`QProcess::splitCommand()` will omit empty strings like `""` so provide
our own replacement.

Closes #13124.
This commit is contained in:
Chocobo1 2022-07-29 11:16:40 +08:00
parent 2ebdf6060d
commit 0802b6d506
No known key found for this signature in database
GPG key ID: 210D9C873253A68C
5 changed files with 172 additions and 55 deletions

View file

@ -33,6 +33,7 @@
#include <QLocale>
#include <QRegularExpression>
#include <QStringList>
#include <QVector>
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
@ -76,6 +77,42 @@ QString Utils::String::wildcardToRegexPattern(const QString &pattern)
}
#endif
QStringList Utils::String::splitCommand(const QString &command)
{
QStringList ret;
ret.reserve(32);
bool inQuotes = false;
QString tmp;
for (const QChar c : command)
{
if (c == u' ')
{
if (!inQuotes)
{
if (!tmp.isEmpty())
{
ret.append(tmp);
tmp.clear();
}
continue;
}
}
else if (c == u'"')
{
inQuotes = !inQuotes;
}
tmp.append(c);
}
if (!tmp.isEmpty())
ret.append(tmp);
return ret;
}
std::optional<bool> Utils::String::parseBool(const QString &string)
{
if (string.compare(u"true", Qt::CaseInsensitive) == 0)