From e013f3fbcf3d48ab962a667f9b0e465fe2f3ab93 Mon Sep 17 00:00:00 2001 From: Thomas Zander Date: Mon, 10 Aug 2009 13:10:02 +0200 Subject: [PATCH] Properly print the end-of-line-has-space warnings --- src/hunks/File.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/hunks/File.cpp b/src/hunks/File.cpp index fd746b6..afb5088 100644 --- a/src/hunks/File.cpp +++ b/src/hunks/File.cpp @@ -463,18 +463,23 @@ void File::outputWhatsChanged(QTextStream &out, Configuration &config, bool prin config.normalColor(out); } else { - QString string = QString::fromLocal8Bit(patch); - const bool trailingLinefeed = string.length() > 1 && string[string.length()-1].unicode() == '\n'; - if (config.colorTerm() && trailingLinefeed) - string = string.left(string.length()-1); - out << string; - if (config.colorTerm() && (!trailingLinefeed || string[string.length()-1].isSpace())) { - config.colorize2(out); - out << "$\n"; - config.normalColor(out); + // per line. + const char *data = patch.constData(); + int lineStart = 0; + for (int index = 0;index < patch.count(); ++index) { + if (patch[index] == '\n' || patch[index] == '\r') { // next line! + QString string = QString::fromLocal8Bit(data + lineStart, index - lineStart); + out << string; + if (config.colorTerm() && string[string.length()-1].isSpace()) { + config.colorize2(out); + out << "$\n"; + config.normalColor(out); + } else { + out << "\n"; + } + lineStart = index+1; + } } - else - out << "\n"; } } } -- 2.11.4.GIT