16 string::size_type i = desc.find(split);
17 if (i == string::npos)
18 throw KeyvalException(
"Bad syntax! keyval should be of the form 'key" + split +
"=value', found '" + desc +
"'.");
19 key = desc.substr(0, i);
20 val = desc.substr(i + 1);
25 unique_ptr<StringTokenizer> st;
31 vector<string> tokens;
40 if (tokens.size() == 0)
41 throw KeyvalException(
"Invalid syntax, found '=' without argument name.");
43 throw KeyvalException(
"Invalid syntax, found '=' without argument value.");
47 tokens[tokens.size() - 1] +=
"=" + nextToken;
51 tokens.push_back(token);
54 for (vector<string>::iterator it = tokens.begin(); it != tokens.end(); it++)
56 singleKeyval(*it, key, val);
65 string::size_type begin = desc.find_first_of(
"(");
66 string::size_type end = desc.find_last_of(
")");
68 if (begin == string::npos && end == string::npos)
73 if (begin == string::npos && end != string::npos)
74 throw KeyvalException(
"Bad keyval procedure, missing opening parenthesis.");
75 if (begin == string::npos && end != string::npos)
76 throw KeyvalException(
"Bad keyval procedure, missing closing parenthesis.");
79 throw KeyvalException(
"Bad keyval procedure, extra characters after closing parenthesis: " + desc.substr(end + 1));
84 string desckv = desc.substr(begin + 1, end - begin - 1);
86 unique_ptr<StringTokenizer> st;
92 vector<string> tokens;
102 if (tokens.size() == 0)
103 throw KeyvalException(
"Invalid syntax, found '=' without argument name.");
105 throw KeyvalException(
"Invalid syntax, found '=' without argument value.");
107 if (nextToken ==
"=")
109 tokens[tokens.size() - 1] +=
"=" + nextToken;
113 tokens.push_back(token);
117 for (vector<string>::iterator it = tokens.begin(); it != tokens.end(); it++)
119 singleKeyval(*it, key, val);
121 if (it != tokens.begin())
124 map<string, string>::const_iterator iter = newkeyvals.find(key);
126 if (iter != newkeyvals.end())
127 newDesc += key +
"=" + iter->second;
139 string::size_type begin = desc.find_first_of(
"(");
140 string::size_type end = desc.find_last_of(
")");
142 if (begin == string::npos && end == string::npos)
148 if (begin == string::npos && end != string::npos)
149 throw KeyvalException(
"Bad keyval procedure, missing opening parenthesis.");
150 if (begin == string::npos && end != string::npos)
151 throw KeyvalException(
"Bad keyval procedure, missing closing parenthesis.");
154 throw KeyvalException(
"Bad keyval procedure, extra characters after closing parenthesis: " + desc.substr(end + 1));
157 multipleKeyvals(desc.substr(begin + 1, end - begin - 1), args);
const std::string & nextToken()
Get the next available token. If no token is availbale, throw an Exception.
bool hasMoreToken() const
Tell if some tokens are still available.
std::string removeSurroundingWhiteSpaces(const std::string &s)
Remove all white spaces characters at the beginning and the end of a string.
std::string removeFirstWhiteSpaces(const std::string &s)
Remove all white spaces characters at the beginning of a string.
Exception thrown by the Keyval parser.
An improved tokenizer for strings.
bool isEmpty(const std::string &s)
Tell if a string is empty. A string is considered to be 'empty' if it is only made of white spaces...
std::vector< std::string > split(const std::string &s, std::size_t n)