From d21700ee919adda0bb72ea44262c99e06b13d04a Mon Sep 17 00:00:00 2001 From: janrupf Date: Tue, 18 Jun 2019 13:16:26 +0200 Subject: NOISSUE Revert INI parser back to single pass --- api/logic/settings/INIFile.cpp | 53 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 10 deletions(-) (limited to 'api/logic') 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) -- cgit v1.2.3