42#include <ufo/utility/string.hpp>
51std::vector<std::string>
ufo::split(std::string
const& s,
char delimiter)
53 std::vector<std::string> result;
55 std::istringstream stream(s);
56 while (std::getline(stream, token, delimiter)) {
57 result.push_back(token);
62std::string
ufo::join(std::vector<std::string>
const& strings,
char delimiter)
64 if (strings.empty()) {
68 std::string result = strings.front();
69 for (std::size_t i{1}; strings.size() > i; ++i) {
78 return s.size() >= prefix.size() && std::equal(prefix.begin(), prefix.end(), s.begin());
83 return s.size() >= suffix.size() &&
84 std::equal(suffix.rbegin(), suffix.rend(), s.rbegin());
89 return s.find(sub) != std::string::npos;
94 std::transform(s.begin(), s.end(), s.begin(),
95 [](
unsigned char c) { return static_cast<char>(std::tolower(c)); });
101 std::transform(s.begin(), s.end(), s.begin(),
102 [](
unsigned char c) { return static_cast<char>(std::toupper(c)); });
108 s.erase(s.begin(), std::find_if(s.begin(), s.end(),
109 [](
unsigned char ch) { return !std::isspace(ch); }));
114 s.erase(std::find_if(s.rbegin(), s.rend(),
115 [](
unsigned char ch) { return !std::isspace(ch); })
std::vector< std::string > split(std::string const &s, char delimiter)
Splits a string into a vector of substrings using a delimiter.
void ltrim(std::string &s)
Removes leading whitespace from the string (in-place).
bool startsWith(std::string const &s, std::string const &prefix)
Checks if a string starts with a given prefix.
bool endsWith(std::string const &s, std::string const &suffix)
Checks if a string ends with a given suffix.
void rtrim(std::string &s)
Removes trailing whitespace from the string (in-place).
std::string toupper(std::string s)
Converts all characters in the string to uppercase.
std::string join(std::vector< std::string > const &strings, char delimiter)
Joins a vector of strings into a single string with a delimiter.
std::string ltrimCopy(std::string s)
Returns a copy of the string with leading whitespace removed.
std::string tolower(std::string s)
Converts all characters in the string to lowercase.
std::string trimCopy(std::string s)
Returns a copy of the string with leading and trailing whitespace removed.
std::string rtrimCopy(std::string s)
Returns a copy of the string with trailing whitespace removed.
constexpr bool contains(A const &a, B const &b)
Checks if a shape contains another shape.
void trim(std::string &s)
Removes leading and trailing whitespace from the string (in-place).