diff options
author | janrupf <werbung.janrupf@t-online.de> | 2019-06-18 13:16:26 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2019-06-21 23:46:54 +0200 |
commit | d21700ee919adda0bb72ea44262c99e06b13d04a (patch) | |
tree | 258bd04e734c61db4b87ca1ff42d4094cad98d0e /api/logic/settings/INIFile.cpp | |
parent | f87c890912ccf60264fe92c220b7707fb237a2e5 (diff) | |
download | MultiMC-d21700ee919adda0bb72ea44262c99e06b13d04a.tar MultiMC-d21700ee919adda0bb72ea44262c99e06b13d04a.tar.gz MultiMC-d21700ee919adda0bb72ea44262c99e06b13d04a.tar.lz MultiMC-d21700ee919adda0bb72ea44262c99e06b13d04a.tar.xz MultiMC-d21700ee919adda0bb72ea44262c99e06b13d04a.zip |
NOISSUE Revert INI parser back to single pass
Diffstat (limited to 'api/logic/settings/INIFile.cpp')
-rw-r--r-- | api/logic/settings/INIFile.cpp | 53 |
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) |