aboutsummaryrefslogtreecommitdiffstats
path: root/src/db
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-01-22 23:17:42 +0100
committerMax Kellermann <max@duempel.org>2014-01-22 23:17:42 +0100
commit0ec1808956ac6eaa08973a4ad609ce99bde4e6d3 (patch)
tree1a5de0d354a062e87be9fa3e31afc79f04298239 /src/db
parent546e7cafa4eba1dd8b4eccbec5a1c5a41b6b7ad2 (diff)
downloadmpd-0ec1808956ac6eaa08973a4ad609ce99bde4e6d3.tar.gz
mpd-0ec1808956ac6eaa08973a4ad609ce99bde4e6d3.tar.xz
mpd-0ec1808956ac6eaa08973a4ad609ce99bde4e6d3.zip
db/proxy: simplify csvToStrings()
Diffstat (limited to 'src/db')
-rw-r--r--src/db/upnp/Util.cxx64
1 files changed, 17 insertions, 47 deletions
diff --git a/src/db/upnp/Util.cxx b/src/db/upnp/Util.cxx
index fba63983d..0fd0d03db 100644
--- a/src/db/upnp/Util.cxx
+++ b/src/db/upnp/Util.cxx
@@ -143,56 +143,26 @@ csvToStrings(const char *s, T &tokens)
{
std::string current;
tokens.clear();
- enum states {TOKEN, ESCAPE};
- states state = TOKEN;
-
- while (*s != 0) {
- const char ch = *s++;
-
- switch (ch) {
- case ',':
- switch(state) {
- case TOKEN:
- tokens.push_back(current);
- current.clear();
- continue;
- case ESCAPE:
- current += ',';
- state = TOKEN;
- continue;
- }
- break;
- case '\\':
- switch(state) {
- case TOKEN:
- state=ESCAPE;
- continue;
- case ESCAPE:
- current += '\\';
- state = TOKEN;
- continue;
- }
- break;
- default:
- switch(state) {
- case ESCAPE:
- state = TOKEN;
- break;
- case TOKEN:
- break;
- }
- current += ch;
+ while (true) {
+ char ch = *s++;
+ if (ch == 0) {
+ tokens.push_back(current);
+ return true;
}
+
+ if (ch == '\\') {
+ ch = *s++;
+ if (ch == 0)
+ return false;
+ } else if (ch == ',') {
+ tokens.push_back(current);
+ current.clear();
+ continue;
+ }
+
+ current.push_back(ch);
}
- switch(state) {
- case TOKEN:
- tokens.push_back(current);
- break;
- case ESCAPE:
- return false;
- }
- return true;
}
template bool csvToStrings<std::list<std::string>>(const char *, std::list<std::string> &);