mirror of git://sigrok.org/pulseview
util: Introduce string tokenize helper routine
Introduce a helper routine which splits a string into tokens that were separated by a delimiter.
This commit is contained in:
parent
a998be27f1
commit
34f4a40baa
22
pv/util.cpp
22
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 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<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
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
#define PULSEVIEW_UTIL_HPP
|
||||
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#ifndef Q_MOC_RUN
|
||||
#include <boost/multiprecision/cpp_dec_float.hpp>
|
||||
|
@ -29,6 +31,9 @@
|
|||
#include <QMetaType>
|
||||
#include <QString>
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
namespace pv {
|
||||
namespace util {
|
||||
|
||||
|
@ -112,6 +117,8 @@ QString format_time_si_adjusted(const Timestamp& t, SIPrefix prefix,
|
|||
QString format_time_minutes(const Timestamp& t, signed precision = 0,
|
||||
bool sign = true);
|
||||
|
||||
vector<string> split_string(string text, string separator);
|
||||
|
||||
} // namespace util
|
||||
} // namespace pv
|
||||
|
||||
|
|
Loading…
Reference in New Issue