]> sigrok.org Git - pulseview.git/blobdiff - pv/util.cpp
Update property widgets before showing device config popup
[pulseview.git] / pv / util.cpp
index 7d711f197013e65dcccca8172e14b9b29239bca6..6424a9b1b5893b13d212ad1deef61221bea30aef 100644 (file)
 
 #include <extdef.h>
 
-#include <cassert>
 #include <algorithm>
+#include <cassert>
 #include <sstream>
 
-#include <QTextStream>
 #include <QDebug>
+#include <QTextStream>
 
 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<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