mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-30 00:00:11 +01:00
35 lines
766 B
C++
35 lines
766 B
C++
#include <vector>
|
|
#include <string>
|
|
|
|
#include <villas/utils.hpp>
|
|
|
|
namespace villas {
|
|
namespace utils {
|
|
|
|
std::vector<std::string>
|
|
tokenize(std::string s, std::string delimiter)
|
|
{
|
|
std::vector<std::string> tokens;
|
|
|
|
size_t lastPos = 0;
|
|
size_t curentPos;
|
|
|
|
while((curentPos = s.find(delimiter, lastPos)) != std::string::npos) {
|
|
const size_t tokenLength = curentPos - lastPos;
|
|
tokens.push_back(s.substr(lastPos, tokenLength));
|
|
|
|
// advance in string
|
|
lastPos = curentPos + delimiter.length();
|
|
}
|
|
|
|
// check if there's a last token behind the last delimiter
|
|
if(lastPos != s.length()) {
|
|
const size_t lastTokenLength = s.length() - lastPos;
|
|
tokens.push_back(s.substr(lastPos, lastTokenLength));
|
|
}
|
|
|
|
return tokens;
|
|
}
|
|
|
|
} // namespace utils
|
|
} // namespace villas
|