mirror of
https://github.com/inspircd/inspircd.git
synced 2025-03-09 18:49:03 -04:00
Add a ConfigTag::getString overload that calls a validation method.
This commit is contained in:
parent
39b51a7c11
commit
e22383c6f4
@ -42,6 +42,8 @@ class CoreExport ConfigTag : public refcountbase
|
||||
const std::string src_name;
|
||||
const int src_line;
|
||||
|
||||
/** Get the value of an option, using def if it does not exist */
|
||||
std::string getString(const std::string& key, const std::string& def, const TR1NS::function<bool(const std::string&)>& validator);
|
||||
/** Get the value of an option, using def if it does not exist */
|
||||
std::string getString(const std::string& key, const std::string& def = "", size_t minlen = 0, size_t maxlen = UINT32_MAX);
|
||||
/** Get the value of an option, using def if it does not exist */
|
||||
|
@ -402,6 +402,21 @@ bool ConfigTag::readString(const std::string& key, std::string& value, bool allo
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string ConfigTag::getString(const std::string& key, const std::string& def, const TR1NS::function<bool(const std::string&)>& validator)
|
||||
{
|
||||
std::string res;
|
||||
if (!readString(key, res))
|
||||
return def;
|
||||
|
||||
if (!validator(res))
|
||||
{
|
||||
ServerInstance->Logs->Log("CONFIG", LOG_DEFAULT, "WARNING: The value of <%s:%s> is not valid; value set to %s.",
|
||||
tag.c_str(), key.c_str(), def.c_str());
|
||||
return def;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
std::string ConfigTag::getString(const std::string& key, const std::string& def, size_t minlen, size_t maxlen)
|
||||
{
|
||||
std::string res;
|
||||
|
Loading…
x
Reference in New Issue
Block a user