Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
KeyValueParser.cpp
Go to the documentation of this file.
1#include "KeyValueParser.h"
2#include <boost/algorithm/string.hpp>
3#include <vector>
4
7
8namespace storm {
9namespace parser {
10
11std::unordered_map<std::string, std::string> parseKeyValueString(std::string const& keyValueString) {
12 std::unordered_map<std::string, std::string> keyValueMap;
13 std::vector<std::string> definitions;
14 boost::split(definitions, keyValueString, boost::is_any_of(","));
15 for (auto& definition : definitions) {
16 boost::trim(definition);
17
18 // Check whether the token could be a legal constant definition.
19 std::size_t positionOfAssignmentOperator = definition.find('=');
20 STORM_LOG_THROW(positionOfAssignmentOperator != std::string::npos, storm::exceptions::InvalidArgumentException,
21 "Illegal key value string: syntax error.");
22
23 // Now extract the variable name and the value from the string.
24 std::string key = definition.substr(0, positionOfAssignmentOperator);
25 boost::trim(key);
26 std::string value = definition.substr(positionOfAssignmentOperator + 1);
27 boost::trim(value);
28 keyValueMap.emplace(key, value);
29 }
30 return keyValueMap;
31}
32} // namespace parser
33} // namespace storm
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
std::unordered_map< std::string, std::string > parseKeyValueString(std::string const &keyValueString)
LabParser.cpp.
Definition cli.cpp:18