Commit cf3b1cf5 authored by François Cartegnie's avatar François Cartegnie 🤞
Browse files

demux: adaptative: add tokenizer helper

parent 20375e97
...@@ -60,3 +60,19 @@ bool Helper::ifind(std::string haystack, std::string needle) ...@@ -60,3 +60,19 @@ bool Helper::ifind(std::string haystack, std::string needle)
transform(needle.begin(), needle.end(), needle.begin(), toupper); transform(needle.begin(), needle.end(), needle.begin(), toupper);
return haystack.find(needle) != std::string::npos; return haystack.find(needle) != std::string::npos;
} }
std::list<std::string> Helper::tokenize(const std::string &str, char c)
{
std::list<std::string> ret;
std::size_t prev = 0;
std::size_t cur = str.find_first_of(c, 0);
while(cur != std::string::npos)
{
ret.push_back(str.substr(prev, cur - prev));
prev = cur + 1;
cur = str.find_first_of(c, cur + 1);
}
ret.push_back(str.substr(prev));
return ret;
}
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#define HELPER_H_ #define HELPER_H_
#include <string> #include <string>
#include <list>
namespace adaptative namespace adaptative
{ {
...@@ -35,6 +36,7 @@ namespace adaptative ...@@ -35,6 +36,7 @@ namespace adaptative
static std::string combinePaths (const std::string &path1, const std::string &path2); static std::string combinePaths (const std::string &path1, const std::string &path2);
static std::string getDirectoryPath (const std::string &path); static std::string getDirectoryPath (const std::string &path);
static bool ifind (std::string haystack, std::string needle); static bool ifind (std::string haystack, std::string needle);
static std::list<std::string> tokenize(const std::string &, char);
}; };
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment