fennec
Loading...
Searching...
No Matches
fennec::cstring

This struct wraps c-style strings. More...

#include <cstring.h>

Detailed Description

Requires that the string is null-terminated. Prevents const qualified memory blocks from being manipulated. This struct should be used when fennec::string would make unnecessary dynamic buffers.

Public Member Functions

constexpr cstring ()
 Default Constructor, initializes with nullptr.
 
constexpr cstring (nullptr_t)
 Default Constructor, initializes with nullptr.
 
constexpr cstring (char *str, size_t n)
 Buffer Constructor, wraps the provided C-Style string.
 
template<size_t n>
constexpr cstring (char(&str)[n])
 Buffer Constructor, wraps the provided C-Style string.
 
constexpr cstring (const char *str, size_t n)
 Const Buffer Constructor, wraps the provided C-Style string.
 
template<size_t n>
constexpr cstring (const char(&str)[n])
 Buffer Constructor, wraps the provided C-Style string.
 
constexpr cstring (cstring &&str) noexcept
 Move Constructor.
 
constexpr size_t size () const
 
constexpr size_t capacity () const
 
constexpr char & operator[] (size_t i)
 Array Access Operator.
 
constexpr char operator[] (size_t i) const
 Const-Array Access Operator.
 
constexpr char * data ()
 Data Access.
 
constexpr const char * data () const
 Data Access.
 
constexpr operator const char * () const
 Implicit Dereference Cast.
 
constexpr size_t length () const
 
constexpr int compare (const cstring &str, size_t i=0, size_t n=npos) const
 String Comparison.
 
template<size_t n>
constexpr bool operator== (const char(&str)[n]) const
 String Equality.
 
constexpr bool operator== (const cstring &str) const
 String Equality.
 
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 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.
 

Constructor & Destructor Documentation

◆ cstring() [1/5]

constexpr fennec::cstring::cstring ( char *  str,
size_t  n 
)
inlineconstexpr
Parameters
strthe buffer to wrap
nthe number of characters in the buffer plus the null terminator

◆ cstring() [2/5]

template<size_t n>
constexpr fennec::cstring::cstring ( char(&)  str[n])
inlineconstexpr
Parameters
strthe buffer to wrap
Template Parameters
nthe number of characters in the buffer plus the null terminator

◆ cstring() [3/5]

constexpr fennec::cstring::cstring ( const char *  str,
size_t  n 
)
inlineconstexpr
Parameters
strthe buffer to wrap
nthe number of characters in the buffer plus the null terminator

◆ cstring() [4/5]

template<size_t n>
constexpr fennec::cstring::cstring ( const char(&)  str[n])
inlineconstexpr
Parameters
strthe buffer to wrap
Template Parameters
nthe number of characters in the buffer plus the null terminator

◆ cstring() [5/5]

constexpr fennec::cstring::cstring ( cstring &&  str)
inlineconstexprnoexcept
Parameters
strobject to move

Member Function Documentation

◆ size()

constexpr size_t fennec::cstring::size ( ) const
inlineconstexpr
Returns
the size of the string excluding its null terminator, i.e. ‘(*str)[size()] == ’\0'`

◆ capacity()

constexpr size_t fennec::cstring::capacity ( ) const
inlineconstexpr
Returns
the size of the string including its null terminator, i.e. ‘(*str)[capacity() - 1] == ’\0'`

◆ operator[]() [1/2]

constexpr char & fennec::cstring::operator[] ( size_t  i)
inlineconstexpr
Parameters
ithe index to access
Returns
a reference to the character

◆ operator[]() [2/2]

constexpr char fennec::cstring::operator[] ( size_t  i) const
inlineconstexpr
Parameters
ithe index to access
Returns
a copy of the character

◆ data() [1/2]

constexpr char * fennec::cstring::data ( )
inlineconstexpr
Returns
A const qualified pointer to the underlying allocation

◆ data() [2/2]

constexpr const char * fennec::cstring::data ( ) const
inlineconstexpr
Returns
A const qualified pointer to the underlying allocation

◆ length()

constexpr size_t fennec::cstring::length ( ) const
inlineconstexpr
Returns
The length of the string to the first null-terminator

◆ compare()

constexpr int fennec::cstring::compare ( const cstring str,
size_t  i = 0,
size_t  n = npos 
) const
inlineconstexpr
Parameters
strthe string to compare against
ithe index to start at
nthe number of characters to compare
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.

◆ operator==() [1/2]

template<size_t n>
constexpr bool fennec::cstring::operator== ( const char(&)  str[n]) const
inlineconstexpr
Parameters
strthe string to compare against
Returns
True if all characters are equal, false otherwise

◆ operator==() [2/2]

constexpr bool fennec::cstring::operator== ( const cstring str) const
inlineconstexpr
Parameters
strthe string to compare against
Returns
True if all characters are equal, false otherwise

◆ find() [1/2]

constexpr size_t fennec::cstring::find ( char  c,
size_t  i = 0 
) const
inlineconstexpr
Parameters
cthe character to find
ithe index to start at
Returns
The index of c if it occurs in the string, otherwise returns size()

◆ find() [2/2]

constexpr size_t fennec::cstring::find ( const cstring str,
size_t  i = 0 
) 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() [1/2]

constexpr size_t fennec::cstring::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/2]

constexpr size_t fennec::cstring::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()

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