Blender  V2.93
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
blender::StringRefBase Class Reference

#include <BLI_string_ref.hh>

Inherited by blender::StringRef, and blender::StringRefNull.

Public Member Functions

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, const 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, const 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
 

Static Public Attributes

static constexpr int64_t not_found = -1
 

Protected Member Functions

constexpr StringRefBase (const char *data, const int64_t size)
 

Protected Attributes

const char * data_
 
int64_t size_
 

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 62 of file BLI_string_ref.hh.

Constructor & Destructor Documentation

◆ StringRefBase()

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

Definition at line 67 of file BLI_string_ref.hh.

Member Function Documentation

◆ back()

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

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

Definition at line 189 of file BLI_string_ref.hh.

References BLI_assert, data_, and size_.

◆ begin()

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

◆ copy() [1/2]

void blender::StringRefBase::copy ( char *  dst,
const 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 145 of file BLI_string_ref.hh.

References BLI_assert, size_, and unsafe_copy().

Referenced by copy(), blender::tests::TEST(), and blender::bke::CustomDataAttributeProvider::try_create().

◆ 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 160 of file BLI_string_ref.hh.

References copy(), and N.

◆ data()

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

◆ end()

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

Definition at line 120 of file BLI_string_ref.hh.

References data_, and size_.

Referenced by blender::string_search::get_fuzzy_match_errors().

◆ endswith()

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

Returns true when the string ends with the given suffix. Otherwise false.

Return true when the string ends with the given suffix.

Definition at line 447 of file BLI_string_ref.hh.

References data_, and size_.

Referenced by blender::bke::cryptomatte::CryptomatteStampDataCallbackData::extract_layer_manifest(), blender::bke::cryptomatte::CryptomatteStampDataCallbackData::extract_layer_names(), blender::gpu::match_renderer(), and blender::tests::TEST().

◆ find() [1/2]

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

The behavior of those functions matches the standard library implementation of std::string_view.

Definition at line 483 of file BLI_string_ref.hh.

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

Referenced by blender::string_search::get_fuzzy_match_errors(), and blender::gpu::match_renderer().

◆ find() [2/2]

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

Definition at line 489 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
inlineconstexpr

Definition at line 526 of file BLI_string_ref.hh.

References Freestyle::c, find_first_not_of(), and pos.

◆ find_first_not_of() [2/2]

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

◆ find_first_of() [1/2]

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

Definition at line 502 of file BLI_string_ref.hh.

References Freestyle::c, find_first_of(), and pos.

◆ find_first_of() [2/2]

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

◆ find_last_not_of() [1/2]

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

Definition at line 538 of file BLI_string_ref.hh.

References Freestyle::c, find_last_not_of(), 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
inlineconstexpr

Definition at line 531 of file BLI_string_ref.hh.

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

Referenced by find_last_not_of().

◆ find_last_of() [1/2]

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

Definition at line 514 of file BLI_string_ref.hh.

References Freestyle::c, find_last_of(), and pos.

◆ find_last_of() [2/2]

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

◆ front()

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

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

Definition at line 180 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
inlineconstexpr

Definition at line 125 of file BLI_string_ref.hh.

References size_.

◆ is_empty()

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

◆ operator Span< char >()

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

Definition at line 96 of file BLI_string_ref.hh.

References data_, and size_.

◆ 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 105 of file BLI_string_ref.hh.

References data_, and size_.

◆ operator std::string_view()

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

Definition at line 110 of file BLI_string_ref.hh.

References data_, and size_.

◆ rfind() [1/2]

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

◆ rfind() [2/2]

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

◆ size()

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

◆ startswith()

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

◆ substr()

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

Return a new #StringRef containing only a sub-string of the original string. This invokes undefined if the start or max_size is negative.

Definition at line 465 of file BLI_string_ref.hh.

References BLI_assert, data_, min, and size_.

Referenced by blender::bke::cryptomatte::BKE_cryptomatte_extract_layer_name(), blender::bke::cryptomatte::CryptomatteStampDataCallbackData::extract_layer_hash(), blender::string_search::extract_normalized_words(), blender::bke::cryptomatte::manifest::from_manifest(), and blender::tests::TEST().

◆ 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 135 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: