summaryrefslogtreecommitdiffstats
path: root/depends/settings
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2014-03-29 21:16:54 +0100
committerPetr Mrázek <peterix@gmail.com>2014-03-29 21:16:54 +0100
commit5f7a48a35ef2b3951fcc6317802a2cdd63c47b76 (patch)
tree092200b204af1b4b347d3b3720745983205665f3 /depends/settings
parent902dc50c873670c7241988758470c87cdde5f429 (diff)
downloadMultiMC-5f7a48a35ef2b3951fcc6317802a2cdd63c47b76.tar
MultiMC-5f7a48a35ef2b3951fcc6317802a2cdd63c47b76.tar.gz
MultiMC-5f7a48a35ef2b3951fcc6317802a2cdd63c47b76.tar.lz
MultiMC-5f7a48a35ef2b3951fcc6317802a2cdd63c47b76.tar.xz
MultiMC-5f7a48a35ef2b3951fcc6317802a2cdd63c47b76.zip
Fix issues with badly encoded escape sequences in config files.
Diffstat (limited to 'depends/settings')
-rw-r--r--depends/settings/inifile.cpp48
-rw-r--r--depends/settings/inifile.h4
2 files changed, 42 insertions, 10 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)
diff --git a/depends/settings/inifile.h b/depends/settings/inifile.h
index 27da7bf0..4fb0054d 100644
--- a/depends/settings/inifile.h
+++ b/depends/settings/inifile.h
@@ -33,6 +33,6 @@ public:
QVariant get(QString key, QVariant def) const;
void set(QString key, QVariant val);
- QString unescape(QString orig);
- QString escape(QString orig);
+ static QString unescape(QString orig);
+ static QString escape(QString orig);
};