Properly print the end-of-line-has-space warnings
authorThomas Zander <thomas.zander@trolltech.com>
Mon, 10 Aug 2009 11:10:02 +0000 (10 13:10 +0200)
committerThomas Zander <thomas.zander@trolltech.com>
Mon, 10 Aug 2009 11:10:02 +0000 (10 13:10 +0200)
src/hunks/File.cpp

index fd746b6..afb5088 100644 (file)
@@ -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";
             }
         }
     }