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.
|
|
|
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:31
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 | UTILS_LIFETIME_BOUND | ) |
|
|
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 | UTILS_LIFETIME_BOUND, |
|
|
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 |
◆ 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:268
- 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: