23#include <fmt/ranges.h>
49 template<
class It,
typename... Tformat>
51 const It &iter,
u32 len,
u32 column_count, fmt::format_string<Tformat...> fmt) {
55 for (
u32 i = 0; i < len; i++) {
57 if (i % column_count == 0) {
59 accum += sham::format(
"{:8} : ", i);
61 accum += sham::format(
"\n{:8} : ", i);
65 accum += sham::format(fmt, iter[i]);
82 return sham::format(
"{:.2f} {}B", res.value, res.prefix);
92 std::ofstream myfile(filename);
106 inline void replace_all(std::string &inout, std::string_view what, std::string_view with) {
107 for (std::string::size_type pos{};
108 inout.npos != (pos = inout.find(what.data(), pos, what.length()));
109 pos += with.length()) {
110 inout.replace(pos, what.length(), with.data(), with.length());
121 std::string out = in;
141 throw std::invalid_argument(
"max len should be above 4");
143 if (s.size() > max_len) {
144 return s.substr(0, max_len - 5) +
" ...";
164 throw std::invalid_argument(
"max len should be above 4");
166 if (s.size() > max_len) {
167 return "... " + s.substr(s.size() - (max_len - 4), s.size());
182 return (str.find(what) != std::string::npos);
197 if (len > str.size()) {
199 "the string is too short to be shortened"
201 + sham::format(
"{} : {} \n {} : {}",
"str", str,
"len", len));
203 return str.substr(0, str.size() - len);
213 inline std::vector<std::string>
split_str(std::string s, std::string delimiter) {
214 std::vector<std::string> ret;
217 while ((pos = s.find(delimiter)) != std::string::npos) {
218 std::string substr = s.substr(0, pos);
219 if (substr.size() > 0)
220 ret.push_back(substr);
221 s.erase(0, pos + delimiter.length());
std::uint32_t u32
32 bit unsigned integer
This header file contains utility functions related to exception handling in the code.
Convert raw numeric values to human-readable SI-formatted pairs.
human_readable_t to_human_readable(double value)
Convert a raw value to a human-readable scaled form with an SI prefix.
namespace for basic c++ utilities
std::string format_array(const It &iter, u32 len, u32 column_count, fmt::format_string< Tformat... > fmt)
Format an array of elements into a string.
std::string trunc_str_start(std::string s, u32 max_len)
Truncate a string to a specified length, adding an ellipsis at the start if necessary.
void write_string_to_file(std::string filename, std::string s)
dump a string to a file
std::string shorten_string(std::string str, u32 len)
Shortens a string by removing the last specified number of characters.
std::string readable_sizeof(double size)
given a sizeof value return a readble string Example : readable_sizeof(1e9) -> "1....
std::string trunc_str(std::string s, u32 max_len)
Truncate a string to a specified length, adding an ellipsis if necessary.
void replace_all(std::string &inout, std::string_view what, std::string_view with)
replace all occurence of a search string with another
ExcptTypes make_except_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Create an exception with a message and a location.
std::string increase_indent(std::string in, std::string delim="\n ")
Increase indentation of a string.
std::vector< std::string > split_str(std::string s, std::string delimiter)
Splits a string into a vector of substrings according to a delimiter.
bool contain_substr(std::string str, std::string what)
Check if a substring is present in a given string.