1#ifndef GIMBAL_STRING_REF_HPP
2#define GIMBAL_STRING_REF_HPP
15 StringRef()
noexcept =
default;
17 StringRef(
const char* pStr, std::size_t len=0)
noexcept:
18 pRef_(GblStringRef_create(pStr, len)) { }
41 ~StringRef()
noexcept {
45 StringRef& operator=(
const char* pCStr)
noexcept {
47 GblStringRef_create(pCStr);
64 operator
const char*()
const noexcept {
68 char operator[](std::size_t index)
const {
70 throw std::out_of_range {
71 "Attempt to index StringRef out-of-range!"
77 StringView view(std::size_t offset=0, std::size_t len=0)
const {
79 len = length() - offset;
81 if(offset + len > length())
82 throw std::out_of_range {
83 "Attempt to create out-of-range StringView from StringRef"
88 view
.pData = pRef_ + offset;
90 view.nullTerminated = (offset + len == length());
95 std::size_t refCount()
const noexcept {
99 std::size_t length()
const noexcept {
103 bool valid()
const noexcept {
107 bool empty()
const noexcept {
111 bool blank()
const noexcept {
size_t GblStringRef_length(const GblStringRef *pSelf)
Returns the cached length of the given GblStringRef.
GblStringRef * GblStringRef_ref(GblStringRef *pRef)
Returns a new reference to pRef, incrementing its internal reference count rather than actually copyi...
GblBool GblStringRef_blank(const GblStringRef *pSelf)
Returns whether the given GblStringRef is blank, containing only NULL or spacing characters.
GblBool GblStringRef_valid(const GblStringRef *pSelf)
Returns whether the given GblStringRef is valid (not NULL)
GblRefCount GblStringRef_unref(GblStringRef *pRef)
Releases a reference to pRef, freeing the allocation if it was the last, returning the new refCount.
GblBool GblStringRef_empty(const GblStringRef *pSelf)
Returns whether the given GblStringRef is empty, with nothing but a NULL terminator.
GblRefCount GblStringRef_refCount(const GblStringRef *pSelf)
Returns the number of active references remaining to the given GblStringRef.
const char GblStringRef
Reference-counted, const char*-compatible string type.
const char * pData
Start address of the string being viewed.
OO C++ binding object around GblStringView.