General Utility Library for C++14  2.7
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/gul.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;
}
gul14::trim_sv
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
gul14::trim_right
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
gul14::trim_left
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.h
Main include file for the General Utility Library.
gul14::trim_right_sv
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
gul14::trim
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
gul14::trim_left_sv
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