allow # escaping in config

This commit is contained in:
Vaxry 2022-10-25 14:32:25 +01:00
parent ba9a8a9ded
commit cdb331076a

View file

@ -1016,13 +1016,26 @@ void CConfigManager::applyUserDefinedVars(std::string& line, const size_t equals
void CConfigManager::parseLine(std::string& line) { void CConfigManager::parseLine(std::string& line) {
// first check if its not a comment // first check if its not a comment
const auto COMMENTSTART = line.find_first_of('#'); if (line[0] == '#')
if (COMMENTSTART == 0)
return; return;
// now, cut the comment off // now, cut the comment off. ## is an escape.
if (COMMENTSTART != std::string::npos) for (long unsigned int i = 1; i < line.length(); ++i) {
line = line.substr(0, COMMENTSTART); if (line[i] == '#') {
if (i + 1 < line.length() && line[i + 1] != '#') {
line = line.substr(0, i);
break; // no need to parse more
}
i++;
}
}
size_t startPos = 0;
while ((startPos = line.find("##", startPos)) != std::string::npos) {
line.replace(startPos, 2, "#");
startPos++;
}
// remove shit at the beginning // remove shit at the beginning
while (line[0] == ' ' || line[0] == '\t') { while (line[0] == ' ' || line[0] == '\t') {