diff --git a/components/fallback/validate.cpp b/components/fallback/validate.cpp new file mode 100644 index 000000000..24865a039 --- /dev/null +++ b/components/fallback/validate.cpp @@ -0,0 +1,28 @@ +#include "validate.hpp" + +void Fallback::validate(boost::any& v, std::vector const& tokens, FallbackMap*, int) +{ + if (v.empty()) + { + v = boost::any(FallbackMap()); + } + + FallbackMap *map = boost::any_cast(&v); + + for (std::vector::const_iterator it = tokens.begin(); it != tokens.end(); ++it) + { + std::string temp = Files::EscapeHashString::processString(*it); + int sep = temp.find(","); + if (sep < 1 || sep == (int)temp.length() - 1) +#if (BOOST_VERSION < 104200) + throw boost::program_options::validation_error("invalid value"); +#else + throw boost::program_options::validation_error(boost::program_options::validation_error::invalid_option_value); +#endif + + std::string key(temp.substr(0, sep)); + std::string value(temp.substr(sep + 1)); + + map->mMap[key] = value; + } +} diff --git a/components/fallback/validate.hpp b/components/fallback/validate.hpp index cef52e462..96690f50a 100644 --- a/components/fallback/validate.hpp +++ b/components/fallback/validate.hpp @@ -16,32 +16,7 @@ namespace Fallback std::map mMap; }; - void validate(boost::any &v, std::vector const &tokens, FallbackMap*, int) - { - if (v.empty()) - { - v = boost::any(FallbackMap()); - } - - FallbackMap *map = boost::any_cast(&v); - - for (std::vector::const_iterator it = tokens.begin(); it != tokens.end(); ++it) - { - std::string temp = Files::EscapeHashString::processString(*it); - int sep = temp.find(","); - if (sep < 1 || sep == (int)temp.length() - 1) -#if (BOOST_VERSION < 104200) - throw boost::program_options::validation_error("invalid value"); -#else - throw boost::program_options::validation_error(boost::program_options::validation_error::invalid_option_value); -#endif - - std::string key(temp.substr(0, sep)); - std::string value(temp.substr(sep + 1)); - - map->mMap[key] = value; - } - } + void validate(boost::any &v, std::vector const &tokens, FallbackMap*, int); } #endif