X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Futil.cpp;h=6424a9b1b5893b13d212ad1deef61221bea30aef;hp=c5f9c832ef44be87034826df96fa7d79f42e9e03;hb=3083cda853bd12d73b741c3bc97b70f5d395a15a;hpb=6f925ba9d6faf1077b73c5a5808259576081716a diff --git a/pv/util.cpp b/pv/util.cpp index c5f9c832..6424a9b1 100644 --- a/pv/util.cpp +++ b/pv/util.cpp @@ -21,12 +21,12 @@ #include -#include #include +#include #include -#include #include +#include using std::fixed; using std::max; @@ -110,12 +110,8 @@ static QTextStream& operator<<(QTextStream& stream, const Timestamp& t) return stream << QString::fromStdString(str); } -QString format_time_si( - const Timestamp& v, - SIPrefix prefix, - unsigned int precision, - QString unit, - bool sign) +QString format_time_si(const Timestamp& v, SIPrefix prefix, + unsigned int precision, QString unit, bool sign) { if (prefix == SIPrefix::unspecified) { // No prefix given, calculate it @@ -142,22 +138,14 @@ QString format_time_si( QTextStream ts(&s); if (sign && !v.is_zero()) ts << forcesign; - ts - << qSetRealNumberPrecision(precision) - << (v * multiplier) - << ' ' - << prefix - << unit; + ts << qSetRealNumberPrecision(precision) << (v * multiplier) << ' ' + << prefix << unit; return s; } -QString format_time_si_adjusted( - const Timestamp& t, - SIPrefix prefix, - unsigned precision, - QString unit, - bool sign) +QString format_time_si_adjusted(const Timestamp& t, SIPrefix prefix, + unsigned precision, QString unit, bool sign) { // The precision is always given without taking the prefix into account // so we need to deduct the number of decimals the prefix might imply @@ -170,7 +158,6 @@ QString format_time_si_adjusted( return format_time_si(t, prefix, relative_prec, unit, sign); } - // Helper for 'format_time_minutes()'. static QString pad_number(unsigned int number, int length) { @@ -237,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