General Utility Library for C++14  2.11
trim.cc

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>
#include <gul14/trim.h>
using std::cout;
int main()
{
cout << "[" << trim("\n \b trim(), default whitespace\t \r") << "]\n";
// prints "[trim(), default whitespace]"
cout << "[" << trim(".:.:.:trim(), custom whitespace.:.:.:.", ".:") << "]\n";
// prints "[trim(), custom whitespace]"
cout << "[" << trim_left("\n \b trim_left(), default whitespace ") << "]\n";
// prints "[trim_left(), default whitespace ]"
cout << "[" << trim_right(".:.:.:trim_right(), custom whitespace.:.:.:.", ".:") << "]\n";
// prints "[.:.:.:trim_right, custom whitespace]"
cout << "[" << trim_left_sv("\n \b trim_left_sv(), default whitespace ") << "]\n";
// prints "[trim_left_sv(), default whitespace ]"
cout << "[" << trim_right_sv(".:.:.:trim_right_sv(), custom whitespace.:.:.:.", ".:") << "]\n";
// prints "[.:.:.:trim_right_sv, custom whitespace]"
std::string str = " string_view ";
auto sv = trim_sv(str); // sv is a string_view that points to the original string
cout << "[" << sv << "]\n";
// prints "[string_view]"
str[5] = 'o'; // modify the original string
cout << "[" << sv << "]\n";
// prints "[strong_view]"
return 0;
}
GUL_EXPORT std::string trim(string_view str, 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 string_view trim_right_sv(string_view str, 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(string_view str, 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 string_view trim_sv(string_view str, 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_right(string_view str, 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 string_view trim_left_sv(string_view str, 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().