From 9bea6ce0c5afd40b4c6dfd2b9d935dab4408e2eb Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Thu, 21 May 2020 17:17:25 -0400 Subject: Add strlist_remove() --- lib/strlist.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'lib/strlist.c') diff --git a/lib/strlist.c b/lib/strlist.c index 3de10dd..aac2755 100644 --- a/lib/strlist.c +++ b/lib/strlist.c @@ -82,6 +82,28 @@ void strlist_append_strlist(StrList *pStrList1, StrList *pStrList2) { } } +/** + * Remove a record by index from a `StrList` + * @param pStrList + * @param index + */ +void strlist_remove(StrList *pStrList, size_t index) { + size_t count = strlist_count(pStrList); + if (count == 0) { + return; + } + + for (size_t i = index; i < count; i++) { + char *next = pStrList->data[i + 1]; + pStrList->data[i] = next; + if (next == NULL) { + break; + } + } + + pStrList->num_inuse--; +} + /** * Compare two `StrList`s * @param a `StrList` structure -- cgit