config/Data: add method FindBlock()
This commit is contained in:
parent
33deb84aa1
commit
15c36baefd
@ -21,6 +21,8 @@
|
|||||||
#include "Data.hxx"
|
#include "Data.hxx"
|
||||||
#include "Param.hxx"
|
#include "Param.hxx"
|
||||||
#include "Block.hxx"
|
#include "Block.hxx"
|
||||||
|
#include "system/FatalError.hxx"
|
||||||
|
#include "util/StringAPI.hxx"
|
||||||
|
|
||||||
void
|
void
|
||||||
ConfigData::Clear()
|
ConfigData::Clear()
|
||||||
@ -35,3 +37,21 @@ ConfigData::Clear()
|
|||||||
i = nullptr;
|
i = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ConfigBlock *
|
||||||
|
ConfigData::FindBlock(ConfigBlockOption option,
|
||||||
|
const char *key, const char *value) const noexcept
|
||||||
|
{
|
||||||
|
for (const auto *block = GetBlock(option);
|
||||||
|
block != nullptr; block = block->next) {
|
||||||
|
const char *value2 = block->GetBlockValue(key);
|
||||||
|
if (value2 == nullptr)
|
||||||
|
FormatFatalError("block without '%s' in line %d",
|
||||||
|
key, block->line);
|
||||||
|
|
||||||
|
if (StringIsEqual(value2, value))
|
||||||
|
return block;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
@ -42,6 +42,10 @@ struct ConfigData {
|
|||||||
const ConfigBlock *GetBlock(ConfigBlockOption option) const noexcept {
|
const ConfigBlock *GetBlock(ConfigBlockOption option) const noexcept {
|
||||||
return blocks[size_t(option)];
|
return blocks[size_t(option)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gcc_pure
|
||||||
|
const ConfigBlock *FindBlock(ConfigBlockOption option,
|
||||||
|
const char *key, const char *value) const noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -89,18 +89,7 @@ config_get_block(ConfigBlockOption option) noexcept
|
|||||||
const ConfigBlock *
|
const ConfigBlock *
|
||||||
config_find_block(ConfigBlockOption option, const char *key, const char *value)
|
config_find_block(ConfigBlockOption option, const char *key, const char *value)
|
||||||
{
|
{
|
||||||
for (const auto *block = config_get_block(option);
|
return config_data.FindBlock(option, key, value);
|
||||||
block != nullptr; block = block->next) {
|
|
||||||
const char *value2 = block->GetBlockValue(key);
|
|
||||||
if (value2 == nullptr)
|
|
||||||
FormatFatalError("block without '%s' name in line %d",
|
|
||||||
key, block->line);
|
|
||||||
|
|
||||||
if (strcmp(value2, value) == 0)
|
|
||||||
return block;
|
|
||||||
}
|
|
||||||
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
|
Loading…
Reference in New Issue
Block a user