X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Futil.cpp;h=a452aac4b6eaef7e51f85b9cd6d0b0f37f7b5e19;hb=34f4a40baa0b4485ebee71d51c0a3bf70a0bad8b;hp=7d711f197013e65dcccca8172e14b9b29239bca6;hpb=c063290ac7189bdd15221450f598504f43286b43;p=pulseview.git diff --git a/pv/util.cpp b/pv/util.cpp index 7d711f1..a452aac 100644 --- a/pv/util.cpp +++ b/pv/util.cpp @@ -21,12 +21,12 @@ #include -#include #include +#include #include -#include #include +#include using std::fixed; using std::max; @@ -224,5 +224,27 @@ QString format_time_minutes(const Timestamp& t, signed precision, bool sign) return s; } +/** + * Split a string into tokens at occurances of the separator. + * + * @param[in] text the input string to split + * @param[in] separator the delimiter between tokens + * + * @return a vector of broken down tokens + */ +vector split_string(string text, string separator) +{ + vector result; + size_t pos; + + while ((pos = text.find(separator)) != std::string::npos) { + result.push_back(text.substr(0, pos)); + text = text.substr(pos + separator.length()); + } + result.push_back(text); + + return result; +} + } // namespace util } // namespace pv