diff --git a/include/maxscale/utils.hh b/include/maxscale/utils.hh index 569b270bc..2faccc388 100644 --- a/include/maxscale/utils.hh +++ b/include/maxscale/utils.hh @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -107,6 +108,29 @@ inline std::string trimmed_copy(const std::string& original) return s; } +/** + * Tokenize a string + * + * @param str String to tokenize + * @param delim List of delimiters (see strtok(3)) + * + * @return List of tokenized strings + */ +inline std::vector strtok(std::string str, const char* delim) +{ + std::vector rval; + char* save_ptr; + char* tok = strtok_r(&str[0], delim, &save_ptr); + + while (tok) + { + rval.emplace_back(tok); + tok = strtok_r(NULL, delim, &save_ptr); + } + + return rval; +} + /** * @class CloserTraits utils.hh *