Commit 4b2c80c2 authored by rswindell's avatar rswindell
Browse files

Created strListSplit() and strListSplitCopy().

parent a2fed57c
......@@ -49,7 +49,7 @@ str_list_t strListAlloc()
return(list);
}
size_t strListCount(str_list_t list)
size_t strListCount(const str_list_t list)
{
size_t i;
......@@ -62,7 +62,7 @@ size_t strListCount(str_list_t list)
return(i);
}
str_list_t strListAddAt(str_list_t* list, char* str, size_t count)
str_list_t strListAddAt(str_list_t* list, const char* str, size_t count)
{
str_list_t lp;
......@@ -80,11 +80,42 @@ str_list_t strListAddAt(str_list_t* list, char* str, size_t count)
}
str_list_t strListAdd(str_list_t* list, char* str)
str_list_t strListAdd(str_list_t* list, const char* str)
{
return strListAddAt(list,str,strListCount(*list));
}
str_list_t strListSplit(str_list_t* list, char* str, const char* delimit)
{
char* token;
if(list==NULL) {
if((*list = strListAlloc())==NULL)
return(NULL);
}
for(token = strtok(str, delimit); token!=NULL; token=strtok(NULL, delimit))
strListAdd(list, token);
return(*list);
}
str_list_t strListSplitCopy(str_list_t* list, const char* str, const char* delimit)
{
char* buf;
if((buf=malloc(strlen(str)+1))==NULL)
return(NULL);
strcpy(buf,str);
*list = strListSplit(list,buf,delimit);
free(buf);
return(*list);
}
static int strListCompareAlpha(const void *arg1, const void *arg2)
{
return stricmp(*(char**)arg1, *(char**)arg2);
......
......@@ -54,13 +54,20 @@ void strListFree(str_list_t* list);
/* Pass a pointer to a string list, the string to add */
/* Returns the updated list or NULL on error */
str_list_t strListAdd(str_list_t* list, char* str);
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, char* str, size_t index);
str_list_t strListAddAt(str_list_t* list, const char* str, 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);
/* Same as above, but copies str to temporary heap buffer first */
str_list_t strListSplitCopy(str_list_t* list, const char* str, const char* delimit);
/* Count the number of strings in the list and returns the count */
size_t strListCount(str_list_t list);
size_t strListCount(const str_list_t list);
void strListSortAlpha(str_list_t list);
void strListSortAlphaReverse(str_list_t list);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment