An in-transit type that can hold either an RcString or std::string_view, to enable transferring the RcString reference or also accepting a non-owning std::string_view from API surfaces.
More...
#include "donner/base/RcStringOrRef.h"
|
|
using | iterator = char* |
| | String iterator.
|
|
using | const_iterator = const char* |
| | Const string iterator.
|
|
|
constexpr | RcStringOrRef ()=default |
| | Create an empty string.
|
|
| ~RcStringOrRef ()=default |
| | Destructor.
|
| constexpr | RcStringOrRef (std::string_view value) |
| | Constructs a new RcStringOrRef containing a non-owning std::string_view.
|
| constexpr | RcStringOrRef (const RcString &value) |
| | Constructs a new RcStringOrRef containing a transferrable RcString.
|
| constexpr | RcStringOrRef (const char *value, size_t len=npos) |
| | Constructs a new RcStringOrRef object from a C-style string reference and optional length.
|
|
constexpr | RcStringOrRef (const RcStringOrRef &other)=default |
| | Copy constructor.
|
|
constexpr | RcStringOrRef (RcStringOrRef &&other) noexcept |
| | Move constructor.
|
|
RcStringOrRef & | operator= (const RcStringOrRef &other)=default |
| | Copy assignment operator.
|
|
RcStringOrRef & | operator= (RcStringOrRef &&other) noexcept |
| | Move assignment operator.
|
|
RcStringOrRef & | operator= (const char *value) |
| | Assignment operator from a C-style string.
|
|
RcStringOrRef & | operator= (std::string_view value) |
| | Assignment operator from a std::string_view.
|
|
RcStringOrRef & | operator= (const RcString &value) |
| | Assignment operator from an RcString.
|
|
| operator std::string_view () const |
| | Cast operator to std::string_view.
|
|
| operator RcString () const |
| | Cast operator to RcString. If the internal storage is a long RcString, it will increment the refcount without copying.
|
| const char * | data () const |
| bool | empty () const |
| size_t | size () const |
| std::string | str () const |
| RcStringOrRef | substr (size_t pos, size_t len=npos) const |
| | Returns a substring of the string.
|
|
const_iterator | begin () const noexcept |
| | Begin iterator.
|
|
const_iterator | end () const noexcept |
| | End iterator.
|
|
const_iterator | cbegin () const noexcept |
| | Begin iterator.
|
|
const_iterator | cend () const noexcept |
| | End iterator.
|
| bool | equalsLowercase (std::string_view lowercaseOther) const |
| | Returns true if the string equals another all-lowercase string, with a case insensitive comparison.
|
| bool | equalsIgnoreCase (std::string_view other) const |
| | Returns true if the string equals another string with a case-insensitive comparison.
|
|
|
static constexpr size_t | npos = std::string_view::npos |
| | Sentinel value for the maximum value of size_t, used to indicate when the size is not known.
|
|
|
std::ostream & | operator<< (std::ostream &os, const RcStringOrRef &self) |
| | Ostream output operator.
|
|
auto | operator<=> (const RcStringOrRef &lhs, const RcStringOrRef &rhs) |
| | Spaceship equality operator to another RcStringOrRef.
|
|
template<StringLike StringT> |
| auto | operator<=> (const RcStringOrRef &lhs, const StringT &rhs) |
| | Spaceship equality operator to a StringLike type such as std::string_view or RcString.
|
|
template<StringLike StringT> |
| auto | operator<=> (const StringT &lhs, const RcStringOrRef &rhs) |
| | Spaceship equality operator to a StringLike type such as std::string_view or RcString.
|
|
bool | operator== (const RcStringOrRef &lhs, const RcStringOrRef &rhs) |
| | Equality operator to another RcString.
|
|
template<StringLike StringT> |
| bool | operator== (const RcStringOrRef &lhs, const StringT &rhs) |
| | Equality operator to a StringLike type such as std::string_view or RcString.
|
|
template<StringLike StringT> |
| bool | operator== (const StringT &lhs, const RcStringOrRef &rhs) |
| | Reversed equality operator to a StringLike type such as std::string_view or RcString.
|
|
std::string | operator+ (const RcStringOrRef &lhs, const RcStringOrRef &rhs) |
| | Concatenation operator with another RcStringOrRef.
|
|
std::string | operator+ (const RcStringOrRef &lhs, const char *rhs) |
| | Concatenation operator with a C-style string.
|
|
std::string | operator+ (const RcStringOrRef &lhs, std::string_view rhs) |
| | Concatenation operator with a std::string_view.
|
|
std::string | operator+ (std::string_view lhs, const RcStringOrRef &rhs) |
| | Reversed concatenation operator with a C-style string.
|
|
std::string | operator+ (const char *lhs, const RcStringOrRef &rhs) |
| | Reversed concatenation operator with a std::string_view.
|
An in-transit type that can hold either an RcString or std::string_view, to enable transferring the RcString reference or also accepting a non-owning std::string_view from API surfaces.
This can be used either for function arguments, or as a key value for a std::map-like type.
As a function:
}
setString("test");
setString(
RcString(
"will addref if this is larger than the small string optimization");
constexpr RcStringOrRef()=default
Create an empty string.
A reference counted string, that is copy-on-write and implements the small-string optimization.
Definition RcString.h:29
As a map key:
std::map<RcStringOrRef, int> myMap;
auto it = myMap.find("key");
const bool found = it != myMap.end();
assert(found);
◆ RcStringOrRef() [1/3]
| donner::RcStringOrRef::RcStringOrRef |
( |
std::string_view | value | ) |
|
|
inlineconstexpr |
Constructs a new RcStringOrRef containing a non-owning std::string_view.
- Parameters
-
| value | Input string to reference. |
◆ RcStringOrRef() [2/3]
| donner::RcStringOrRef::RcStringOrRef |
( |
const RcString & | value | ) |
|
|
inlineconstexpr |
◆ RcStringOrRef() [3/3]
| donner::RcStringOrRef::RcStringOrRef |
( |
const char * | value, |
|
|
size_t | len = npos ) |
|
inlineconstexpr |
Constructs a new RcStringOrRef object from a C-style string reference and optional length.
- Parameters
-
| value | C-style string. |
| len | Length of the string, or npos to automatically measure, which requires that data is null-terminated. |
◆ data()
| const char * donner::RcStringOrRef::data |
( |
| ) |
const |
|
inline |
- Returns
- a pointer to the string data.
◆ empty()
| bool donner::RcStringOrRef::empty |
( |
| ) |
const |
|
inline |
- Returns
- if the string is empty.
◆ equalsIgnoreCase()
| bool donner::RcStringOrRef::equalsIgnoreCase |
( |
std::string_view | other | ) |
const |
|
inline |
Returns true if the string equals another string with a case-insensitive comparison.
- Parameters
-
| other | string to compare to. |
- Returns
- true If the strings are equal (case insensitive).
◆ equalsLowercase()
| bool donner::RcStringOrRef::equalsLowercase |
( |
std::string_view | lowercaseOther | ) |
const |
|
inline |
Returns true if the string equals another all-lowercase string, with a case insensitive comparison.
Example:
bool equalsLowercase(std::string_view lowercaseOther) const
Returns true if the string equals another all-lowercase string, with a case insensitive comparison.
Definition RcString.h:246
- Parameters
-
| lowercaseOther | string to compare to, must be lowercase. |
- Returns
- true If the strings are equal (case insensitive).
◆ size()
| size_t donner::RcStringOrRef::size |
( |
| ) |
const |
|
inline |
- Returns
- the length of the string.
◆ str()
| std::string donner::RcStringOrRef::str |
( |
| ) |
const |
|
inline |
- Returns
- the string as a std::string.
◆ substr()
Returns a substring of the string.
- Parameters
-
| pos | The position to start the substring. |
| len | The length of the substring, or RcStringOrRef::npos to return the whole string. |
- Returns
- An RcStringOrRef containing the substring.
The documentation for this class was generated from the following file: