From cc34d91857263de4c04dd2fd45587621099b3ca6 Mon Sep 17 00:00:00 2001 From: rswindell <> Date: Thu, 27 May 2004 21:02:59 +0000 Subject: [PATCH] Fixed the strListInsert() routines. Added strListRemove() , to remove a single string from a string list. --- src/xpdev/str_list.c | 30 ++++++++++++++++++++++++++++-- src/xpdev/str_list.h | 9 ++++++--- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/xpdev/str_list.c b/src/xpdev/str_list.c index 454a2090f8..5bea0281ab 100644 --- a/src/xpdev/str_list.c +++ b/src/xpdev/str_list.c @@ -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; diff --git a/src/xpdev/str_list.h b/src/xpdev/str_list.h index d1d1f208d4..795a7bded2 100644 --- a/src/xpdev/str_list.h +++ b/src/xpdev/str_list.h @@ -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); -- GitLab