C Collections

cstring · Section 3

cstring_c_str

cstring_c_str - return a pointer to the null-terminated character data

C Collections (libccollections, -lccollections)

#include <ccollections/cstring.h>
 
const char *cstring_c_str(cstr s);

Returns a read-only pointer to the internal null-terminated buffer.
The pointer becomes invalid after any operation that changes the
string and may reallocate the buffer; NOTES gives the exact list.
 
Use this function to pass a cstr to chashmap or cbstmap.  Those
containers understand char * keys, which they hash and compare by
content, but they have no special handling for the cstr type, so take
the C string out first and pass that as the key:
 
    char *k = (char *)cstring_c_str(my_cstr);
    chmap_insert(map, k, value);
 
The map copies the content of the string into its own storage at
once, so you can change or destroy the cstr afterwards and the map
entry stays as it is.

s   String to query

A pointer to the null-terminated character data

Any call that may reallocate makes the pointer invalid: Append, prepend,
insert, set, replace, reserve and reset
Asserts if s is NULL

cstring_length(3), cstring_at(3)