aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2020-02-04 11:50:49 -0500
committerJoseph Hunkeler <jhunkeler@gmail.com>2020-02-04 15:29:29 -0500
commit7cb43a7996afa4a2a2578f1ce3302866bb79f55b (patch)
treece3cc3be77fef5a34763a062ca5b776bee87f890
parentabc714e9a5dc047e768562e207b95a4991c27516 (diff)
downloadspmc-7cb43a7996afa4a2a2578f1ce3302866bb79f55b.tar.gz
Initial commit of strlist.[c,h]
-rw-r--r--include/strlist.h4
-rw-r--r--src/strlist.c24
2 files changed, 25 insertions, 3 deletions
diff --git a/include/strlist.h b/include/strlist.h
index 285880a..4cf76c6 100644
--- a/include/strlist.h
+++ b/include/strlist.h
@@ -31,12 +31,10 @@ unsigned char strlist_item_as_uchar(StrList *pStrList, size_t index);
char strlist_item_as_char(StrList *pStrList, size_t index);
char *strlist_item_as_str(StrList *pStrList, size_t index);
char *strlist_item(StrList *pStrList, size_t index);
+void strlist_set(StrList *pStrList, size_t index, char *value);
size_t strlist_count(StrList *pStrList);
void strlist_reverse(StrList *pStrList);
void strlist_sort(StrList *pStrList, unsigned int mode);
-static int _strlist_dsc_cmpfn(const void *a, const void *b);
-static int _strlist_asc_cmpfn(const void *a, const void *b);
-static int _strlist_cmpfn(const void *a, const void *b);
void strlist_append_strlist(StrList *pStrList1, StrList *pStrList2);
void strlist_append(StrList *pStrList, char *str);
void strlist_free(StrList *pStrList);
diff --git a/src/strlist.c b/src/strlist.c
index ccd1925..5f93201 100644
--- a/src/strlist.c
+++ b/src/strlist.c
@@ -140,6 +140,30 @@ size_t strlist_count(StrList *pStrList) {
}
/**
+ * Set value at index
+ * @param pStrList
+ * @param value string
+ * @return
+ */
+void strlist_set(StrList *pStrList, size_t index, char *value) {
+ char *tmp = NULL;
+ char *item = NULL;
+ if (index > strlist_count(pStrList)) {
+ return;
+ }
+ if ((item = strlist_item(pStrList, index)) == NULL) {
+ return;
+ }
+ if ((tmp = realloc(pStrList->data[index], strlen(value) + 1)) == NULL) {
+ perror("realloc strlist_set replacement value");
+ return;
+ }
+ pStrList->data[index] = tmp;
+ memset(pStrList->data[index], '\0', strlen(value) + 1);
+ strncpy(pStrList->data[index], value, strlen(value));
+}
+
+/**
* Retrieve data from a `StrList`
* @param pStrList
* @param index