2020-10-23 12:03:36 +00:00
|
|
|
#include "validate.hpp"
|
|
|
|
|
2022-06-25 15:51:01 +00:00
|
|
|
#include <boost/any.hpp>
|
|
|
|
#include <boost/program_options/errors.hpp>
|
|
|
|
|
2020-10-23 12:03:36 +00:00
|
|
|
void Fallback::validate(boost::any& v, std::vector<std::string> const& tokens, FallbackMap*, int)
|
|
|
|
{
|
|
|
|
if (v.empty())
|
|
|
|
{
|
|
|
|
v = boost::any(FallbackMap());
|
|
|
|
}
|
|
|
|
|
|
|
|
FallbackMap* map = boost::any_cast<FallbackMap>(&v);
|
|
|
|
|
2020-10-23 12:13:47 +00:00
|
|
|
for (const auto& token : tokens)
|
2020-10-23 12:03:36 +00:00
|
|
|
{
|
2021-10-17 22:40:34 +00:00
|
|
|
size_t sep = token.find(',');
|
|
|
|
if (sep < 1 || sep == token.length() - 1 || sep == std::string::npos)
|
2020-10-23 12:03:36 +00:00
|
|
|
throw boost::program_options::validation_error(
|
|
|
|
boost::program_options::validation_error::invalid_option_value);
|
|
|
|
|
2021-10-17 22:40:34 +00:00
|
|
|
std::string key(token.substr(0, sep));
|
|
|
|
std::string value(token.substr(sep + 1));
|
2020-10-23 12:03:36 +00:00
|
|
|
|
|
|
|
map->mMap[key] = value;
|
|
|
|
}
|
|
|
|
}
|