summaryrefslogtreecommitdiffstats
path: root/depends/settings/inifile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'depends/settings/inifile.cpp')
-rw-r--r--depends/settings/inifile.cpp48
1 files changed, 40 insertions, 8 deletions
diff --git a/depends/settings/inifile.cpp b/depends/settings/inifile.cpp
index 1170f0b1..b2098913 100644
--- a/depends/settings/inifile.cpp
+++ b/depends/settings/inifile.cpp
@@ -25,17 +25,49 @@ INIFile::INIFile()
QString INIFile::unescape(QString orig)
{
- orig.replace("\\n", "\n");
- orig.replace("\\t", "\t");
- orig.replace("\\\\", "\\");
- return orig;
+ QString out;
+ QChar prev = 0;
+ for(auto c: orig)
+ {
+ if(prev == '\\')
+ {
+ if(c == 'n')
+ out += '\n';
+ else if (c == 't')
+ out += '\t';
+ else
+ out += c;
+ prev = 0;
+ }
+ else
+ {
+ if(c == '\\')
+ {
+ prev = c;
+ continue;
+ }
+ out += c;
+ prev = 0;
+ }
+ }
+ return out;
}
+
QString INIFile::escape(QString orig)
{
- orig.replace("\\", "\\\\");
- orig.replace("\n", "\\n");
- orig.replace("\t", "\\t");
- return orig;
+ QString out;
+ for(auto c: orig)
+ {
+ if(c == '\n')
+ out += "\\n";
+ else if (c == '\t')
+ out += "\\t";
+ else if(c == '\\')
+ out += "\\\\";
+ else
+ out += c;
+ }
+ return out;
}
bool INIFile::saveFile(QString fileName)