Some simple string allocation and handling functions.
This module contains functions for object-oriented handling of const char* strings in C. Strings can be either zero-terminated or have some fixed length. The contents of the string cannot be (easily) changed.
MX_STRING is bit-copy-correct which means that a binary copy retains proper functioning and takes over ownership of internal buffers. The copy source MX_STRING should not be used once the copy takes place.
Memory containing a MX_STRING can be realloc'd without affecting proper operation. Therefore it can be used inside a MX_VECTOR. (../include/deds/string.h)
Part of the deds library.
MX_STRING
A string object
void mx_string_realloc(MX_STRING* string, const MX_ALLOC alloc, const MX_FREE dfree)
Reallocate a MX_STRING
This function changes the memory allocation of the text inside a MX_STRING to the ones in the argumnets. Memory is allocated using the alloc function and the current contents of the string is copied to the newly allocated memory. The free function will be called when the memory associated with the text needs to be freed. (../include/deds/string/realloc.c)
void mx_string_set(MX_STRING* string, const char* text, int len, const MX_FREE dfree)
Set MX_STRING text and length
This function sets the text, length and free function of a MX_STRING object. When mx_string_free() is called the free function will be called to release the memory associated with the text. The free parameter may be 0 in which case no function will be called to release the text memory. (../include/deds/string/set.c)
If the len parameter is less than 0 (usually -1) then the string is assumed to be zero terminated. (../include/deds/string/set.c)
void mx_string(MX_STRING* string)
Construct a MX_STRING
This function initializes a MX_STRING object. It writes the memory full with 0 values. (../include/deds/string/string.c)
Since a MX_STRING filled with 0 is correctly constructed then static instances dont necessarily have to be constructed before use. (../include/deds/string/string.c)
void mx_string_free(MX_STRING* string)
Destruct a MX_STRING
This function frees a MX_STRING object. If the associated free will be called to release any internal memory. (../include/deds/string/string.c)
const char* mx_string_text(const MX_STRING* string, int* len)
Get MX_STRING text and length
This function return the text of the string along with the length of the text segment. (../include/deds/string/text.c)
The len argument can be 0 in which case the length is not returned. (../include/deds/string/text.c)
int mx_string_len(const MX_STRING* string)
Get MX_STRING length
This function return the length of the text segment. (../include/deds/string/text.c)
Generated by MXDOC 2.2 on Sun Feb 4 15:16:26 2007