Commit 2a120865 authored by rswindell's avatar rswindell
Browse files

New strList functions (for truncating strings in a list):

- strListTruncateStrings()
- strListTruncateTrailingWhitespaces()
- strListTruncateTrailingLineEndings()
parent a3554a8f
......@@ -631,3 +631,47 @@ void DLLCALL strListFreeBlock(char* block)
if(block!=NULL)
free(block); /* this must be done here for Windows-DLL reasons */
}
int DLLCALL strListTruncateTrailingWhitespaces(str_list_t list)
{
size_t i;
if(list==NULL)
return(0);
for(i=0; list[i]!=NULL; i++) {
truncsp(list[i]);
}
return i;
}
int DLLCALL strListTruncateTrailingLineEndings(str_list_t list)
{
size_t i;
if(list==NULL)
return(0);
for(i=0; list[i]!=NULL; i++) {
truncnl(list[i]);
}
return i;
}
/* Truncate strings in list at first occurrence of any char in 'set' */
int DLLCALL strListTruncateStrings(str_list_t list, const char* set)
{
size_t i;
char* p;
if(list==NULL)
return(0);
for(i=0; list[i]!=NULL; i++) {
p=strpbrk(list[i], set);
if(p!=NULL && *p!=0)
*p=0;
}
return i;
}
......@@ -60,7 +60,10 @@ DLLEXPORT void DLLCALL strListFree(str_list_t*);
/* Frees the strings in the list */
DLLEXPORT void DLLCALL strListFreeStrings(str_list_t);
/* Adds a string to the end of a string list (see strListPush) */
/* Pass a pointer to a string list, the string to add (append) */
/* The string to add is duplicated (using strdup) and the duplicate is added to the list */
/* If you already know the index of the last string, pass it, otherwise pass STR_LIST_LAST_INDEX */
/* Returns the updated list or NULL on error */
DLLEXPORT char* DLLCALL strListAppend(str_list_t*, const char* str, size_t index);
......@@ -68,6 +71,8 @@ DLLEXPORT char* DLLCALL strListAppend(str_list_t*, const char* str, size_t inde
DLLEXPORT size_t DLLCALL strListAppendList(str_list_t*, const str_list_t append_list);
/* Inserts a string into the list at a specific index */
/* Pass a pointer to a string list, the string to add (insert) */
/* The string to add is duplicated (using strdup) and the duplicate is added to the list */
DLLEXPORT char* DLLCALL strListInsert(str_list_t*, const char* str, size_t index);
/* Insert a string list into another string list */
......@@ -134,11 +139,17 @@ DLLEXPORT str_list_t DLLCALL strListDup(str_list_t list);
/* Compares two lists */
DLLEXPORT int DLLCALL strListCmp(str_list_t list1, str_list_t list2);
/* Modifies strings in list (returns count of items in list) */
DLLEXPORT int DLLCALL strListTruncateTrailingWhitespaces(str_list_t);
DLLEXPORT int DLLCALL strListTruncateTrailingLineEndings(str_list_t);
/* Truncate strings in list at first occurrence of any char in 'set' */
DLLEXPORT int DLLCALL strListTruncateStrings(str_list_t, const char* set);
/************/
/* File I/O */
/************/
/* Read lines from file appending each line to string list */
/* Read lines from file appending each line (with '\n' char) to string list */
/* Pass NULL list to have list allocated for you */
DLLEXPORT str_list_t DLLCALL strListReadFile(FILE*, str_list_t*, size_t max_line_len);
DLLEXPORT size_t DLLCALL strListInsertFile(FILE*, str_list_t*, size_t index, size_t max_line_len);
......
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