|
LibSWOC++ 1.5.14
Solid Wall of C++
|
#include <TextView.h>


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_type & | operator= (super_type const &that) |
Assign a super class instance, std::string_view to this. | |
| template<size_t N> | |
| self_type & | operator= (const char(&s)[N]) |
| self_type & | operator= (char *&s) |
| Assign from C-string s. | |
| self_type & | operator= (char const *&s) |
| Assign from C-string s. | |
| self_type & | operator= (const std::string &s) |
Assign from a std::string. | |
| self_type & | assign (char *&c_str) |
| self_type & | assign (char const *&c_str) |
| self_type & | assign (char const *ptr, size_t n) |
| self_type & | assign (char const *b, char const *e) |
| self_type & | assign (std::string const &s) |
Explicitly set the view from a std::string. | |
| template<size_t N> | |
| self_type & | assign (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_type & | assign (C const &c) |
| constexpr char | operator* () const |
| self_type & | operator++ () |
| self_type | operator++ (int) |
| self_type & | operator+= (size_t n) |
| constexpr bool | operator! () const noexcept |
| constexpr | operator bool () const noexcept |
| self_type & | clear () |
| 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_type & | ltrim (char c) |
| self_type & | ltrim (CharSet const &delimiters) |
| self_type & | ltrim (std::string_view const &delimiters) |
| self_type & | ltrim (const char *delimiters) |
| template<typename F> | |
| self_type & | ltrim_if (F const &pred) |
| self_type & | rtrim (char c) |
| self_type & | rtrim (CharSet const &delimiters) |
| self_type & | rtrim (std::string_view const &delimiters) |
| template<typename F> | |
| self_type & | rtrim_if (F const &pred) |
| self_type & | trim (char c) |
| self_type & | trim (CharSet const &delimiters) |
| self_type & | trim (std::string_view const &delimiters) |
| self_type & | trim (const char *delimiters) |
| template<typename F> | |
| self_type & | trim_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_type & | remove_prefix (size_t n) |
| self_type & | remove_suffix (size_t n) |
| self_type & | remove_prefix_at (char c) |
| self_type & | remove_prefix_at (std::string_view const &delimiters) |
| template<typename F> | |
| self_type & | remove_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_type & | remove_suffix_at (char c) |
| self_type & | remove_suffix_at (std::string_view const &delimiters) |
| template<typename F> | |
| self_type & | remove_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. | |
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.
strlen on a character pointer. Definition at line 94 of file TextView.h.
|
constexprnoexcept |
|
constexprnoexcept |
Construct from pointer and size.
| ptr | Pointer to first character. |
| n | Number 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.
|
constexprnoexcept |
Construct from pointer and size.
| ptr | Pointer to first character. |
| n | Number of characters. |
|
constexprnoexcept |
Construct from pointer and size.
| ptr | Pointer to first character. |
| n | Number 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.
|
constexprnoexcept |
Construct from pointer and size.
| ptr | Pointer to first character. |
| n | Number 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.
|
inlineexplicitnoexcept |
Construct from a half open range [first, last).
| first | Start of half open range. |
| last | End of half open range. |
The character at first will be in the view, but the character at last will not.
explicit to avoid interpreting a string initializer list as a view. Definition at line 167 of file TextView.h.
|
constexpr |
Construct from any character container following STL standards.
| C | Container type. |
| c | container |
The container type must have the methods data and size which must return values convertible to char const * and size_t respectively.
|
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.
The last character in a will be 'g'.
|
inline |
Construct from a C-string.
| src | A pointer to a C-string. |
The view does not include the terminating nul.
Definition at line 205 of file TextView.h.
|
inline |
Construct from a const C-string.
| src | Pointer to a const C-string. |
The view does not include the terminating nul.
Definition at line 215 of file TextView.h.
|
constexprnoexcept |
Construct from nullptr. This implicitly makes the length 0.
|
noexcept |
Construct from std::string, referencing the entire string contents.
|
inlineconstexpr |
Assign from any character container following STL standards.
| C | Container type. |
| c | container |
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.
| self_type & swoc::TextView::assign | ( | char *& | c_str | ) |
Assign a view of the c_str
| c_str | Pointer to C string. |
c_str must be a null terminated string. The null byte is not included in the view. | self_type & swoc::TextView::assign | ( | char const *& | c_str | ) |
Assign a view of the c_str
| c_str | Pointer to C string. |
c_str must be a null terminated string. The null byte is not included in the view. | self_type & swoc::TextView::assign | ( | char const * | b, |
| char const * | e ) |
Assign the half open view [ b , e ) to this
| b | First character in the view. |
| e | One character after the last character in the view. |
| self_type & swoc::TextView::assign | ( | char const * | ptr, |
| size_t | n ) |
Assign from a pointer and size.
| ptr | Pointer to first character of the view. |
| n | Length of the view. |
if n is npos then strlen is used determine the size of the view.
|
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.
The last character in tv will be 'g'.
| self_type swoc::TextView::clip_prefix_of | ( | F const & | pred | ) |
Remove and return a prefix of characters satisfying pred
| F | Predicate functor type. |
| pred | A function taking char and returning bool. |
The returned prefix is removed from this. That prefix may be empty if the first character does not satisfy pred.
ltrim_if but returns the removed text instead of the modified view. | self_type swoc::TextView::clip_suffix_of | ( | F const & | pred | ) |
Remove and return a suffix of characters satisfying pred
| F | Predicate functor type. |
| pred | A function taking char and returning bool. |
The returned suffix is removed from this. That suffix may be empty if the last character does not satisfy pred.
rtrim_if but returns the removed text instead of the modified view.
|
constexprnoexcept |
A pointer to the first byte.
|
constexprnoexcept |
A pointer to past the last byte.
This is effectively std::string_view::end() except it explicit returns a pointer and not (potentially) an iterator class, to match up with data().
|
noexcept |
Check the view ends with the character c.
| c | Character to check. |
true if the string is non-empty and the last character is c. | bool swoc::TextView::ends_with | ( | char const * | suffix | ) | const |
Check if the view ends with a specific suffix.
| suffix | String to check against this. |
true if this->suffix(suffix.size()) == suffix, false otherwise.
|
noexcept |
Check if the view ends with a specific suffix.
| suffix | String to check against this. |
true if this->suffix(suffix.size()) == suffix, false otherwise.
|
noexcept |
Check the view ends with the character c, ignoring case.
| c | Character to check. |
true if the string is non-empty and the last character is c. | bool swoc::TextView::ends_with_nocase | ( | char const * | suffix | ) | const |
Check if the view starts with a specific suffix, ignoring case.
| suffix | String to check against this. |
true if this->suffix(suffix.size()) == suffix without regard to case, false otherwise.
|
noexcept |
Check if the view starts with a specific suffix, ignoring case.
| suffix | String to check against this. |
true if this->suffix(suffix.size()) == suffix without regard to case, false otherwise. | self_type & swoc::TextView::ltrim | ( | char | c | ) |
Remove bytes that match c from the start of the view.
| self_type & swoc::TextView::ltrim | ( | CharSet const & | delimiters | ) |
Remove bytes from the start of the view that are in delimiters.
| self_type & swoc::TextView::ltrim | ( | const char * | delimiters | ) |
Remove bytes from the start of the view that are in delimiters.
| self_type & swoc::TextView::ltrim | ( | std::string_view const & | delimiters | ) |
Remove bytes from the start of the view that are in delimiters.
| 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.
*this
|
explicitconstexprnoexcept |
Check for non-empty view.
true if the view refers to a non-empty range of bytes.
|
constexprnoexcept |
Check for empty view.
true if the view has a nullptr or zero size.
|
constexpr |
Dereference operator.
| self_type & swoc::TextView::operator++ | ( | ) |
Discard the first byte of the view.
| self_type swoc::TextView::operator++ | ( | int | ) |
Discard the first byte of the view.
| self_type & swoc::TextView::operator+= | ( | size_t | n | ) |
Discard the first n bytes of the view.
Equivalent to remove_prefix(n).
| self_type & swoc::TextView::operator= | ( | const char(&) | s[N] | ) |
Assign a constant array to this.
|
constexprnoexcept |
Get a view of the first n bytes.
| n | Number of chars in the prefix. |
| self_type swoc::TextView::prefix_at | ( | char | c | ) | const |
Get a view of a prefix bounded by c.
| c | Delimiter character. |
| self_type swoc::TextView::prefix_at | ( | std::string_view const & | delimiters | ) | const |
Get a view of a prefix bounded by a character in delimiters.
| delimiters | A set of characters. |
| 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.
| pred | A character predicate. |
true for any characer.| self_type & swoc::TextView::remove_prefix | ( | size_t | n | ) |
Remove bytes from the start of the view.
| n | Number of bytes to remove. |
| self_type & swoc::TextView::remove_prefix_at | ( | char | c | ) |
Remove the leading characters of this up to and including c.
| c | Delimiter character. |
| 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.
| delimiters | Characters to match. |
| self_type & swoc::TextView::remove_prefix_if | ( | F const & | pred | ) |
Remove the leading characters up to and including the character selected by pred.
| F | Predicate function type. |
| pred | The predicate instance. |
Characters are removed until pred returns true. The matching character is also removed.
| self_type & swoc::TextView::remove_suffix | ( | size_t | n | ) |
Remove bytes from the end of the view.
| n | Number of bytes to remove. |
| self_type & swoc::TextView::remove_suffix_at | ( | char | c | ) |
Remove the trailing characters of this up to and including c.
| c | Delimiter character. |
| 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.
| delimiters | Characters to match. |
| self_type & swoc::TextView::remove_suffix_if | ( | F const & | pred | ) |
Remove the trailing characters up to and including the character selected by pred.
| F | Predicate function type. |
| pred | The predicate instance. |
If predicate is never true the view is cleared.
| self_type & swoc::TextView::rtrim | ( | char | c | ) |
Remove bytes that match c from the end of the view.
| self_type & swoc::TextView::rtrim | ( | CharSet const & | delimiters | ) |
Remove bytes from the end of the view that are in delimiters.
| self_type & swoc::TextView::rtrim | ( | std::string_view const & | delimiters | ) |
Remove bytes from the end of the view that are in delimiters.
| 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.
*this | self_type swoc::TextView::split_prefix | ( | size_t | n | ) |
Remove and return a prefix of size n.
| n | Size of the prefix. |
The prefix is removed and returned if the requested prefix is no larger than this, otherwise this is not modified.
take_prefix | self_type swoc::TextView::split_prefix_at | ( | char | c | ) |
Remove and return a prefix bounded by the first occurrence of c.
| c | The character to match. |
The prefix is removed and returned if c is found, otherwise this is not modified.
take_prefix | 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.
| delimiters | The characters to match. |
The prefix is removed and returned if a delimiter is found, otherwise this is not modified.
take_prefix_at | self_type swoc::TextView::split_prefix_if | ( | F const & | pred | ) |
Remove and return a prefix bounded by the first character that satisfies pred.
| F | Predicate functor type. |
| pred | A function taking char and returning bool. |
The prefix is removed and returned if a character satisfying pred is found, otherwise this is not modified.
take_prefix_if | self_type swoc::TextView::split_suffix | ( | size_t | n | ) |
Remove and return a suffix of size n.
| n | Size of the suffix. |
The prefix is removed and returned if the requested suffix is no larger than this, otherwise this is not modified.
take_suffix | self_type swoc::TextView::split_suffix_at | ( | char | c | ) |
Remove and return a suffix bounded by the last occurrence of c.
| c | The character to match. |
The suffix is removed and returned if c is found, otherwise this is not modified.
take_suffix_at | 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.
| delimiters | The characters to match. |
The suffix is removed and returned if delimiter is found, otherwise this is not modified.
take_suffix_at | self_type swoc::TextView::split_suffix_if | ( | F const & | pred | ) |
Remove and return a suffix bounded by the last character that satisfies pred.
| F | Predicate functor type. |
| pred | A function taking char and returning bool. |
The prefix is removed and returned if a character satisfying pred if found, otherwise this is not modified.
take_suffix_if
|
noexcept |
Check if the view begins with the character c.
| c | Character to check. |
true if the string is non-empty and the first character is c. | bool swoc::TextView::starts_with | ( | char const * | prefix | ) | const |
Check if the view begins with a specific prefix.
| prefix | String to check against this. |
true if this->prefix(prefix.size()) == prefix, false otherwise.
|
noexcept |
Check if the view begins with a specific prefix.
| prefix | String to check against this. |
true if this->prefix(prefix.size()) == prefix, false otherwise.
|
noexcept |
Check if the view begins with the character c, ignoring case.
| c | Character to check. |
true if the string is non-empty and the first character is c. | bool swoc::TextView::starts_with_nocase | ( | char const * | prefix | ) | const |
Check if the view begins with a specific prefix.
| prefix | String to check against this. |
true if this->prefix(prefix.size()) == prefix, false otherwise.
|
noexcept |
Check if the view begins with a specific prefix, ignoring case.
| prefix | String to check against this. |
true if this->prefix(prefix.size()) == prefix without regard to case, false otherwise. | TextView_INTERNAL template std::ostream & swoc::TextView::stream_write | ( | Stream & | os, |
| const TextView & | b ) const |
Specialized stream operator implementation.
|
constexprnoexcept |
Get a view of part of this view.
| pos | Offset of first byte in the new view. |
| count | Number of bytes in the view. |
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.
TextView instead of a std::string_view.
|
constexprnoexcept |
Get a view of the last n bytes.
| n | Number of chars in the suffix. |
| self_type swoc::TextView::suffix_at | ( | char | c | ) | const |
Get a view of a suffix bounded by c.
| c | Delimiter character. |
| self_type swoc::TextView::suffix_at | ( | std::string_view const & | delimiters | ) | const |
Get a view of a suffix bounded by a character in delimiters.
| delimiters | A set of characters. |
| 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.
| pred | A character predicate. |
true for any character.| self_type swoc::TextView::take_prefix | ( | size_t | n | ) |
Remove and return the first n characters.
| n | Size of the return prefix. |
The prefix is removed and returned if the requested prefix is no larger than this, otherwise all of this is removed and returned.
split_prefix | self_type swoc::TextView::take_prefix_at | ( | char | c | ) |
Remove and return a prefix bounded by the first occurrence of c.
| c | The character to match. |
The prefix is removed and returned if c is found, otherwise all of this is removed and returned.
split_prefix_at | 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.
| delimiters | The characters to match. |
The prefix is removed and returned if a delimiter is found, otherwise all of this is removed and returned.
split_prefix_at | self_type swoc::TextView::take_prefix_if | ( | F const & | pred | ) |
Remove and return a prefix bounded by the first character that satisfies pred.
| F | Predicate functor type. |
| pred | A function taking char and returning bool. |
The prefix is removed and returned if a character satisfying pred is found, otherwise all of this is removed and returned.
split_prefix_if | self_type swoc::TextView::take_suffix | ( | size_t | n | ) |
Remove and return a suffix of size n.
| n | Size of the suffix. |
The returned suffix is removed from this, along with the character at offset n if present.
split_suffix | self_type swoc::TextView::take_suffix_at | ( | char | c | ) |
Remove and return a suffix bounded by the last occurrence of c.
| c | The character to match. |
The returned suffix is removed from this, along with the delimiter character if found.
split_suffix_at | 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.
| delimiters | The characters to match. |
The returned suffix is removed from this, along with the delimiter character if found.
split_suffix_at | self_type swoc::TextView::take_suffix_if | ( | F const & | pred | ) |
Remove and return a suffix bounded by the last character that satisfies pred.
| F | Predicate functor type. |
| pred | A function taking char and returning bool. |
split_suffix_if | self_type & swoc::TextView::trim | ( | char | c | ) |
Remove bytes that match c from the start and end of this view.
| self_type & swoc::TextView::trim | ( | CharSet const & | delimiters | ) |
Remove bytes from the start and end of the view that are in delimiters.
| self_type & swoc::TextView::trim | ( | const char * | delimiters | ) |
Remove bytes from the start and end of the view that are in delimiters.
| self_type & swoc::TextView::trim | ( | std::string_view const & | delimiters | ) |
Remove bytes from the start and end of the view that are in delimiters.
| 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.
*this