libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gbl::StringRef Class Reference

Public Member Functions

 StringRef (const char *pStr, std::size_t len=0) noexcept
 
 StringRef (const StringRef &rhs) noexcept
 
 StringRef (StringRef &&rhs) noexcept
 
StringRef fromGblRef (GblStringRef *pRef) noexcept
 
GblStringReftoGblRef () noexcept
 
StringRefoperator= (const char *pCStr) noexcept
 
StringRefoperator= (const StringRef &rhs) noexcept
 
StringRefoperator= (StringRef &&rhs) noexcept
 
 operator const char * () const noexcept
 
char operator[] (std::size_t index) const
 
StringView view (std::size_t offset=0, std::size_t len=0) const
 
std::size_t refCount () const noexcept
 
std::size_t length () const noexcept
 
bool valid () const noexcept
 
bool empty () const noexcept
 
bool blank () const noexcept
 

Detailed Description

Definition at line 11 of file gimbal_string_ref.hpp.

Constructor & Destructor Documentation

◆ StringRef() [1/3]

gbl::StringRef::StringRef ( const char *  pStr,
std::size_t  len = 0 
)
inlinenoexcept

Definition at line 19 of file gimbal_string_ref.hpp.

19 :
20 pRef_(GblStringRef_create(pStr, len)) { }
GblStringRef * GblStringRef_create(const char *pString, size_t len, GblContext *pCtx)
Creates and returns a reference containing pString, with optional length and context.

◆ StringRef() [2/3]

gbl::StringRef::StringRef ( const StringRef rhs)
inlinenoexcept

Definition at line 22 of file gimbal_string_ref.hpp.

22 :
23 pRef_(GblStringRef_ref(rhs.pRef_)) { }
GblStringRef * GblStringRef_ref(const GblStringRef *pRef)
Returns a new reference to pRef, incrementing its internal reference count rather than actually copyi...

◆ StringRef() [3/3]

gbl::StringRef::StringRef ( StringRef &&  rhs)
inlinenoexcept

Definition at line 25 of file gimbal_string_ref.hpp.

25 :
26 pRef_(rhs.pRef_)
27 {
28 rhs.pRef_ = nullptr;
29 }

◆ ~StringRef()

gbl::StringRef::~StringRef ( )
inlinenoexcept

Definition at line 43 of file gimbal_string_ref.hpp.

43 {
44 GblStringRef_unref(pRef_);
45 }
GblRefCount GblStringRef_unref(const GblStringRef *pRef)
Releases a reference to pRef, freeing the allocation if it was the last, returning the new refCount.

Member Function Documentation

◆ fromGblRef()

StringRef gbl::StringRef::fromGblRef ( GblStringRef pRef)
inlinenoexcept

Definition at line 31 of file gimbal_string_ref.hpp.

31 {
32 StringRef ref;
33 ref.pRef_ = pRef;
34 return ref;
35 }

◆ toGblRef()

GblStringRef * gbl::StringRef::toGblRef ( )
inlinenoexcept

Definition at line 37 of file gimbal_string_ref.hpp.

37 {
38 GblStringRef* pTemp = pRef_;
39 pRef_ = nullptr;
40 return pTemp;
41 }
const char GblStringRef
Reference-counted, const char*-compatible string type.

◆ operator=() [1/3]

StringRef & gbl::StringRef::operator= ( const char *  pCStr)
inlinenoexcept

Definition at line 47 of file gimbal_string_ref.hpp.

47 {
48 GblStringRef_unref(pRef_);
50 return *this;
51 }

◆ operator=() [2/3]

StringRef & gbl::StringRef::operator= ( const StringRef rhs)
inlinenoexcept

Definition at line 53 of file gimbal_string_ref.hpp.

53 {
54 GblStringRef_unref(pRef_);
55 GblStringRef_ref(rhs.pRef_);
56 return *this;
57 }

◆ operator=() [3/3]

StringRef & gbl::StringRef::operator= ( StringRef &&  rhs)
inlinenoexcept

Definition at line 59 of file gimbal_string_ref.hpp.

59 {
60 GblStringRef_unref(pRef_);
61 pRef_ = rhs.pRef_;
62 rhs.pRef_ = nullptr;
63 return *this;
64 }

◆ operator const char *()

gbl::StringRef::operator const char * ( ) const
inlinenoexcept

Definition at line 66 of file gimbal_string_ref.hpp.

66 {
67 return pRef_;
68 }

◆ operator[]()

char gbl::StringRef::operator[] ( std::size_t  index) const
inline

Definition at line 70 of file gimbal_string_ref.hpp.

70 {
71 if(index >= length())
72 throw std::out_of_range {
73 "Attempt to index StringRef out-of-range!"
74 };
75
76 return pRef_[index];
77 }

◆ view()

StringView gbl::StringRef::view ( std::size_t  offset = 0,
std::size_t  len = 0 
) const
inline

Definition at line 79 of file gimbal_string_ref.hpp.

79 {
80 if(!len)
81 len = length() - offset;
82
83 if(offset + len > length())
84 throw std::out_of_range {
85 "Attempt to create out-of-range StringView from StringRef"
86 };
87
88
89 return GblStringView {
90 .pData = pRef_ + offset,
91 .nullTerminated = (offset + len == length()),
92 .length = len
93 };
94 }
Immutable substring type.
const char * pData
Start address of the string being viewed.

◆ refCount()

std::size_t gbl::StringRef::refCount ( ) const
inlinenoexcept

Definition at line 96 of file gimbal_string_ref.hpp.

96 {
97 return GblStringRef_refCount(pRef_);
98 }
GblRefCount GblStringRef_refCount(const GblStringRef *pSelf)
Returns the number of active references remaining to the given GblStringRef.

◆ length()

std::size_t gbl::StringRef::length ( ) const
inlinenoexcept

Definition at line 100 of file gimbal_string_ref.hpp.

100 {
101 return GblStringRef_length(pRef_);
102 }
size_t GblStringRef_length(const GblStringRef *pSelf)
Returns the cached length of the given GblStringRef.

◆ valid()

bool gbl::StringRef::valid ( ) const
inlinenoexcept

Definition at line 104 of file gimbal_string_ref.hpp.

104 {
105 return GblStringRef_valid(pRef_);
106 }
GblBool GblStringRef_valid(const GblStringRef *pSelf)
Returns whether the given GblStringRef is valid (not NULL)

◆ empty()

bool gbl::StringRef::empty ( ) const
inlinenoexcept

Definition at line 108 of file gimbal_string_ref.hpp.

108 {
109 return GblStringRef_empty(pRef_);
110 }
GblBool GblStringRef_empty(const GblStringRef *pSelf)
Returns whether the given GblStringRef is empty, with nothing but a NULL terminator.

◆ blank()

bool gbl::StringRef::blank ( ) const
inlinenoexcept

Definition at line 112 of file gimbal_string_ref.hpp.

112 {
113 return GblStringRef_blank(pRef_);
114 }
GblBool GblStringRef_blank(const GblStringRef *pSelf)
Returns whether the given GblStringRef is blank, containing only NULL or spacing characters.

The documentation for this class was generated from the following file: