Skip to content
Snippets Groups Projects
Commit 27f55277 authored by rswindell's avatar rswindell
Browse files

Added strListJoin() and strListIsEmpty() functions (for use in SBBSecho).

parent 8ef6b662
No related branches found
No related tags found
No related merge requests found
......@@ -61,6 +61,11 @@ size_t DLLCALL strListCount(const str_list_t list)
return(i);
}
BOOL DLLCALL strListIsEmpty(const str_list_t list)
{
return (list == NULL) || (list[0] == NULL);
}
int DLLCALL strListIndexOf(const str_list_t list, const char* str)
{
size_t i;
......@@ -614,6 +619,31 @@ size_t DLLCALL strListWriteFile(FILE* fp, const str_list_t list, const char* sep
return(i);
}
char* strListJoin(const str_list_t list, char* buf, size_t buflen, const char* separator)
{
size_t i;
if(buflen < 1)
return NULL;
*buf = '\0';
if(list == NULL)
return buf;
if(separator == NULL)
separator = ", ";
for(i = 0; list[i] != NULL; i++) {
if(strlen(buf) + strlen(separator) + strlen(list[i]) >= buflen)
break;
if(i > 0)
strcat(buf, separator);
strcat(buf, list[i]);
}
return buf;
}
size_t DLLCALL strListBlockLength(char* block)
{
char* p=block;
......
......@@ -71,7 +71,7 @@ DLLEXPORT char* DLLCALL strListAppend(str_list_t*, const char* str, size_t inde
DLLEXPORT size_t DLLCALL strListAppendList(str_list_t*, const str_list_t append_list);
/* Append a malloc'd formatted string to the end of the list */
DLLEXPORT char* DLLCALL strListAppendFormat(str_list_t* list, const char* format, ...);
DLLEXPORT char* DLLCALL strListAppendFormat(str_list_t* list, const char* format, ...);
/* Inserts a string into the list at a specific index */
/* Pass a pointer to a string list, the string to add (insert) */
......@@ -82,7 +82,7 @@ DLLEXPORT char* DLLCALL strListInsert(str_list_t*, const char* str, size_t inde
DLLEXPORT size_t DLLCALL strListInsertList(str_list_t*, const str_list_t append_list, size_t index);
/* Insert a malloc'd formatted string into the list */
DLLEXPORT char* DLLCALL strListInsertFormat(str_list_t* list, size_t index, const char* format, ...);
DLLEXPORT char* DLLCALL strListInsertFormat(str_list_t* list, size_t index, const char* format, ...);
/* Remove a string at a specific index */
DLLEXPORT char* DLLCALL strListRemove(str_list_t*, size_t index);
......@@ -93,6 +93,9 @@ DLLEXPORT BOOL DLLCALL strListDelete(str_list_t*, size_t index);
/* Replace a string at a specific index */
DLLEXPORT char* DLLCALL strListReplace(const str_list_t, size_t index, const char* str);
/* Return a single-string representation of the entire string list, joined with the specified separator */
DLLEXPORT char* DLLCALL strListJoin(const str_list_t, char* buf, size_t buflen, const char* separator);
/* Call a modification callback function for each string in a list */
/* and replace each string with the result of the modification callback. */
/* If the modification callback function returns NULL, the string is not modified. */
......@@ -127,6 +130,7 @@ DLLEXPORT char* DLLCALL strListCombine(str_list_t, char* buf, size_t maxlen, co
/* Count the number of strings in the list and returns the count */
DLLEXPORT size_t DLLCALL strListCount(const str_list_t);
DLLEXPORT BOOL DLLCALL strListIsEmpty(const str_list_t);
/* Returns the index of the specified str (by ptr compare) or -1 if not found */
DLLEXPORT int DLLCALL strListIndexOf(const str_list_t, const char* str);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment