Fix regex for key-value-pair

First group was a greedy match for the key, followed by a greedy match
for the whitespace up to the '='. This caused the white space to become
a suffix of the key... Solved by making it a non-greedy match.
This commit is contained in:
Bob Polis 2024-03-27 17:07:30 +01:00
parent 1da96ede92
commit 37c866054a

View File

@ -93,7 +93,7 @@ map<string, string> sc::parse_ini_file(const string& path, bool ignore_sections)
prefix = string{m[1]} + '.'; prefix = string{m[1]} + '.';
} }
} }
regex key_value_pat {R"(^\s*(.*)\s*=\s*("?)(.*)\2)"}; regex key_value_pat {R"(^\s*(.*?)\s*=\s*("?)(.*)\2)"};
smatch match; smatch match;
if (regex_search(line, match, key_value_pat)) { if (regex_search(line, match, key_value_pat)) {
result[prefix + string{match[1]}] = match[3]; result[prefix + string{match[1]}] = match[3];