]> sigrok.org Git - pulseview.git/blobdiff - pv/util.cpp
DecodeSignal: Re-set decoder metadata after stack termination
[pulseview.git] / pv / util.cpp
index 8f2d7d2544cd8e30301a28c56f6537269dbe759a..6424a9b1b5893b13d212ad1deef61221bea30aef 100644 (file)
@@ -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<string> split_string(string text, string separator)
+{
+       vector<string> 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