Use alternative way of checking for file end. Also refactor this code a bit.
authorunc0rr
Fri, 23 Nov 2012 16:16:02 +0400 (2012-11-23)
changeset 8110 9f5fe3fc9d16
parent 8107 ee21b816394f
child 8112 d85dc8a8f41c
Use alternative way of checking for file end. Also refactor this code a bit.
QTfrontend/util/namegen.cpp
--- a/QTfrontend/util/namegen.cpp	Fri Nov 23 13:08:50 2012 +0400
+++ b/QTfrontend/util/namegen.cpp	Fri Nov 23 16:16:02 2012 +0400
@@ -125,22 +125,21 @@
     QStringList list;
 
     // find .txt to load the names from
-    QFile * file = new QFile(QString("physfs://Names/%1.txt").arg(filename));
+    QFile file(QString("physfs://Names/%1.txt").arg(filename));
 
-    if (file->exists() && file->open(QIODevice::ReadOnly | QIODevice::Text))
+    if (file.open(QIODevice::ReadOnly | QIODevice::Text))
     {
-        QTextStream in(file);
-        while (!in.atEnd())
+        QTextStream in(&file);
+        QString line;
+        do
         {
-            QString line = in.readLine();
+            line = in.readLine();
+
             if(!line.isEmpty())
                 list.append(line);
-        }
+        } while (!line.isNull());
     }
 
-    // this QFile isn't needed any further
-    delete file;
-
     if (list.size() == 0)
         list.append(filename);
 
@@ -153,22 +152,21 @@
     QStringList list;
 
     // find .cfg to load the dicts from
-    QFile * file = new QFile(QString("physfs://Names/%1.cfg").arg(hatname));
+    QFile file(QString("physfs://Names/%1.cfg").arg(hatname));
 
-    if (file->exists() && file->open(QIODevice::ReadOnly | QIODevice::Text))
+    if (file.open(QIODevice::ReadOnly | QIODevice::Text))
     {
-        QTextStream in(file);
-        while (!in.atEnd())
+        QTextStream in(&file);
+        QString line;
+        do
         {
-            QString line = in.readLine();
+            line = in.readLine();
+
             if(!line.isEmpty())
                 list.append(line);
-        }
+        } while (!line.isNull());
     }
 
-    // this QFile isn't needed any further
-    delete file;
-
     if (list.size() == 0)
         list.append(QString("generic"));