mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-15 09:43:07 -07:00
Refactor out helper function Utils::String::unquote
Remove redundant include
This commit is contained in:
parent
47960b2592
commit
712e6a0e5c
2 changed files with 25 additions and 24 deletions
|
@ -44,6 +44,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "base/utils/misc.h"
|
#include "base/utils/misc.h"
|
||||||
|
#include "base/utils/string.h"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
@ -153,7 +154,7 @@ namespace
|
||||||
{
|
{
|
||||||
QStringList parts = arg.split(QLatin1Char('='));
|
QStringList parts = arg.split(QLatin1Char('='));
|
||||||
if (parts.size() == 2)
|
if (parts.size() == 2)
|
||||||
return unquote(parts[1]);
|
return Utils::String::unquote(parts[1], QLatin1String("'\""));
|
||||||
throw CommandLineParameterError(QObject::tr("Parameter '%1' must follow syntax '%1=%2'",
|
throw CommandLineParameterError(QObject::tr("Parameter '%1' must follow syntax '%1=%2'",
|
||||||
"e.g. Parameter '--webui-port' must follow syntax '--webui-port=value'")
|
"e.g. Parameter '--webui-port' must follow syntax '--webui-port=value'")
|
||||||
.arg(fullParameter()).arg(QLatin1String("<value>")));
|
.arg(fullParameter()).arg(QLatin1String("<value>")));
|
||||||
|
@ -162,7 +163,7 @@ namespace
|
||||||
QString value(const QProcessEnvironment &env, const QString &defaultValue = QString()) const
|
QString value(const QProcessEnvironment &env, const QString &defaultValue = QString()) const
|
||||||
{
|
{
|
||||||
QString val = env.value(envVarName());
|
QString val = env.value(envVarName());
|
||||||
return val.isEmpty() ? defaultValue : unquote(val);
|
return val.isEmpty() ? defaultValue : Utils::String::unquote(val, QLatin1String("'\""));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString usage(const QString &valueName) const
|
QString usage(const QString &valueName) const
|
||||||
|
@ -175,19 +176,6 @@ namespace
|
||||||
{
|
{
|
||||||
return fullParameter() + QLatin1Char('=');
|
return fullParameter() + QLatin1Char('=');
|
||||||
}
|
}
|
||||||
|
|
||||||
static QString unquote(const QString &s)
|
|
||||||
{
|
|
||||||
auto isStringQuoted =
|
|
||||||
[](const QString &s, QChar quoteChar)
|
|
||||||
{
|
|
||||||
return (s.startsWith(quoteChar) && s.endsWith(quoteChar));
|
|
||||||
};
|
|
||||||
|
|
||||||
if ((s.size() >= 2) && (isStringQuoted(s, QLatin1Char('\'')) || isStringQuoted(s, QLatin1Char('"'))))
|
|
||||||
return s.mid(1, s.size() - 2);
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
bool operator==(const QString &s, const StringOption &o)
|
bool operator==(const QString &s, const StringOption &o)
|
||||||
|
|
|
@ -30,10 +30,10 @@
|
||||||
#ifndef UTILS_STRING_H
|
#ifndef UTILS_STRING_H
|
||||||
#define UTILS_STRING_H
|
#define UTILS_STRING_H
|
||||||
|
|
||||||
#include <string>
|
#include <QString>
|
||||||
|
|
||||||
class QByteArray;
|
class QByteArray;
|
||||||
class QString;
|
class QLatin1String;
|
||||||
|
|
||||||
namespace Utils
|
namespace Utils
|
||||||
{
|
{
|
||||||
|
@ -49,6 +49,19 @@ namespace Utils
|
||||||
bool naturalCompareCaseInsensitive(const QString &left, const QString &right);
|
bool naturalCompareCaseInsensitive(const QString &left, const QString &right);
|
||||||
|
|
||||||
QString wildcardToRegex(const QString &pattern);
|
QString wildcardToRegex(const QString &pattern);
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
T unquote(const T &str, const QString "es = QLatin1String("\""))
|
||||||
|
{
|
||||||
|
if (str.length() < 2) return str;
|
||||||
|
|
||||||
|
for (auto const quote : quotes) {
|
||||||
|
if (str.startsWith(quote) && str.endsWith(quote))
|
||||||
|
return str.mid(1, str.length() - 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue