Skip to content
Snippets Groups Projects
Commit af97cb67 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Added non-realloc (read-only/fast) versions of Delete and Remove

Added both "Fast" and reallocing variants of DeleteBlanks() functions that remove all the blank strings from a string list.
parent 25f668a0
No related branches found
No related tags found
1 merge request!123New file base
...@@ -151,6 +151,28 @@ char* strListRemove(str_list_t* list, size_t index) ...@@ -151,6 +151,28 @@ char* strListRemove(str_list_t* list, size_t index)
return(str); return(str);
} }
// Remove without realloc
char* strListFastRemove(str_list_t list, size_t index)
{
char* str;
size_t i;
size_t count;
count = strListCount(list);
if(index == STR_LIST_LAST_INDEX && count)
index = count-1;
if(index >= count) /* invalid index, do nothing */
return NULL;
str = list[index];
for(i = index; i < count; i++)
list[i] = list[i + 1];
return str;
}
BOOL strListDelete(str_list_t* list, size_t index) BOOL strListDelete(str_list_t* list, size_t index)
{ {
char* str; char* str;
...@@ -163,6 +185,18 @@ BOOL strListDelete(str_list_t* list, size_t index) ...@@ -163,6 +185,18 @@ BOOL strListDelete(str_list_t* list, size_t index)
return(TRUE); return(TRUE);
} }
BOOL strListFastDelete(str_list_t list, size_t index)
{
char* str;
if((str=strListFastRemove(list, index))==NULL)
return(FALSE);
free(str);
return(TRUE);
}
char* strListReplace(const str_list_t list, size_t index, const char* str) char* strListReplace(const str_list_t list, size_t index, const char* str)
{ {
char* buf; char* buf;
...@@ -802,3 +836,35 @@ int strListDedupe(str_list_t* list, BOOL case_sensitive) ...@@ -802,3 +836,35 @@ int strListDedupe(str_list_t* list, BOOL case_sensitive)
} }
return i; return i;
} }
int strListDeleteBlanks(str_list_t* list)
{
size_t i;
if(list == NULL || *list == NULL)
return 0;
for(i = 0; (*list)[i] != NULL; ) {
if((*list)[i][0] == '\0')
strListDelete(list, i);
else
i++;
}
return i;
}
int strListFastDeleteBlanks(str_list_t list)
{
size_t i;
if(list == NULL || *list == NULL)
return 0;
for(i = 0; list[i] != NULL; ) {
if(list[i][0] == '\0')
strListFastDelete(list, i);
else
i++;
}
return i;
}
...@@ -70,9 +70,11 @@ DLLEXPORT char* strListInsertFormat(str_list_t* list, size_t index, const char ...@@ -70,9 +70,11 @@ DLLEXPORT char* strListInsertFormat(str_list_t* list, size_t index, const char
/* Remove a string at a specific index */ /* Remove a string at a specific index */
DLLEXPORT char* strListRemove(str_list_t*, size_t index); DLLEXPORT char* strListRemove(str_list_t*, size_t index);
DLLEXPORT char* strListFastRemove(str_list_t, size_t index);
/* Remove and free a string at a specific index */ /* Remove and free a string at a specific index */
DLLEXPORT BOOL strListDelete(str_list_t*, size_t index); DLLEXPORT BOOL strListDelete(str_list_t*, size_t index);
DLLEXPORT BOOL strListFastDelete(str_list_t, size_t index);
/* Replace a string at a specific index */ /* Replace a string at a specific index */
DLLEXPORT char* strListReplace(const str_list_t, size_t index, const char* str); DLLEXPORT char* strListReplace(const str_list_t, size_t index, const char* str);
...@@ -152,6 +154,9 @@ DLLEXPORT int strListTruncateStrings(str_list_t, const char* set); ...@@ -152,6 +154,9 @@ DLLEXPORT int strListTruncateStrings(str_list_t, const char* set);
DLLEXPORT int strListStripStrings(str_list_t, const char* set); DLLEXPORT int strListStripStrings(str_list_t, const char* set);
/* Remove duplicate strings from list, return the new list length */ /* Remove duplicate strings from list, return the new list length */
DLLEXPORT int strListDedupe(str_list_t*, BOOL case_sensitive); DLLEXPORT int strListDedupe(str_list_t*, BOOL case_sensitive);
/* Remove blank strings from list, return the new list length */
DLLEXPORT int strListDeleteBlanks(str_list_t*);
DLLEXPORT int strListFastDeleteBlanks(str_list_t);
/************/ /************/
/* File I/O */ /* File I/O */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment