summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Powell <petpow@saberuk.com>2018-06-29 11:26:51 +0100
committerPeter Powell <petpow@saberuk.com>2018-07-10 21:14:56 +0100
commite22383c6f4f4c5f16e40e04db0f14ad4b357a142 (patch)
tree521ebd5d0b899942df032c72f861b88270e75fd7 /src
parent39b51a7c11e384603102c01de1c46c28e7699046 (diff)
Add a ConfigTag::getString overload that calls a validation method.
Diffstat (limited to 'src')
-rw-r--r--src/configparser.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/configparser.cpp b/src/configparser.cpp
index 8a3042eba..627cd78e1 100644
--- a/src/configparser.cpp
+++ b/src/configparser.cpp
@@ -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;