File: validate.cpp

package info (click to toggle)
openmw 0.47.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 23,276 kB
  • sloc: cpp: 249,935; xml: 1,978; sh: 1,327; python: 63; makefile: 26
file content (24 lines) | stat: -rw-r--r-- 746 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "validate.hpp"

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);

    for (const auto& token : tokens)
    {
        std::string temp = Files::EscapeHashString::processString(token);
        size_t sep = temp.find(',');
        if (sep < 1 || sep == temp.length() - 1 || sep == std::string::npos)
            throw boost::program_options::validation_error(boost::program_options::validation_error::invalid_option_value);

        std::string key(temp.substr(0, sep));
        std::string value(temp.substr(sep + 1));

        map->mMap[key] = value;
    }
}