config/Data: FindBlock() throws on error
This commit is contained in:
parent
15c36baefd
commit
eeaaea802a
@ -21,7 +21,7 @@
|
|||||||
#include "Data.hxx"
|
#include "Data.hxx"
|
||||||
#include "Param.hxx"
|
#include "Param.hxx"
|
||||||
#include "Block.hxx"
|
#include "Block.hxx"
|
||||||
#include "system/FatalError.hxx"
|
#include "util/RuntimeError.hxx"
|
||||||
#include "util/StringAPI.hxx"
|
#include "util/StringAPI.hxx"
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -40,14 +40,14 @@ ConfigData::Clear()
|
|||||||
|
|
||||||
const ConfigBlock *
|
const ConfigBlock *
|
||||||
ConfigData::FindBlock(ConfigBlockOption option,
|
ConfigData::FindBlock(ConfigBlockOption option,
|
||||||
const char *key, const char *value) const noexcept
|
const char *key, const char *value) const
|
||||||
{
|
{
|
||||||
for (const auto *block = GetBlock(option);
|
for (const auto *block = GetBlock(option);
|
||||||
block != nullptr; block = block->next) {
|
block != nullptr; block = block->next) {
|
||||||
const char *value2 = block->GetBlockValue(key);
|
const char *value2 = block->GetBlockValue(key);
|
||||||
if (value2 == nullptr)
|
if (value2 == nullptr)
|
||||||
FormatFatalError("block without '%s' in line %d",
|
throw FormatRuntimeError("block without '%s' in line %d",
|
||||||
key, block->line);
|
key, block->line);
|
||||||
|
|
||||||
if (StringIsEqual(value2, value))
|
if (StringIsEqual(value2, value))
|
||||||
return block;
|
return block;
|
||||||
|
@ -43,9 +43,12 @@ struct ConfigData {
|
|||||||
return blocks[size_t(option)];
|
return blocks[size_t(option)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Throws if a block doesn't have the specified (mandatory) key.
|
||||||
|
*/
|
||||||
gcc_pure
|
gcc_pure
|
||||||
const ConfigBlock *FindBlock(ConfigBlockOption option,
|
const ConfigBlock *FindBlock(ConfigBlockOption option,
|
||||||
const char *key, const char *value) const noexcept;
|
const char *key, const char *value) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user