summaryrefslogtreecommitdiffstats
path: root/api/logic/settings
diff options
context:
space:
mode:
authorjanrupf <werbung.janrupf@t-online.de>2019-06-17 16:38:32 +0200
committerPetr Mrázek <peterix@gmail.com>2019-06-21 23:46:54 +0200
commitf87c890912ccf60264fe92c220b7707fb237a2e5 (patch)
tree089786e4f28d64c91eb7181970b5809c75a743b8 /api/logic/settings
parentce12f1a734e08f1653aa482279a4dc6b6f3667eb (diff)
downloadMultiMC-f87c890912ccf60264fe92c220b7707fb237a2e5.tar
MultiMC-f87c890912ccf60264fe92c220b7707fb237a2e5.tar.gz
MultiMC-f87c890912ccf60264fe92c220b7707fb237a2e5.tar.lz
MultiMC-f87c890912ccf60264fe92c220b7707fb237a2e5.tar.xz
MultiMC-f87c890912ccf60264fe92c220b7707fb237a2e5.zip
GH-1813 Escape # in INI (and better reader)
Diffstat (limited to 'api/logic/settings')
-rw-r--r--api/logic/settings/INIFile.cpp59
1 files changed, 19 insertions, 40 deletions
diff --git a/api/logic/settings/INIFile.cpp b/api/logic/settings/INIFile.cpp
index 42244131..04e9aa2c 100644
--- a/api/logic/settings/INIFile.cpp
+++ b/api/logic/settings/INIFile.cpp
@@ -28,49 +28,20 @@ INIFile::INIFile()
QString INIFile::unescape(QString 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;
+ return orig
+ .replace("\\#", "#")
+ .replace("\\t", "\t")
+ .replace("\\n", "\n")
+ .replace("\\\\", "\\");
}
QString INIFile::escape(QString 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;
+ return orig
+ .replace('\\', "\\\\")
+ .replace('\n', "\\n")
+ .replace('\t', "\\t")
+ .replace('#', "\\#");
}
bool INIFile::saveFile(QString fileName)
@@ -120,7 +91,15 @@ bool INIFile::loadFile(QByteArray file)
{
QString &lineRaw = lines[i];
// Ignore comments.
- QString line = lineRaw.left(lineRaw.indexOf('#')).trimmed();
+ int commentIndex = 0;
+ QString line = lineRaw;
+ // Search for comments until no more escaped # are available
+ while((commentIndex = line.indexOf('#', commentIndex + 1)) != -1) {
+ if(commentIndex > 0 && line.at(commentIndex - 1) == '\\') {
+ continue;
+ }
+ line = line.left(lineRaw.indexOf('#')).trimmed();
+ }
int eqPos = line.indexOf('=');
if (eqPos == -1)