|
a/src/upmpdutils.cxx |
|
b/src/upmpdutils.cxx |
|
... |
|
... |
256 |
startPos = ++pos;
|
256 |
startPos = ++pos;
|
257 |
}
|
257 |
}
|
258 |
}
|
258 |
}
|
259 |
}
|
259 |
}
|
260 |
|
260 |
|
|
|
261 |
|
|
|
262 |
template <class T> bool stringToStrings(const string &s, T &tokens,
|
|
|
263 |
const string& addseps)
|
|
|
264 |
{
|
|
|
265 |
string current;
|
|
|
266 |
tokens.clear();
|
|
|
267 |
enum states {SPACE, TOKEN, INQUOTE, ESCAPE};
|
|
|
268 |
states state = SPACE;
|
|
|
269 |
for (unsigned int i = 0; i < s.length(); i++) {
|
|
|
270 |
switch (s[i]) {
|
|
|
271 |
case '"':
|
|
|
272 |
switch(state) {
|
|
|
273 |
case SPACE:
|
|
|
274 |
state=INQUOTE; continue;
|
|
|
275 |
case TOKEN:
|
|
|
276 |
current += '"';
|
|
|
277 |
continue;
|
|
|
278 |
case INQUOTE:
|
|
|
279 |
tokens.insert(tokens.end(), current);
|
|
|
280 |
current.clear();
|
|
|
281 |
state = SPACE;
|
|
|
282 |
continue;
|
|
|
283 |
case ESCAPE:
|
|
|
284 |
current += '"';
|
|
|
285 |
state = INQUOTE;
|
|
|
286 |
continue;
|
|
|
287 |
}
|
|
|
288 |
break;
|
|
|
289 |
case '\\':
|
|
|
290 |
switch(state) {
|
|
|
291 |
case SPACE:
|
|
|
292 |
case TOKEN:
|
|
|
293 |
current += '\\';
|
|
|
294 |
state=TOKEN;
|
|
|
295 |
continue;
|
|
|
296 |
case INQUOTE:
|
|
|
297 |
state = ESCAPE;
|
|
|
298 |
continue;
|
|
|
299 |
case ESCAPE:
|
|
|
300 |
current += '\\';
|
|
|
301 |
state = INQUOTE;
|
|
|
302 |
continue;
|
|
|
303 |
}
|
|
|
304 |
break;
|
|
|
305 |
|
|
|
306 |
case ' ':
|
|
|
307 |
case '\t':
|
|
|
308 |
case '\n':
|
|
|
309 |
case '\r':
|
|
|
310 |
switch(state) {
|
|
|
311 |
case SPACE:
|
|
|
312 |
continue;
|
|
|
313 |
case TOKEN:
|
|
|
314 |
tokens.insert(tokens.end(), current);
|
|
|
315 |
current.clear();
|
|
|
316 |
state = SPACE;
|
|
|
317 |
continue;
|
|
|
318 |
case INQUOTE:
|
|
|
319 |
case ESCAPE:
|
|
|
320 |
current += s[i];
|
|
|
321 |
continue;
|
|
|
322 |
}
|
|
|
323 |
break;
|
|
|
324 |
|
|
|
325 |
default:
|
|
|
326 |
if (!addseps.empty() && addseps.find(s[i]) != string::npos) {
|
|
|
327 |
switch(state) {
|
|
|
328 |
case ESCAPE:
|
|
|
329 |
state = INQUOTE;
|
|
|
330 |
break;
|
|
|
331 |
case INQUOTE:
|
|
|
332 |
break;
|
|
|
333 |
case SPACE:
|
|
|
334 |
tokens.insert(tokens.end(), string(1, s[i]));
|
|
|
335 |
continue;
|
|
|
336 |
case TOKEN:
|
|
|
337 |
tokens.insert(tokens.end(), current);
|
|
|
338 |
current.erase();
|
|
|
339 |
tokens.insert(tokens.end(), string(1, s[i]));
|
|
|
340 |
state = SPACE;
|
|
|
341 |
continue;
|
|
|
342 |
}
|
|
|
343 |
} else switch(state) {
|
|
|
344 |
case ESCAPE:
|
|
|
345 |
state = INQUOTE;
|
|
|
346 |
break;
|
|
|
347 |
case SPACE:
|
|
|
348 |
state = TOKEN;
|
|
|
349 |
break;
|
|
|
350 |
case TOKEN:
|
|
|
351 |
case INQUOTE:
|
|
|
352 |
break;
|
|
|
353 |
}
|
|
|
354 |
current += s[i];
|
|
|
355 |
}
|
|
|
356 |
}
|
|
|
357 |
switch(state) {
|
|
|
358 |
case SPACE:
|
|
|
359 |
break;
|
|
|
360 |
case TOKEN:
|
|
|
361 |
tokens.insert(tokens.end(), current);
|
|
|
362 |
break;
|
|
|
363 |
case INQUOTE:
|
|
|
364 |
case ESCAPE:
|
|
|
365 |
return false;
|
|
|
366 |
}
|
|
|
367 |
return true;
|
|
|
368 |
}
|
|
|
369 |
|
|
|
370 |
template bool stringToStrings<vector<string> >(const string &,
|
|
|
371 |
vector<string> &,const string&);
|
|
|
372 |
|
261 |
// Translate 0-100% MPD volume to UPnP VolumeDB: we do db upnp-encoded
|
373 |
// Translate 0-100% MPD volume to UPnP VolumeDB: we do db upnp-encoded
|
262 |
// values from -10240 (0%) to 0 (100%)
|
374 |
// values from -10240 (0%) to 0 (100%)
|
263 |
int percentodbvalue(int value)
|
375 |
int percentodbvalue(int value)
|
264 |
{
|
376 |
{
|
265 |
int dbvalue;
|
377 |
int dbvalue;
|