27 namespace stringutils {
41 [[nodiscard]]
static inline std::string
ltrim(std::string
text) {
43 std::find_if(
text.begin(),
text.end(), [](
int c) { return !std::isspace(c); }));
51 [[nodiscard]]
static inline std::string
rtrim(std::string
text) {
53 std::find_if(
text.rbegin(),
text.rend(), [](
int c) { return !std::isspace(c); }).base(),
63 [[nodiscard]]
static inline std::string
trim(std::string
text) {
118 std::vector<std::string> elements;
119 std::stringstream ss(
text);
122 while (std::getline(ss, item, delimiter)) {
123 elements.push_back(item);
135 static inline bool ends_with(
const std::string& haystack,
const std::string& needle) {
136 if (needle.empty()) {
140 auto n_chars = needle.size();
141 if (haystack.size() < n_chars) {
145 auto haystack_begin = haystack.begin() + haystack.size() - n_chars;
146 return std::equal(haystack_begin, haystack.end(), needle.begin(), needle.end());
154 static inline bool starts_with(
const std::string& haystack,
const std::string& needle) {
155 return haystack.rfind(needle, 0) == 0;
174 const int padding = width -
static_cast<int>(
text.size());
178 right = std::string(padding,
' ');
180 left = std::string(padding,
' ');
182 left = std::string(padding / 2,
' ');
183 right = std::string(padding / 2,
' ');
185 if (padding % 2 != 0) {
198 [[nodiscard]]
static inline std::string
tolower(std::string
text) {
211 std::string
to_string(
double value,
const std::string& format_spec =
"{:.16g}");
static std::string ltrim(std::string text)
static std::string align_text(const std::string &text, int width, text_alignment type)
Aligns a text within a field of width width.
static std::string tolower(std::string text)
To lower case.
text_alignment
text alignment when printing in the tabular form
static bool ends_with(const std::string &haystack, const std::string &needle)
Check if haystack ends with needle.
static std::string rtrim(std::string text)
static std::string remove_character(std::string text, const char c)
Remove all occurrences of a given character in a text.
static std::string trim(std::string text)
static std::vector< std::string > split_string(const std::string &text, char delimiter)
Split a text in a list of words, using a given delimiter character.
std::string join_arguments(const std::string &lhs, const std::string &rhs)
Joint two (list of) arguments.
std::string to_string(double value, const std::string &format_spec)
Convert double value to string without trailing zeros.
static std::string trim_newline(std::string text)
static std::string escape_quotes(const std::string &text)
Escape double-quote in a text, useful for JSON pretty printer.
static bool starts_with(const std::string &haystack, const std::string &needle)
Check if haystack starts with needle.
void move(Item *q1, Item *q2, Item *q3)
encapsulates code generation backend implementations
data_handle< T > transform(data_handle< T > handle, Transform type)
static double remove(void *v)
static int equal(const char *c1, const char *c2)