StelIniParser.cpp   StelIniParser.cpp 
skipping to change at line 32 skipping to change at line 32
#include <QSettings> #include <QSettings>
#include <QString> #include <QString>
#include <QVariant> #include <QVariant>
#include <QStringList> #include <QStringList>
#include <QIODevice> #include <QIODevice>
#include <QRegExp> #include <QRegExp>
bool readStelIniFile(QIODevice &device, QSettings::SettingsMap &map) bool readStelIniFile(QIODevice &device, QSettings::SettingsMap &map)
{ {
// Is this the right conversion? // Is this the right conversion?
QString data = QString::fromUtf8(device.readAll().data()); const QString& data = QString::fromUtf8(device.readAll().data());
// Split by a RE which should match any platform's line breaking rul es // Split by a RE which should match any platform's line breaking rul es
QStringList lines = data.split(QRegExp("[\\n\\r]+"), QString::SkipEm QRegExp matchLbr("[\\n\\r]+");
ptyParts); const QStringList& lines = data.split(matchLbr, QString::SkipEmptyPa
rts);
QString currentSection = ""; QString currentSection = "";
QRegExp sectionRe("^\\[(.+)\\]$"); QRegExp sectionRe("^\\[(.+)\\]$");
QRegExp keyRe("^([^=]+)\\s*=\\s*(.+)$"); QRegExp keyRe("^([^=]+)\\s*=\\s*(.+)$");
QRegExp cleanComment("#.*$");
QRegExp cleanWhiteSpaces("^\\s+");
QRegExp reg1("\\s+$");
for(int i=0; i<lines.size(); i++) for(int i=0; i<lines.size(); i++)
{ {
QString l = lines.at(i); QString l = lines.at(i);
l.replace(QRegExp("#.*$"), ""); // clean comments l.replace(cleanComment, ""); // clean comments
l.replace(QRegExp("^\\s+"), ""); // clean whitespace l.replace(cleanWhiteSpaces, ""); // clean whitespace
l.replace(QRegExp("\\s+$"), ""); l.replace(reg1, "");
// If it's a section marker set the section variable // If it's a section marker set the section variable
if(sectionRe.exactMatch(l)) if (sectionRe.exactMatch(l))
currentSection = sectionRe.cap(1); currentSection = sectionRe.cap(1);
// Otherwise only process if it macthes an re which looks li ke: key = value // Otherwise only process if it macthes an re which looks li ke: key = value
else if (keyRe.exactMatch(l)) else if (keyRe.exactMatch(l))
{ {
// Let REs do the work for us exatracting the key an d value // Let REs do the work for us exatracting the key an d value
// and cleaning them up by removing whitespace // and cleaning them up by removing whitespace
QString k = keyRe.cap(1); QString v = keyRe.cap(2); QString k = keyRe.cap(1);
v.replace(QRegExp("^\\s+"), ""); k.replace(QRegExp(" QString v = keyRe.cap(2);
\\s+$"), ""); v.replace(cleanWhiteSpaces, "");
k.replace(reg1, "");
// keys with no section should have no leading /, so only // keys with no section should have no leading /, so only
// add it when there is a valid section. // add it when there is a valid section.
if (currentSection != "") if (currentSection != "")
k = currentSection + "/" + k; k = currentSection + "/" + k;
// Set the map item. // Set the map item.
map[k] = QVariant(v); map[k] = QVariant(v);
} }
} }
 End of changes. 7 change blocks. 
10 lines changed or deleted 16 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/