A simple example on how to use the trim() family of functions for stripping characters from one or both sides of a string.
A simple example on how to use the trim() family of functions for stripping characters from one or both sides of a string.
#include <iostream>
using std::cout;
int main()
{
cout << "[" << trim("\n \b trim(), default whitespace\t \r") << "]\n";
cout << "[" << trim(".:.:.:trim(), custom whitespace.:.:.:.", ".:") << "]\n";
cout << "[" << trim_left("\n \b trim_left(), default whitespace ") << "]\n";
cout << "[" << trim_right(".:.:.:trim_right(), custom whitespace.:.:.:.", ".:") << "]\n";
cout << "[" << trim_left_sv("\n \b trim_left_sv(), default whitespace ") << "]\n";
cout << "[" << trim_right_sv(".:.:.:trim_right_sv(), custom whitespace.:.:.:.", ".:") << "]\n";
std::string str = " string_view ";
auto sv = trim_sv(str);
cout << "[" << sv << "]\n";
str[5] = 'o';
cout << "[" << sv << "]\n";
return 0;
}
GUL_EXPORT std::string_view trim_sv(std::string_view str, std::string_view ws_chars=default_whitespace_characters)
Trim leading and trailing whitespace (or a custom set of characters) from a string,...
Definition trim.cc:34
GUL_EXPORT std::string trim(std::string_view str, std::string_view ws_chars=default_whitespace_characters)
Trim leading and trailing whitespace (or a custom set of characters) from a string,...
Definition trim.cc:29
GUL_EXPORT std::string trim_right(std::string_view str, std::string_view ws_chars=default_whitespace_characters)
Trim trailing whitespace (or a custom set of characters) from a string, returning a new std::string.
Definition trim.cc:61
GUL_EXPORT std::string_view trim_right_sv(std::string_view str, std::string_view ws_chars=default_whitespace_characters)
Trim trailing whitespace (or a custom set of characters) from a string, returning a view into the ori...
Definition trim.cc:66
GUL_EXPORT std::string trim_left(std::string_view str, std::string_view ws_chars=default_whitespace_characters)
Trim leading whitespace (or a custom set of characters) from a string, returning a new std::string.
Definition trim.cc:46
GUL_EXPORT std::string_view trim_left_sv(std::string_view str, std::string_view ws_chars=default_whitespace_characters)
Trim leading whitespace (or a custom set of characters) from a string, returning a view into the orig...
Definition trim.cc:51
Declarations of trim(), trim_left(), trim_right(), trim_sv(), trim_left_sv(), and trim_right_sv().