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 9 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 17 of file gimbal_string_ref.hpp.

17 :
18 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 20 of file gimbal_string_ref.hpp.

20 :
21 pRef_(GblStringRef_ref(rhs.pRef_)) { }
GblStringRef * GblStringRef_ref(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 23 of file gimbal_string_ref.hpp.

23 :
24 pRef_(rhs.pRef_)
25 {
26 rhs.pRef_ = nullptr;
27 }

◆ ~StringRef()

gbl::StringRef::~StringRef ( )
inlinenoexcept

Definition at line 41 of file gimbal_string_ref.hpp.

41 {
42 GblStringRef_unref(pRef_);
43 }
GblRefCount GblStringRef_unref(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 29 of file gimbal_string_ref.hpp.

29 {
30 StringRef ref;
31 ref.pRef_ = pRef;
32 return ref;
33 }

◆ toGblRef()

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

Definition at line 35 of file gimbal_string_ref.hpp.

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

◆ operator=() [1/3]

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

Definition at line 45 of file gimbal_string_ref.hpp.

45 {
46 GblStringRef_unref(pRef_);
48 return *this;
49 }

◆ operator=() [2/3]

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

Definition at line 51 of file gimbal_string_ref.hpp.

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

◆ operator=() [3/3]

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

Definition at line 57 of file gimbal_string_ref.hpp.

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

◆ operator const char *()

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

Definition at line 64 of file gimbal_string_ref.hpp.

64 {
65 return pRef_;
66 }

◆ operator[]()

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

Definition at line 68 of file gimbal_string_ref.hpp.

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

◆ view()

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

Definition at line 77 of file gimbal_string_ref.hpp.

77 {
78 if(!len)
79 len = length() - offset;
80
81 if(offset + len > length())
82 throw std::out_of_range {
83 "Attempt to create out-of-range StringView from StringRef"
84 };
85
86
87 GblStringView view;
88 view.pData = pRef_ + offset;
89 view.length = len;
90 view.nullTerminated = (offset + len == length());
91
92 return view;
93 }

◆ refCount()

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

Definition at line 95 of file gimbal_string_ref.hpp.

95 {
96 return GblStringRef_refCount(pRef_);
97 }
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 99 of file gimbal_string_ref.hpp.

99 {
100 return GblStringRef_length(pRef_);
101 }
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 103 of file gimbal_string_ref.hpp.

103 {
104 return GblStringRef_valid(pRef_);
105 }
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 107 of file gimbal_string_ref.hpp.

107 {
108 return GblStringRef_empty(pRef_);
109 }
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 111 of file gimbal_string_ref.hpp.

111 {
112 return GblStringRef_blank(pRef_);
113 }
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: