11 namespace StringUtils {
17 template<
typename T,
typename D>
19 std::ostringstream
oss{};
20 auto it =
con.begin();
21 if (
it ==
con.end()) {
31 template<
typename T,
typename D>
41 std::vector<std::string>
res;
42 std::stringstream
ss{
str};
80 str.erase(
str.begin(), std::find_if(
str.begin(),
str.end(), [](
unsigned char ch) {
81 return !std::isspace(ch);
88 str.erase(std::find_if(
str.rbegin(),
str.rend(), [](
unsigned char ch) {
89 return !std::isspace(ch);
132 if (
str.size() <
prefix.size())
return false;
135 [](
char a,
char b) { return std::tolower(a) == std::tolower(b); });
145 if (
str.size() <
suffix.size())
return false;
148 [](
char a,
char b) { return std::tolower(a) == std::tolower(b); });
157 if (
search.empty())
return;
188 std::istringstream
oss{
str};
195 static std::random_device
seed{};
196 static std::default_random_engine
engine{
seed()};
197 static std::uniform_int_distribution<short>
choice(0, 2);
198 static std::uniform_int_distribution<int>
lowercaseAlpha(
'a',
'z');
199 static std::uniform_int_distribution<int>
uppercaseAlpha(
'A',
'Z');
200 static std::uniform_int_distribution<int>
digits(
'0',
'9');
202 std::string
str(length,
'\000');
static bool startsWith(const std::string &str, const std::string &prefix, bool ignoreCase=false)
Returns true if str starts with prefix.
static void toLower(std::string &str)
Lowercase original string str.
static std::string toUpperCopy(std::string str)
Uppercase a string.
static void rtrim(std::string &str)
Right trim a string from end (in place)
static std::string replaceCopy(std::string str, const std::string &search, const std::string &replace)
static std::string trimCopy(std::string s)
Left and Right trim a string from start and end (copy)
static std::string join(std::span< T > con, const D &delim)
Form a string from a container with a delimiter.
static void trim(std::string &str)
Left and right trim a string (from beginning and end) (in place)
static std::vector< std::string > split(const std::string &str, char delim)
Split a string by delimiter.
static void replace(std::string &str, const std::string &search, const std::string &replace)
static std::string random(std::size_t length)
Returns a random string of length characters.
static std::string ltrimCopy(std::string s)
Left trim a string from start (copy)
static void toUpper(std::string &str)
Uppercase original string str.
static void ltrim(std::string &str)
Left trim a string from start (in place)
static std::string rtrimCopy(std::string s)
Right trim a string from end (copy)
static bool endsWith(const std::string &str, const std::string &suffix, bool ignoreCase=false)
Returns true if str ends with suffix.
static std::string toLowerCopy(std::string str)
Lowercase a string.
static T to(const std::string &str)