Utils: Remove NameValueDictionary::expandVariables()

These functions were inadvertently copied from the Environment class in
4bae5de36b.

Change-Id: Iede8d4b43bd97e8d6d3a0641bd3224e5829fe4b0
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Kandeler
2019-07-15 14:17:54 +02:00
parent 4077bc869c
commit 375e4dee2b
2 changed files with 0 additions and 84 deletions

View File

@@ -198,85 +198,4 @@ QString NameValueDictionary::userName() const
return value(QString::fromLatin1(m_osType == OsTypeWindows ? "USERNAME" : "USER"));
}
/** Expand environment variables in a string.
*
* KeyValueDictionary variables are accepted in the following forms:
* $SOMEVAR, ${SOMEVAR} on Unix and %SOMEVAR% on Windows.
* No escapes and quoting are supported.
* If a variable is not found, it is not substituted.
*/
QString NameValueDictionary::expandVariables(const QString &input) const
{
QString result = input;
if (m_osType == OsTypeWindows) {
for (int vStart = -1, i = 0; i < result.length();) {
if (result.at(i++) == '%') {
if (vStart > 0) {
const_iterator it = findKey(m_values, m_osType, result.mid(vStart, i - vStart - 1));
if (it != m_values.constEnd()) {
result.replace(vStart - 1, i - vStart + 1, *it);
i = vStart - 1 + it->length();
vStart = -1;
} else {
vStart = i;
}
} else {
vStart = i;
}
}
}
} else {
enum { BASE, OPTIONALVARIABLEBRACE, VARIABLE, BRACEDVARIABLE } state = BASE;
int vStart = -1;
for (int i = 0; i < result.length();) {
QChar c = result.at(i++);
if (state == BASE) {
if (c == '$')
state = OPTIONALVARIABLEBRACE;
} else if (state == OPTIONALVARIABLEBRACE) {
if (c == '{') {
state = BRACEDVARIABLE;
vStart = i;
} else if (c.isLetterOrNumber() || c == '_') {
state = VARIABLE;
vStart = i - 1;
} else {
state = BASE;
}
} else if (state == BRACEDVARIABLE) {
if (c == '}') {
const_iterator it = m_values.constFind(result.mid(vStart, i - 1 - vStart));
if (it != constEnd()) {
result.replace(vStart - 2, i - vStart + 2, *it);
i = vStart - 2 + it->length();
}
state = BASE;
}
} else if (state == VARIABLE) {
if (!c.isLetterOrNumber() && c != '_') {
const_iterator it = m_values.constFind(result.mid(vStart, i - vStart - 1));
if (it != constEnd()) {
result.replace(vStart - 1, i - vStart, *it);
i = vStart - 1 + it->length();
}
state = BASE;
}
}
}
if (state == VARIABLE) {
const_iterator it = m_values.constFind(result.mid(vStart));
if (it != constEnd())
result.replace(vStart - 1, result.length() - vStart + 1, *it);
}
}
return result;
}
QStringList NameValueDictionary::expandVariables(const QStringList &variables) const
{
return Utils::transform(variables, [this](const QString &i) { return expandVariables(i); });
}
} // namespace Utils

View File

@@ -71,9 +71,6 @@ public:
NameValueDictionary::const_iterator constFind(const QString &name) const;
QString expandVariables(const QString &input) const;
QStringList expandVariables(const QStringList &input) const;
friend bool operator!=(const NameValueDictionary &first, const NameValueDictionary &second)
{
return !(first == second);