47 string *exA =
str_new(20,
"Testing String Lib.");
50 fprintf(stderr,
"Failed to create example string A\n");
58 fprintf(stderr,
"Failed to create example string B\n");
66 fprintf(stderr,
"Failed to create example string C\n");
74 fprintf(stderr,
"Failed to create example string D\n");
80 fprintf(stderr,
"Failed to copy example string A into example string E\n");
88 fprintf(stderr,
"Failed to create example string E\n");
93 if (!
str_update(exE, 50,
"This is an updated test message for the Example E")) {
95 fprintf(stderr,
"Failed to update string\n");
103 fprintf(stderr,
"Failed to allocate string array\n");
110 fprintf(stderr,
"Failed to set SA entry 0\n");
117 fprintf(stderr,
"Failed to set SA entry 1\n");
124 fprintf(stderr,
"Failed to set SA entry 2\n");
131 fprintf(stderr,
"Failed to set SA entry 3\n");
138 fprintf(stderr,
"Failed to set SA entry 4\n");
143 if (!
sa_create_entry(SA, 5, 35,
"Creating string in place on array\n")) {
145 fprintf(stderr,
"Failed to set SA entry 5\n");
153 fprintf(stderr,
"Failed to clear SA entry 3\n");
172 fprintf(stderr,
"Unable to move string array contents\n");
186 fprintf(stdout,
"All tests succeeded\n");
void sa_destroy(strarray *sa)
Destroy array and contents.
bool str_copy(string *dst, const string *src)
Update an existing string by copying the contents from another.
bool sa_move(strarray *dst, strarray *src)
Move strings from one array to another.
bool str_update(string *str, const size_t len, const char *src)
Update an existing string from a character array of given length.
bool sa_set_entry(strarray *array, const int index, string *str)
Copy a string to a given position in the array.
string * str_duplicate(const string *src)
Allocate a new string containing the contents of another.
string * str_new(const size_t len, const char *ca)
Create new string from character array.
void str_destroy(string *str)
Destroy a string and free its contents.
strarray * sa_new(int entries)
Allocate storage for a new array.
void sa_clear_entry(strarray *array, const int index)
Clear an array entry.
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.
int entries
Maximum number of strings in array, set when calling sa_new()
string * strings
Simple array of string structures.
char * data
Character array, should be null terminated.