Utils: Move QtcProcess::normalizeNewlines() into StringUtils

Change-Id: I515d2554497d5c27fd75e50c80ba373fbbe8dcb5
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Jarek Kobus
2023-01-27 18:37:27 +01:00
parent 825fea1fe9
commit 6758b5f69f
5 changed files with 20 additions and 20 deletions

View File

@@ -8,7 +8,7 @@
#include "fileinprojectfinder.h"
#include "link.h"
#include "qtcassert.h"
#include "qtcprocess.h"
#include "stringutils.h"
#include "theme/theme.h"
#include <QDir>
@@ -624,7 +624,7 @@ void OutputFormatter::appendMessage(const QString &text, OutputFormat format)
d->prependCarriageReturn = false;
out.prepend('\r');
}
out = QtcProcess::normalizeNewlines(out);
out = Utils::normalizeNewlines(out);
if (out.endsWith('\r')) {
d->prependCarriageReturn = true;
out.chop(1);

View File

@@ -11,6 +11,7 @@
#include "launchersocket.h"
#include "processreaper.h"
#include "processutils.h"
#include "stringutils.h"
#include "terminalprocess_p.h"
#include "threadutils.h"
@@ -1305,17 +1306,6 @@ bool QtcProcess::readDataFromProcess(QByteArray *stdOut, QByteArray *stdErr, int
return finished;
}
QString QtcProcess::normalizeNewlines(const QString &text)
{
QString res = text;
const auto newEnd = std::unique(res.begin(), res.end(), [](const QChar c1, const QChar c2) {
return c1 == '\r' && c2 == '\r'; // QTCREATORBUG-24556
});
res.chop(std::distance(newEnd, res.end()));
res.replace("\r\n", "\n");
return res;
}
ProcessResult QtcProcess::result() const
{
return d->m_result;
@@ -1593,12 +1583,12 @@ QString QtcProcess::stdErr() const
QString QtcProcess::cleanedStdOut() const
{
return normalizeNewlines(stdOut());
return Utils::normalizeNewlines(stdOut());
}
QString QtcProcess::cleanedStdErr() const
{
return normalizeNewlines(stdErr());
return Utils::normalizeNewlines(stdErr());
}
static QStringList splitLines(const QString &text)
@@ -1681,7 +1671,7 @@ void ChannelBuffer::append(const QByteArray &text)
break;
// Get completed lines and remove them from the incompleteLinesBuffer:
const QString line = QtcProcess::normalizeNewlines(incompleteLineBuffer.left(pos + 1));
const QString line = Utils::normalizeNewlines(incompleteLineBuffer.left(pos + 1));
incompleteLineBuffer = incompleteLineBuffer.mid(pos + 1);
QTC_ASSERT(outputCallback, return);

View File

@@ -127,10 +127,6 @@ public:
// These (or some of them) may be potentially moved outside of the class.
// For some we may aggregate in another public utils class (or subclass of QtcProcess)?
// TODO: How below method relates to QtcProcess?
// Action: move/merge it somewhere else
static QString normalizeNewlines(const QString &text);
// TODO: Unused currently? Should it serve as a compartment for contrary of remoteEnvironment?
static Environment systemEnvironmentForBinary(const FilePath &filePath);

View File

@@ -443,6 +443,17 @@ QTCREATOR_UTILS_EXPORT QStringView chopIfEndsWith(QStringView str, QChar c)
return str;
}
QTCREATOR_UTILS_EXPORT QString normalizeNewlines(const QString &text)
{
QString res = text;
const auto newEnd = std::unique(res.begin(), res.end(), [](const QChar c1, const QChar c2) {
return c1 == '\r' && c2 == '\r'; // QTCREATORBUG-24556
});
res.chop(std::distance(newEnd, res.end()));
res.replace("\r\n", "\n");
return res;
}
QTCREATOR_UTILS_EXPORT QString appendHelper(const QString &base, int n)
{
return base + QString::number(n);

View File

@@ -107,4 +107,7 @@ QTCREATOR_UTILS_EXPORT void setClipboardAndSelection(const QString &text);
QTCREATOR_UTILS_EXPORT QString chopIfEndsWith(QString str, QChar c);
QTCREATOR_UTILS_EXPORT QStringView chopIfEndsWith(QStringView str, QChar c);
QTCREATOR_UTILS_EXPORT QString normalizeNewlines(const QString &text);
} // namespace Utils