aboutsummaryrefslogtreecommitdiffstats
path: root/src/db/upnp/Util.cxx
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/db/upnp/Util.cxx35
1 files changed, 35 insertions, 0 deletions
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)