forked from qt-creator/qt-creator
ProWriter: Remove foreach and forever
Change-Id: I817cbab3b126d2e246a00c36bf3ecfb138dffdbe Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
committed by
André Hartmann
parent
406336bab7
commit
456bcc2da8
@@ -27,6 +27,8 @@
|
|||||||
#include "prowriter.h"
|
#include "prowriter.h"
|
||||||
#include "proitems.h"
|
#include "proitems.h"
|
||||||
|
|
||||||
|
#include <utils/algorithm.h>
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QRegExp>
|
#include <QRegExp>
|
||||||
#include <QPair>
|
#include <QPair>
|
||||||
@@ -87,7 +89,7 @@ static void skipBlock(const ushort *&tokPtr)
|
|||||||
static void skipExpression(const ushort *&pTokPtr, int &lineNo)
|
static void skipExpression(const ushort *&pTokPtr, int &lineNo)
|
||||||
{
|
{
|
||||||
const ushort *tokPtr = pTokPtr;
|
const ushort *tokPtr = pTokPtr;
|
||||||
forever {
|
for (;;) {
|
||||||
ushort tok = *tokPtr++;
|
ushort tok = *tokPtr++;
|
||||||
switch (tok) {
|
switch (tok) {
|
||||||
case TokLine:
|
case TokLine:
|
||||||
@@ -323,7 +325,7 @@ void ProWriter::putVarValues(ProFile *profile, QStringList *lines, const QString
|
|||||||
if (eqs >= 0) // If this is not true, we mess up the file a bit.
|
if (eqs >= 0) // If this is not true, we mess up the file a bit.
|
||||||
line.truncate(eqs + 1);
|
line.truncate(eqs + 1);
|
||||||
// put new values
|
// put new values
|
||||||
foreach (const QString &v, values) {
|
for (const QString &v : values) {
|
||||||
line += ((flags & MultiLine) ? QLatin1String(" \\\n") + effectiveContIndent(contInfo)
|
line += ((flags & MultiLine) ? QLatin1String(" \\\n") + effectiveContIndent(contInfo)
|
||||||
: QString::fromLatin1(" ")) + v;
|
: QString::fromLatin1(" ")) + v;
|
||||||
}
|
}
|
||||||
@@ -386,9 +388,10 @@ void ProWriter::putVarValues(ProFile *profile, QStringList *lines, const QString
|
|||||||
if (lNo != scopeStart + 1)
|
if (lNo != scopeStart + 1)
|
||||||
added += QLatin1Char('\n');
|
added += QLatin1Char('\n');
|
||||||
added += indent + var + QLatin1String((flags & AppendOperator) ? " +=" : " =");
|
added += indent + var + QLatin1String((flags & AppendOperator) ? " +=" : " =");
|
||||||
foreach (const QString &v, values)
|
for (const QString &v : values) {
|
||||||
added += ((flags & MultiLine) ? QLatin1String(" \\\n") + effectiveContIndent(contInfo)
|
added += ((flags & MultiLine) ? QLatin1String(" \\\n") + effectiveContIndent(contInfo)
|
||||||
: QString::fromLatin1(" ")) + v;
|
: QString::fromLatin1(" ")) + v;
|
||||||
|
}
|
||||||
if (!scope.isEmpty() && scopeStart < 0)
|
if (!scope.isEmpty() && scopeStart < 0)
|
||||||
added += QLatin1String("\n}");
|
added += QLatin1String("\n}");
|
||||||
lines->insert(lNo, added);
|
lines->insert(lNo, added);
|
||||||
@@ -403,7 +406,7 @@ void ProWriter::addFiles(ProFile *profile, QStringList *lines, const QStringList
|
|||||||
QDir baseDir = QFileInfo(profile->fileName()).absoluteDir();
|
QDir baseDir = QFileInfo(profile->fileName()).absoluteDir();
|
||||||
if (profile->fileName().endsWith(QLatin1String(".pri")))
|
if (profile->fileName().endsWith(QLatin1String(".pri")))
|
||||||
prefixPwd = QLatin1String("$$PWD/");
|
prefixPwd = QLatin1String("$$PWD/");
|
||||||
foreach (const QString &v, values)
|
for (const QString &v : values)
|
||||||
valuesToWrite << (prefixPwd + baseDir.relativeFilePath(v));
|
valuesToWrite << (prefixPwd + baseDir.relativeFilePath(v));
|
||||||
|
|
||||||
putVarValues(profile, lines, valuesToWrite, var, AppendValues | MultiLine | AppendOperator,
|
putVarValues(profile, lines, valuesToWrite, var, AppendValues | MultiLine | AppendOperator,
|
||||||
@@ -451,7 +454,7 @@ QList<int> ProWriter::removeVarValues(ProFile *profile, QStringList *lines,
|
|||||||
|
|
||||||
// This code expects proVars to be sorted by the variables' appearance in the file.
|
// This code expects proVars to be sorted by the variables' appearance in the file.
|
||||||
int delta = 1;
|
int delta = 1;
|
||||||
foreach (int ln, varLines) {
|
for (int ln : qAsConst(varLines)) {
|
||||||
bool first = true;
|
bool first = true;
|
||||||
int lineNo = ln - delta;
|
int lineNo = ln - delta;
|
||||||
typedef QPair<int, int> ContPos;
|
typedef QPair<int, int> ContPos;
|
||||||
@@ -465,7 +468,7 @@ QList<int> ProWriter::removeVarValues(ProFile *profile, QStringList *lines,
|
|||||||
if (idx >= 0)
|
if (idx >= 0)
|
||||||
lineLen = idx;
|
lineLen = idx;
|
||||||
QChar *chars = line.data();
|
QChar *chars = line.data();
|
||||||
forever {
|
for (;;) {
|
||||||
if (!lineLen) {
|
if (!lineLen) {
|
||||||
if (idx >= 0)
|
if (idx >= 0)
|
||||||
goto nextLine;
|
goto nextLine;
|
||||||
@@ -528,7 +531,7 @@ QList<int> ProWriter::removeVarValues(ProFile *profile, QStringList *lines,
|
|||||||
// Entries existed, but were all removed
|
// Entries existed, but were all removed
|
||||||
if (contCol < 0) {
|
if (contCol < 0) {
|
||||||
// This is the last line, so clear continuations leading to it
|
// This is the last line, so clear continuations leading to it
|
||||||
foreach (const ContPos &pos, contPos) {
|
for (const ContPos &pos : qAsConst(contPos)) {
|
||||||
QString &bline = (*lines)[pos.first];
|
QString &bline = (*lines)[pos.first];
|
||||||
bline.remove(pos.second, 1);
|
bline.remove(pos.second, 1);
|
||||||
if (pos.second == bline.length())
|
if (pos.second == bline.length())
|
||||||
@@ -562,12 +565,12 @@ QStringList ProWriter::removeFiles(ProFile *profile, QStringList *lines,
|
|||||||
// This is a tad stupid - basically, it can remove only entries which
|
// This is a tad stupid - basically, it can remove only entries which
|
||||||
// the above code added.
|
// the above code added.
|
||||||
QStringList valuesToFind;
|
QStringList valuesToFind;
|
||||||
foreach (const QString &absoluteFilePath, values)
|
for (const QString &absoluteFilePath : values)
|
||||||
valuesToFind << proFileDir.relativeFilePath(absoluteFilePath);
|
valuesToFind << proFileDir.relativeFilePath(absoluteFilePath);
|
||||||
|
|
||||||
QStringList notYetChanged;
|
const QStringList notYetChanged =
|
||||||
foreach (int i, removeVarValues(profile, lines, valuesToFind, vars))
|
Utils::transform(removeVarValues(profile, lines, valuesToFind, vars),
|
||||||
notYetChanged.append(values.at(i));
|
[values](int i) { return values.at(i); });
|
||||||
|
|
||||||
if (!profile->fileName().endsWith(QLatin1String(".pri")))
|
if (!profile->fileName().endsWith(QLatin1String(".pri")))
|
||||||
return notYetChanged;
|
return notYetChanged;
|
||||||
@@ -578,12 +581,12 @@ QStringList ProWriter::removeFiles(ProFile *profile, QStringList *lines,
|
|||||||
valuesToFind.clear();
|
valuesToFind.clear();
|
||||||
const QDir baseDir = QFileInfo(profile->fileName()).absoluteDir();
|
const QDir baseDir = QFileInfo(profile->fileName()).absoluteDir();
|
||||||
const QString prefixPwd = QLatin1String("$$PWD/");
|
const QString prefixPwd = QLatin1String("$$PWD/");
|
||||||
foreach (const QString &absoluteFilePath, notYetChanged)
|
for (const QString &absoluteFilePath : notYetChanged)
|
||||||
valuesToFind << (prefixPwd + baseDir.relativeFilePath(absoluteFilePath));
|
valuesToFind << (prefixPwd + baseDir.relativeFilePath(absoluteFilePath));
|
||||||
|
|
||||||
QStringList notChanged;
|
const QStringList notChanged =
|
||||||
foreach (int i, removeVarValues(profile, lines, valuesToFind, vars))
|
Utils::transform(removeVarValues(profile, lines, valuesToFind, vars),
|
||||||
notChanged.append(notYetChanged.at(i));
|
[notYetChanged](int i) { return notYetChanged.at(i); });
|
||||||
|
|
||||||
return notChanged;
|
return notChanged;
|
||||||
}
|
}
|
||||||
|
@@ -3,6 +3,7 @@ import qbs
|
|||||||
QtcAutotest {
|
QtcAutotest {
|
||||||
name: "ProFileWriter autotest"
|
name: "ProFileWriter autotest"
|
||||||
Depends { name: "Qt.xml" }
|
Depends { name: "Qt.xml" }
|
||||||
|
Depends { name: "Utils"; cpp.link: false }
|
||||||
Group {
|
Group {
|
||||||
name: "Sources from ProParser"
|
name: "Sources from ProParser"
|
||||||
id: proParserGroup
|
id: proParserGroup
|
||||||
|
Reference in New Issue
Block a user