cstring · Section 3
cstring_c_str
NAME
cstring_c_str - return a pointer to the null-terminated character data
LIBRARY
C Collections (libccollections, -lccollections)
SYNOPSIS
#include <ccollections/cstring.h> const char *cstring_c_str(cstr s);
DESCRIPTION
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.
PARAMETERS
s String to query
RETURN VALUE
A pointer to the null-terminated character data
NOTES
Any call that may reallocate makes the pointer invalid: Append, prepend, insert, set, replace, reserve and reset Asserts if s is NULL