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

New convenience functions: strListInsertFormat and strListAppendFormat

these are printf-style functions for inserting or appending a string into a
string list.
parent c6272c0b
No related branches found
No related tags found
No related merge requests found
......@@ -39,6 +39,7 @@
#include <string.h> /* strtok */
#include "genwrap.h" /* stricmp */
#include "str_list.h"
#include "xpprintf.h"
str_list_t DLLCALL strListInit(void)
{
......@@ -269,6 +270,26 @@ size_t DLLCALL strListAppendList(str_list_t* list, const str_list_t add_list)
return(count);
}
char* DLLCALL strListAppendFormat(str_list_t* list, const char* format, ...)
{
char *ret;
char* buf = NULL;
int len;
va_list va;
va_start(va, format);
len = vasprintf(&buf, format, va);
va_end(va);
if(len == -1 || buf == NULL)
return NULL;
ret = str_list_append(list, buf, strListCount(*list));
if (ret == NULL)
free(buf);
return ret;
}
char* DLLCALL strListInsert(str_list_t* list, const char* str, size_t index)
{
char* buf;
......@@ -297,6 +318,26 @@ size_t DLLCALL strListInsertList(str_list_t* list, const str_list_t add_list, si
return(i);
}
char* DLLCALL strListInsertFormat(str_list_t* list, size_t index, const char* format, ...)
{
char *ret;
char* buf = NULL;
int len;
va_list va;
va_start(va, format);
len = vasprintf(&buf, format, va);
va_end(va);
if(len == -1 || buf == NULL)
return NULL;
ret = str_list_insert(list, buf, index);
if (ret == NULL)
free(buf);
return ret;
}
str_list_t DLLCALL strListSplit(str_list_t* lp, char* str, const char* delimit)
{
size_t count;
......
......@@ -70,6 +70,9 @@ DLLEXPORT char* DLLCALL strListAppend(str_list_t*, const char* str, size_t inde
/* Append a string list onto another string list */
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, ...);
/* Inserts a string into the list at a specific index */
/* Pass a pointer to a string list, the string to add (insert) */
/* The string to add is duplicated (using strdup) and the duplicate is added to the list */
......@@ -78,6 +81,9 @@ DLLEXPORT char* DLLCALL strListInsert(str_list_t*, const char* str, size_t inde
/* Insert a string list into another string list */
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, ...);
/* Remove a string at a specific index */
DLLEXPORT char* DLLCALL strListRemove(str_list_t*, size_t index);
......
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