fennec
Loading...
Searching...
No Matches
fennec::_string< AllocT >

Struct for wrapping c-style strings. More...

#include <string.h>

Detailed Description

template<typename AllocT>
struct fennec::_string< AllocT >

behaviour guarantees that the underlying string is null-terminated

Public Member Functions

constexpr _string ()
 Default Constructor, initializes empty string.
 
constexpr _string (size_t n, char c='\0')
 Sized Constructor, initializes a null-terminated string of size n with ‘'c’...`.
 
template<size_t n>
constexpr _string (const char(&str)[n])
 Buffer Constructor, wraps the provided C-Style string, appending a null-terminator if not present.
 
constexpr _string (const char *buf, size_t n)
 Buffer Constructor, wraps the provided C-Style string, appending a null-terminator if not present.
 
constexpr _string (const _string &str)=default
 String Copy Constructor.
 
constexpr _string (_string &&str) noexcept=default
 String Move Constructor.
 
constexpr ~_string ()=default
 Destructor, cleans up underlying allocation.
 
constexpr size_t size () const
 
constexpr size_t capacity () const
 
constexpr char & operator[] (size_t i)
 Array Access Operator.
 
constexpr const char & operator[] (size_t i) const
 Const-Array Access Operator.
 
constexpr size_t length () const
 
constexpr int compare (const cstring &str, size_t i=0, size_t n=npos) const
 String Comparison.
 
constexpr int compare (const string &str, size_t i=0, size_t n=npos) const
 String Comparison.
 
constexpr bool contains (char c, size_t i=0) const
 Check if the string contains a character.
 
constexpr size_t find (char c, size_t i=0) const
 Finds the index of the first occurrence of c in the string.
 
constexpr size_t find (const string &str, size_t i=0) const
 Finds the index of the first occurrence of str in the string.
 
constexpr size_t find (const cstring &str, size_t i=0) const
 Finds the index of the first occurrence of str in the string.
 
constexpr size_t rfind (char c, size_t i=npos) const
 Finds the index of the last occurrence of c in the string.
 
constexpr size_t rfind (const cstring &str, size_t i=npos) const
 Finds the index of the last occurrence of str in the string.
 
constexpr size_t rfind (const string &str, size_t i=npos) const
 Finds the index of the last occurrence of str in the string.
 
constexpr _string substring (size_t i, size_t n=npos) const
 Retrieve a substring of a string.
 

Constructor & Destructor Documentation

◆ _string() [1/5]

template<typename AllocT >
constexpr fennec::_string< AllocT >::_string ( size_t  n,
char  c = '\0' 
)
inlineconstexpr
Parameters
nthe number of characters
cthe character to fill with

adds additional character for null termination.

◆ _string() [2/5]

template<typename AllocT >
template<size_t n>
constexpr fennec::_string< AllocT >::_string ( const char(&)  str[n])
inlineexplicitconstexpr
Parameters
strthe buffer to wrap
Template Parameters
nthe number of characters in the buffer including the null-terminator, if present

This constructor is explicit because we want to be explicit about when we are allocating memory for a string.

◆ _string() [3/5]

template<typename AllocT >
constexpr fennec::_string< AllocT >::_string ( const char *  buf,
size_t  n 
)
inlineconstexpr
Parameters
strthe buffer to wrap
nthe number of characters in the buffer including the null-terminator, if present

◆ _string() [4/5]

template<typename AllocT >
constexpr fennec::_string< AllocT >::_string ( const _string< AllocT > &  str)
constexprdefault
Parameters
strthe string to copy

◆ _string() [5/5]

template<typename AllocT >
constexpr fennec::_string< AllocT >::_string ( _string< AllocT > &&  str)
constexprdefaultnoexcept
Parameters
strthe string to take ownership of

Member Function Documentation

◆ size()

template<typename AllocT >
constexpr size_t fennec::_string< AllocT >::size ( ) const
inlineconstexpr
Returns
The size of the string excluding null terminator

◆ capacity()

template<typename AllocT >
constexpr size_t fennec::_string< AllocT >::capacity ( ) const
inlineconstexpr
Returns
The size of the string including null terminator

◆ operator[]() [1/2]

template<typename AllocT >
constexpr char & fennec::_string< AllocT >::operator[] ( size_t  i)
inlineconstexpr
Parameters
ithe index to access
Returns
a reference to the character

◆ operator[]() [2/2]

template<typename AllocT >
constexpr const char & fennec::_string< AllocT >::operator[] ( size_t  i) const
inlineconstexpr
Parameters
ithe index to access
Returns
a copy of the character

◆ length()

template<typename AllocT >
constexpr size_t fennec::_string< AllocT >::length ( ) const
inlineconstexpr
Returns
The length of the string to the first null-terminator

◆ compare() [1/2]

template<typename AllocT >
constexpr int fennec::_string< AllocT >::compare ( const cstring str,
size_t  i = 0,
size_t  n = npos 
) const
inlineconstexpr
Parameters
ostrthe string to compare against
Returns
Zero if both strings are equal, otherwise a negative value if lhs appears before rhs according to the current locale, otherwise a positive value.

◆ compare() [2/2]

template<typename AllocT >
constexpr int fennec::_string< AllocT >::compare ( const string str,
size_t  i = 0,
size_t  n = npos 
) const
inlineconstexpr
Parameters
ostrthe string to compare against
Returns
Zero if both strings are equal, otherwise a negative value if lhs appears before rhs according to the current locale, otherwise a positive value.

◆ contains()

template<typename AllocT >
constexpr bool fennec::_string< AllocT >::contains ( char  c,
size_t  i = 0 
) const
inlineconstexpr
Parameters
c
i
Returns

◆ find() [1/3]

template<typename AllocT >
constexpr size_t fennec::_string< AllocT >::find ( char  c,
size_t  i = 0 
) const
inlineconstexpr
Parameters
cthe character to find
Returns
The index of c if it occurs in the string, otherwise returns size()

◆ find() [2/3]

template<typename AllocT >
constexpr size_t fennec::_string< AllocT >::find ( const string str,
size_t  i = 0 
) const
inlineconstexpr
Parameters
strthe string to find
Returns
The index of str if it occurs in the string, otherwise returns size()

◆ find() [3/3]

template<typename AllocT >
constexpr size_t fennec::_string< AllocT >::find ( const cstring str,
size_t  i = 0 
) const
inlineconstexpr
Parameters
strthe string to find
Returns
The index of str if it occurs in the string, otherwise returns size()

◆ rfind() [1/3]

template<typename AllocT >
constexpr size_t fennec::_string< AllocT >::rfind ( char  c,
size_t  i = npos 
) const
inlineconstexpr
Parameters
cthe string to find
ithe index to start at
Returns
The index of c if it occurs in the string, otherwise returns size()

◆ rfind() [2/3]

template<typename AllocT >
constexpr size_t fennec::_string< AllocT >::rfind ( const cstring str,
size_t  i = npos 
) const
inlineconstexpr
Parameters
strthe string to find
ithe index to start at
Returns
The index of str if it occurs in the string, otherwise returns size()

◆ rfind() [3/3]

template<typename AllocT >
constexpr size_t fennec::_string< AllocT >::rfind ( const string str,
size_t  i = npos 
) const
inlineconstexpr
Parameters
strthe string to find
ithe index to start at
Returns
The index of str if it occurs in the string, otherwise returns size()

◆ substring()

template<typename AllocT >
constexpr _string fennec::_string< AllocT >::substring ( size_t  i,
size_t  n = npos 
) const
inlineconstexpr
Parameters
ithe start index
nthe number of characters
Returns

The documentation for this struct was generated from the following file: