mirror of
https://github.com/hyprwm/hyprlang.git
synced 2026-05-05 07:27:59 +02:00
core: fix explicit key and nested
This commit is contained in:
parent
85d2defd78
commit
b561328930
2 changed files with 24 additions and 5 deletions
|
|
@ -289,7 +289,6 @@ CParseResult CConfig::configSetValueSafe(const std::string& command, const std::
|
|||
|
||||
valueName += command;
|
||||
|
||||
// FIXME: this will bug with nested.
|
||||
if (valueName.contains('[') && valueName.contains(']')) {
|
||||
const auto L = valueName.find_first_of('[');
|
||||
const auto R = valueName.find_last_of(']');
|
||||
|
|
@ -300,12 +299,26 @@ CParseResult CConfig::configSetValueSafe(const std::string& command, const std::
|
|||
|
||||
valueName = valueName.substr(0, L) + valueName.substr(R + 1);
|
||||
|
||||
// if it doesn't exist, make it
|
||||
for (auto& sc : impl->specialCategoryDescriptors) {
|
||||
if (sc->key.empty() || !valueName.starts_with(sc->name + ":"))
|
||||
continue;
|
||||
|
||||
// bingo
|
||||
bool keyExists = false;
|
||||
for (const auto& specialCat : impl->specialCategories) {
|
||||
if (specialCat->key != sc->key || specialCat->name != sc->name)
|
||||
continue;
|
||||
|
||||
if (strcmp(std::any_cast<const char*>(specialCat->values[sc->key].getValue()), CATKEY.c_str()))
|
||||
continue;
|
||||
|
||||
// existing special
|
||||
keyExists = true;
|
||||
}
|
||||
|
||||
if (keyExists)
|
||||
break;
|
||||
|
||||
// if it doesn't exist, make it
|
||||
const auto PCAT = impl->specialCategories.emplace_back(std::make_unique<SSpecialCategory>()).get();
|
||||
PCAT->descriptor = sc.get();
|
||||
PCAT->name = sc->name;
|
||||
|
|
@ -549,7 +562,7 @@ std::optional<std::string> CConfigImpl::parseComment(const std::string& comment)
|
|||
|
||||
if (!ifBlockVariable.empty()) {
|
||||
if (ifBlockVariable.starts_with("!")) {
|
||||
negated = true;
|
||||
negated = true;
|
||||
ifBlockVariable = ifBlockVariable.substr(1);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -294,6 +294,12 @@ int main(int argc, char** argv, char** envp) {
|
|||
EXPECT(std::any_cast<int64_t>(config.getSpecialConfigValue("specialGeneric:two", "value")), 2);
|
||||
EXPECT(config.parseDynamic("special[b]:value = 3").error, false);
|
||||
EXPECT(std::any_cast<int64_t>(config.getSpecialConfigValue("special", "value", "b")), 3);
|
||||
EXPECT(config.parseDynamic("specialAnonymousNested[c]:nested:value1 = 4").error, false);
|
||||
EXPECT(config.parseDynamic("specialAnonymousNested[c]:nested:value2 = 5").error, false);
|
||||
EXPECT(std::any_cast<int64_t>(config.getSpecialConfigValue("specialAnonymousNested", "nested:value1", "c")), (Hyprlang::INT)4);
|
||||
EXPECT(std::any_cast<int64_t>(config.getSpecialConfigValue("specialAnonymousNested", "nested:value2", "c")), (Hyprlang::INT)5);
|
||||
EXPECT(config.parseDynamic("specialAnonymousNested[c]:nested:value2 = 6").error, false);
|
||||
EXPECT(std::any_cast<int64_t>(config.getSpecialConfigValue("specialAnonymousNested", "nested:value2", "c")), (Hyprlang::INT)6);
|
||||
|
||||
// test dynamic special variable
|
||||
EXPECT(config.parseDynamic("$SPECIALVAL1 = 2").error, false);
|
||||
|
|
@ -312,7 +318,7 @@ int main(int argc, char** argv, char** envp) {
|
|||
EXPECT(std::any_cast<int64_t>(config.getSpecialConfigValue("specialAnonymous", "value", KEYS[1].c_str())), 3);
|
||||
|
||||
// test anonymous nested
|
||||
EXPECT(config.listKeysForSpecialCategory("specialAnonymousNested").size(), 2);
|
||||
EXPECT(config.listKeysForSpecialCategory("specialAnonymousNested").size(), 2 + /*from dynamic*/ 1);
|
||||
const auto KEYS2 = config.listKeysForSpecialCategory("specialAnonymousNested");
|
||||
EXPECT(std::any_cast<int64_t>(config.getSpecialConfigValue("specialAnonymousNested", "nested:value1", KEYS2[0].c_str())), 1);
|
||||
EXPECT(std::any_cast<int64_t>(config.getSpecialConfigValue("specialAnonymousNested", "nested:value2", KEYS2[0].c_str())), 2);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue