summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2018-07-17 21:14:53 +0200
committerMax Kellermann <max@musicpd.org>2018-07-17 21:16:20 +0200
commit15c36baefddbafc0e46f9b7e2c0c1254cc91d9f1 (patch)
tree1ec439d2bbd20424c5778d55980a662a46a9e943 /src
parent33deb84aa1342df026edb3b604f8e19c5f3a49e2 (diff)
config/Data: add method FindBlock()
Diffstat (limited to 'src')
-rw-r--r--src/config/Data.cxx20
-rw-r--r--src/config/Data.hxx4
-rw-r--r--src/config/Global.cxx13
3 files changed, 25 insertions, 12 deletions
diff --git a/src/config/Data.cxx b/src/config/Data.cxx
index 2eee5e23e..f4535c599 100644
--- a/src/config/Data.cxx
+++ b/src/config/Data.cxx
@@ -21,6 +21,8 @@
#include "Data.hxx"
#include "Param.hxx"
#include "Block.hxx"
+#include "system/FatalError.hxx"
+#include "util/StringAPI.hxx"
void
ConfigData::Clear()
@@ -35,3 +37,21 @@ ConfigData::Clear()
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;
+}
diff --git a/src/config/Data.hxx b/src/config/Data.hxx
index 11969231c..940440d7d 100644
--- a/src/config/Data.hxx
+++ b/src/config/Data.hxx
@@ -42,6 +42,10 @@ struct ConfigData {
const ConfigBlock *GetBlock(ConfigBlockOption option) const noexcept {
return blocks[size_t(option)];
}
+
+ gcc_pure
+ const ConfigBlock *FindBlock(ConfigBlockOption option,
+ const char *key, const char *value) const noexcept;
};
#endif
diff --git a/src/config/Global.cxx b/src/config/Global.cxx
index 547e5fa27..78ea175cf 100644
--- a/src/config/Global.cxx
+++ b/src/config/Global.cxx
@@ -89,18 +89,7 @@ config_get_block(ConfigBlockOption option) noexcept
const ConfigBlock *
config_find_block(ConfigBlockOption option, const char *key, const char *value)
{
- for (const auto *block = config_get_block(option);
- 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;
+ return config_data.FindBlock(option, key, value);
}
const char *