16 #ifndef OSMANIP_UTILITY_GENERIC_HPP
17 #define OSMANIP_UTILITY_GENERIC_HPP
29 #include <string_view>
30 #include <type_traits>
52 extern std::vector<std::string>
split_string(
const std::string& input,
const std::string& regex);
67 template <
typename T_err = std::runtime_error>
69 const std::string& end =
"") {
70 using namespace std::literals::string_literals;
72 static std::ostringstream oss;
75 oss <<
"\033[31m" << beg <<
" \""s
76 <<
"\033[1m" << var <<
"\033[22m"
77 <<
"\" "s << end <<
"\033[39m";
79 return T_err(oss.str());
98 if constexpr (std::is_convertible_v<T, std::string_view> && !std::is_same_v<T, std::nullptr_t>) {
101 return (std::string_view(str).length() < 7) && (str[0] ==
'\033');
104 return (std::string_view(str).find(
'\033') != std::string_view::npos);
122 template <
typename T>
124 T pow_10 = std::pow(10.0f,
static_cast<T
>(prec));
126 return round(value * pow_10) / pow_10;
139 template <
typename T>
141 return std::is_floating_point<T>::value;
155 template <
typename T>
156 inline T
one(
const T& iterating_var) {
157 std::vector<T> counter_;
160 if (counter_.size() < 2) counter_.push_back(iterating_var);
161 if (counter_.size() == 2)
return abs(abs(counter_.front()) - abs(counter_.back()));
162 return static_cast<T
>(0);
180 inline std::string
operator*(
const std::string& generic_string,
unsigned int integer) {
182 output.reserve(integer * generic_string.size());
185 output += generic_string;
std::string operator*(const std::string &generic_string, unsigned int integer)
Function to multiply a string by an integer.
Definition: generic.hpp:180
Definition: canvas.cpp:30
const T empty_space
Definition: generic.hpp:42
bool isFloatingPoint(const T &)
Function to check if an expression (not a type) is a floating point or not. I know this function is a...
Definition: generic.hpp:140
bool is_escape(const T &str, const ANSI_SEARCH &flag)
This method is used to check if an input variable is an ANSI escape sequency or not.
Definition: generic.hpp:97
T_err except_error_func(const std::string &beg="", std::string var=nullptr, const std::string &end="")
Function used to throw customized stdexception error. This function is extremely specific to my purpo...
Definition: generic.hpp:68
T one(const T &iterating_var)
Function to find the incremented unit of a loop. Not easy to understand its purpose without context,...
Definition: generic.hpp:156
std::string getCommandOut(const char *command)
Function used to get the output of a shell command.
Definition: generic.cpp:54
const T null_str
Definition: generic.hpp:39
ANSI_SEARCH
Definition: generic.hpp:47
std::vector< std::string > split_string(const std::string &input, const std::string ®ex)
Function used to split a string based on a certain reges.
Definition: generic.cpp:39
T roundoff(T value, unsigned char prec)
Function to round a floating point to n-th decimal place after comma.
Definition: generic.hpp:123