mirror of
https://github.com/hyprwm/hyprlang.git
synced 2024-11-16 18:25:57 +01:00
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:
parent
95471ec86f
commit
c140261214
2 changed files with 18 additions and 4 deletions
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue