libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
GblStringBuffer Struct Reference

#include <gimbal_string_buffer.h>

Inheritance diagram for GblStringBuffer:
gimbal::String gimbal::FlexibleString< ExtraStackSize >

Data Fields

GblArrayList data
 

Related Symbols

(Note that these are not member symbols.)

Lifetime Management

Methods for consruction, destruction, moving, etc

GBL_RESULT GblStringBuffer_construct (GblStringBuffer *pSelf, const char *pString, size_t length, size_t structSize, GblContext *pCtx)
 
GBL_RESULT GblStringBuffer_destruct (GblStringBuffer *pSelf)
 
GBL_RESULT GblStringBuffer_acquire (GblStringBuffer *pSelf, char *pData, size_t capacity)
 
GBL_RESULT GblStringBuffer_release (GblStringBuffer *pSelf, char **ppStrPtr, size_t *pCapacity)
 
Properties

Methods for querying or retrieving associated data

char * GblStringBuffer_data (GblStringBuffer *pSelf)
 
size_t GblStringBuffer_length (const GblStringBuffer *pSelf)
 
size_t GblStringBuffer_capacity (const GblStringBuffer *pSelf)
 
size_t GblStringBuffer_stackBytes (const GblStringBuffer *pSelf)
 
char * GblStringBuffer_stackBuffer (const GblStringBuffer *pSelf)
 
GblContextGblStringBuffer_context (const GblStringBuffer *pSelf)
 
GblBool GblStringBuffer_empty (const GblStringBuffer *pSelf)
 
GblBool GblStringBuffer_valid (const GblStringBuffer *pSelf)
 
GblBool GblStringBuffer_blank (const GblStringBuffer *pSelf)
 
GblBool GblStringBuffer_stack (const GblStringBuffer *pSelf)
 
Conversions

Methods for converting to other string types

const GblStringRefGblStringBuffer_createRef (const GblStringBuffer *pSelf)
 
const char * GblStringBuffer_cString (const GblStringBuffer *pSelf)
 
const char * GblStringBuffer_intern (const GblStringBuffer *pSelf)
 
GblQuark GblStringBuffer_quark (const GblStringBuffer *pSelf)
 
GblQuark GblStringBuffer_tryQuark (const GblStringBuffer *pSelf)
 
GblStringView GblStringBuffer_view (const GblStringBuffer *pSelf, size_t offset, size_t len)
 
Per-Character Access

Methods for getting and setting individual indices

char GblStringBuffer_at (const GblStringBuffer *pSelf, size_t index)
 
GBL_RESULT GblStringBuffer_setChar (const GblStringBuffer *pSelf, size_t index, char value)
 
Assignment

Methods for setting the value of a constructed string

const char * GblStringBuffer_set (GblStringBuffer *pSelf, const char *pStr, size_t len)
 
const char * GblStringBuffer_printf (GblStringBuffer *pSelf, const char *pFmt,...)
 
const char * GblStringBuffer_vPrintf (GblStringBuffer *pSelf, const char *pFmt, va_list varArgs)
 
Prepending

Methods for adding to the beginning of the a string

GBL_RESULT GblStringBuffer_prepend (GblStringBuffer *pSelf, const char *pStr, size_t len)
 
GBL_RESULT GblStringBuffer_prependPadding (GblStringBuffer *pSelf, char value, size_t count)
 
Appending

Methods for adding to the end of a string

GBL_RESULT GblStringBuffer_append (GblStringBuffer *pSelf, const char *pStr, size_t len)
 
GBL_RESULT GblStringBuffer_appendPrintf (GblStringBuffer *pSelf, const char *pFmt,...)
 
GBL_RESULT GblStringBuffer_appendVPrintf (GblStringBuffer *pSelf, const char *pFmt, va_list varArgs)
 
GBL_RESULT GblStringBuffer_appendPadding (GblStringBuffer *pSelf, char value, size_t count)
 
GBL_RESULT GblStringBuffer_appendNil (GblStringBuffer *pSelf)
 
GBL_RESULT GblStringBuffer_appendBool (GblStringBuffer *pSelf, GblBool value)
 
GBL_RESULT GblStringBuffer_appendInt (GblStringBuffer *pSelf, int value)
 
GBL_RESULT GblStringBuffer_appendUint (GblStringBuffer *pSelf, unsigned value)
 
GBL_RESULT GblStringBuffer_appendFloat (GblStringBuffer *pSelf, float value)
 
GBL_RESULT GblStringBuffer_appendDouble (GblStringBuffer *pSelf, double value)
 
GBL_RESULT GblStringBuffer_appendPointer (GblStringBuffer *pSelf, const void *pPtr)
 
Modifying

Methods for general string modifications

GBL_RESULT GblStringBuffer_insert (GblStringBuffer *pSelf, size_t index, const char *pString, size_t length)
 
GBL_RESULT GblStringBuffer_overwrite (GblStringBuffer *pSelf, size_t index, const char *pString, size_t length)
 
size_t GblStringBuffer_replace (GblStringBuffer *pSelf, const char *pSubstr, const char *pReplacement, size_t limit, size_t substrLen, size_t replLen)
 
Removing

Methods for erasing portions of a string

GBL_RESULT GblStringBuffer_erase (GblStringBuffer *pSelf, size_t offset, size_t len)
 
GBL_RESULT GblStringBuffer_clear (GblStringBuffer *pSelf)
 
size_t GblStringBuffer_remove (GblStringBuffer *pSelf, const char *pStr, size_t len)
 
GBL_RESULT GblStringBuffer_chop (GblStringBuffer *pSelf)
 
GBL_RESULT GblStringBuffer_chomp (GblStringBuffer *pSelf)
 
GBL_RESULT GblStringBuffer_trimStart (GblStringBuffer *pSelf, char value)
 
GBL_RESULT GblStringBuffer_trimEnd (GblStringBuffer *pSelf, char value)
 
Miscellaneous

Methods for other utilities and string operations

GBL_RESULT GblStringBuffer_lower (GblStringBuffer *pSelf)
 
GBL_RESULT GblStringBuffer_upper (GblStringBuffer *pSelf)
 
GBL_RESULT GblStringBuffer_reverse (GblStringBuffer *pSelf)
 
Sizing

Methods for managing size and capacity

GBL_RESULT GblStringBuffer_reserve (GblStringBuffer *pSelf, size_t capacity)
 
GBL_RESULT GblStringBuffer_resize (GblStringBuffer *pSelf, size_t size)
 
GBL_RESULT GblStringBuffer_grow (GblStringBuffer *pSelf, size_t delta)
 
GBL_RESULT GblStringBuffer_shrink (GblStringBuffer *pSelf, size_t delta)
 
GBL_RESULT GblStringBuffer_shrinkToFit (GblStringBuffer *pSelf)
 

Detailed Description

Mutable string type optimized for building and writing.

GblStringBuffer is a type of string which is optimized for efficient piece-wise construction, appending, and writing. It's equivalent to a "String Builder" type in other languages, such as C# and Java.

It is typically used temporarily to construct a string, afterwards it is usually converted to another type for storage, such as a GblStringRef or the internal buffer is taken away from it to be stored elsewhere.

Internally it is implemented similarly to a C++-vector, with both a size and a capacity, growing when needed, but not immediatley shrinking.

Note
The API around GblStringBuffer is based around modifying strings. For read-only operations on them, such as searching or match counting, use GblStringBuffer_view() and the GblStringView API.
GblStringBuffer supports being created with additional trailing storage, allowing it to be over-allocated with malloc() or GBL_ALLOCA(). This means it will not create a separate heap allocation until necessary, and will instead useits trailing allocation region as its internal buffer. This can be very efficient when building temporary strings.
See also
GblStringRef, GblStringView, GblQuark

Definition at line 65 of file gimbal_string_buffer.h.

Friends And Related Symbol Documentation

◆ GblStringBuffer_construct()

GBL_RESULT GblStringBuffer_construct ( GblStringBuffer pSelf,
const char *  pString,
size_t  length,
size_t  structSize,
GblContext pCtx 
)
related

Constructs the given GblStringBuffer struct with any given initial values (or defaults), returning a result code.

◆ GblStringBuffer_destruct()

GBL_RESULT GblStringBuffer_destruct ( GblStringBuffer pSelf)
related

Destructs the given GblStringBuffer structure, releasing any allocated resources and returning a result code.

◆ GblStringBuffer_acquire()

GBL_RESULT GblStringBuffer_acquire ( GblStringBuffer pSelf,
char *  pData,
size_t  capacity 
)
related

Transfers ownership of a given C string to the given buffer, assigning its value and updating its capacity.

◆ GblStringBuffer_release()

GBL_RESULT GblStringBuffer_release ( GblStringBuffer pSelf,
char **  ppStrPtr,
size_t *  pCapacity 
)
related

Takes ownership of the given GblStringBuffer's internal buffer, also returning its capacity and a result code.

◆ GblStringBuffer_data()

char * GblStringBuffer_data ( GblStringBuffer pSelf)
related

Returns a mutable pointer to the internal data buffer of the given GblStringBuffer.

◆ GblStringBuffer_length()

size_t GblStringBuffer_length ( const GblStringBuffer pSelf)
related

Returns the string length of the string held by the given GblStringBuffer.

◆ GblStringBuffer_capacity()

size_t GblStringBuffer_capacity ( const GblStringBuffer pSelf)
related

Returns the actual size of the internal data buffer held by the given GblStringBuffer.

◆ GblStringBuffer_stackBytes()

size_t GblStringBuffer_stackBytes ( const GblStringBuffer pSelf)
related

Returns the number of bytes the given GblStringBuffer can store before falling back to the heap.

◆ GblStringBuffer_stackBuffer()

char * GblStringBuffer_stackBuffer ( const GblStringBuffer pSelf)
related

Returns a mutable pointer to the extra stack storage region, if present.

◆ GblStringBuffer_context()

GblContext * GblStringBuffer_context ( const GblStringBuffer pSelf)
related

Returns a pointer to the context the GblStringBuffer was created with.

◆ GblStringBuffer_empty()

GblBool GblStringBuffer_empty ( const GblStringBuffer pSelf)
related

Returns GBL_TRUE if the given GblStringBuffer is empty, otherwise returns GBL_FALSE.

◆ GblStringBuffer_valid()

GblBool GblStringBuffer_valid ( const GblStringBuffer pSelf)
related

Returns GBL_TRUE if the given GblStringBuffer holds a valid C string (with NULL terminator)

◆ GblStringBuffer_blank()

GblBool GblStringBuffer_blank ( const GblStringBuffer pSelf)
related

Returns GBL_TRUE if the given GblStringBuffer is empty or holds only spacing characters.

◆ GblStringBuffer_stack()

GblBool GblStringBuffer_stack ( const GblStringBuffer pSelf)
related

Returns GBL_TRUE if the given GblStringBuffer's internal buffer is on the stack and not heap.

◆ GblStringBuffer_createRef()

const GblStringRef * GblStringBuffer_createRef ( const GblStringBuffer pSelf)
related

Creates and returns a new GblStringRef based on the contents of the given buffer (don't forget to unref it)

◆ GblStringBuffer_cString()

const char * GblStringBuffer_cString ( const GblStringBuffer pSelf)
related

Returns a pointer to a constant NULL-terminated C string for the given GblStringBuffer.

◆ GblStringBuffer_intern()

const char * GblStringBuffer_intern ( const GblStringBuffer pSelf)
related

Returns a pointer to the interned string representation of the buffer, interning it if it hasn't been already.

◆ GblStringBuffer_quark()

GblQuark GblStringBuffer_quark ( const GblStringBuffer pSelf)
related

Converts the GblStringBuffer to a GblQuark, possibly interning it, and returning its GblQuark.

◆ GblStringBuffer_tryQuark()

GblQuark GblStringBuffer_tryQuark ( const GblStringBuffer pSelf)
related

Returns the GblQuark corresponding to the given GblStringBuffer only if it already exists.

◆ GblStringBuffer_view()

GblStringView GblStringBuffer_view ( const GblStringBuffer pSelf,
size_t  offset,
size_t  len 
)
related

Creates a GblStringView containing either the whole buffer or a subsection of it.

◆ GblStringBuffer_at()

char GblStringBuffer_at ( const GblStringBuffer pSelf,
size_t  index 
)
related

Returns the character stored in the given buffer at index, throwing an error and returning '\0' if invalid.

◆ GblStringBuffer_setChar()

GBL_RESULT GblStringBuffer_setChar ( const GblStringBuffer pSelf,
size_t  index,
char  value 
)
related

Sets the character stored in the given buffer at index to value, returning an error upon failure.

◆ GblStringBuffer_set()

const char * GblStringBuffer_set ( GblStringBuffer pSelf,
const char *  pStr,
size_t  len 
)
related

Assigns the value of the given GblStringBuffer to pStr, optionally taking its length, len.

◆ GblStringBuffer_printf()

const char * GblStringBuffer_printf ( GblStringBuffer pSelf,
const char *  pFmt,
  ... 
)
related

Assings the value of the formatted string to the given GblStringBuffer, similarly to C's sscanf()

◆ GblStringBuffer_vPrintf()

const char * GblStringBuffer_vPrintf ( GblStringBuffer pSelf,
const char *  pFmt,
va_list  varArgs 
)
related

Equivalent to GblStringBuffer_printf(), except passing additional arguments via a va_list.

◆ GblStringBuffer_prepend()

GBL_RESULT GblStringBuffer_prepend ( GblStringBuffer pSelf,
const char *  pStr,
size_t  len 
)
related

Inserts pStr (with optional length, len) at the beginning of the given buffer, returning a result code.

◆ GblStringBuffer_prependPadding()

GBL_RESULT GblStringBuffer_prependPadding ( GblStringBuffer pSelf,
char  value,
size_t  count 
)
related

Inserts count copies of value at the beginning of the given buffer, returning a result code.

◆ GblStringBuffer_append()

GBL_RESULT GblStringBuffer_append ( GblStringBuffer pSelf,
const char *  pStr,
size_t  len 
)
related

Appends pStr (with optional length, len) to the given GblStringBuffer, returning a result code.

◆ GblStringBuffer_appendPrintf()

GBL_RESULT GblStringBuffer_appendPrintf ( GblStringBuffer pSelf,
const char *  pFmt,
  ... 
)
related

Appends a printf()-style formatted string to the given GblStringBuffer, returning a result code.

◆ GblStringBuffer_appendVPrintf()

GBL_RESULT GblStringBuffer_appendVPrintf ( GblStringBuffer pSelf,
const char *  pFmt,
va_list  varArgs 
)
related

Equivalent to GblStringBuffer_appendPrintf(), except additional arguments are provided as a va_list.

◆ GblStringBuffer_appendPadding()

GBL_RESULT GblStringBuffer_appendPadding ( GblStringBuffer pSelf,
char  value,
size_t  count 
)
related

Adds count copies of value to the end of the given GblStringBuffer, returning a result code.

◆ GblStringBuffer_appendNil()

GBL_RESULT GblStringBuffer_appendNil ( GblStringBuffer pSelf)
related

Adds the word "nil" to the end of the given GblStringBuffer, returning a result code.

◆ GblStringBuffer_appendBool()

GBL_RESULT GblStringBuffer_appendBool ( GblStringBuffer pSelf,
GblBool  value 
)
related

Adds either "true" or "false" to the end of the given GblStringBuffer, depending on value, and returning a result code.

◆ GblStringBuffer_appendInt()

GBL_RESULT GblStringBuffer_appendInt ( GblStringBuffer pSelf,
int  value 
)
related

Adds the stringified representation of the integer, value, to the end of the given GblStringBuffer, returning a result code.

◆ GblStringBuffer_appendUint()

GBL_RESULT GblStringBuffer_appendUint ( GblStringBuffer pSelf,
unsigned  value 
)
related

Adds the stringified respresentation of the unsigned integer, value, to the end of the given GblStringBuffer, returning a result code.

◆ GblStringBuffer_appendFloat()

GBL_RESULT GblStringBuffer_appendFloat ( GblStringBuffer pSelf,
float  value 
)
related

Adds the stringified representation of the float, value, to the end of the given GblStringBuffer, returning a result code.

◆ GblStringBuffer_appendDouble()

GBL_RESULT GblStringBuffer_appendDouble ( GblStringBuffer pSelf,
double  value 
)
related

Adds the stringified representation of the double, value, to the end of the given GblStringBuffer, returning a result code.

◆ GblStringBuffer_appendPointer()

GBL_RESULT GblStringBuffer_appendPointer ( GblStringBuffer pSelf,
const void *  pPtr 
)
related

Adds the hexadecimal string representation of the pointer, pPtr, to the end of the given GblStringBuffer, returning a result code.

◆ GblStringBuffer_insert()

GBL_RESULT GblStringBuffer_insert ( GblStringBuffer pSelf,
size_t  index,
const char *  pString,
size_t  length 
)
related

Inserts pString at the given index with optional length, returning a result code.

◆ GblStringBuffer_overwrite()

GBL_RESULT GblStringBuffer_overwrite ( GblStringBuffer pSelf,
size_t  index,
const char *  pString,
size_t  length 
)
related

Ovewrites a prtion of the string starting at index, with pString (length is optional), resizing as needed, and returning a result code.

◆ GblStringBuffer_replace()

size_t GblStringBuffer_replace ( GblStringBuffer pSelf,
const char *  pSubstr,
const char *  pReplacement,
size_t  limit,
size_t  substrLen,
size_t  replLen 
)
related

Replaces limit instances (0 is infinite) of Substr with pReplacement, with both lenghts being optional, and returning a result code.

◆ GblStringBuffer_erase()

GBL_RESULT GblStringBuffer_erase ( GblStringBuffer pSelf,
size_t  offset,
size_t  len 
)
related

Erases the portion of the string from offset to offset + len, resizing it, and returning a result code.

◆ GblStringBuffer_clear()

GBL_RESULT GblStringBuffer_clear ( GblStringBuffer pSelf)
related

Clears the contents of the given GblStringBuffer, resetting it back to an empty state and returning a result code.

◆ GblStringBuffer_remove()

size_t GblStringBuffer_remove ( GblStringBuffer pSelf,
const char *  pStr,
size_t  len 
)
related

Removes all instances of pStr (len is optional) from the given buffer, returning the number of entries removed.

◆ GblStringBuffer_chop()

GBL_RESULT GblStringBuffer_chop ( GblStringBuffer pSelf)
related

Removes the last character from the given GblStringBuffer, returning a result code.

◆ GblStringBuffer_chomp()

GBL_RESULT GblStringBuffer_chomp ( GblStringBuffer pSelf)
related

Removes any trailing newline characters (\r and \n) from the given GblStringBuffer, returning a result code.

◆ GblStringBuffer_trimStart()

GBL_RESULT GblStringBuffer_trimStart ( GblStringBuffer pSelf,
char  value 
)
related

Removes any leading instances of value from the beginning of the given GblStringBuffer, returning a result code.

◆ GblStringBuffer_trimEnd()

GBL_RESULT GblStringBuffer_trimEnd ( GblStringBuffer pSelf,
char  value 
)
related

Returns any trailing instances of value from the end of the given GblStringBuffer, returning a result code.

◆ GblStringBuffer_lower()

GBL_RESULT GblStringBuffer_lower ( GblStringBuffer pSelf)
related

Changes the casing of every character within the GblStringBuffer to lowercase, returning a result code.

◆ GblStringBuffer_upper()

GBL_RESULT GblStringBuffer_upper ( GblStringBuffer pSelf)
related

Changes the casing of every character within the GblStringBuffer to uppercase, returning a result code.

◆ GblStringBuffer_reverse()

GBL_RESULT GblStringBuffer_reverse ( GblStringBuffer pSelf)
related

Reverses the order of the characters with the given GblStringBuffer, returninga result code.

◆ GblStringBuffer_reserve()

GBL_RESULT GblStringBuffer_reserve ( GblStringBuffer pSelf,
size_t  capacity 
)
related

Ensures that there is room for capacity characters within the given GblStringBuffer, returning a result code.

◆ GblStringBuffer_resize()

GBL_RESULT GblStringBuffer_resize ( GblStringBuffer pSelf,
size_t  size 
)
related

Sets the length of the given GblStringBuffer to size, regrowing if necessary, but not shrinking, and returning a result code.

◆ GblStringBuffer_grow()

GBL_RESULT GblStringBuffer_grow ( GblStringBuffer pSelf,
size_t  delta 
)
related

Resizes the length of the given GblStringBuffer to be its current length + delta, returning a result code.

◆ GblStringBuffer_shrink()

GBL_RESULT GblStringBuffer_shrink ( GblStringBuffer pSelf,
size_t  delta 
)
related

Resizes the length of the given GblStringBuffer to be its current length - delta, returning a result code.

◆ GblStringBuffer_shrinkToFit()

GBL_RESULT GblStringBuffer_shrinkToFit ( GblStringBuffer pSelf)
related

Shrinks the capacity of the given GblStringBuffer to match its length, if it doesn't already, returning a result code.

Field Documentation

◆ data

GblArrayList GblStringBuffer::data

Internal storage buffer.

Definition at line 66 of file gimbal_string_buffer.h.


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