summaryrefslogtreecommitdiff
path: root/src/linguist
diff options
context:
space:
mode:
authorDaniel Teske <daniel.teske@digia.com>2014-09-09 15:16:27 +0200
committerOswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>2015-12-18 14:45:47 +0000
commit3a99ec35159be6b03739d8468aa77a4d912732e5 (patch)
tree96e23de8d6fb51193a67fb923625c9a5ce483cb3 /src/linguist
parent0f04bcce9330328d44660a538aed11ec6bb278fb (diff)
downloadqttools-3a99ec35159be6b03739d8468aa77a4d912732e5.tar.gz
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> Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com> (cherry picked from qtcreator/2cc17a61eb6d0fee80fd388fcc5be03a59e4f2b5) Reviewed-by: hjk <hjk@theqtcompany.com> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Diffstat (limited to 'src/linguist')
-rw-r--r--src/linguist/shared/qmakeglobals.cpp42
1 files changed, 18 insertions, 24 deletions
diff --git a/src/linguist/shared/qmakeglobals.cpp b/src/linguist/shared/qmakeglobals.cpp
index dda9c1f13..853309cae 100644
--- a/src/linguist/shared/qmakeglobals.cpp
+++ b/src/linguist/shared/qmakeglobals.cpp
@@ -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;
}