Blender  V3.3
Static Public Attributes | Protected Attributes | List of all members
blender::StringRefBase Class Reference

#include <BLI_string_ref.hh>

Inheritance diagram for blender::StringRefBase:
blender::StringRef blender::StringRefNull

Static Public Attributes

static constexpr int64_t not_found = -1
 

Protected Attributes

const char * data_
 
int64_t size_
 

#StringRefBase Inline Methods

constexpr StringRefBase (const char *data, int64_t size)
 
constexpr int64_t size () const
 
constexpr bool is_empty () const
 
constexpr const char * data () const
 
constexpr operator Span< char > () const
 
 operator std::string () const
 
constexpr operator std::string_view () const
 
constexpr const char * begin () const
 
constexpr const char * end () const
 
constexpr IndexRange index_range () const
 
void unsafe_copy (char *dst) const
 
void copy (char *dst, int64_t dst_size) const
 
template<size_t N>
void copy (char(&dst)[N]) const
 
constexpr bool startswith (StringRef prefix) const
 
constexpr bool endswith (StringRef suffix) const
 
constexpr StringRef substr (int64_t start, int64_t size) const
 
constexpr const char & front () const
 
constexpr const char & back () const
 
constexpr int64_t find (char c, int64_t pos=0) const
 
constexpr int64_t find (StringRef str, int64_t pos=0) const
 
constexpr int64_t rfind (char c, int64_t pos=INT64_MAX) const
 
constexpr int64_t rfind (StringRef str, int64_t pos=INT64_MAX) const
 
constexpr int64_t find_first_of (StringRef chars, int64_t pos=0) const
 
constexpr int64_t find_first_of (char c, int64_t pos=0) const
 
constexpr int64_t find_last_of (StringRef chars, int64_t pos=INT64_MAX) const
 
constexpr int64_t find_last_of (char c, int64_t pos=INT64_MAX) const
 
constexpr int64_t find_first_not_of (StringRef chars, int64_t pos=0) const
 
constexpr int64_t find_first_not_of (char c, int64_t pos=0) const
 
constexpr int64_t find_last_not_of (StringRef chars, int64_t pos=INT64_MAX) const
 
constexpr int64_t find_last_not_of (char c, int64_t pos=INT64_MAX) const
 
constexpr StringRef trim () const
 
constexpr StringRef trim (StringRef characters_to_remove) const
 
constexpr StringRef trim (char character_to_remove) const
 

Detailed Description

A common base class for StringRef and StringRefNull. This should never be used in other files. It only exists to avoid some code duplication.

Definition at line 48 of file BLI_string_ref.hh.

Constructor & Destructor Documentation

◆ StringRefBase()

constexpr blender::StringRefBase::StringRefBase ( const char *  data,
int64_t  size 
)
constexprprotected

Definition at line 144 of file BLI_string_ref.hh.

Member Function Documentation

◆ back()

constexpr const char & blender::StringRefBase::back ( ) const
constexpr

Get the last char in the string. This invokes undefined behavior when the string is empty.

Definition at line 299 of file BLI_string_ref.hh.

References BLI_assert, data_, and size_.

◆ begin()

constexpr const char * blender::StringRefBase::begin ( ) const
constexpr

◆ copy() [1/2]

void blender::StringRefBase::copy ( char *  dst,
int64_t  dst_size 
) const
inline

Copy the string into a buffer. The copied string will be null-terminated. This invokes undefined behavior when dst_size is too small. (Should we define the behavior?)

Definition at line 221 of file BLI_string_ref.hh.

References BLI_assert, size_, and unsafe_copy().

Referenced by blender::bke::add_generic_custom_data_layer(), BKE_asset_metadata_catalog_id_set(), copy(), blender::gpu::GPUSource::material_functions_parse(), and blender::tests::TEST().

◆ copy() [2/2]

template<size_t N>
void blender::StringRefBase::copy ( char(&)  dst[N]) const
inline

Copy the string into a char array. The copied string will be null-terminated. This invokes undefined behavior when dst is too small.

Definition at line 236 of file BLI_string_ref.hh.

References copy(), and N.

◆ data()

constexpr const char * blender::StringRefBase::data ( ) const
constexpr

◆ end()

constexpr const char * blender::StringRefBase::end ( ) const
constexpr

◆ endswith()

constexpr bool blender::StringRefBase::endswith ( StringRef  suffix) const
constexpr

◆ find() [1/2]

constexpr int64_t blender::StringRefBase::find ( char  c,
int64_t  pos = 0 
) const
constexpr

◆ find() [2/2]

constexpr int64_t blender::StringRefBase::find ( StringRef  str,
int64_t  pos = 0 
) const
constexpr

Definition at line 320 of file BLI_string_ref.hh.

References BLI_assert, blender::index_or_npos_to_int64(), pos, and str.

◆ find_first_not_of() [1/2]

constexpr int64_t blender::StringRefBase::find_first_not_of ( char  c,
int64_t  pos = 0 
) const
constexpr

Definition at line 372 of file BLI_string_ref.hh.

References BLI_assert, Freestyle::c, blender::index_or_npos_to_int64(), and pos.

◆ find_first_not_of() [2/2]

constexpr int64_t blender::StringRefBase::find_first_not_of ( StringRef  chars,
int64_t  pos = 0 
) const
constexpr

◆ find_first_of() [1/2]

constexpr int64_t blender::StringRefBase::find_first_of ( char  c,
int64_t  pos = 0 
) const
constexpr

Definition at line 345 of file BLI_string_ref.hh.

References BLI_assert, Freestyle::c, blender::index_or_npos_to_int64(), and pos.

◆ find_first_of() [2/2]

constexpr int64_t blender::StringRefBase::find_first_of ( StringRef  chars,
int64_t  pos = 0 
) const
constexpr

◆ find_last_not_of() [1/2]

constexpr int64_t blender::StringRefBase::find_last_not_of ( char  c,
int64_t  pos = INT64_MAX 
) const
constexpr

Definition at line 386 of file BLI_string_ref.hh.

References BLI_assert, Freestyle::c, blender::index_or_npos_to_int64(), and pos.

◆ find_last_not_of() [2/2]

constexpr int64_t blender::StringRefBase::find_last_not_of ( StringRef  chars,
int64_t  pos = INT64_MAX 
) const
constexpr

Definition at line 379 of file BLI_string_ref.hh.

References BLI_assert, blender::index_or_npos_to_int64(), and pos.

Referenced by trim().

◆ find_last_of() [1/2]

constexpr int64_t blender::StringRefBase::find_last_of ( char  c,
int64_t  pos = INT64_MAX 
) const
constexpr

Definition at line 359 of file BLI_string_ref.hh.

References BLI_assert, Freestyle::c, blender::index_or_npos_to_int64(), and pos.

◆ find_last_of() [2/2]

constexpr int64_t blender::StringRefBase::find_last_of ( StringRef  chars,
int64_t  pos = INT64_MAX 
) const
constexpr

◆ front()

constexpr const char & blender::StringRefBase::front ( ) const
constexpr

Get the first char in the string. This invokes undefined behavior when the string is empty.

Definition at line 290 of file BLI_string_ref.hh.

References BLI_assert, data_, and size_.

Referenced by blender::bke::cryptomatte::manifest::from_manifest().

◆ index_range()

constexpr IndexRange blender::StringRefBase::index_range ( ) const
constexpr

Definition at line 199 of file BLI_string_ref.hh.

References size_.

◆ is_empty()

constexpr bool blender::StringRefBase::is_empty ( ) const
constexpr

◆ operator Span< char >()

constexpr blender::StringRefBase::operator Span< char > ( ) const
constexpr

Definition at line 170 of file BLI_string_ref.hh.

References data_.

◆ operator std::string()

blender::StringRefBase::operator std::string ( ) const
inline

Implicitly convert to std::string. This is convenient in most cases, but you have to be a bit careful not to convert to std::string accidentally.

Definition at line 179 of file BLI_string_ref.hh.

References data_.

◆ operator std::string_view()

constexpr blender::StringRefBase::operator std::string_view ( ) const
constexpr

Definition at line 184 of file BLI_string_ref.hh.

References data_.

◆ rfind() [1/2]

constexpr int64_t blender::StringRefBase::rfind ( char  c,
int64_t  pos = INT64_MAX 
) const
constexpr

Definition at line 326 of file BLI_string_ref.hh.

References BLI_assert, Freestyle::c, blender::index_or_npos_to_int64(), and pos.

◆ rfind() [2/2]

constexpr int64_t blender::StringRefBase::rfind ( StringRef  str,
int64_t  pos = INT64_MAX 
) const
constexpr

Definition at line 332 of file BLI_string_ref.hh.

References BLI_assert, blender::index_or_npos_to_int64(), pos, and str.

◆ size()

constexpr int64_t blender::StringRefBase::size ( ) const
constexpr

◆ startswith()

constexpr bool blender::StringRefBase::startswith ( StringRef  prefix) const
constexpr

◆ substr()

constexpr StringRef blender::StringRefBase::substr ( int64_t  start,
int64_t  size = INT64_MAX 
) const
constexpr

◆ trim() [1/3]

constexpr StringRef blender::StringRefBase::trim ( ) const
constexpr

◆ trim() [2/3]

constexpr StringRef blender::StringRefBase::trim ( char  character_to_remove) const
constexpr

Return a new StringRef that does not contain leading and trailing white-space.

Definition at line 401 of file BLI_string_ref.hh.

References trim().

◆ trim() [3/3]

constexpr StringRef blender::StringRefBase::trim ( StringRef  characters_to_remove) const
constexpr

Return a new StringRef that removes all the leading and trailing characters that occur in characters_to_remove.

Definition at line 410 of file BLI_string_ref.hh.

References BLI_assert_msg, find_first_not_of(), find_last_not_of(), not_found, and substr().

◆ unsafe_copy()

void blender::StringRefBase::unsafe_copy ( char *  dst) const
inline

Copy the string into a buffer. The buffer has to be one byte larger than the size of the string, because the copied string will be null-terminated. Only use this when you are absolutely sure that the buffer is large enough.

Definition at line 209 of file BLI_string_ref.hh.

References data_, and size_.

Referenced by copy().

Member Data Documentation

◆ data_

const char* blender::StringRefBase::data_
protected

◆ not_found

constexpr int64_t blender::StringRefBase::not_found = -1
staticconstexpr

◆ size_

int64_t blender::StringRefBase::size_
protected

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