A constant reference to a string and its size.
More...
#include <gf/StringRef.h>
|
constexpr | StringRef () |
| Default constructor. More...
|
|
constexpr | StringRef (std::nullptr_t) |
| Null constructor. More...
|
|
constexpr | StringRef (const char *str, std::size_t size) |
| Constructor from a pointer and a size. More...
|
|
| StringRef (const char *str) |
| Constructor from a null-terminated string. More...
|
|
| StringRef (const std::string &str) |
| Constructor from a std::string More...
|
|
constexpr const char * | getData () const noexcept |
| Get a pointer to the string. More...
|
|
constexpr std::size_t | getSize () const noexcept |
| Get the size of the string. More...
|
|
constexpr bool | isEmpty () const noexcept |
| Check if the string is empty. More...
|
|
constexpr const char * | begin () const noexcept |
| Get an iterator to the beginning of the string. More...
|
|
constexpr const char * | end () const noexcept |
| Get an iterator past the end of the string. More...
|
|
constexpr char | operator[] (std::size_t index) const |
| Get a character at a given index. More...
|
|
std::string | toString () const |
| Get a std::string. More...
|
|
A constant reference to a string and its size.
This class stores a pointer to a string and its size. It can be built from various inputs: std::string
, C string.
- See also
- gf::ArrayRef, gf::BufferRef
◆ StringRef() [1/5]
constexpr gf::StringRef::StringRef |
( |
| ) |
|
|
inline |
Default constructor.
Data is nullptr
and size is 0.
◆ StringRef() [2/5]
constexpr gf::StringRef::StringRef |
( |
std::nullptr_t |
| ) |
|
|
inline |
Null constructor.
Data is nullptr
and size is 0.
◆ StringRef() [3/5]
constexpr gf::StringRef::StringRef |
( |
const char * |
str, |
|
|
std::size_t |
size |
|
) |
| |
|
inline |
Constructor from a pointer and a size.
- Parameters
-
str | A pointer to a string |
size | The size of the string |
◆ StringRef() [4/5]
gf::StringRef::StringRef |
( |
const char * |
str | ) |
|
|
inline |
Constructor from a null-terminated string.
The size is computed with std::strlen
.
- Parameters
-
str | A null-terminated string |
◆ StringRef() [5/5]
gf::StringRef::StringRef |
( |
const std::string & |
str | ) |
|
|
inline |
Constructor from a std::string
- Parameters
-
◆ begin()
constexpr const char* gf::StringRef::begin |
( |
| ) |
const |
|
inlinenoexcept |
Get an iterator to the beginning of the string.
- Returns
- A pointer to the first character
- See also
- end()
◆ end()
constexpr const char* gf::StringRef::end |
( |
| ) |
const |
|
inlinenoexcept |
Get an iterator past the end of the string.
- Returns
- A pointer past the last character
- See also
- begin()
◆ getData()
constexpr const char* gf::StringRef::getData |
( |
| ) |
const |
|
inlinenoexcept |
Get a pointer to the string.
- Returns
- A pointer to the beginning of the string
◆ getSize()
constexpr std::size_t gf::StringRef::getSize |
( |
| ) |
const |
|
inlinenoexcept |
Get the size of the string.
- Returns
- The size of the string
◆ isEmpty()
constexpr bool gf::StringRef::isEmpty |
( |
| ) |
const |
|
inlinenoexcept |
Check if the string is empty.
An empty string is a string with size 0. So the null string is empty.
- Returns
- True if the string is empty
◆ operator[]()
constexpr char gf::StringRef::operator[] |
( |
std::size_t |
index | ) |
const |
|
inline |
Get a character at a given index.
No verification is done on the index.
- Parameters
-
index | The index of character |
- Returns
- The character at the given index
◆ toString()
std::string gf::StringRef::toString |
( |
| ) |
const |
|
inline |
Get a std::string.
- Returns
- A string with the same data