lib: Allow comment escaping with multiple `#` if it's the first char (#38)

* parse line - ignore leading spaces, tabs

* removed unnecessary substr functions

* parse line - discard empty lines sooner
This commit is contained in:
Micovec 2024-03-29 01:24:51 +01:00 committed by GitHub
parent 95471ec86f
commit c140261214
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 4 deletions

View File

@ -513,7 +513,13 @@ CParseResult CConfig::parseVariable(const std::string& lhs, const std::string& r
CParseResult CConfig::parseLine(std::string line, bool dynamic) {
CParseResult result;
line = removeBeginEndSpacesTabs(line);
auto commentPos = line.find('#');
if (commentPos == 0)
return result;
size_t lastHashPos = 0;
while (commentPos != std::string::npos) {
@ -536,9 +542,12 @@ CParseResult CConfig::parseLine(std::string line, bool dynamic) {
line = removeBeginEndSpacesTabs(line);
if (line.empty())
return result;
auto equalsPos = line.find('=');
if (equalsPos == std::string::npos && !line.ends_with("{") && line != "}" && !line.empty()) {
if (equalsPos == std::string::npos && !line.ends_with("{") && line != "}") {
// invalid line
result.setError("Invalid config line");
return result;
@ -607,7 +616,7 @@ CParseResult CConfig::parseLine(std::string line, bool dynamic) {
if (ret.error)
return ret;
} else if (!line.empty()) {
} else {
// has to be a set
if (line.contains("}")) {
// easiest. } or invalid.

View File

@ -1,5 +1,10 @@
# Test comment
## This is also a comment
## This is a comment with space as a first character
## This is a comment with tab as a first character
## This is a comment with leading spaces and tabs
##### Comment with more hash tags
testInt = 123
testFloat = 123.456