libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
|
Go to the source code of this file.
Typedefs | |
typedef const char | GblStringRef |
Functions | |
Lifetime Management | |
Methods for managing GblStringRef references | |
GblStringRef * | GblStringRef_create (const char *pString, size_t len, GblContext *pCtx) |
GblStringRef * | GblStringRef_ref (const GblStringRef *pRef) |
GblRefCount | GblStringRef_unref (const GblStringRef *pRef) |
Properties | |
Methods for reading stored and derived data | |
GblContext * | GblStringRef_context (const GblStringRef *pSelf) |
GblRefCount | GblStringRef_refCount (const GblStringRef *pSelf) |
size_t | GblStringRef_length (const GblStringRef *pSelf) |
GblBool | GblStringRef_valid (const GblStringRef *pSelf) |
GblBool | GblStringRef_empty (const GblStringRef *pSelf) |
GblBool | GblStringRef_blank (const GblStringRef *pSelf) |
GblHash | GblStringRef_hash (const GblStringRef *pSelf) |
Accessors | |
Methods for accessing character and substrings | |
char | GblStringRef_at (const GblStringRef *pSelf, size_t idx) |
GblStringView | GblStringRef_view (const GblStringRef *pSelf, size_t offset, size_t len) |
GblStringRef type and related functions
GblStringRef is a read-only, reference-counted string used to efficiently store, reference, and copy strings. It is also type-compatible with const char*, so it masquerades as a regular C-string to conveniently support regular C string APIs and character array accesses.
The following example illustrates how it may be used:
GblStringRef* pRef = GblStringRef_create("lolol"); // Look, I'm a regular C string! assert(pRef[0] == 'l'); assert(strlen(pRef) == 5); assert(strcmp(pRef, "lolol") == 0); // owait, no, I'm not. GblStringRef* pRef2 = GblStringRef_ref(pRef); assert(GblStringRef_refCount(pRef2) == 2); // even stores length to save on strlen() / StringView time assert(GblStringRef_length(pRef2) == 5); // no strlen() happening here, fast. GblStringView view = GblStringRef_view(pRef); GblStringRef_unref(pRef); // now refCount is 1 GblStringRef_unref(pRef2); // now it's deleted
Definition in file gimbal_string_ref.h.
GblStringRef * GblStringRef_create | ( | const char * | pString, |
size_t | len, | ||
GblContext * | pCtx | ||
) |
Creates and returns a reference containing pString
, with optional length and context.
GblStringRef * GblStringRef_ref | ( | const GblStringRef * | pRef | ) |
Returns a new reference to pRef
, incrementing its internal reference count rather than actually copying.
GblRefCount GblStringRef_unref | ( | const GblStringRef * | pRef | ) |
Releases a reference to pRef
, freeing the allocation if it was the last, returning the new refCount.
GblContext * GblStringRef_context | ( | const GblStringRef * | pSelf | ) |
Returns the GblContext that was created with the given GblStringRef.
GblRefCount GblStringRef_refCount | ( | const GblStringRef * | pSelf | ) |
Returns the number of active references remaining to the given GblStringRef.
size_t GblStringRef_length | ( | const GblStringRef * | pSelf | ) |
Returns the cached length of the given GblStringRef.
GblBool GblStringRef_valid | ( | const GblStringRef * | pSelf | ) |
Returns whether the given GblStringRef is valid (not NULL)
GblBool GblStringRef_empty | ( | const GblStringRef * | pSelf | ) |
Returns whether the given GblStringRef is empty, with nothing but a NULL terminator.
GblBool GblStringRef_blank | ( | const GblStringRef * | pSelf | ) |
Returns whether the given GblStringRef is blank, containing only NULL or spacing characters.
GblHash GblStringRef_hash | ( | const GblStringRef * | pSelf | ) |
Calculates and returns the 32-bit hash value associated with the givne GblStringRef.
char GblStringRef_at | ( | const GblStringRef * | pSelf, |
size_t | idx | ||
) |
Returns the character located at position idx
, raising an error upon out-of-range.
GblStringView GblStringRef_view | ( | const GblStringRef * | pSelf, |
size_t | offset, | ||
size_t | len | ||
) |
Returns a GblStringView containing the character window given by offset
and len
.