summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLouis Burda <quent.burda@gmail.com>2023-06-04 03:18:32 +0200
committerLouis Burda <quent.burda@gmail.com>2023-06-04 03:18:32 +0200
commit88c361d98175622a93cca38c824cea335435cfff (patch)
tree41ceda4581dbfee68bcfbcf4537b72cf84a6987b /src
parent808d5506ce033fee5b1e8b002e9d47a92355a582 (diff)
downloadlibstrvec-c-88c361d98175622a93cca38c824cea335435cfff.tar.gz
libstrvec-c-88c361d98175622a93cca38c824cea335435cfff.zip
Add strvec_find
Diffstat (limited to 'src')
-rw-r--r--src/strvec.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/strvec.c b/src/strvec.c
index e668e35..5d140cf 100644
--- a/src/strvec.c
+++ b/src/strvec.c
@@ -2,6 +2,7 @@
#include "dvec.h"
#include "allocator.h"
+#include <stddef.h>
#include <string.h>
int
@@ -229,6 +230,23 @@ strvec_remove_str(struct strvec *strvec, const char *str,
return 0;
}
+ssize_t
+strvec_find(struct strvec *strvec, size_t start, const char *str)
+{
+ const char **ent;
+ size_t i;
+
+ LIBSTRVEC_ABORT_ON_ARGS(!strvec);
+
+ for (i = start; i < strvec->vec.len; i++) {
+ ent = strvec_at(strvec, i);
+ if (!str && !*ent) return (ssize_t) i;
+ if (!strcmp(str, *ent)) return (ssize_t) i;
+ }
+
+ return -1;
+}
+
char *
strvec_join(struct strvec *strvec, const char *sep,
const struct allocator *allocator, int *_rc)