LibSWOC++ 1.5.14
Solid Wall of C++
Loading...
Searching...
No Matches
TextView Class Reference

#include <TextView.h>

Inheritance diagram for TextView:
Inheritance graph
Collaboration diagram for TextView:
Collaboration graph

Classes

struct  CaselessEqual
 Support for containers that need case insensitive comparisons between views. More...
 
struct  LessThan
 Ordering functor, lexicographic comparison. More...
 
struct  LessThanNoCase
 Ordering functor, case ignoring lexicographic comparison. More...
 

Public Member Functions

constexpr TextView () noexcept=default
 Default constructor (empty buffer).
 
constexpr TextView (super_type const &that) noexcept
 
constexpr TextView (char const *ptr, size_t n) noexcept
 
constexpr TextView (char const *ptr, unsigned n) noexcept
 
constexpr TextView (char const *ptr, ssize_t n) noexcept
 
constexpr TextView (char const *ptr, int n) noexcept
 
template<typename T>
 TextView (T first, std::enable_if_t<!std::is_array_v< T > &&std::is_pointer_v< T > &&std::is_convertible_v< T, char const * >, T > last) noexcept
 
template<typename C, typename = std::enable_if_t<std::is_convertible_v<decltype(std::declval<C>().data()), char const *> && std::is_convertible_v<decltype(std::declval<C>().size()), size_t>>
constexpr TextView (C const &c)
 
template<size_t N>
constexpr TextView (const char(&s)[N]) noexcept
 
 TextView (char *&src)
 
 TextView (char const *&src)
 
constexpr TextView (std::nullptr_t) noexcept
 
 TextView (std::string const &str) noexcept
 
self_typeoperator= (super_type const &that)
 Assign a super class instance, std::string_view to this.
 
template<size_t N>
self_typeoperator= (const char(&s)[N])
 
self_typeoperator= (char *&s)
 Assign from C-string s.
 
self_typeoperator= (char const *&s)
 Assign from C-string s.
 
self_typeoperator= (const std::string &s)
 Assign from a std::string.
 
self_typeassign (char *&c_str)
 
self_typeassign (char const *&c_str)
 
self_typeassign (char const *ptr, size_t n)
 
self_typeassign (char const *b, char const *e)
 
self_typeassign (std::string const &s)
 Explicitly set the view from a std::string.
 
template<size_t N>
self_typeassign (const char(&s)[N]) noexcept
 
template<typename C, typename = std::enable_if_t<std::is_convertible_v<decltype(std::declval<C>().data()), char const *> && std::is_convertible_v<decltype(std::declval<C>().size()), size_t>>
constexpr self_typeassign (C const &c)
 
constexpr char operator* () const
 
self_typeoperator++ ()
 
self_type operator++ (int)
 
self_typeoperator+= (size_t n)
 
constexpr bool operator! () const noexcept
 
constexpr operator bool () const noexcept
 
self_typeclear ()
 Clear the view (become an empty view).
 
template<typename F>
size_t find_if (F const &pred) const
 Get the offset of the first character for which pred is true.
 
template<typename F>
size_t rfind_if (F const &pred) const
 Get the offset of the last character for which pred is true.
 
self_typeltrim (char c)
 
self_typeltrim (CharSet const &delimiters)
 
self_typeltrim (std::string_view const &delimiters)
 
self_typeltrim (const char *delimiters)
 
template<typename F>
self_typeltrim_if (F const &pred)
 
self_typertrim (char c)
 
self_typertrim (CharSet const &delimiters)
 
self_typertrim (std::string_view const &delimiters)
 
template<typename F>
self_typertrim_if (F const &pred)
 
self_typetrim (char c)
 
self_typetrim (CharSet const &delimiters)
 
self_typetrim (std::string_view const &delimiters)
 
self_typetrim (const char *delimiters)
 
template<typename F>
self_typetrim_if (F const &pred)
 
constexpr self_type prefix (size_t n) const noexcept
 
self_type prefix_at (char c) const
 
self_type prefix_at (std::string_view const &delimiters) const
 
template<typename F>
self_type prefix_if (F const &pred) const
 
self_typeremove_prefix (size_t n)
 
self_typeremove_suffix (size_t n)
 
self_typeremove_prefix_at (char c)
 
self_typeremove_prefix_at (std::string_view const &delimiters)
 
template<typename F>
self_typeremove_prefix_if (F const &pred)
 
self_type split_prefix (size_t n)
 
self_type split_prefix_at (char c)
 
self_type split_prefix_at (std::string_view const &delimiters)
 
template<typename F>
self_type split_prefix_if (F const &pred)
 
self_type take_prefix (size_t n)
 
self_type take_prefix_at (char c)
 
self_type take_prefix_at (std::string_view const &delimiters)
 
template<typename F>
self_type take_prefix_if (F const &pred)
 
template<typename F>
self_type clip_prefix_of (F const &pred)
 
constexpr self_type suffix (size_t n) const noexcept
 
self_type suffix_at (char c) const
 
self_type suffix_at (std::string_view const &delimiters) const
 
template<typename F>
self_type suffix_if (F const &pred) const
 
self_typeremove_suffix_at (char c)
 
self_typeremove_suffix_at (std::string_view const &delimiters)
 
template<typename F>
self_typeremove_suffix_if (F const &pred)
 
self_type split_suffix (size_t n)
 
self_type split_suffix_at (char c)
 
self_type split_suffix_at (std::string_view const &delimiters)
 
template<typename F>
self_type split_suffix_if (F const &pred)
 
self_type take_suffix (size_t n)
 
self_type take_suffix_at (char c)
 
self_type take_suffix_at (std::string_view const &delimiters)
 
template<typename F>
self_type take_suffix_if (F const &pred)
 
template<typename F>
self_type clip_suffix_of (F const &pred)
 
constexpr self_type substr (size_type pos=0, size_type count=npos) const noexcept
 
bool starts_with (std::string_view const &prefix) const noexcept
 
bool starts_with (char const *prefix) const
 
bool starts_with (char c) const noexcept
 
bool starts_with_nocase (std::string_view const &prefix) const noexcept
 
bool starts_with_nocase (char const *prefix) const
 
bool starts_with_nocase (char c) const noexcept
 
bool ends_with (std::string_view const &suffix) const noexcept
 
bool ends_with (char const *suffix) const
 
bool ends_with (char c) const noexcept
 
bool ends_with_nocase (std::string_view const &suffix) const noexcept
 
bool ends_with_nocase (char const *suffix) const
 
bool ends_with_nocase (char c) const noexcept
 
constexpr value_type const * data () const noexcept
 
constexpr value_type const * data_end () const noexcept
 
template<typename Stream>
Stream & stream_write (Stream &os, const TextView &b) const
 

Static Protected Member Functions

static void init_delimiter_set (std::string_view const &delimiters, std::bitset< 256 > &set)
 Initialize a bit mask to mark which characters are in this view.
 

Detailed Description

A read only view of a contiguous piece of memory.

A TextView does not own the memory to which it refers, it is simply a view of part of some (presumably) larger memory object. The purpose is to allow working in a read only way a specific part of the memory. A classic example for ATS is working with HTTP header fields and values which need to be accessed independently but preferably without copying. A TextView supports this style.

Note
To simplify the interface there is no constructor taking only a character pointer. Constructors require either a literal string or an explicit length. This avoid ambiguities which are much more annoying that explicitly calling strlen on a character pointer.

Definition at line 94 of file TextView.h.

Constructor & Destructor Documentation

◆ TextView() [1/12]

swoc::TextView::TextView ( super_type const & that)
constexprnoexcept

Construct from a std::string_view or TextView

Note
This provides an user defined conversion from std::string_view to TextView. The reverse conversion is implicit in TextView being a subclass of std::string_view.

◆ TextView() [2/12]

swoc::TextView::TextView ( char const * ptr,
size_t n )
constexprnoexcept

Construct from pointer and size.

Parameters
ptrPointer to first character.
nNumber of characters.

If n is npos then ptr is presumed to be a C string and checked for length. If ptr is nullptr the length is 0. Otherwise strlen is used to calculate the length.

◆ TextView() [3/12]

swoc::TextView::TextView ( char const * ptr,
unsigned n )
constexprnoexcept

Construct from pointer and size.

Parameters
ptrPointer to first character.
nNumber of characters.

◆ TextView() [4/12]

swoc::TextView::TextView ( char const * ptr,
ssize_t n )
constexprnoexcept

Construct from pointer and size.

Parameters
ptrPointer to first character.
nNumber of characters.

If n is negative then ptr is presumed to be a C string and checked for length. If ptr is nullptr the length is 0. Otherwise strlen is used to calculate the length.

◆ TextView() [5/12]

swoc::TextView::TextView ( char const * ptr,
int n )
constexprnoexcept

Construct from pointer and size.

Parameters
ptrPointer to first character.
nNumber of characters.

If n is negative then ptr is presumed to be a C string and checked for length. If ptr is nullptr the length is 0. Otherwise strlen is used to calculate the length.

◆ TextView() [6/12]

template<typename T>
swoc::TextView::TextView ( T first,
std::enable_if_t<!std::is_array_v< T > &&std::is_pointer_v< T > &&std::is_convertible_v< T, char const * >, T > last )
inlineexplicitnoexcept

Construct from a half open range [first, last).

Parameters
firstStart of half open range.
lastEnd of half open range.

The character at first will be in the view, but the character at last will not.

Note
explicit to avoid interpreting a string initializer list as a view.

Definition at line 167 of file TextView.h.

◆ TextView() [7/12]

template<typename C, typename = std::enable_if_t<std::is_convertible_v<decltype(std::declval<C>().data()), char const *> && std::is_convertible_v<decltype(std::declval<C>().size()), size_t>>
swoc::TextView::TextView ( C const & c)
constexpr

Construct from any character container following STL standards.

Template Parameters
CContainer type.
Parameters
ccontainer

The container type must have the methods data and size which must return values convertible to char const * and size_t respectively.

◆ TextView() [8/12]

template<size_t N>
swoc::TextView::TextView ( const char(&) s[N])
constexprnoexcept

Construct from literal string or array.

All elements of the array are included in the view unless the last element is nul, in which case it is elided. If this is inappropriate then a constructor with an explicit size should be used.

TextView a("A literal string");
constexpr TextView() noexcept=default
Default constructor (empty buffer).

The last character in a will be 'g'.

◆ TextView() [9/12]

swoc::TextView::TextView ( char *& src)
inline

Construct from a C-string.

Parameters
srcA pointer to a C-string.

The view does not include the terminating nul.

Definition at line 205 of file TextView.h.

◆ TextView() [10/12]

swoc::TextView::TextView ( char const *& src)
inline

Construct from a const C-string.

Parameters
srcPointer to a const C-string.

The view does not include the terminating nul.

Definition at line 215 of file TextView.h.

◆ TextView() [11/12]

swoc::TextView::TextView ( std::nullptr_t )
constexprnoexcept

Construct from nullptr. This implicitly makes the length 0.

◆ TextView() [12/12]

swoc::TextView::TextView ( std::string const & str)
noexcept

Construct from std::string, referencing the entire string contents.

Member Function Documentation

◆ assign() [1/6]

template<typename C, typename = std::enable_if_t<std::is_convertible_v<decltype(std::declval<C>().data()), char const *> && std::is_convertible_v<decltype(std::declval<C>().size()), size_t>>
self_type & swoc::TextView::assign ( C const & c)
inlineconstexpr

Assign from any character container following STL standards.

Template Parameters
CContainer type.
Parameters
ccontainer

The container type must have the methods data and size which must return values convertible to char const * and size_t respectively.

Definition at line 305 of file TextView.h.

◆ assign() [2/6]

self_type & swoc::TextView::assign ( char *& c_str)

Assign a view of the c_str

Parameters
c_strPointer to C string.
Returns
this
Note
c_str must be a null terminated string. The null byte is not included in the view.

◆ assign() [3/6]

self_type & swoc::TextView::assign ( char const *& c_str)

Assign a view of the c_str

Parameters
c_strPointer to C string.
Returns
this
Note
c_str must be a null terminated string. The null byte is not included in the view.

◆ assign() [4/6]

self_type & swoc::TextView::assign ( char const * b,
char const * e )

Assign the half open view [ b , e ) to this

Parameters
bFirst character in the view.
eOne character after the last character in the view.
Returns
this

◆ assign() [5/6]

self_type & swoc::TextView::assign ( char const * ptr,
size_t n )

Assign from a pointer and size.

Parameters
ptrPointer to first character of the view.
nLength of the view.
Returns
this

if n is npos then strlen is used determine the size of the view.

◆ assign() [6/6]

template<size_t N>
self_type & swoc::TextView::assign ( const char(&) s[N])
noexcept

Assign literal string or array.

All elements of the array are included in the view unless the last element is nul, in which case it is elided. If this is inappropriate then a constructor with an explicit size should be used.

tv.assign("A literal string");

The last character in tv will be 'g'.

◆ clip_prefix_of()

template<typename F>
self_type swoc::TextView::clip_prefix_of ( F const & pred)

Remove and return a prefix of characters satisfying pred

Template Parameters
FPredicate functor type.
Parameters
predA function taking char and returning bool.
Returns
The prefix of characters that satisfy pred.

The returned prefix is removed from this. That prefix may be empty if the first character does not satisfy pred.

Note
This is very similar to ltrim_if but returns the removed text instead of the modified view.

◆ clip_suffix_of()

template<typename F>
self_type swoc::TextView::clip_suffix_of ( F const & pred)

Remove and return a suffix of characters satisfying pred

Template Parameters
FPredicate functor type.
Parameters
predA function taking char and returning bool.
Returns
The suffix of characters that satisfy pred.

The returned suffix is removed from this. That suffix may be empty if the last character does not satisfy pred.

Note
This is very similar to rtrim_if but returns the removed text instead of the modified view.

◆ data()

value_type const * swoc::TextView::data ( ) const
constexprnoexcept

A pointer to the first byte.

Returns
Address of the first byte of the view.

◆ data_end()

value_type const * swoc::TextView::data_end ( ) const
constexprnoexcept

A pointer to past the last byte.

Returns
Address of the first byte past the end of the view.

This is effectively std::string_view::end() except it explicit returns a pointer and not (potentially) an iterator class, to match up with data().

◆ ends_with() [1/3]

bool swoc::TextView::ends_with ( char c) const
noexcept

Check the view ends with the character c.

Parameters
cCharacter to check.
Returns
true if the string is non-empty and the last character is c.

◆ ends_with() [2/3]

bool swoc::TextView::ends_with ( char const * suffix) const

Check if the view ends with a specific suffix.

Parameters
suffixString to check against this.
Returns
true if this->suffix(suffix.size()) == suffix, false otherwise.

◆ ends_with() [3/3]

bool swoc::TextView::ends_with ( std::string_view const & suffix) const
noexcept

Check if the view ends with a specific suffix.

Parameters
suffixString to check against this.
Returns
true if this->suffix(suffix.size()) == suffix, false otherwise.

◆ ends_with_nocase() [1/3]

bool swoc::TextView::ends_with_nocase ( char c) const
noexcept

Check the view ends with the character c, ignoring case.

Parameters
cCharacter to check.
Returns
true if the string is non-empty and the last character is c.

◆ ends_with_nocase() [2/3]

bool swoc::TextView::ends_with_nocase ( char const * suffix) const

Check if the view starts with a specific suffix, ignoring case.

Parameters
suffixString to check against this.
Returns
true if this->suffix(suffix.size()) == suffix without regard to case, false otherwise.

◆ ends_with_nocase() [3/3]

bool swoc::TextView::ends_with_nocase ( std::string_view const & suffix) const
noexcept

Check if the view starts with a specific suffix, ignoring case.

Parameters
suffixString to check against this.
Returns
true if this->suffix(suffix.size()) == suffix without regard to case, false otherwise.

◆ ltrim() [1/4]

self_type & swoc::TextView::ltrim ( char c)

Remove bytes that match c from the start of the view.

Returns
this

◆ ltrim() [2/4]

self_type & swoc::TextView::ltrim ( CharSet const & delimiters)

Remove bytes from the start of the view that are in delimiters.

Returns
this

◆ ltrim() [3/4]

self_type & swoc::TextView::ltrim ( const char * delimiters)

Remove bytes from the start of the view that are in delimiters.

◆ ltrim() [4/4]

self_type & swoc::TextView::ltrim ( std::string_view const & delimiters)

Remove bytes from the start of the view that are in delimiters.

Returns
this

◆ ltrim_if()

template<typename F>
self_type & swoc::TextView::ltrim_if ( F const & pred)

Remove bytes from the start of the view for which pred is true. pred must be a functor taking a char argument and returning bool.

Returns
*this

◆ operator bool()

swoc::TextView::operator bool ( ) const
explicitconstexprnoexcept

Check for non-empty view.

Returns
true if the view refers to a non-empty range of bytes.

◆ operator!()

bool swoc::TextView::operator! ( ) const
constexprnoexcept

Check for empty view.

Returns
true if the view has a nullptr or zero size.

◆ operator*()

char swoc::TextView::operator* ( ) const
constexpr

Dereference operator.

Note
This allows the view to be used as if it were a character iterator to a null terminated string which is handy for several other STL interfaces.
Returns
The first byte in the view, or a nul character if the view is empty.
The first byte in the view.

◆ operator++() [1/2]

self_type & swoc::TextView::operator++ ( )

Discard the first byte of the view.

Returns
this.

◆ operator++() [2/2]

self_type swoc::TextView::operator++ ( int )

Discard the first byte of the view.

Returns
The view before discarding the byte.

◆ operator+=()

self_type & swoc::TextView::operator+= ( size_t n)

Discard the first n bytes of the view.

Equivalent to remove_prefix(n).

Returns
this

◆ operator=()

template<size_t N>
self_type & swoc::TextView::operator= ( const char(&) s[N])

Assign a constant array to this.

Note
If the last character of s is a nul byte, it is not included in the view.

◆ prefix()

self_type swoc::TextView::prefix ( size_t n) const
constexprnoexcept

Get a view of the first n bytes.

Parameters
nNumber of chars in the prefix.
Returns
A view of the first n characters in this, bounded by the size of this.

◆ prefix_at() [1/2]

self_type swoc::TextView::prefix_at ( char c) const

Get a view of a prefix bounded by c.

Parameters
cDelimiter character.
Returns
A view of the prefix bounded by c, or all of this if c is not found.
Note
The character c is not included in the returned view.

◆ prefix_at() [2/2]

self_type swoc::TextView::prefix_at ( std::string_view const & delimiters) const

Get a view of a prefix bounded by a character in delimiters.

Parameters
delimitersA set of characters.
Returns
A view of the prefix bounded by any character in delimiters, or empty if none are found.
Note
The delimiter character is not included in the returned view.

◆ prefix_if()

template<typename F>
self_type swoc::TextView::prefix_if ( F const & pred) const

Get a view of a prefix bounded by a character predicate pred.

pred must be a functor which takes a char argument and returns bool. Each character in this is tested by pred and the prefix is delimited by the first character for which pred is true.

Parameters
predA character predicate.
Returns
A view of the prefix bounded by pred or empty if pred is not true for any characer.
Note
The deliminting character is not included in the returned view.

◆ remove_prefix()

self_type & swoc::TextView::remove_prefix ( size_t n)

Remove bytes from the start of the view.

Parameters
nNumber of bytes to remove.
Returns
this.

◆ remove_prefix_at() [1/2]

self_type & swoc::TextView::remove_prefix_at ( char c)

Remove the leading characters of this up to and including c.

Parameters
cDelimiter character.
Returns
this.
Note
The first occurrence of character c is removed along with all preceding characters, or the view is cleared if c is not found.

◆ remove_prefix_at() [2/2]

self_type & swoc::TextView::remove_prefix_at ( std::string_view const & delimiters)

Remove the leading characters of this up to and including the first character matching delimiters.

Parameters
delimitersCharacters to match.
Returns
this.
Note
The first occurrence of any character in delimiters is removed along with all preceding characters, or the view is cleared if none are found.

◆ remove_prefix_if()

template<typename F>
self_type & swoc::TextView::remove_prefix_if ( F const & pred)

Remove the leading characters up to and including the character selected by pred.

Template Parameters
FPredicate function type.
Parameters
predThe predicate instance.
Returns
this.

Characters are removed until pred returns true. The matching character is also removed.

◆ remove_suffix()

self_type & swoc::TextView::remove_suffix ( size_t n)

Remove bytes from the end of the view.

Parameters
nNumber of bytes to remove.
Returns
this.

◆ remove_suffix_at() [1/2]

self_type & swoc::TextView::remove_suffix_at ( char c)

Remove the trailing characters of this up to and including c.

Parameters
cDelimiter character.
Returns
this.
Note
The last occurrence of character c is removed along with all succeeding characters, or the view is cleared if c is not found.

◆ remove_suffix_at() [2/2]

self_type & swoc::TextView::remove_suffix_at ( std::string_view const & delimiters)

Remove the trailing characters of this up to and including the last character matching delimiters.

Parameters
delimitersCharacters to match.
Returns
this.
Note
The first occurrence of any character in delimiters is removed along with all preceding characters, or the view is cleared if none are found.

◆ remove_suffix_if()

template<typename F>
self_type & swoc::TextView::remove_suffix_if ( F const & pred)

Remove the trailing characters up to and including the character selected by pred.

Template Parameters
FPredicate function type.
Parameters
predThe predicate instance.
Returns
this.

If predicate is never true the view is cleared.

◆ rtrim() [1/3]

self_type & swoc::TextView::rtrim ( char c)

Remove bytes that match c from the end of the view.

Returns
this

◆ rtrim() [2/3]

self_type & swoc::TextView::rtrim ( CharSet const & delimiters)

Remove bytes from the end of the view that are in delimiters.

Returns
this

◆ rtrim() [3/3]

self_type & swoc::TextView::rtrim ( std::string_view const & delimiters)

Remove bytes from the end of the view that are in delimiters.

Returns
this

◆ rtrim_if()

template<typename F>
self_type & swoc::TextView::rtrim_if ( F const & pred)

Remove bytes from the end of the view for which pred is true.

pred must be a functor taking a char argument and returning bool.

Returns
*this

◆ split_prefix()

self_type swoc::TextView::split_prefix ( size_t n)

Remove and return a prefix of size n.

Parameters
nSize of the prefix.
Returns
The first n bytes of this if n is in this, otherwise an empty view.

The prefix is removed and returned if the requested prefix is no larger than this, otherwise this is not modified.

Note
The character at offset n is discarded if this is modified.
See also
take_prefix

◆ split_prefix_at() [1/2]

self_type swoc::TextView::split_prefix_at ( char c)

Remove and return a prefix bounded by the first occurrence of c.

Parameters
cThe character to match.
Returns
The prefix bounded by c if c is found, an empty view if not.

The prefix is removed and returned if c is found, otherwise this is not modified.

Note
The delimiter character is discarded if this is modified.
See also
take_prefix

◆ split_prefix_at() [2/2]

self_type swoc::TextView::split_prefix_at ( std::string_view const & delimiters)

Remove and return a prefix bounded by the first occurrence of any of delimiters.

Parameters
delimitersThe characters to match.
Returns
The prefix bounded by a delimiter if one is found, otherwise an empty view.

The prefix is removed and returned if a delimiter is found, otherwise this is not modified.

Note
The matching character is discarded if this is modified.
See also
take_prefix_at

◆ split_prefix_if()

template<typename F>
self_type swoc::TextView::split_prefix_if ( F const & pred)

Remove and return a prefix bounded by the first character that satisfies pred.

Template Parameters
FPredicate functor type.
Parameters
predA function taking char and returning bool.
Returns
The prefix bounded by the first character satisfying pred.

The prefix is removed and returned if a character satisfying pred is found, otherwise this is not modified.

Note
The matching character is discarded if this is modified.
See also
take_prefix_if

◆ split_suffix()

self_type swoc::TextView::split_suffix ( size_t n)

Remove and return a suffix of size n.

Parameters
nSize of the suffix.
Returns
The first n bytes of this if n is in this, otherwise an empty view.

The prefix is removed and returned if the requested suffix is no larger than this, otherwise this is not modified.

Note
The character at offset n is discarded if this is modified.
See also
take_suffix

◆ split_suffix_at() [1/2]

self_type swoc::TextView::split_suffix_at ( char c)

Remove and return a suffix bounded by the last occurrence of c.

Parameters
cThe character to match.
Returns
The suffix bounded by c if c is found, an empty view if not.

The suffix is removed and returned if c is found, otherwise this is not modified.

Note
The character at offset n is discarded if this is modified.
See also
take_suffix_at

◆ split_suffix_at() [2/2]

self_type swoc::TextView::split_suffix_at ( std::string_view const & delimiters)

Remove and return a suffix bounded by the last occurrence of any of delimiters.

Parameters
delimitersThe characters to match.
Returns
The suffix bounded by a delimiter if found, an empty view if none found.

The suffix is removed and returned if delimiter is found, otherwise this is not modified.

Note
The delimiter character is discarded if this is modified.
See also
take_suffix_at

◆ split_suffix_if()

template<typename F>
self_type swoc::TextView::split_suffix_if ( F const & pred)

Remove and return a suffix bounded by the last character that satisfies pred.

Template Parameters
FPredicate functor type.
Parameters
predA function taking char and returning bool.
Returns
The suffix bounded by the first character satisfying pred if found, otherwise this is not modified.

The prefix is removed and returned if a character satisfying pred if found, otherwise this is not modified.

Note
The matching character is discarded if this is modified.
See also
take_suffix_if

◆ starts_with() [1/3]

bool swoc::TextView::starts_with ( char c) const
noexcept

Check if the view begins with the character c.

Parameters
cCharacter to check.
Returns
true if the string is non-empty and the first character is c.

◆ starts_with() [2/3]

bool swoc::TextView::starts_with ( char const * prefix) const

Check if the view begins with a specific prefix.

Parameters
prefixString to check against this.
Returns
true if this->prefix(prefix.size()) == prefix, false otherwise.

◆ starts_with() [3/3]

bool swoc::TextView::starts_with ( std::string_view const & prefix) const
noexcept

Check if the view begins with a specific prefix.

Parameters
prefixString to check against this.
Returns
true if this->prefix(prefix.size()) == prefix, false otherwise.

◆ starts_with_nocase() [1/3]

bool swoc::TextView::starts_with_nocase ( char c) const
noexcept

Check if the view begins with the character c, ignoring case.

Parameters
cCharacter to check.
Returns
true if the string is non-empty and the first character is c.

◆ starts_with_nocase() [2/3]

bool swoc::TextView::starts_with_nocase ( char const * prefix) const

Check if the view begins with a specific prefix.

Parameters
prefixString to check against this.
Returns
true if this->prefix(prefix.size()) == prefix, false otherwise.

◆ starts_with_nocase() [3/3]

bool swoc::TextView::starts_with_nocase ( std::string_view const & prefix) const
noexcept

Check if the view begins with a specific prefix, ignoring case.

Parameters
prefixString to check against this.
Returns
true if this->prefix(prefix.size()) == prefix without regard to case, false otherwise.

◆ stream_write()

template<typename Stream>
TextView_INTERNAL template std::ostream & swoc::TextView::stream_write ( Stream & os,
const TextView & b ) const

Specialized stream operator implementation.

Note
Use the standard stream operator unless there is a specific need for this, which is unlikely.
Returns
The stream os.

◆ substr()

self_type swoc::TextView::substr ( size_type pos = 0,
size_type count = npos ) const
constexprnoexcept

Get a view of part of this view.

Parameters
posOffset of first byte in the new view.
countNumber of bytes in the view.
Returns
The view starting at pos for count bytes.

The returned view is clipped by this - that is, it will not extend beyond the original view. count is reduced such that it covers only data in this.

Note
This is provided primarily for co-variance, i.e. the returned view is a TextView instead of a std::string_view.

◆ suffix()

self_type swoc::TextView::suffix ( size_t n) const
constexprnoexcept

Get a view of the last n bytes.

Parameters
nNumber of chars in the suffix.
Returns
A view of the last n characters in this, bounded by the size of this.

◆ suffix_at() [1/2]

self_type swoc::TextView::suffix_at ( char c) const

Get a view of a suffix bounded by c.

Parameters
cDelimiter character.
Returns
A view of the suffix bounded by c, or all of this if c is not found.
Note
The character c is not included in the returned view.

◆ suffix_at() [2/2]

self_type swoc::TextView::suffix_at ( std::string_view const & delimiters) const

Get a view of a suffix bounded by a character in delimiters.

Parameters
delimitersA set of characters.
Returns
A view of the suffix bounded by any character in delimiters, or mepty if none are found.
Note
The delimiter character is not included in the returned view.

◆ suffix_if()

template<typename F>
self_type swoc::TextView::suffix_if ( F const & pred) const

Get a view of a suffix bounded by a character predicate pred.

pred must be a functor which takes a char argument and returns bool. Each character in this is tested by pred and the suffix is delimited by the last character for which pred is true.

Parameters
predA character predicate.
Returns
A view of the suffix bounded by pred or empty if pred is not true for any character.
Note
The delimiting character is not included in the returned view.

◆ take_prefix()

self_type swoc::TextView::take_prefix ( size_t n)

Remove and return the first n characters.

Parameters
nSize of the return prefix.
Returns
The first n bytes of this if n is in this, otherwise all of this.

The prefix is removed and returned if the requested prefix is no larger than this, otherwise all of this is removed and returned.

Note
The character at offset n is discarded if n is within the bounds of this.
See also
split_prefix

◆ take_prefix_at() [1/2]

self_type swoc::TextView::take_prefix_at ( char c)

Remove and return a prefix bounded by the first occurrence of c.

Parameters
cThe character to match.
Returns
The prefix bounded by c if c is found, all of this if not.

The prefix is removed and returned if c is found, otherwise all of this is removed and returned.

Note
The character at offset n is discarded if found.
See also
split_prefix_at

◆ take_prefix_at() [2/2]

self_type swoc::TextView::take_prefix_at ( std::string_view const & delimiters)

Remove and return a prefix bounded by the first occurrence of any of delimiters.

Parameters
delimitersThe characters to match.
Returns
The prefix bounded by a delimiter if one is found, otherwise all of this.

The prefix is removed and returned if a delimiter is found, otherwise all of this is removed and returned.

Note
The matching character is discarded if found.
See also
split_prefix_at

◆ take_prefix_if()

template<typename F>
self_type swoc::TextView::take_prefix_if ( F const & pred)

Remove and return a prefix bounded by the first character that satisfies pred.

Template Parameters
FPredicate functor type.
Parameters
predA function taking char and returning bool.
Returns
The prefix bounded by the first character satisfying pred, or all of this if none is found.

The prefix is removed and returned if a character satisfying pred is found, otherwise all of this is removed and returned.

Note
The matching character is discarded if found.
See also
split_prefix_if

◆ take_suffix()

self_type swoc::TextView::take_suffix ( size_t n)

Remove and return a suffix of size n.

Parameters
nSize of the suffix.
Returns
The first n bytes of this if n is in this, otherwise all of this.

The returned suffix is removed from this, along with the character at offset n if present.

See also
split_suffix

◆ take_suffix_at() [1/2]

self_type swoc::TextView::take_suffix_at ( char c)

Remove and return a suffix bounded by the last occurrence of c.

Parameters
cThe character to match.
Returns
The suffix bounded by c if c is found, all of this if not.

The returned suffix is removed from this, along with the delimiter character if found.

See also
split_suffix_at

◆ take_suffix_at() [2/2]

self_type swoc::TextView::take_suffix_at ( std::string_view const & delimiters)

Remove and return a suffix bounded by the last occurrence of any of delimiters.

Parameters
delimitersThe characters to match.
Returns
The suffix bounded by a delimiter if c is found, all of this if not.

The returned suffix is removed from this, along with the delimiter character if found.

See also
split_suffix_at

◆ take_suffix_if()

template<typename F>
self_type swoc::TextView::take_suffix_if ( F const & pred)

Remove and return a suffix bounded by the last character that satisfies pred.

Template Parameters
FPredicate functor type.
Parameters
predA function taking char and returning bool.
Returns
The suffix bounded by the first character satisfying pred if found, otherwise all of this.
Note
The matching character is discarded if found.
See also
split_suffix_if

◆ trim() [1/4]

self_type & swoc::TextView::trim ( char c)

Remove bytes that match c from the start and end of this view.

Returns
this

◆ trim() [2/4]

self_type & swoc::TextView::trim ( CharSet const & delimiters)

Remove bytes from the start and end of the view that are in delimiters.

Returns
this

◆ trim() [3/4]

self_type & swoc::TextView::trim ( const char * delimiters)

Remove bytes from the start and end of the view that are in delimiters.

◆ trim() [4/4]

self_type & swoc::TextView::trim ( std::string_view const & delimiters)

Remove bytes from the start and end of the view that are in delimiters.

Returns
this

◆ trim_if()

template<typename F>
self_type & swoc::TextView::trim_if ( F const & pred)

Remove bytes from the start and end of the view for which pred is true. pred must be a functor taking a char argument and returning bool.

Returns
*this

The documentation for this class was generated from the following files: