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;
|
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 util
|
||||||
} // namespace pv
|
} // namespace pv
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
#define PULSEVIEW_UTIL_HPP
|
#define PULSEVIEW_UTIL_HPP
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#ifndef Q_MOC_RUN
|
#ifndef Q_MOC_RUN
|
||||||
#include <boost/multiprecision/cpp_dec_float.hpp>
|
#include <boost/multiprecision/cpp_dec_float.hpp>
|
||||||
|
@ -29,6 +31,9 @@
|
||||||
#include <QMetaType>
|
#include <QMetaType>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
|
using std::string;
|
||||||
|
using std::vector;
|
||||||
|
|
||||||
namespace pv {
|
namespace pv {
|
||||||
namespace util {
|
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,
|
QString format_time_minutes(const Timestamp& t, signed precision = 0,
|
||||||
bool sign = true);
|
bool sign = true);
|
||||||
|
|
||||||
|
vector<string> split_string(string text, string separator);
|
||||||
|
|
||||||
} // namespace util
|
} // namespace util
|
||||||
} // namespace pv
|
} // namespace pv
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue