X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Futil.cpp;h=6424a9b1b5893b13d212ad1deef61221bea30aef;hp=7d711f197013e65dcccca8172e14b9b29239bca6;hb=eaa02ef436fb9d8217a94076e1258da47d3cd8e0;hpb=c063290ac7189bdd15221450f598504f43286b43 diff --git a/pv/util.cpp b/pv/util.cpp index 7d711f19..6424a9b1 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 occurences 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