QMakeGlobals::expandEnvVars: Make sane
Use indexOf() to match individual characters, which is a lot faster than QRegExp. As a side effect, don't try to expand what we just inserted. Change-Id: I964fbd92055f2f2649e7d8ed5739cf1fc7cae927 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com> Reviewed-by: Daniel Teske <daniel.teske@digia.com> (cherry picked from qtcreator/2cc17a61eb6d0fee80fd388fcc5be03a59e4f2b5) Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
This commit is contained in:
parent
b7205053ed
commit
99a4a62977
@ -74,27 +74,8 @@ QT_BEGIN_NAMESPACE
|
||||
|
||||
#define fL1S(s) QString::fromLatin1(s)
|
||||
|
||||
namespace { // MSVC doesn't seem to know the semantics of "static" ...
|
||||
|
||||
static struct {
|
||||
QRegExp reg_variableName;
|
||||
} statics;
|
||||
|
||||
}
|
||||
|
||||
static void initStatics()
|
||||
{
|
||||
if (!statics.reg_variableName.isEmpty())
|
||||
return;
|
||||
|
||||
statics.reg_variableName.setPattern(QLatin1String("\\$\\(.*\\)"));
|
||||
statics.reg_variableName.setMinimal(true);
|
||||
}
|
||||
|
||||
QMakeGlobals::QMakeGlobals()
|
||||
{
|
||||
initStatics();
|
||||
|
||||
do_cache = true;
|
||||
|
||||
#ifdef PROEVALUATOR_DEBUG
|
||||
@ -292,11 +273,24 @@ QStringList QMakeGlobals::getPathListEnv(const QString &var) const
|
||||
QString QMakeGlobals::expandEnvVars(const QString &str) const
|
||||
{
|
||||
QString string = str;
|
||||
int rep;
|
||||
QRegExp reg_variableName = statics.reg_variableName; // Copy for thread safety
|
||||
while ((rep = reg_variableName.indexIn(string)) != -1)
|
||||
string.replace(rep, reg_variableName.matchedLength(),
|
||||
getEnv(string.mid(rep + 2, reg_variableName.matchedLength() - 3)));
|
||||
int startIndex = 0;
|
||||
forever {
|
||||
startIndex = string.indexOf(QLatin1Char('$'), startIndex);
|
||||
if (startIndex < 0)
|
||||
break;
|
||||
if (string.length() < startIndex + 3)
|
||||
break;
|
||||
if (string.at(startIndex + 1) != QLatin1Char('(')) {
|
||||
startIndex++;
|
||||
continue;
|
||||
}
|
||||
int endIndex = string.indexOf(QLatin1Char(')'), startIndex + 2);
|
||||
if (endIndex < 0)
|
||||
break;
|
||||
QString value = getEnv(string.mid(startIndex + 2, endIndex - startIndex - 2));
|
||||
string.replace(startIndex, endIndex - startIndex + 1, value);
|
||||
startIndex += value.length();
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user