|
ESPHome 2026.11.0-dev
|
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 size_type | length () const |
| constexpr bool | empty () const |
| constexpr const_reference | operator[] (size_type pos) const |
| bool | starts_with (const StringRef &prefix) const |
| True if the view begins with the given prefix (std::string::starts_with-like) | |
| bool | starts_with (const char *prefix) const |
| bool | starts_with (const std::string &prefix) const |
| size_type | copy (char *dest, size_type count, size_type pos=0) const |
| Copy characters to destination buffer (std::string::copy-like, but returns 0 instead of throwing on out-of-range) | |
| std::string | str () const |
| const uint8_t * | byte () const |
| operator std::string () const | |
| int | compare (const StringRef &other) const |
| Compare (compatible with std::string::compare) | |
| int | compare (const char *s) const |
| int | compare (const std::string &s) const |
| size_type | find (const char *s, size_type pos=0) const |
| Find first occurrence of substring, returns std::string::npos if not found. | |
| size_type | find (char c, size_type pos=0) const |
| std::string | substr (size_type pos=0, size_type count=std::string::npos) const |
| Return substring as std::string. | |
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) |
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
A StringRef may carry a null pointer while its length is zero (the generated api messages start their encode only string fields that way). Every member treats that as the empty string: the iterators form an empty range, and c_str() and byte() return the null pointer, so callers that print or copy through those must check empty() first.
Definition at line 31 of file string_ref.h.
| using esphome::StringRef::allocator_type = std::allocator<char> |
Definition at line 35 of file string_ref.h.
Definition at line 40 of file string_ref.h.
| using esphome::StringRef::const_pointer = const value_type * |
Definition at line 39 of file string_ref.h.
| using esphome::StringRef::const_reference = const value_type & |
Definition at line 38 of file string_ref.h.
| using esphome::StringRef::const_reverse_iterator = std::reverse_iterator<const_iterator> |
Definition at line 41 of file string_ref.h.
| using esphome::StringRef::difference_type = std::allocator_traits<allocator_type>::difference_type |
Definition at line 37 of file string_ref.h.
| using esphome::StringRef::size_type = std::allocator_traits<allocator_type>::size_type |
Definition at line 36 of file string_ref.h.
| using esphome::StringRef::traits_type = std::char_traits<char> |
Definition at line 33 of file string_ref.h.
| using esphome::StringRef::value_type = traits_type::char_type |
Definition at line 34 of file string_ref.h.
|
inlineconstexpr |
Definition at line 43 of file string_ref.h.
|
inlineexplicit |
Definition at line 44 of file string_ref.h.
|
inlineexplicit |
Definition at line 45 of file string_ref.h.
|
inlineconstexpr |
Definition at line 46 of file string_ref.h.
|
inlineconstexpr |
Definition at line 48 of file string_ref.h.
|
inline |
Definition at line 50 of file string_ref.h.
|
inline |
Definition at line 53 of file string_ref.h.
|
inlineconstexpr |
Definition at line 66 of file string_ref.h.
|
inline |
Definition at line 101 of file string_ref.h.
|
inlineconstexpr |
Definition at line 78 of file string_ref.h.
|
inlineconstexpr |
Definition at line 67 of file string_ref.h.
|
inlineconstexpr |
Definition at line 70 of file string_ref.h.
|
inline |
Definition at line 117 of file string_ref.h.
|
inline |
Definition at line 118 of file string_ref.h.
|
inline |
Compare (compatible with std::string::compare)
Definition at line 106 of file string_ref.h.
Copy characters to destination buffer (std::string::copy-like, but returns 0 instead of throwing on out-of-range)
Definition at line 92 of file string_ref.h.
|
inline |
Definition at line 73 of file string_ref.h.
|
inline |
Definition at line 76 of file string_ref.h.
|
inlineconstexpr |
Definition at line 81 of file string_ref.h.
|
inlineconstexpr |
Definition at line 69 of file string_ref.h.
Definition at line 131 of file string_ref.h.
Find first occurrence of substring, returns std::string::npos if not found.
Note: Requires the underlying string to be null-terminated.
Definition at line 122 of file string_ref.h.
|
inlinestaticconstexpr |
Definition at line 55 of file string_ref.h.
|
inlinestatic |
Definition at line 58 of file string_ref.h.
|
inlineconstexpr |
Definition at line 80 of file string_ref.h.
|
inline |
Definition at line 103 of file string_ref.h.
|
inlineconstexpr |
Definition at line 82 of file string_ref.h.
|
inline |
Definition at line 72 of file string_ref.h.
|
inline |
Definition at line 75 of file string_ref.h.
|
inlineconstexpr |
Definition at line 79 of file string_ref.h.
|
inline |
Definition at line 88 of file string_ref.h.
|
inline |
Definition at line 89 of file string_ref.h.
|
inline |
True if the view begins with the given prefix (std::string::starts_with-like)
Definition at line 85 of file string_ref.h.
|
inline |
Definition at line 100 of file string_ref.h.
|
inline |
Return substring as std::string.
Definition at line 139 of file string_ref.h.