forked from qt-creator/qt-creator
ProWriter: Remove QLatin1(Char|String)
Change-Id: I84f564ec5b12e5a397040cd3a132995327526f7d Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
committed by
André Hartmann
parent
88d1d92728
commit
6eac37a7d9
@@ -178,7 +178,7 @@ QString ProWriter::compileScope(const QString &scope)
|
|||||||
if (scope.isEmpty())
|
if (scope.isEmpty())
|
||||||
return QString();
|
return QString();
|
||||||
QMakeParser parser(nullptr, nullptr, nullptr);
|
QMakeParser parser(nullptr, nullptr, nullptr);
|
||||||
ProFile *includeFile = parser.parsedProBlock(QStringRef(&scope), 0, QLatin1String("no-file"), 1);
|
ProFile *includeFile = parser.parsedProBlock(QStringRef(&scope), 0, "no-file", 1);
|
||||||
if (!includeFile)
|
if (!includeFile)
|
||||||
return QString();
|
return QString();
|
||||||
const QString result = includeFile->items();
|
const QString result = includeFile->items();
|
||||||
@@ -321,13 +321,13 @@ void ProWriter::putVarValues(ProFile *profile, QStringList *lines, const QString
|
|||||||
lines->erase(lines->begin() + lineNo + 1, lines->begin() + contInfo.lineNo);
|
lines->erase(lines->begin() + lineNo + 1, lines->begin() + contInfo.lineNo);
|
||||||
// remove rest of the line
|
// remove rest of the line
|
||||||
QString &line = (*lines)[lineNo];
|
QString &line = (*lines)[lineNo];
|
||||||
int eqs = line.indexOf(QLatin1Char('='));
|
int eqs = line.indexOf('=');
|
||||||
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
|
||||||
for (const QString &v : values) {
|
for (const QString &v : values) {
|
||||||
line += ((flags & MultiLine) ? QLatin1String(" \\\n") + effectiveContIndent(contInfo)
|
line += ((flags & MultiLine) ? QString(" \\\n") + effectiveContIndent(contInfo)
|
||||||
: QString::fromLatin1(" ")) + v;
|
: QString(" ")) + v;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const ContinuationInfo contInfo = skipContLines(lines, lineNo, false);
|
const ContinuationInfo contInfo = skipContLines(lines, lineNo, false);
|
||||||
@@ -354,15 +354,14 @@ void ProWriter::putVarValues(ProFile *profile, QStringList *lines, const QString
|
|||||||
ContinuationInfo contInfo;
|
ContinuationInfo contInfo;
|
||||||
if (!scope.isEmpty()) {
|
if (!scope.isEmpty()) {
|
||||||
if (scopeStart < 0) {
|
if (scopeStart < 0) {
|
||||||
added = QLatin1Char('\n') + scope + QLatin1String(" {");
|
added = '\n' + scope + " {";
|
||||||
} else {
|
} else {
|
||||||
// TODO use anchoredPattern() once Qt 5.12 is mandatory
|
// TODO use anchoredPattern() once Qt 5.12 is mandatory
|
||||||
const QRegularExpression rx("\\A(\\s*" + scope + "\\s*:\\s*)[^\\s{].*\\z");
|
const QRegularExpression rx("\\A(\\s*" + scope + "\\s*:\\s*)[^\\s{].*\\z");
|
||||||
const QRegularExpressionMatch match(rx.match(lines->at(scopeStart)));
|
const QRegularExpressionMatch match(rx.match(lines->at(scopeStart)));
|
||||||
if (match.hasMatch()) {
|
if (match.hasMatch()) {
|
||||||
(*lines)[scopeStart].replace(0, match.captured(1).length(),
|
(*lines)[scopeStart].replace(0, match.captured(1).length(),
|
||||||
QString(scope + QLatin1String(" {\n")
|
scope + " {\n" + continuationIndent);
|
||||||
+ continuationIndent));
|
|
||||||
contInfo = skipContLines(lines, scopeStart, false);
|
contInfo = skipContLines(lines, scopeStart, false);
|
||||||
lNo = contInfo.lineNo;
|
lNo = contInfo.lineNo;
|
||||||
scopeStart = -1;
|
scopeStart = -1;
|
||||||
@@ -376,26 +375,26 @@ void ProWriter::putVarValues(ProFile *profile, QStringList *lines, const QString
|
|||||||
const QString &line = (*lines).at(lNo);
|
const QString &line = (*lines).at(lNo);
|
||||||
for (int i = 0; i < line.size(); i++)
|
for (int i = 0; i < line.size(); i++)
|
||||||
// This is pretty sick, but qmake does pretty much the same ...
|
// This is pretty sick, but qmake does pretty much the same ...
|
||||||
if (line.at(i) == QLatin1Char('{')) {
|
if (line.at(i) == '{') {
|
||||||
++braces;
|
++braces;
|
||||||
} else if (line.at(i) == QLatin1Char('}')) {
|
} else if (line.at(i) == '}') {
|
||||||
if (!--braces)
|
if (!--braces)
|
||||||
break;
|
break;
|
||||||
} else if (line.at(i) == QLatin1Char('#')) {
|
} else if (line.at(i) == '#') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (braces && ++lNo < lines->size());
|
} while (braces && ++lNo < lines->size());
|
||||||
}
|
}
|
||||||
for (; lNo > scopeStart + 1 && lines->at(lNo - 1).isEmpty(); lNo--) ;
|
for (; lNo > scopeStart + 1 && lines->at(lNo - 1).isEmpty(); lNo--) ;
|
||||||
if (lNo != scopeStart + 1)
|
if (lNo != scopeStart + 1)
|
||||||
added += QLatin1Char('\n');
|
added += '\n';
|
||||||
added += indent + var + QLatin1String((flags & AppendOperator) ? " +=" : " =");
|
added += indent + var + ((flags & AppendOperator) ? " +=" : " =");
|
||||||
for (const QString &v : values) {
|
for (const QString &v : values) {
|
||||||
added += ((flags & MultiLine) ? QLatin1String(" \\\n") + effectiveContIndent(contInfo)
|
added += ((flags & MultiLine) ? QString(" \\\n") + effectiveContIndent(contInfo)
|
||||||
: QString::fromLatin1(" ")) + v;
|
: QString(" ")) + v;
|
||||||
}
|
}
|
||||||
if (!scope.isEmpty() && scopeStart < 0)
|
if (!scope.isEmpty() && scopeStart < 0)
|
||||||
added += QLatin1String("\n}");
|
added += "\n}";
|
||||||
lines->insert(lNo, added);
|
lines->insert(lNo, added);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -406,8 +405,8 @@ void ProWriter::addFiles(ProFile *profile, QStringList *lines, const QStringList
|
|||||||
QStringList valuesToWrite;
|
QStringList valuesToWrite;
|
||||||
QString prefixPwd;
|
QString prefixPwd;
|
||||||
QDir baseDir = QFileInfo(profile->fileName()).absoluteDir();
|
QDir baseDir = QFileInfo(profile->fileName()).absoluteDir();
|
||||||
if (profile->fileName().endsWith(QLatin1String(".pri")))
|
if (profile->fileName().endsWith(".pri"))
|
||||||
prefixPwd = QLatin1String("$$PWD/");
|
prefixPwd = "$$PWD/";
|
||||||
for (const QString &v : values)
|
for (const QString &v : values)
|
||||||
valuesToWrite << (prefixPwd + baseDir.relativeFilePath(v));
|
valuesToWrite << (prefixPwd + baseDir.relativeFilePath(v));
|
||||||
|
|
||||||
@@ -466,7 +465,7 @@ QList<int> ProWriter::removeVarValues(ProFile *profile, QStringList *lines,
|
|||||||
int lineLen = line.length();
|
int lineLen = line.length();
|
||||||
bool killed = false;
|
bool killed = false;
|
||||||
bool saved = false;
|
bool saved = false;
|
||||||
int idx = line.indexOf(QLatin1Char('#'));
|
int idx = line.indexOf('#');
|
||||||
if (idx >= 0)
|
if (idx >= 0)
|
||||||
lineLen = idx;
|
lineLen = idx;
|
||||||
QChar *chars = line.data();
|
QChar *chars = line.data();
|
||||||
@@ -477,30 +476,30 @@ QList<int> ProWriter::removeVarValues(ProFile *profile, QStringList *lines,
|
|||||||
goto nextVar;
|
goto nextVar;
|
||||||
}
|
}
|
||||||
QChar c = chars[lineLen - 1];
|
QChar c = chars[lineLen - 1];
|
||||||
if (c != QLatin1Char(' ') && c != QLatin1Char('\t'))
|
if (c != ' ' && c != '\t')
|
||||||
break;
|
break;
|
||||||
lineLen--;
|
lineLen--;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
int contCol = -1;
|
int contCol = -1;
|
||||||
if (chars[lineLen - 1] == QLatin1Char('\\'))
|
if (chars[lineLen - 1] == '\\')
|
||||||
contCol = --lineLen;
|
contCol = --lineLen;
|
||||||
int colNo = 0;
|
int colNo = 0;
|
||||||
if (first) {
|
if (first) {
|
||||||
colNo = line.indexOf(QLatin1Char('=')) + 1;
|
colNo = line.indexOf('=') + 1;
|
||||||
first = false;
|
first = false;
|
||||||
saved = true;
|
saved = true;
|
||||||
}
|
}
|
||||||
while (colNo < lineLen) {
|
while (colNo < lineLen) {
|
||||||
QChar c = chars[colNo];
|
QChar c = chars[colNo];
|
||||||
if (c == QLatin1Char(' ') || c == QLatin1Char('\t')) {
|
if (c == ' ' || c == '\t') {
|
||||||
colNo++;
|
colNo++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int varCol = colNo;
|
int varCol = colNo;
|
||||||
while (colNo < lineLen) {
|
while (colNo < lineLen) {
|
||||||
QChar c = chars[colNo];
|
QChar c = chars[colNo];
|
||||||
if (c == QLatin1Char(' ') || c == QLatin1Char('\t'))
|
if (c == (' ') || c == ('\t'))
|
||||||
break;
|
break;
|
||||||
colNo++;
|
colNo++;
|
||||||
}
|
}
|
||||||
@@ -519,7 +518,7 @@ QList<int> ProWriter::removeVarValues(ProFile *profile, QStringList *lines,
|
|||||||
contCol -= len;
|
contCol -= len;
|
||||||
idx -= len;
|
idx -= len;
|
||||||
if (idx >= 0)
|
if (idx >= 0)
|
||||||
line.insert(idx, QLatin1String("# ") + fn + QLatin1Char(' '));
|
line.insert(idx, "# " + fn + ' ');
|
||||||
chars = line.data();
|
chars = line.data();
|
||||||
killed = true;
|
killed = true;
|
||||||
} else {
|
} else {
|
||||||
@@ -537,8 +536,7 @@ QList<int> ProWriter::removeVarValues(ProFile *profile, QStringList *lines,
|
|||||||
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())
|
||||||
while (bline.endsWith(QLatin1Char(' '))
|
while (bline.endsWith(' ') || bline.endsWith('\t'))
|
||||||
|| bline.endsWith(QLatin1Char('\t')))
|
|
||||||
bline.chop(1);
|
bline.chop(1);
|
||||||
}
|
}
|
||||||
contPos.clear();
|
contPos.clear();
|
||||||
@@ -574,7 +572,7 @@ QStringList ProWriter::removeFiles(ProFile *profile, QStringList *lines,
|
|||||||
Utils::transform(removeVarValues(profile, lines, valuesToFind, vars),
|
Utils::transform(removeVarValues(profile, lines, valuesToFind, vars),
|
||||||
[values](int i) { return values.at(i); });
|
[values](int i) { return values.at(i); });
|
||||||
|
|
||||||
if (!profile->fileName().endsWith(QLatin1String(".pri")))
|
if (!profile->fileName().endsWith(".pri"))
|
||||||
return notYetChanged;
|
return notYetChanged;
|
||||||
|
|
||||||
// If we didn't find them with a relative path to the .pro file
|
// If we didn't find them with a relative path to the .pro file
|
||||||
@@ -582,7 +580,7 @@ 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 = "$$PWD/";
|
||||||
for (const QString &absoluteFilePath : notYetChanged)
|
for (const QString &absoluteFilePath : notYetChanged)
|
||||||
valuesToFind << (prefixPwd + baseDir.relativeFilePath(absoluteFilePath));
|
valuesToFind << (prefixPwd + baseDir.relativeFilePath(absoluteFilePath));
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user