8#if __has_include(<format>)
33#ifdef __cpp_lib_format
34 return QString::fromStdString(std::format(
"{:0{}d}", n, width));
36 return QString(
"%1").arg(n, width, 10, QChar(
'0'));
40inline QString
indentSpaces(
unsigned int level,
unsigned int size = 4)
42 return {
static_cast<int>(level * size), QChar(
' ')};
50 return val ? QStringLiteral(
"true") : QStringLiteral(
"false");
54std::strong_ordering
naturalCompare(
const QString &_a,
const QString &_b,
55 Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive);
62 Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive)
79inline std::vector<std::string_view>
split_sv(
const std::string_view s,
const std::string_view delimiter)
82 if (delimiter.empty())
84 std::vector<std::string_view> tokens;
86 size_t pos = s.find(delimiter);
87 while (pos != std::string_view::npos)
89 tokens.emplace_back(s.substr(last_pos, pos - last_pos));
90 last_pos = pos + delimiter.size();
91 pos = s.find(delimiter, last_pos);
93 tokens.emplace_back(s.substr(last_pos));
MBASE_PUBLIC bool isValidUTF8(const QByteArray &data)
std::vector< std::string_view > split_sv(const std::string_view s, const std::string_view delimiter)
Split a std::string_view into a std::vector of std::string_views.
QString bool_to_string(bool val)
This is equivalent to QVariant(bool).toString()
MBASE_PUBLIC std::strong_ordering naturalCompare(const QString &_a, const QString &_b, Qt::CaseSensitivity caseSensitivity=Qt::CaseSensitive)
This method chops the input a and b into pieces of digits and non-digits (a1.05 becomes a | 1 | .
bool naturalSortCompare(const QString &a, const QString &b, Qt::CaseSensitivity caseSensitivity=Qt::CaseSensitive)
naturalCompare as a std::sort compatible function (ignoring the third parameter, which is never used)...
MBASE_PUBLIC QString formatBytes(int64_t sizeB, int prec=1)
QString intToPaddedString(int n, int width=2)
Creates a zero padded string representation of an integer.
QString indentSpaces(unsigned int level, unsigned int size=4)
MBASE_PUBLIC QString formatKBytes(int64_t sizeKB, int prec=1)