aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-01-11 01:30:05 +0100
committerMax Kellermann <max@duempel.org>2014-01-11 01:30:05 +0100
commitb50d79542c95ab88387418b34999e942e6b6a583 (patch)
tree072d8bf2a90375af038569e0b1212e70f9b360f0
parent8351543c0f43ee281032ef712cc5168beb662d31 (diff)
downloadmpd-b50d79542c95ab88387418b34999e942e6b6a583.tar.gz
mpd-b50d79542c95ab88387418b34999e942e6b6a583.tar.xz
mpd-b50d79542c95ab88387418b34999e942e6b6a583.zip
db/upnp: move stringToTokens() to Util.cxx
-rw-r--r--src/db/UpnpDatabasePlugin.cxx37
-rw-r--r--src/db/upnp/Util.cxx35
-rw-r--r--src/db/upnp/Util.hxx8
3 files changed, 44 insertions, 36 deletions
diff --git a/src/db/UpnpDatabasePlugin.cxx b/src/db/UpnpDatabasePlugin.cxx
index dbc0cdfd7..be035bb00 100644
--- a/src/db/UpnpDatabasePlugin.cxx
+++ b/src/db/UpnpDatabasePlugin.cxx
@@ -24,6 +24,7 @@
#include "upnp/Discovery.hxx"
#include "upnp/ContentDirectoryService.hxx"
#include "upnp/Directory.hxx"
+#include "upnp/Util.hxx"
#include "LazyDatabase.hxx"
#include "DatabasePlugin.hxx"
#include "DatabaseSelection.hxx"
@@ -146,42 +147,6 @@ private:
Error &error) const;
};
-gcc_pure
-static std::vector<std::string>
-stringToTokens(const std::string &str,
- const char *delims = "/", bool skipinit = true)
-{
- std::vector<std::string> tokens;
-
- std::string::size_type startPos = 0;
-
- // Skip initial delims, return empty if this eats all.
- if (skipinit &&
- (startPos = str.find_first_not_of(delims, 0)) == std::string::npos)
- return tokens;
-
- while (startPos < str.size()) {
- // Find next delimiter or end of string (end of token)
- auto pos = str.find_first_of(delims, startPos);
-
- // Add token to the vector and adjust start
- if (pos == std::string::npos) {
- tokens.push_back(str.substr(startPos));
- break;
- } else if (pos == startPos) {
- // Dont' push empty tokens after first
- if (tokens.empty())
- tokens.push_back(std::string());
- startPos = ++pos;
- } else {
- tokens.push_back(str.substr(startPos, pos - startPos));
- startPos = ++pos;
- }
- }
-
- return tokens;
-}
-
Database *
UpnpDatabase::Create(gcc_unused EventLoop &loop,
gcc_unused DatabaseListener &listener,
diff --git a/src/db/upnp/Util.cxx b/src/db/upnp/Util.cxx
index 52d2bc63f..afe68e619 100644
--- a/src/db/upnp/Util.cxx
+++ b/src/db/upnp/Util.cxx
@@ -89,6 +89,41 @@ path_getfather(const std::string &s)
return father;
}
+std::vector<std::string>
+stringToTokens(const std::string &str,
+ const char *delims, bool skipinit)
+{
+ std::vector<std::string> tokens;
+
+ std::string::size_type startPos = 0;
+
+ // Skip initial delims, return empty if this eats all.
+ if (skipinit &&
+ (startPos = str.find_first_not_of(delims, 0)) == std::string::npos)
+ return tokens;
+
+ while (startPos < str.size()) {
+ // Find next delimiter or end of string (end of token)
+ auto pos = str.find_first_of(delims, startPos);
+
+ // Add token to the vector and adjust start
+ if (pos == std::string::npos) {
+ tokens.push_back(str.substr(startPos));
+ break;
+ } else if (pos == startPos) {
+ // Dont' push empty tokens after first
+ if (tokens.empty())
+ tokens.push_back(std::string());
+ startPos = ++pos;
+ } else {
+ tokens.push_back(str.substr(startPos, pos - startPos));
+ startPos = ++pos;
+ }
+ }
+
+ return tokens;
+}
+
template <class T>
bool
csvToStrings(const std::string &s, T &tokens)
diff --git a/src/db/upnp/Util.hxx b/src/db/upnp/Util.hxx
index 3cdc57cd5..08fe5f497 100644
--- a/src/db/upnp/Util.hxx
+++ b/src/db/upnp/Util.hxx
@@ -20,7 +20,10 @@
#ifndef MPD_UPNP_UTIL_HXX
#define MPD_UPNP_UTIL_HXX
+#include "Compiler.h"
+
#include <string>
+#include <vector>
std::string
caturl(const std::string& s1, const std::string& s2);
@@ -31,6 +34,11 @@ trimstring(std::string &s, const char *ws = " \t\n");
std::string
path_getfather(const std::string &s);
+gcc_pure
+std::vector<std::string>
+stringToTokens(const std::string &str,
+ const char *delims = "/", bool skipinit = true);
+
template <class T>
bool csvToStrings(const std::string& s, T &tokens);