16 #include <boost/algorithm/string.hpp>
23 std::string result = name;
24 result.resize(length,
' ');
30 const std::string& delimiter)
32 std::vector<std::string> tokens;
38 const std::vector<std::string>& items,
39 const std::string& replacement)
41 for (
size_t i = 0; i < items.size(); ++i)
42 boost::replace_all(text, items[i], replacement);
46 const std::string& joint)
49 size_t n = joinable.size();
52 for (
size_t i = 0; i < n - 1; ++i)
53 result += joinable[i] + joint;
54 result += joinable[n - 1];
66 const char* first = str.data() + str.find_first_not_of(
' ');
67 const char* last = str.data() + str.size();
69 auto [p, ec] = std::from_chars(first, last, _result);
71 if (ec != std::errc())
76 const size_t pos = p - str.data();
77 const auto hasNonSpaceLeft = str.find_first_not_of(
' ', pos) != std::string::npos;
82 if (result !=
nullptr)
89 const auto strBegin = str.find_first_not_of(whitespace);
91 if (strBegin == std::string::npos)
94 const auto strEnd = str.find_last_not_of(whitespace);
95 const auto strRange = strEnd - strBegin + 1;
97 return str.substr(strBegin, strRange);
102 const auto strBegin = str.find_first_not_of(whitespace);
104 if (strBegin == std::string::npos)
107 return str.substr(strBegin);
112 return str.rfind(substr, 0) == 0;
Defines a few helper functions.
std::vector< std::string > split(const std::string &text, const std::string &delimiter)
Split string into vector of string using delimiter.
void replaceItemsFromString(std::string &text, const std::vector< std::string > &items, const std::string &replacement="")
Replaces all occurrences of items from string text with delimiter.
std::string join(const std::vector< std::string > &joinable, const std::string &joint)
Returns string obtain by joining vector elements.
std::string trim(const std::string &str, const std::string &whitespace=" \t")
Cuts any of the chars given in whitespace from start and end of str.
bool to_int(const std::string &str, int *result)
Interprets the contained text as an integer and returns it in result. Space chars at its begin and en...
std::string trimFront(const std::string &str, const std::string &whitespace=" \t")
Cuts any of the chars given in whitespace from start.
std::string to_lower(std::string text)
Returns new string which is lower case of text.
bool startsWith(const std::string &str, const std::string &substr)
True if the string starts with substr. The comparison is case sensitive.
std::string padRight(const std::string &name, size_t length)
Returns string right-padded with blanks.