diff options
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | 2018-03-31 16:55:15 +0200 |
---|---|---|
committer | louiz’ <louiz@louiz.org> | 2018-04-16 00:53:25 +0200 |
commit | a429b2ea271158fcda8a2f7a5b0179686bab3aa2 (patch) | |
tree | 3df36cc6b925165f3a5937b68c9157b66460fde8 | |
parent | 39a32d55248808637cee78b9218053306964f7aa (diff) | |
download | biboumi-a429b2ea271158fcda8a2f7a5b0179686bab3aa2.tar.gz biboumi-a429b2ea271158fcda8a2f7a5b0179686bab3aa2.tar.bz2 biboumi-a429b2ea271158fcda8a2f7a5b0179686bab3aa2.tar.xz biboumi-a429b2ea271158fcda8a2f7a5b0179686bab3aa2.zip |
Add a Config::is_in_list() method
-rw-r--r-- | src/config/config.cpp | 17 | ||||
-rw-r--r-- | src/config/config.hpp | 5 |
2 files changed, 19 insertions, 3 deletions
diff --git a/src/config/config.cpp b/src/config/config.cpp index 412b170..2f64b9e 100644 --- a/src/config/config.cpp +++ b/src/config/config.cpp @@ -1,10 +1,12 @@ #include <config/config.hpp> #include <utils/tolower.hpp> +#include <utils/split.hpp> -#include <iostream> -#include <cstring> - +#include <algorithm> #include <cstdlib> +#include <cstring> +#include <iostream> +#include <vector> using namespace std::string_literals; @@ -40,6 +42,15 @@ int Config::get_int(const std::string& option, const int& def) return def; } +bool Config::is_in_list(const std::string& option, const std::string& value) +{ + std::string res = Config::get(option, ""); + if (res.empty()) + return false; + std::vector<std::string> list = utils::split(res, ':'); + return std::find(list.cbegin(), list.cend(), value) != list.cend(); +} + void Config::set(const std::string& option, const std::string& value, bool save) { Config::values[option] = value; diff --git a/src/config/config.hpp b/src/config/config.hpp index c5ef15d..9c28e8c 100644 --- a/src/config/config.hpp +++ b/src/config/config.hpp @@ -46,6 +46,11 @@ public: static int get_int(const std::string&, const int&); static bool get_bool(const std::string&, const bool); /** + * Returns true if value is present in a colon-separated list, otherwise + * false. + */ + static bool is_in_list(const std::string& option, const std::string& value); + /** * Set a value for the given option. And write all the config * in the file from which it was read if save is true. */ |