ESPHome  2024.11.2
Public Types | Public Member Functions | Static Public Member Functions
esphome::StringRef Class Reference

StringRef is a reference to a string owned by something else. More...

#include <string_ref.h>

Public Types

using traits_type = std::char_traits< char >
 
using value_type = traits_type::char_type
 
using allocator_type = std::allocator< char >
 
using size_type = std::allocator_traits< allocator_type >::size_type
 
using difference_type = std::allocator_traits< allocator_type >::difference_type
 
using const_reference = const value_type &
 
using const_pointer = const value_type *
 
using const_iterator = const_pointer
 
using const_reverse_iterator = std::reverse_iterator< const_iterator >
 

Public Member Functions

constexpr StringRef ()
 
 StringRef (const std::string &s)
 
 StringRef (const char *s)
 
constexpr StringRef (const char *s, size_t n)
 
template<typename CharT >
constexpr StringRef (const CharT *s, size_t n)
 
template<typename InputIt >
 StringRef (InputIt first, InputIt last)
 
template<typename InputIt >
 StringRef (InputIt *first, InputIt *last)
 
constexpr const_iterator begin () const
 
constexpr const_iterator cbegin () const
 
constexpr const_iterator end () const
 
constexpr const_iterator cend () const
 
const_reverse_iterator rbegin () const
 
const_reverse_iterator crbegin () const
 
const_reverse_iterator rend () const
 
const_reverse_iterator crend () const
 
constexpr const char * c_str () const
 
constexpr size_type size () const
 
constexpr bool empty () const
 
constexpr const_reference operator[] (size_type pos) const
 
std::string str () const
 
const uint8_t * byte () const
 
 operator std::string () const
 

Static Public Member Functions

template<typename CharT , size_t N>
static constexpr StringRef from_lit (const CharT(&s)[N])
 
static StringRef from_maybe_nullptr (const char *s)
 

Detailed Description

StringRef is a reference to a string owned by something else.

So it behaves like simple string, but it does not own pointer. When it is default constructed, it has empty string. You can freely copy or move around this struct, but never free its pointer. str() function can be used to export the content as std::string. StringRef is adopted from https://github.com/nghttp2/nghttp2/blob/29cbf8b83ff78faf405d1086b16adc09a8772eca/src/template.h#L376

Definition at line 21 of file string_ref.h.

Member Typedef Documentation

◆ allocator_type

using esphome::StringRef::allocator_type = std::allocator<char>

Definition at line 25 of file string_ref.h.

◆ const_iterator

Definition at line 30 of file string_ref.h.

◆ const_pointer

Definition at line 29 of file string_ref.h.

◆ const_reference

Definition at line 28 of file string_ref.h.

◆ const_reverse_iterator

Definition at line 31 of file string_ref.h.

◆ difference_type

Definition at line 27 of file string_ref.h.

◆ size_type

using esphome::StringRef::size_type = std::allocator_traits<allocator_type>::size_type

Definition at line 26 of file string_ref.h.

◆ traits_type

using esphome::StringRef::traits_type = std::char_traits<char>

Definition at line 23 of file string_ref.h.

◆ value_type

using esphome::StringRef::value_type = traits_type::char_type

Definition at line 24 of file string_ref.h.

Constructor & Destructor Documentation

◆ StringRef() [1/7]

constexpr esphome::StringRef::StringRef ( )
inline

Definition at line 33 of file string_ref.h.

◆ StringRef() [2/7]

esphome::StringRef::StringRef ( const std::string &  s)
inlineexplicit

Definition at line 34 of file string_ref.h.

◆ StringRef() [3/7]

esphome::StringRef::StringRef ( const char *  s)
inlineexplicit

Definition at line 35 of file string_ref.h.

◆ StringRef() [4/7]

constexpr esphome::StringRef::StringRef ( const char *  s,
size_t  n 
)
inline

Definition at line 36 of file string_ref.h.

◆ StringRef() [5/7]

template<typename CharT >
constexpr esphome::StringRef::StringRef ( const CharT *  s,
size_t  n 
)
inline

Definition at line 38 of file string_ref.h.

◆ StringRef() [6/7]

template<typename InputIt >
esphome::StringRef::StringRef ( InputIt  first,
InputIt  last 
)
inline

Definition at line 40 of file string_ref.h.

◆ StringRef() [7/7]

template<typename InputIt >
esphome::StringRef::StringRef ( InputIt *  first,
InputIt *  last 
)
inline

Definition at line 43 of file string_ref.h.

Member Function Documentation

◆ begin()

constexpr const_iterator esphome::StringRef::begin ( ) const
inline

Definition at line 56 of file string_ref.h.

◆ byte()

const uint8_t* esphome::StringRef::byte ( ) const
inline

Definition at line 74 of file string_ref.h.

◆ c_str()

constexpr const char* esphome::StringRef::c_str ( ) const
inline

Definition at line 68 of file string_ref.h.

◆ cbegin()

constexpr const_iterator esphome::StringRef::cbegin ( ) const
inline

Definition at line 57 of file string_ref.h.

◆ cend()

constexpr const_iterator esphome::StringRef::cend ( ) const
inline

Definition at line 60 of file string_ref.h.

◆ crbegin()

const_reverse_iterator esphome::StringRef::crbegin ( ) const
inline

Definition at line 63 of file string_ref.h.

◆ crend()

const_reverse_iterator esphome::StringRef::crend ( ) const
inline

Definition at line 66 of file string_ref.h.

◆ empty()

constexpr bool esphome::StringRef::empty ( ) const
inline

Definition at line 70 of file string_ref.h.

◆ end()

constexpr const_iterator esphome::StringRef::end ( ) const
inline

Definition at line 59 of file string_ref.h.

◆ from_lit()

template<typename CharT , size_t N>
static constexpr StringRef esphome::StringRef::from_lit ( const CharT(&)  s[N])
inlinestatic

Definition at line 45 of file string_ref.h.

◆ from_maybe_nullptr()

static StringRef esphome::StringRef::from_maybe_nullptr ( const char *  s)
inlinestatic

Definition at line 48 of file string_ref.h.

◆ operator std::string()

esphome::StringRef::operator std::string ( ) const
inline

Definition at line 76 of file string_ref.h.

◆ operator[]()

constexpr const_reference esphome::StringRef::operator[] ( size_type  pos) const
inline

Definition at line 71 of file string_ref.h.

◆ rbegin()

const_reverse_iterator esphome::StringRef::rbegin ( ) const
inline

Definition at line 62 of file string_ref.h.

◆ rend()

const_reverse_iterator esphome::StringRef::rend ( ) const
inline

Definition at line 65 of file string_ref.h.

◆ size()

constexpr size_type esphome::StringRef::size ( ) const
inline

Definition at line 69 of file string_ref.h.

◆ str()

std::string esphome::StringRef::str ( ) const
inline

Definition at line 73 of file string_ref.h.


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