Commit a429b2ea authored by Link Mauve's avatar Link Mauve Committed by louiz’

Add a Config::is_in_list() method

parent 39a32d55
#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;
......@@ -45,6 +45,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.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment