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

Fixed the strListInsert() routines.

Added strListRemove() , to remove a single string from a string list.
parent 2b2762b8
Branches
Tags
No related merge requests found
......@@ -85,17 +85,43 @@ static str_list_t str_list_insert(str_list_t* list, char* str, size_t index)
str_list_t lp;
count = strListCount(*list);
if(index > count) /* invalid index, do nothing */
return(NULL);
count++;
if((lp=(str_list_t)realloc(*list,sizeof(char*)*(count+1)))==NULL)
return(NULL);
*list=lp;
for(i=index;i<=count;i++)
lp[i+1]=lp[i];
for(i=count; i>index; i--)
lp[i]=lp[i-1];
lp[index]=str;
return(lp);
}
str_list_t strListRemove(str_list_t* list, size_t index)
{
size_t i;
size_t count;
str_list_t lp;
count = strListCount(*list);
if(index >= count) /* invalid index, do nothing */
return(NULL);
count--;
if((lp=(str_list_t)realloc(*list,sizeof(char*)*(count+1)))==NULL)
return(NULL);
*list=lp;
for(i=index; i<count; i++)
lp[i]=lp[i+1];
lp[count]=NULL;
return(lp);
}
str_list_t strListAddAt(str_list_t* list, const char* str, size_t count)
{
char* buf;
......
......@@ -55,22 +55,25 @@ void strListFree(str_list_t* list);
/* Frees the strings in the list */
void strListFreeStrings(str_list_t list);
/* Pass a pointer to a string list, the string to add */
/* Pass a pointer to a string list, the string to add (append) */
/* Returns the updated list or NULL on error */
str_list_t strListAdd(str_list_t* list, const char* str);
/* Adds a string into the list at a specific index */
str_list_t strListAddAt(str_list_t* list, const char* str, size_t index);
/* Append a string list onto an another string list */
/* Append a string list onto another string list */
str_list_t strListAddList(str_list_t* list, const str_list_t append_list);
/* Inserts a string into the list at a specific index */
str_list_t strListInsert(str_list_t* list, const char* str, size_t index);
/* Insert a string list onto an another string list */
/* Insert a string list into another string list */
str_list_t strListInsertList(str_list_t* list, const str_list_t append_list, size_t index);
/* Remove a string at a specific index */
str_list_t strListRemove(str_list_t* list, size_t index);
/* Add to an exiting or new string list by splitting specified string (str) */
/* into multiple strings, separated by one of the delimit characters */
str_list_t strListSplit(str_list_t* list, char* str, const char* delimit);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment