Gamedev Framework (gf)  0.17.0
A C++14 framework for 2D games
Public Types | Public Member Functions | List of all members
gf::StringRef Class Reference

A constant reference to a string and its size. More...

#include <gf/StringRef.h>

Public Types

using iterator = const char *
 
using const_iterator = const char *
 

Public Member Functions

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 StringRef (const char *b, const char *e)
 Constructor from two iterators. 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 int getISize () const noexcept
 Get the size of the string as an int. More...
 
constexpr bool isEmpty () const noexcept
 Check if the string is empty. More...
 
constexpr const_iterator begin () const noexcept
 Get an iterator to the beginning of the string. More...
 
constexpr const_iterator 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...
 

Detailed Description

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

Member Typedef Documentation

◆ const_iterator

using gf::StringRef::const_iterator = const char*

◆ iterator

using gf::StringRef::iterator = const char*

Constructor & Destructor Documentation

◆ StringRef() [1/6]

constexpr gf::StringRef::StringRef ( )
inline

Default constructor.

Data is nullptr and size is 0.

◆ StringRef() [2/6]

constexpr gf::StringRef::StringRef ( std::nullptr_t  )
inline

Null constructor.

Data is nullptr and size is 0.

◆ StringRef() [3/6]

constexpr gf::StringRef::StringRef ( const char *  str,
std::size_t  size 
)
inline

Constructor from a pointer and a size.

Parameters
strA pointer to a string
sizeThe size of the string

◆ StringRef() [4/6]

gf::StringRef::StringRef ( const char *  str)
inline

Constructor from a null-terminated string.

The size is computed with std::strlen.

Parameters
strA null-terminated string

◆ StringRef() [5/6]

gf::StringRef::StringRef ( const std::string &  str)
inline

Constructor from a std::string

Parameters
strA C++ string

◆ StringRef() [6/6]

constexpr gf::StringRef::StringRef ( const char *  b,
const char *  e 
)
inline

Constructor from two iterators.

Parameters
bA pointer to the beginning of a string
eA pointer to the end of the same string

Member Function Documentation

◆ begin()

constexpr const_iterator 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_iterator 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

◆ getISize()

constexpr int gf::StringRef::getISize ( ) const
inlinenoexcept

Get the size of the string as an int.

Returns
The size of the string as an int

◆ 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
indexThe 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