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

Lightweight non-owning string view over a character sequence. More...

#include <str.h>

Public Member Functions

 str_view ()=default
 Constructs an empty string view.
 
constexpr str_view (const char *data, uint32_t size)
 Constructs a string view from a pointer and an explicit length.
 
template<size_t N>
constexpr str_view (const char(&lit)[N])
 Constructs a string view from a literal, excluding its trailing null terminator.
 
GAIA_NODISCARD constexpr const char * data () const
 Returns the underlying character pointer.
 
GAIA_NODISCARD constexpr uint32_t size () const
 Returns the number of characters in the view.
 
GAIA_NODISCARD constexpr bool empty () const
 Checks whether the view contains no characters.
 
GAIA_NODISCARD constexpr uint32_t find (str_view value, uint32_t pos=0) const
 Finds the first occurrence of substring value starting at index pos.
 
GAIA_NODISCARD constexpr 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 constexpr 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 constexpr uint32_t find (char ch, uint32_t pos=0) const
 Finds the first occurrence of character ch starting at index pos.
 
GAIA_NODISCARD constexpr 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 constexpr 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 constexpr 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 constexpr 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 constexpr 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 constexpr 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 constexpr 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 constexpr 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 constexpr 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 constexpr 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 constexpr 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 constexpr 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.
 
template<size_t N>
GAIA_NODISCARD constexpr bool operator== (const char(&lit)[N]) const
 Compares this view with literal lit for exact byte equality.
 
GAIA_NODISCARD constexpr bool operator== (str_view other) const
 Compares this view with view other for exact byte equality.
 
GAIA_NODISCARD constexpr bool operator!= (str_view other) const
 Compares this view with view other for exact byte inequality.
 

Public Attributes

const char * m_data = nullptr
 
uint32_t m_size = 0
 

Detailed Description

Lightweight non-owning string view over a character sequence.

Constructor & Destructor Documentation

◆ str_view() [1/2]

constexpr gaia::util::str_view::str_view ( const char *  data,
uint32_t  size 
)
inlineconstexpr

Constructs a string view from a pointer and an explicit length.

Parameters
dataPointer to the first character. Can be nullptr if size is 0.
sizeNumber of characters in the view.

◆ str_view() [2/2]

template<size_t N>
constexpr gaia::util::str_view::str_view ( const char(&)  lit[N])
inlineconstexpr

Constructs a string view from a literal, excluding its trailing null terminator.

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

Member Function Documentation

◆ data()

GAIA_NODISCARD constexpr const char * gaia::util::str_view::data ( ) const
inlineconstexpr

Returns the underlying character pointer.

Returns
Pointer to the first character or nullptr for default-constructed empty views.

◆ empty()

GAIA_NODISCARD constexpr bool gaia::util::str_view::empty ( ) const
inlineconstexpr

Checks whether the view contains no characters.

Returns
True if size() == 0.

◆ find() [1/4]

GAIA_NODISCARD constexpr uint32_t gaia::util::str_view::find ( char  ch,
uint32_t  pos = 0 
) const
inlineconstexpr

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

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

◆ find() [2/4]

GAIA_NODISCARD constexpr uint32_t gaia::util::str_view::find ( const char *  value,
uint32_t  len,
uint32_t  pos 
) const
inlineconstexpr

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

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

◆ find() [3/4]

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

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 view.
Returns
Index of first match or BadIndex.

◆ find() [4/4]

GAIA_NODISCARD constexpr uint32_t gaia::util::str_view::find ( str_view  value,
uint32_t  pos = 0 
) const
inlineconstexpr

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

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

◆ find_first_not_of() [1/3]

GAIA_NODISCARD constexpr uint32_t gaia::util::str_view::find_first_not_of ( char  ch,
uint32_t  pos = 0 
) const
inlineconstexpr

Finds the first character that is different from ch.

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

◆ find_first_not_of() [2/3]

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

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 view.
Returns
Index of first non-matching character or BadIndex.

◆ find_first_not_of() [3/3]

GAIA_NODISCARD constexpr uint32_t gaia::util::str_view::find_first_not_of ( str_view  chars,
uint32_t  pos = 0 
) const
inlineconstexpr

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

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

◆ find_first_of() [1/3]

GAIA_NODISCARD constexpr uint32_t gaia::util::str_view::find_first_of ( char  ch,
uint32_t  pos = 0 
) const
inlineconstexpr

Finds the first occurrence of character ch.

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

◆ find_first_of() [2/3]

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

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 view.
Returns
Index of first matching character or BadIndex.

◆ find_first_of() [3/3]

GAIA_NODISCARD constexpr uint32_t gaia::util::str_view::find_first_of ( str_view  chars,
uint32_t  pos = 0 
) const
inlineconstexpr

Finds the first character that is present in set chars.

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

◆ find_last_not_of() [1/3]

GAIA_NODISCARD constexpr uint32_t gaia::util::str_view::find_last_not_of ( char  ch,
uint32_t  pos = BadIndex 
) const
inlineconstexpr

Finds the last character that is different from ch.

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

◆ find_last_not_of() [2/3]

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

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 view.
Returns
Index of last non-matching character or BadIndex.

◆ find_last_not_of() [3/3]

GAIA_NODISCARD constexpr uint32_t gaia::util::str_view::find_last_not_of ( str_view  chars,
uint32_t  pos = BadIndex 
) const
inlineconstexpr

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

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

◆ find_last_of() [1/3]

GAIA_NODISCARD constexpr uint32_t gaia::util::str_view::find_last_of ( char  ch,
uint32_t  pos = BadIndex 
) const
inlineconstexpr

Finds the last occurrence of character ch.

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

◆ find_last_of() [2/3]

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

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 view.
Returns
Index of last matching character or BadIndex.

◆ find_last_of() [3/3]

GAIA_NODISCARD constexpr uint32_t gaia::util::str_view::find_last_of ( str_view  chars,
uint32_t  pos = BadIndex 
) const
inlineconstexpr

Finds the last character that is present in set chars.

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

◆ operator!=()

GAIA_NODISCARD constexpr bool gaia::util::str_view::operator!= ( str_view  other) const
inlineconstexpr

Compares this view with view other for exact byte inequality.

Parameters
otherView to compare with.
Returns
True when lengths or contents differ.

◆ operator==() [1/2]

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

Compares this view 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/2]

GAIA_NODISCARD constexpr bool gaia::util::str_view::operator== ( str_view  other) const
inlineconstexpr

Compares this view with view other for exact byte equality.

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

◆ size()

GAIA_NODISCARD constexpr uint32_t gaia::util::str_view::size ( ) const
inlineconstexpr

Returns the number of characters in the view.

Returns
Character count.

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