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

View file

@ -1,5 +1,10 @@
# Test comment # 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 testInt = 123
testFloat = 123.456 testFloat = 123.456