From 1bda0b3ec1188552a6c3fae810947a0bce6783fc Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Fri, 7 Mar 2014 14:23:40 +0100 Subject: [PATCH] Vcs: Leave lone CRs alone when normalizing line endings Change-Id: I426d850d96fff724c718471a5cab262ce0bf7d05 Reviewed-by: Orgad Shaneh Reviewed-by: Tobias Hunger --- src/libs/utils/synchronousprocess.cpp | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/libs/utils/synchronousprocess.cpp b/src/libs/utils/synchronousprocess.cpp index bb31af4f069..5ede9bcc6b4 100644 --- a/src/libs/utils/synchronousprocess.cpp +++ b/src/libs/utils/synchronousprocess.cpp @@ -188,7 +188,8 @@ void ChannelBuffer::clearForRun() QString ChannelBuffer::linesRead() { // Any new lines? - const int lastLineIndex = data.lastIndexOf(QLatin1Char('\n')); + const int lastLineIndex = qMax(data.lastIndexOf(QLatin1Char('\n')), + data.lastIndexOf(QLatin1Char('\r'))); if (lastLineIndex == -1 || lastLineIndex <= bufferPos) return QString(); const int nextBufferPos = lastLineIndex + 1; @@ -719,20 +720,8 @@ QString SynchronousProcess::locateBinary(const QString &path, const QString &bin 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; - } - } + QString res = text; + res.replace(QLatin1String("\r\n"), QLatin1String("\n")); return res; }