17 std::vector<std::string>
split(std::string_view input, std::string_view delim)
noexcept
19 std::size_t start = 0;
22 std::vector<std::string> splits;
23 while ((start = input.find_first_not_of(delim, end)) != std::string::npos)
25 end = input.find(delim, start);
27 const auto split = input.substr(start, end - start);
30 splits.emplace_back(
split);
37 void replace_first(std::string& input, std::string_view to_replace, std::string_view replace_with)
noexcept
39 const auto pos = input.find(to_replace);
41 if (pos != std::string::npos)
43 input.replace(pos, to_replace.length(), replace_with);
47 void replace_all(std::string& input, std::string_view to_replace, std::string_view replace_with)
noexcept
51 while (pos != std::string::npos)
53 pos = input.find(to_replace, pos);
55 if (pos != std::string::npos)
57 input.replace(pos, to_replace.length(), replace_with);
62 bool begins_with(
const std::string& input,
const std::string& find)
noexcept
64 return (input.rfind(find, 0) == 0);
67 void ltrim(std::string& input)
noexcept
70 input.erase(input.begin(), std::find_if(input.begin(), input.end(), [](
const auto ch) {
71 return !std::isspace(ch);
75 void rtrim(std::string& input)
noexcept
77 input.erase(std::find_if(input.rbegin(), input.rend(), [](
const auto ch) {
78 return !std::isspace(ch);
79 }).base(), input.end());
83 void trim(std::string& input)
noexcept
91 const auto trim_from = std::unique(input.begin(), input.end(), [](
const auto lhs,
const auto rhs) {
92 return (lhs == rhs) && (lhs ==
' ');
95 input.erase(trim_from, input.end());
96 input.shrink_to_fit();
void make_single_spaced(std::string &input) noexcept
Make a string single spaced.
void trim(std::string &input) noexcept
Trim both ends of string.
void rtrim(std::string &input) noexcept
Trim string from start.
bool begins_with(const std::string &input, const std::string &find) noexcept
Check if string begins with another string.
std::vector< std::string > split(std::string_view input, std::string_view delim) noexcept
Split a string based on a delimiter.
void replace_all(std::string &input, std::string_view to_replace, std::string_view replace_with) noexcept
Replaces all occurrences of a string.
void replace_first(std::string &input, std::string_view to_replace, std::string_view replace_with) noexcept
Replace first occurrence of a string.
void ltrim(std::string &input) noexcept
Trim string from end.