39 if (newarray == NULL) {
return NULL; }
40 if (!
sa_init(newarray, entries)) {
62 dst->
strings = calloc(entries,
sizeof(
string));
63 if (dst->
strings == NULL) {
return false; }
77 if (dst == NULL || src == NULL) {
return false; }
88 for (
int ix = 0; ix < dst->
entries; ix++) {
113 if (dst == NULL || src == NULL) {
return false; }
132 if (array == NULL) {
return false; }
134 if (index >= array->
entries) {
return false; }
150 if (array == NULL) {
return false; }
151 if (index >= array->
entries) {
return false; }
164 if (array == NULL) {
return; }
165 if (index >= array->
entries) {
return; }
183 if (sa == NULL) {
return; }
198 for (
int ix = 0; ix < sa->
entries; ix++) {
217 string *
str_new(
const size_t len,
const char *ca) {
218 string *ns = calloc(1,
sizeof(
string));
219 if (ns == NULL) {
return NULL; }
229 if (ca[len - 1] != 0) { alen++; }
230 ns->
data = malloc(alen);
231 if (ns->
data == NULL) {
238 strncpy(ns->
data, ca, len);
239 ns->
data[alen - 1] = 0;
257 if (dst->
data == NULL) {
263 if (src->
data == NULL) {
294 bool str_update(
string *str,
const size_t len,
const char *src) {
296 if (len == 0 || src == NULL) {
301 size_t checklen = strnlen(src, len);
302 str->
length = checklen + 1;
304 if (str->
data == NULL) {
310 strncpy(str->
data, src, checklen);
324 if (str == NULL) {
return; }
void sa_destroy(strarray *sa)
Destroy array and contents.
bool sa_copy(strarray *dst, const strarray *src)
Copy an array of strings from src to dst.
bool str_copy(string *dst, const string *src)
Update an existing string by copying the contents from another.
bool sa_init(strarray *dst, const int entries)
Initialise an already allocated array.
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.
size_t length
This should include a terminating null byte where possible.