Gaia-ECS v0.9.3
A simple and powerful entity component system
Loading...
Searching...
No Matches
gaia::util::str Struct Reference

Lightweight owning string container with explicit length semantics (no implicit null terminator). More...

#include <str.h>

Public Member Functions

 str ()=default
 Constructs an empty string.
 
 str (str_view view)
 Constructs a string by copying view contents.
 
template<size_t N>
 str (const char(&lit)[N])
 Constructs a string from literal lit, excluding trailing null terminator.
 
void clear ()
 Removes all characters from the string.
 
void reserve (uint32_t len)
 Reserves capacity for at least len characters.
 
void assign (const char *data, uint32_t size)
 Replaces contents with size characters from data.
 
void assign (str_view view)
 Replaces contents with view contents.
 
template<size_t N>
void assign (const char(&lit)[N])
 Replaces contents with literal lit.
 
void append (const char *data, uint32_t size)
 Appends size characters from data.
 
void append (str_view view)
 Appends view contents.
 
template<size_t N>
void append (const char(&lit)[N])
 Appends literal lit.
 
void append (char ch)
 Appends a single character.
 
GAIA_NODISCARD const char * data () const
 Returns read-only pointer to internal data.
 
GAIA_NODISCARD char * data ()
 Returns mutable pointer to internal data.
 
GAIA_NODISCARD uint32_t size () const
 Returns number of characters stored in the string.
 
GAIA_NODISCARD bool empty () const
 Checks whether the string contains no characters.
 
GAIA_NODISCARD str_view view () const
 Returns a non-owning view over the current contents.
 
GAIA_NODISCARD operator str_view () const
 Implicit conversion to non-owning view.
 
template<size_t N>
GAIA_NODISCARD bool operator== (const char(&lit)[N]) const
 Compares this string with literal lit for exact byte equality.
 
GAIA_NODISCARD bool operator== (str_view other) const
 Compares this string with view other for exact byte equality.
 
GAIA_NODISCARD bool operator== (const str &other) const
 Compares this string with string other for exact byte equality.
 
GAIA_NODISCARD uint32_t find (str_view value, uint32_t pos=0) const
 Finds the first occurrence of substring value starting at index pos.
 
GAIA_NODISCARD uint32_t find (const char *value, uint32_t len, uint32_t pos) const
 Finds the first occurrence of a character sequence starting at index pos.
 
template<size_t N>
GAIA_NODISCARD uint32_t find (const char(&lit)[N], uint32_t pos=0) const
 Finds the first occurrence of literal lit starting at index pos.
 
GAIA_NODISCARD uint32_t find (char ch, uint32_t pos=0) const
 Finds the first occurrence of character ch starting at index pos.
 
GAIA_NODISCARD uint32_t find_first_of (str_view chars, uint32_t pos=0) const
 Finds the first character that is present in set chars.
 
GAIA_NODISCARD uint32_t find_first_of (char ch, uint32_t pos=0) const
 Finds the first occurrence of character ch.
 
template<size_t N>
GAIA_NODISCARD uint32_t find_first_of (const char(&lit)[N], uint32_t pos=0) const
 Finds the first character that is present in literal set lit.
 
GAIA_NODISCARD uint32_t find_last_of (str_view chars, uint32_t pos=BadIndex) const
 Finds the last character that is present in set chars.
 
GAIA_NODISCARD uint32_t find_last_of (char ch, uint32_t pos=BadIndex) const
 Finds the last occurrence of character ch.
 
template<size_t N>
GAIA_NODISCARD uint32_t find_last_of (const char(&lit)[N], uint32_t pos=BadIndex) const
 Finds the last character that is present in literal set lit.
 
GAIA_NODISCARD uint32_t find_first_not_of (str_view chars, uint32_t pos=0) const
 Finds the first character that is NOT present in set chars.
 
GAIA_NODISCARD uint32_t find_first_not_of (char ch, uint32_t pos=0) const
 Finds the first character that is different from ch.
 
template<size_t N>
GAIA_NODISCARD uint32_t find_first_not_of (const char(&lit)[N], uint32_t pos=0) const
 Finds the first character that is NOT present in literal set lit.
 
GAIA_NODISCARD uint32_t find_last_not_of (str_view chars, uint32_t pos=BadIndex) const
 Finds the last character that is NOT present in set chars.
 
GAIA_NODISCARD uint32_t find_last_not_of (char ch, uint32_t pos=BadIndex) const
 Finds the last character that is different from ch.
 
template<size_t N>
GAIA_NODISCARD uint32_t find_last_not_of (const char(&lit)[N], uint32_t pos=BadIndex) const
 Finds the last character that is NOT present in literal set lit.
 

Public Attributes

cnt::darray< char > m_data
 

Detailed Description

Lightweight owning string container with explicit length semantics (no implicit null terminator).

Constructor & Destructor Documentation

◆ str() [1/2]

gaia::util::str::str ( str_view  view)
inlineexplicit

Constructs a string by copying view contents.

Parameters
viewSource view.

◆ str() [2/2]

template<size_t N>
gaia::util::str::str ( const char(&)  lit[N])
inlineexplicit

Constructs a string from literal lit, excluding trailing null terminator.

Template Parameters
NNumber of characters in the literal including the trailing null terminator.
Parameters
litSource literal.

Member Function Documentation

◆ append() [1/4]

void gaia::util::str::append ( char  ch)
inline

Appends a single character.

Parameters
chCharacter to append.

◆ append() [2/4]

void gaia::util::str::append ( const char *  data,
uint32_t  size 
)
inline

Appends size characters from data.

Parameters
dataSource pointer.
sizeNumber of characters to append.

◆ append() [3/4]

template<size_t N>
void gaia::util::str::append ( const char(&)  lit[N])
inline

Appends literal lit.

Template Parameters
NNumber of characters in the literal including the trailing null terminator.
Parameters
litSource literal.

◆ append() [4/4]

void gaia::util::str::append ( str_view  view)
inline

Appends view contents.

Parameters
viewSource view.

◆ assign() [1/3]

void gaia::util::str::assign ( const char *  data,
uint32_t  size 
)
inline

Replaces contents with size characters from data.

Parameters
dataSource pointer.
sizeNumber of characters to copy.

◆ assign() [2/3]

template<size_t N>
void gaia::util::str::assign ( const char(&)  lit[N])
inline

Replaces contents with literal lit.

Template Parameters
NNumber of characters in the literal including the trailing null terminator.
Parameters
litSource literal.

◆ assign() [3/3]

void gaia::util::str::assign ( str_view  view)
inline

Replaces contents with view contents.

Parameters
viewSource view.

◆ data() [1/2]

GAIA_NODISCARD char * gaia::util::str::data ( )
inline

Returns mutable pointer to internal data.

Returns
Pointer to first character or nullptr when empty.

◆ data() [2/2]

GAIA_NODISCARD const char * gaia::util::str::data ( ) const
inline

Returns read-only pointer to internal data.

Returns
Pointer to first character or nullptr when empty.

◆ empty()

GAIA_NODISCARD bool gaia::util::str::empty ( ) const
inline

Checks whether the string contains no characters.

Returns
True if size() == 0.

◆ find() [1/4]

GAIA_NODISCARD uint32_t gaia::util::str::find ( char  ch,
uint32_t  pos = 0 
) const
inline

Finds the first occurrence of character ch starting at index pos.

Parameters
chNeedle character.
posStart position in this string.
Returns
Index of first match or BadIndex.

◆ find() [2/4]

GAIA_NODISCARD uint32_t gaia::util::str::find ( const char *  value,
uint32_t  len,
uint32_t  pos 
) const
inline

Finds the first occurrence of a character sequence starting at index pos.

Parameters
valueNeedle pointer.
lenNumber of needle characters.
posStart position in this string.
Returns
Index of first match or BadIndex.

◆ find() [3/4]

template<size_t N>
GAIA_NODISCARD uint32_t gaia::util::str::find ( const char(&)  lit[N],
uint32_t  pos = 0 
) const
inline

Finds the first occurrence of literal lit starting at index pos.

Template Parameters
NNumber of characters in the literal including the trailing null terminator.
Parameters
litNeedle literal.
posStart position in this string.
Returns
Index of first match or BadIndex.

◆ find() [4/4]

GAIA_NODISCARD uint32_t gaia::util::str::find ( str_view  value,
uint32_t  pos = 0 
) const
inline

Finds the first occurrence of substring value starting at index pos.

Parameters
valueNeedle view.
posStart position in this string.
Returns
Index of first match or BadIndex.

◆ find_first_not_of() [1/3]

GAIA_NODISCARD uint32_t gaia::util::str::find_first_not_of ( char  ch,
uint32_t  pos = 0 
) const
inline

Finds the first character that is different from ch.

Parameters
chExcluded character.
posStart position in this string.
Returns
Index of first non-matching character or BadIndex.

◆ find_first_not_of() [2/3]

template<size_t N>
GAIA_NODISCARD uint32_t gaia::util::str::find_first_not_of ( const char(&)  lit[N],
uint32_t  pos = 0 
) const
inline

Finds the first character that is NOT present in literal set lit.

Template Parameters
NNumber of characters in the literal including the trailing null terminator.
Parameters
litSet literal.
posStart position in this string.
Returns
Index of first non-matching character or BadIndex.

◆ find_first_not_of() [3/3]

GAIA_NODISCARD uint32_t gaia::util::str::find_first_not_of ( str_view  chars,
uint32_t  pos = 0 
) const
inline

Finds the first character that is NOT present in set chars.

Parameters
charsSet of excluded characters.
posStart position in this string.
Returns
Index of first non-matching character or BadIndex.

◆ find_first_of() [1/3]

GAIA_NODISCARD uint32_t gaia::util::str::find_first_of ( char  ch,
uint32_t  pos = 0 
) const
inline

Finds the first occurrence of character ch.

Parameters
chNeedle character.
posStart position in this string.
Returns
Index of first match or BadIndex.

◆ find_first_of() [2/3]

template<size_t N>
GAIA_NODISCARD uint32_t gaia::util::str::find_first_of ( const char(&)  lit[N],
uint32_t  pos = 0 
) const
inline

Finds the first character that is present in literal set lit.

Template Parameters
NNumber of characters in the literal including the trailing null terminator.
Parameters
litSet literal.
posStart position in this string.
Returns
Index of first matching character or BadIndex.

◆ find_first_of() [3/3]

GAIA_NODISCARD uint32_t gaia::util::str::find_first_of ( str_view  chars,
uint32_t  pos = 0 
) const
inline

Finds the first character that is present in set chars.

Parameters
charsSet of accepted characters.
posStart position in this string.
Returns
Index of first matching character or BadIndex.

◆ find_last_not_of() [1/3]

GAIA_NODISCARD uint32_t gaia::util::str::find_last_not_of ( char  ch,
uint32_t  pos = BadIndex 
) const
inline

Finds the last character that is different from ch.

Parameters
chExcluded character.
posMaximum position to consider, BadIndex means end of string.
Returns
Index of last non-matching character or BadIndex.

◆ find_last_not_of() [2/3]

template<size_t N>
GAIA_NODISCARD uint32_t gaia::util::str::find_last_not_of ( const char(&)  lit[N],
uint32_t  pos = BadIndex 
) const
inline

Finds the last character that is NOT present in literal set lit.

Template Parameters
NNumber of characters in the literal including the trailing null terminator.
Parameters
litSet literal.
posMaximum position to consider, BadIndex means end of string.
Returns
Index of last non-matching character or BadIndex.

◆ find_last_not_of() [3/3]

GAIA_NODISCARD uint32_t gaia::util::str::find_last_not_of ( str_view  chars,
uint32_t  pos = BadIndex 
) const
inline

Finds the last character that is NOT present in set chars.

Parameters
charsSet of excluded characters.
posMaximum position to consider, BadIndex means end of string.
Returns
Index of last non-matching character or BadIndex.

◆ find_last_of() [1/3]

GAIA_NODISCARD uint32_t gaia::util::str::find_last_of ( char  ch,
uint32_t  pos = BadIndex 
) const
inline

Finds the last occurrence of character ch.

Parameters
chNeedle character.
posMaximum position to consider, BadIndex means end of string.
Returns
Index of last match or BadIndex.

◆ find_last_of() [2/3]

template<size_t N>
GAIA_NODISCARD uint32_t gaia::util::str::find_last_of ( const char(&)  lit[N],
uint32_t  pos = BadIndex 
) const
inline

Finds the last character that is present in literal set lit.

Template Parameters
NNumber of characters in the literal including the trailing null terminator.
Parameters
litSet literal.
posMaximum position to consider, BadIndex means end of string.
Returns
Index of last matching character or BadIndex.

◆ find_last_of() [3/3]

GAIA_NODISCARD uint32_t gaia::util::str::find_last_of ( str_view  chars,
uint32_t  pos = BadIndex 
) const
inline

Finds the last character that is present in set chars.

Parameters
charsSet of accepted characters.
posMaximum position to consider, BadIndex means end of string.
Returns
Index of last matching character or BadIndex.

◆ operator str_view()

GAIA_NODISCARD gaia::util::str::operator str_view ( ) const
inline

Implicit conversion to non-owning view.

Returns
View of this string.

◆ operator==() [1/3]

template<size_t N>
GAIA_NODISCARD bool gaia::util::str::operator== ( const char(&)  lit[N]) const
inline

Compares this string with literal lit for exact byte equality.

Template Parameters
NNumber of characters in the literal including the trailing null terminator.
Parameters
litLiteral to compare with.
Returns
True when lengths and contents are equal.

◆ operator==() [2/3]

GAIA_NODISCARD bool gaia::util::str::operator== ( const str other) const
inline

Compares this string with string other for exact byte equality.

Parameters
otherString to compare with.
Returns
True when lengths and contents are equal.

◆ operator==() [3/3]

GAIA_NODISCARD bool gaia::util::str::operator== ( str_view  other) const
inline

Compares this string with view other for exact byte equality.

Parameters
otherView to compare with.
Returns
True when lengths and contents are equal.

◆ reserve()

void gaia::util::str::reserve ( uint32_t  len)
inline

Reserves capacity for at least len characters.

Parameters
lenTarget character capacity.

◆ size()

GAIA_NODISCARD uint32_t gaia::util::str::size ( ) const
inline

Returns number of characters stored in the string.

Returns
Character count.

◆ view()

GAIA_NODISCARD str_view gaia::util::str::view ( ) const
inline

Returns a non-owning view over the current contents.

Returns
View of this string.

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