NOISSUE Revert INI parser back to single pass

This commit is contained in:
janrupf 2019-06-18 13:16:26 +02:00 committed by Petr Mrázek
parent f87c890912
commit d21700ee91

View File

@ -28,20 +28,53 @@ INIFile::INIFile()
QString INIFile::unescape(QString orig) QString INIFile::unescape(QString orig)
{ {
return orig QString out;
.replace("\\#", "#") QChar prev = 0;
.replace("\\t", "\t") for(auto c: orig)
.replace("\\n", "\n") {
.replace("\\\\", "\\"); if(prev == '\\')
{
if(c == 'n')
out += '\n';
else if(c == 't')
out += '\t';
else if(c == '#')
out += '#';
else
out += c;
prev = 0;
}
else
{
if(c == '\\')
{
prev = c;
continue;
}
out += c;
prev = 0;
}
}
return out;
} }
QString INIFile::escape(QString orig) QString INIFile::escape(QString orig)
{ {
return orig QString out;
.replace('\\', "\\\\") for(auto c: orig)
.replace('\n', "\\n") {
.replace('\t', "\\t") if(c == '\n')
.replace('#', "\\#"); out += "\\n";
else if (c == '\t')
out += "\\t";
else if(c == '\\')
out += "\\\\";
else if(c == '#')
out += "\\#";
else
out += c;
}
return out;
} }
bool INIFile::saveFile(QString fileName) bool INIFile::saveFile(QString fileName)