diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-05-21 17:17:25 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-05-21 17:17:25 -0400 |
commit | 9bea6ce0c5afd40b4c6dfd2b9d935dab4408e2eb (patch) | |
tree | 33128738346bdb2c44a72b42191b61a8b55aa4a1 | |
parent | 3b323fcc82d3d06d671c55c2b77f74558706420e (diff) | |
download | spmc-9bea6ce0c5afd40b4c6dfd2b9d935dab4408e2eb.tar.gz |
Add strlist_remove()
-rw-r--r-- | include/strlist.h | 1 | ||||
-rw-r--r-- | lib/strlist.c | 22 |
2 files changed, 23 insertions, 0 deletions
diff --git a/include/strlist.h b/include/strlist.h index e236473..76b6d5f 100644 --- a/include/strlist.h +++ b/include/strlist.h @@ -12,6 +12,7 @@ typedef struct { } StrList; StrList *strlist_init(); +void strlist_remove(StrList *pStrList, size_t index); long double strlist_item_as_long_double(StrList *pStrList, size_t index); double strlist_item_as_double(StrList *pStrList, size_t index); float strlist_item_as_float(StrList *pStrList, size_t index); diff --git a/lib/strlist.c b/lib/strlist.c index 3de10dd..aac2755 100644 --- a/lib/strlist.c +++ b/lib/strlist.c @@ -83,6 +83,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 * @param b `StrList` structure |