summaryrefslogtreecommitdiffstats
path: root/api/logic
diff options
context:
space:
mode:
Diffstat (limited to 'api/logic')
-rw-r--r--api/logic/settings/INIFile.cpp53
1 files changed, 43 insertions, 10 deletions
diff --git a/api/logic/settings/INIFile.cpp b/api/logic/settings/INIFile.cpp
index 04e9aa2c..ff6d5cf3 100644
--- a/api/logic/settings/INIFile.cpp
+++ b/api/logic/settings/INIFile.cpp
@@ -28,20 +28,53 @@ INIFile::INIFile()
QString INIFile::unescape(QString orig)
{
- return orig
- .replace("\\#", "#")
- .replace("\\t", "\t")
- .replace("\\n", "\n")
- .replace("\\\\", "\\");
+ QString out;
+ QChar prev = 0;
+ for(auto c: orig)
+ {
+ 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)
{
- return orig
- .replace('\\', "\\\\")
- .replace('\n', "\\n")
- .replace('\t', "\\t")
- .replace('#', "\\#");
+ QString out;
+ for(auto c: orig)
+ {
+ if(c == '\n')
+ 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)