Commit 04fdfd8b authored by Oswald Buddenhagen's avatar Oswald Buddenhagen
Browse files

move some functions into ProStringList for saner OO design



Change-Id: I60f00f38f459fc9f8eebee9187158e4198fc9546
Reviewed-by: default avatarJoerg Bornemann <joerg.bornemann@theqtcompany.com>
(cherry picked from qtbase/ab74cf09a8f71aa939ac3de6165f9d6b45465ef8)
parent b6fb8da6
......@@ -379,6 +379,20 @@ void ProStringList::removeAll(const char *str)
remove(i);
}
void ProStringList::removeEach(const ProStringList &value)
{
foreach (const ProString &str, value)
if (!str.isEmpty())
removeAll(str);
}
void ProStringList::removeEmpty()
{
for (int i = size(); --i >= 0;)
if (at(i).isEmpty())
remove(i);
}
void ProStringList::removeDuplicates()
{
int n = size();
......@@ -398,6 +412,13 @@ void ProStringList::removeDuplicates()
erase(begin() + j, end());
}
void ProStringList::insertUnique(const ProStringList &value)
{
foreach (const ProString &str, value)
if (!str.isEmpty() && !contains(str))
append(str);
}
ProStringList::ProStringList(const QStringList &list)
{
reserve(list.size());
......
......@@ -236,9 +236,13 @@ public:
QString join(const QString &sep) const;
QString join(QChar sep) const;
void insertUnique(const ProStringList &value);
void removeAll(const ProString &str);
void removeAll(const char *str);
void removeEach(const ProStringList &value);
void removeAt(int idx) { remove(idx); }
void removeEmpty();
void removeDuplicates();
bool contains(const ProString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
......
......@@ -1688,7 +1688,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
if (mode == CacheAdd)
newval += diffval;
else
removeEach(&newval, diffval);
newval.removeEach(diffval);
}
if (oldval != newval) {
if (target != TargetStash || !m_stashfile.isEmpty()) {
......
......@@ -347,34 +347,6 @@ ProStringList QMakeEvaluator::split_value_list(const QString &vals, const ProFil
return ret;
}
static void zipEmpty(ProStringList *value)
{
for (int i = value->size(); --i >= 0;)
if (value->at(i).isEmpty())
value->remove(i);
}
static void insertUnique(ProStringList *varlist, const ProStringList &value)
{
foreach (const ProString &str, value)
if (!str.isEmpty() && !varlist->contains(str))
varlist->append(str);
}
static void removeAll(ProStringList *varlist, const ProString &value)
{
for (int i = varlist->size(); --i >= 0; )
if (varlist->at(i) == value)
varlist->remove(i);
}
void QMakeEvaluator::removeEach(ProStringList *varlist, const ProStringList &value)
{
foreach (const ProString &str, value)
if (!str.isEmpty())
removeAll(varlist, str);
}
static void replaceInList(ProStringList *varlist,
const QRegExp &regexp, const QString &replace, bool global, QString &tmp)
{
......@@ -918,24 +890,24 @@ void QMakeEvaluator::visitProVariable(
switch (tok) {
default: // whatever - cannot happen
case TokAssign: // =
zipEmpty(&varVal);
varVal.removeEmpty();
// FIXME: add check+warning about accidental value removal.
// This may be a bit too noisy, though.
m_valuemapStack.top()[varName] = varVal;
debugMsg(2, "assigning");
break;
case TokAppendUnique: // *=
insertUnique(&valuesRef(varName), varVal);
valuesRef(varName).insertUnique(varVal);
debugMsg(2, "appending unique");
break;
case TokAppend: // +=
zipEmpty(&varVal);
varVal.removeEmpty();
valuesRef(varName) += varVal;
debugMsg(2, "appending");
break;
case TokRemove: // -=
if (!m_cumulative) {
removeEach(&valuesRef(varName), varVal);
valuesRef(varName).removeEach(varVal);
} else {
// We are stingy with our values.
}
......
......@@ -240,8 +240,6 @@ public:
#endif
QByteArray getCommandOutput(const QString &args) const;
static void removeEach(ProStringList *varlist, const ProStringList &value);
QMakeEvaluator *m_caller;
#ifdef PROEVALUATOR_CUMULATIVE
bool m_cumulative;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment