X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Futil.cpp;h=6424a9b1b5893b13d212ad1deef61221bea30aef;hp=8f2d7d2544cd8e30301a28c56f6537269dbe759a;hb=dbed5609ae31cdfc3e9db10f3ab91b7607c08372;hpb=aca9aa834c742ba70f49d1ac3eb2d1e02e759416 diff --git a/pv/util.cpp b/pv/util.cpp index 8f2d7d25..6424a9b1 100644 --- a/pv/util.cpp +++ b/pv/util.cpp @@ -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