move some functions into ProStringList for saner OO design

Change-Id: I60f00f38f459fc9f8eebee9187158e4198fc9546
Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
This commit is contained in:
Oswald Buddenhagen 2015-01-30 19:18:54 +01:00
parent f76d14673f
commit ab74cf09a8
5 changed files with 30 additions and 35 deletions

View File

@ -386,6 +386,20 @@ void ProStringList::removeAll(const char *str)
remove(i); 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() void ProStringList::removeDuplicates()
{ {
int n = size(); int n = size();
@ -405,6 +419,13 @@ void ProStringList::removeDuplicates()
erase(begin() + j, end()); 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) ProStringList::ProStringList(const QStringList &list)
{ {
reserve(list.size()); reserve(list.size());

View File

@ -239,9 +239,13 @@ public:
QString join(const QString &sep) const; QString join(const QString &sep) const;
QString join(QChar sep) const; QString join(QChar sep) const;
void insertUnique(const ProStringList &value);
void removeAll(const ProString &str); void removeAll(const ProString &str);
void removeAll(const char *str); void removeAll(const char *str);
void removeEach(const ProStringList &value);
void removeAt(int idx) { remove(idx); } void removeAt(int idx) { remove(idx); }
void removeEmpty();
void removeDuplicates(); void removeDuplicates();
bool contains(const ProString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; bool contains(const ProString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;

View File

@ -1687,7 +1687,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
if (mode == CacheAdd) if (mode == CacheAdd)
newval += diffval; newval += diffval;
else else
removeEach(&newval, diffval); newval.removeEach(diffval);
} }
if (oldval != newval) { if (oldval != newval) {
if (target != TargetStash || !m_stashfile.isEmpty()) { if (target != TargetStash || !m_stashfile.isEmpty()) {

View File

@ -350,34 +350,6 @@ ProStringList QMakeEvaluator::split_value_list(const QString &vals, const ProFil
return ret; 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, static void replaceInList(ProStringList *varlist,
const QRegExp &regexp, const QString &replace, bool global, QString &tmp) const QRegExp &regexp, const QString &replace, bool global, QString &tmp)
{ {
@ -916,24 +888,24 @@ void QMakeEvaluator::visitProVariable(
switch (tok) { switch (tok) {
default: // whatever - cannot happen default: // whatever - cannot happen
case TokAssign: // = case TokAssign: // =
zipEmpty(&varVal); varVal.removeEmpty();
// FIXME: add check+warning about accidental value removal. // FIXME: add check+warning about accidental value removal.
// This may be a bit too noisy, though. // This may be a bit too noisy, though.
m_valuemapStack.top()[varName] = varVal; m_valuemapStack.top()[varName] = varVal;
debugMsg(2, "assigning"); debugMsg(2, "assigning");
break; break;
case TokAppendUnique: // *= case TokAppendUnique: // *=
insertUnique(&valuesRef(varName), varVal); valuesRef(varName).insertUnique(varVal);
debugMsg(2, "appending unique"); debugMsg(2, "appending unique");
break; break;
case TokAppend: // += case TokAppend: // +=
zipEmpty(&varVal); varVal.removeEmpty();
valuesRef(varName) += varVal; valuesRef(varName) += varVal;
debugMsg(2, "appending"); debugMsg(2, "appending");
break; break;
case TokRemove: // -= case TokRemove: // -=
if (!m_cumulative) { if (!m_cumulative) {
removeEach(&valuesRef(varName), varVal); valuesRef(varName).removeEach(varVal);
} else { } else {
// We are stingy with our values. // We are stingy with our values.
} }

View File

@ -243,8 +243,6 @@ public:
#endif #endif
QByteArray getCommandOutput(const QString &args) const; QByteArray getCommandOutput(const QString &args) const;
static void removeEach(ProStringList *varlist, const ProStringList &value);
QMakeEvaluator *m_caller; QMakeEvaluator *m_caller;
#ifdef PROEVALUATOR_CUMULATIVE #ifdef PROEVALUATOR_CUMULATIVE
bool m_cumulative; bool m_cumulative;