53 string::size_type i = desc.find(
split);
54 if (i == string::npos)
55 throw KeyvalException(
"Bad syntax! keyval should be of the form 'key" +
split +
"=value', found '" + desc +
"'.");
56 key = desc.substr(0, i);
57 val = desc.substr(i + 1);
62 unique_ptr<StringTokenizer> st;
68 vector<string> tokens;
71 while (st->hasMoreToken())
73 token = st->nextToken();
77 if (tokens.size() == 0)
78 throw KeyvalException(
"Invalid syntax, found '=' without argument name.");
79 if (!st->hasMoreToken())
80 throw KeyvalException(
"Invalid syntax, found '=' without argument value.");
81 string nextToken = st->nextToken();
84 tokens[tokens.size() - 1] +=
"=" + nextToken;
88 tokens.push_back(token);
91 for (vector<string>::iterator it = tokens.begin(); it != tokens.end(); it++)
93 singleKeyval(*it, key, val);
102 string::size_type begin = desc.find_first_of(
"(");
103 string::size_type end = desc.find_last_of(
")");
105 if (begin == string::npos && end == string::npos)
110 if (begin == string::npos && end != string::npos)
111 throw KeyvalException(
"Bad keyval procedure, missing opening parenthesis.");
112 if (begin == string::npos && end != string::npos)
113 throw KeyvalException(
"Bad keyval procedure, missing closing parenthesis.");
116 throw KeyvalException(
"Bad keyval procedure, extra characters after closing parenthesis: " + desc.substr(end + 1));
121 string desckv = desc.substr(begin + 1, end - begin - 1);
123 unique_ptr<StringTokenizer> st;
129 vector<string> tokens;
133 while (st->hasMoreToken())
135 token = st->nextToken();
139 if (tokens.size() == 0)
140 throw KeyvalException(
"Invalid syntax, found '=' without argument name.");
141 if (!st->hasMoreToken())
142 throw KeyvalException(
"Invalid syntax, found '=' without argument value.");
143 string nextToken = st->nextToken();
144 if (nextToken ==
"=")
146 tokens[tokens.size() - 1] +=
"=" + nextToken;
150 tokens.push_back(token);
154 for (vector<string>::iterator it = tokens.begin(); it != tokens.end(); it++)
156 singleKeyval(*it, key, val);
158 if (it != tokens.begin())
161 map<string, string>::const_iterator iter = newkeyvals.find(key);
163 if (iter != newkeyvals.end())
164 newDesc += key +
"=" + iter->second;
176 string::size_type begin = desc.find_first_of(
"(");
177 string::size_type end = desc.find_last_of(
")");
179 if (begin == string::npos && end == string::npos)
185 if (begin == string::npos && end != string::npos)
186 throw KeyvalException(
"Bad keyval procedure, missing opening parenthesis.");
187 if (begin == string::npos && end != string::npos)
188 throw KeyvalException(
"Bad keyval procedure, missing closing parenthesis.");
191 throw KeyvalException(
"Bad keyval procedure, extra characters after closing parenthesis: " + desc.substr(end + 1));
194 multipleKeyvals(desc.substr(begin + 1, end - begin - 1), args);
Exception thrown by the Keyval parser.
An improved tokenizer for strings.
std::string removeSurroundingWhiteSpaces(const std::string &s)
Remove all white spaces characters at the beginning and the end of a string.
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)
std::string removeFirstWhiteSpaces(const std::string &s)
Remove all white spaces characters at the beginning of a string.