Commit 6697291f authored by rswindell's avatar rswindell
Browse files

Add strListDedupe().

parent 233aabc8
......@@ -81,7 +81,7 @@ int strListIndexOf(const str_list_t list, const char* str)
return -1;
}
int strListFind(const str_list_t list, const char* str, BOOL case_sensistive)
int strListFind(const str_list_t list, const char* str, BOOL case_sensitive)
{
size_t i;
......@@ -89,7 +89,7 @@ int strListFind(const str_list_t list, const char* str, BOOL case_sensistive)
return -1;
for(i=0; list[i]!=NULL; i++) {
if(case_sensistive) {
if(case_sensitive) {
if(strcmp(list[i],str) == 0)
return i;
} else {
......@@ -798,3 +798,21 @@ int strListStripStrings(str_list_t list, const char* set)
}
return i;
}
/* Remove duplicate strings from list, return the new list length */
int strListDedupe(str_list_t* list, BOOL case_sensitive)
{
size_t i,j;
if(list == NULL || *list == NULL)
return 0;
for(i = 0; (*list)[i] != NULL; i++) {
for(j = i + 1; (*list)[j] != NULL; j++) {
if((case_sensitive && strcmp((*list)[i], (*list)[j]) == 0)
|| (!case_sensitive && stricmp((*list)[i], (*list)[j]) == 0))
strListDelete(list, j);
}
}
return i;
}
......@@ -166,6 +166,8 @@ DLLEXPORT int strListTruncateTrailingLineEndings(str_list_t);
DLLEXPORT int strListTruncateStrings(str_list_t, const char* set);
/* Remove all occurrences of chars in set from string in list */
DLLEXPORT int strListStripStrings(str_list_t, const char* set);
/* Remove duplicate strings from list, return the new list length */
DLLEXPORT int strListDedupe(str_list_t*, BOOL case_sensitive);
/************/
/* File I/O */
......
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