Introduce Utils::SynchronousProcess::normalizeNewlines

Replaces \r\n? with \n.

Some console applications (e.g. git-push, git-rebase) use \r alone to
move the cursor to the line's beginning. This should be replaced by \n
rather than just be erased.

Change-Id: I8d614d2b471e59decdbfa7f173ffa7fbdb11759b
Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
Orgad Shaneh
2013-08-02 12:15:04 +03:00
committed by Orgad Shaneh
parent 1b13122cd1
commit 208aeb79ed
8 changed files with 43 additions and 27 deletions

View File

@@ -476,8 +476,8 @@ void SynchronousProcess::stdErrReady()
QString SynchronousProcess::convertOutput(const QByteArray &ba) const
{
QString output = d->m_codec ? d->m_codec->toUnicode(ba) : QString::fromLocal8Bit(ba.constData(), ba.size());
return output.remove(QLatin1Char('\r'));
return normalizeNewlines(d->m_codec ? d->m_codec->toUnicode(ba)
: QString::fromLocal8Bit(ba.constData(), ba.size()));
}
void SynchronousProcess::processStdOut(bool emitSignals)
@@ -676,6 +676,25 @@ QString SynchronousProcess::locateBinary(const QString &path, const QString &bin
return QString();
}
QString SynchronousProcess::normalizeNewlines(const QString &text)
{
const QChar cr(QLatin1Char('\r'));
const QChar lf(QLatin1Char('\n'));
QString res;
res.reserve(text.size());
for (int i = 0, count = text.size(); i < count; ++i) {
const QChar c = text.at(i);
if (c == cr) {
res += lf;
if (i + 1 < count && text.at(i + 1) == lf)
++i;
} else {
res += c;
}
}
return res;
}
QString SynchronousProcess::locateBinary(const QString &binary)
{
const QByteArray path = qgetenv("PATH");