dynamic_string.h v0.2.2
A modern, efficient, single-file string library for C
Loading...
Searching...
No Matches
Functions
Core String Functions

Basic string creation, retention, and release functions. More...

Functions

DS_DEF ds_string ds_new (const char *text)
 Create a new string from a C string.
 
DS_DEF ds_string ds_create_length (const char *text, size_t length)
 Create a string from a buffer with explicit length.
 
DS_DEF ds_string ds_retain (ds_string str)
 Increment reference count and return shared handle.
 
DS_DEF void ds_release (ds_string *str)
 Decrement reference count and free memory if last reference.
 

Detailed Description

Basic string creation, retention, and release functions.

Function Documentation

◆ ds_create_length()

DS_DEF ds_string ds_create_length ( const char *  text,
size_t  length 
)

Create a string from a buffer with explicit length.

Parameters
textSource buffer (may contain embedded nulls)
lengthNumber of bytes to copy from buffer
Returns
New ds_string instance, or NULL on failure

◆ ds_new()

DS_DEF ds_string ds_new ( const char *  text)

Create a new string from a C string.

Parameters
textNull-terminated C string to copy (must not be NULL)
Returns
New ds_string instance, or NULL on failure
Since
0.0.1
ds_string greeting = ds_new("Hello World");
printf("%s\n", greeting); // Direct usage with C functions
ds_release(&greeting);
char * ds_string
String handle - points directly to null-terminated string data.
Definition dynamic_string.h:125
DS_DEF ds_string ds_new(const char *text)
Create a new string from a C string.
DS_DEF void ds_release(ds_string *str)
Decrement reference count and free memory if last reference.
See also
ds_create_length() for creating strings with explicit length
ds_release() for memory cleanup

◆ ds_release()

DS_DEF void ds_release ( ds_string str)

Decrement reference count and free memory if last reference.

Parameters
strPointer to string handle to release (may be NULL)

◆ ds_retain()

DS_DEF ds_string ds_retain ( ds_string  str)

Increment reference count and return shared handle.

Parameters
strString to retain (must not be NULL)
Returns
New handle to the same string data