SELKIELogger
1.0.0
|
Classes | |
struct | string |
Simple string type. More... | |
struct | strarray |
Array of strings. More... | |
Functions | |
strarray * | sa_new (int entries) |
Allocate storage for a new array. More... | |
bool | sa_init (strarray *dst, const int entries) |
Initialise an already allocated array. More... | |
bool | sa_copy (strarray *dst, const strarray *src) |
Copy an array of strings from src to dst. More... | |
bool | sa_move (strarray *dst, strarray *src) |
Move strings from one array to another. More... | |
bool | sa_set_entry (strarray *array, const int index, string *str) |
Copy a string to a given position in the array. More... | |
bool | sa_create_entry (strarray *array, const int index, const size_t len, const char *src) |
Create an string in a given position from a character array and length. More... | |
void | sa_clear_entry (strarray *array, const int index) |
Clear an array entry. More... | |
void | sa_destroy (strarray *sa) |
Destroy array and contents. More... | |
string * | str_new (const size_t len, const char *ca) |
Create new string from character array. More... | |
bool | str_copy (string *dst, const string *src) |
Update an existing string by copying the contents from another. More... | |
string * | str_duplicate (const string *src) |
Allocate a new string containing the contents of another. More... | |
bool | str_update (string *str, const size_t len, const char *src) |
Update an existing string from a character array of given length. More... | |
void | str_destroy (string *str) |
Destroy a string and free its contents. More... | |
void sa_clear_entry | ( | strarray * | array, |
const int | index | ||
) |
Clear an array entry.
Hands off to str_destroy() if the specified index is within the array, and noops if the array is invalid or index is out of bounds
[in] | array | Pointer to array being modified |
[in] | index | Position in array to clear |
Definition at line 163 of file strarray.c.
Copy an array of strings from src to dst.
Destroys the existing contents of the destination array, which cannot be restored in the event of an error, and then creates new strings to match the contents of the source array.
[out] | dst | Pointer to destination array (all existing data will be lost) |
[in] | src | Pointer to source array |
Definition at line 76 of file strarray.c.
bool sa_create_entry | ( | strarray * | array, |
const int | index, | ||
const size_t | len, | ||
const char * | src | ||
) |
Create an string in a given position from a character array and length.
Checks that the array is valid and the index is within bounds, then hands off to str_update() to copy in the new string data.
[in] | array | Pointer to array being modified |
[in] | index | Position in array to modify |
[in] | len | Length of character array |
[in] | src | Character array to be copied into array |
Definition at line 149 of file strarray.c.
void sa_destroy | ( | strarray * | sa | ) |
Destroy array and contents.
Iterates over all array entries and calls str_destroy() for each string before freeing the array's internal storage.
Internal pointer is nulled and number of entries set to zero, so there should be no side effects if called repeatedly on an array, if that should happen for some reason. Don't do it deliberately just to check.
Caller is responsible for freeing the array itself, if required.
[in] | sa | Pointer to array to be destroyed. |
Definition at line 182 of file strarray.c.
bool sa_init | ( | strarray * | dst, |
const int | entries | ||
) |
Initialise an already allocated array.
Take an array and initialise internal storage for the stated number of entries.
Will destroy existing contents
[in] | dst | Pointer to array |
[in] | entries | Number of strings to allocate |
Definition at line 59 of file strarray.c.
Move strings from one array to another.
Moves strings from one array to anther by copying the internal pointer of the source array to the internal pointer of the destination. No additional memory allocations are made.
The source array is invalidated and the internal pointer nulled so that it can be destroyed without affecting the destination array.
[out] | dst | Pointer to destination array (all existing data will be lost) |
[in] | src | Pointer to source array (will be emptied) |
Definition at line 112 of file strarray.c.
strarray* sa_new | ( | int | entries | ) |
Allocate storage for a new array.
Allocate a new string array and initialise with sa_init()
All allocated data is zeroed.
Must be destroyed with sa_destroy() before being freed.
[in] | entries | Number of entries in array |
Definition at line 37 of file strarray.c.
Copy a string to a given position in the array.
str_copy() does the heavy lifting, with this function performing bounds checks on the string array itself.
[in] | array | Pointer to array being modified |
[in] | index | Position in array to modify |
[in] | str | String to be copied into array |
Definition at line 131 of file strarray.c.
Update an existing string by copying the contents from another.
Allocates memory and copies the string from src.
No explicit null termination checks, but the source string declared length is used as an upper bound. Uses strncpy() internally, so should be safe enough.
[out] | dst | Pointer to destination string (Existing data will be destroyed) |
[in] | src | Pointer to source string. |
Definition at line 253 of file strarray.c.
void str_destroy | ( | string * | str | ) |
Destroy a string and free its contents.
Frees the internal storage and sets length to zero
Caller is responsible for freeing string itself, if required.
[in] | str | Pointer to string to be destroyed |
Definition at line 323 of file strarray.c.
Allocate a new string containing the contents of another.
Wrapper around str_new(), passing it the length and internal character array of the source string.
[in] | src | Pointer to source string |
Definition at line 281 of file strarray.c.
string* str_new | ( | const size_t | len, |
const char * | ca | ||
) |
Create new string from character array.
Allocates a new string structure and copies in the character array.
If last character of ca is not null then an extra byte is allocated and zeroed. The declared length represents an upper bound on the string length - the copy will stop at the first null byte found (strncpy() used internally)
[in] | len | Maximum length of character array to be copied |
[in] | ca | Pointer to character array |
Definition at line 217 of file strarray.c.
bool str_update | ( | string * | str, |
const size_t | len, | ||
const char * | src | ||
) |
Update an existing string from a character array of given length.
Destroys the string, then allocates new memory and copies the array using strncpy() as described for str_new()
[out] | str | Pointer to destination string |
[in] | len | Maximum length of new character array to copy in |
[in] | src | Pointer to source character array |
Definition at line 294 of file strarray.c.