diff src/mainwindow.cpp @ 606:372b191247da

Add carriage return to hgignore file before new material, if it didn't end with one before
author Chris Cannam
date Tue, 03 Jul 2012 11:39:03 +0100
parents 10ef94e51f44
children d35ed7488ccd
line wrap: on
line diff
--- a/src/mainwindow.cpp	Tue Jul 03 11:22:10 2012 +0100
+++ b/src/mainwindow.cpp	Tue Jul 03 11:39:03 2012 +0100
@@ -766,9 +766,12 @@
 
     f.open(QFile::ReadOnly);
     bool glob = false;
+    bool cr = false; // whether the last line examined ended with a CR
     while (!f.atEnd()) {
         QByteArray ba = f.readLine();
-        QString s = QString::fromLocal8Bit(ba).trimmed();
+        QString s = QString::fromLocal8Bit(ba);
+        cr = (s.endsWith('\n') || s.endsWith('\r'));
+        s = s.trimmed();
         if (s.startsWith("syntax:")) {
             if (s.endsWith("glob")) {
                 glob = true;
@@ -782,6 +785,10 @@
     f.open(QFile::Append);
     QTextStream out(&f);
 
+    if (!cr) {
+        out << endl;
+    }
+
     if (!glob) {
         out << "syntax: glob" << endl;
     }