From c18720f0c4552854eb210000b8c9f42b56ca2956 Mon Sep 17 00:00:00 2001 From: Patrick Stephens Date: Thu, 19 Dec 2024 14:38:13 +0000 Subject: [PATCH] kvlist: provide options for case sensitivity fetch Signed-off-by: Patrick Stephens --- include/cfl/cfl_kvlist.h | 1 + src/cfl_kvlist.c | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/include/cfl/cfl_kvlist.h b/include/cfl/cfl_kvlist.h index ab25b16..10f9013 100644 --- a/include/cfl/cfl_kvlist.h +++ b/include/cfl/cfl_kvlist.h @@ -124,6 +124,7 @@ int cfl_kvlist_insert_s(struct cfl_kvlist *list, struct cfl_variant *value); struct cfl_variant *cfl_kvlist_fetch_s(struct cfl_kvlist *list, char *key, size_t key_size); +struct cfl_variant *cfl_kvlist_fetch_case_s(struct cfl_kvlist *list, char *key, size_t key_size); int cfl_kvlist_contains(struct cfl_kvlist *kvlist, char *name); int cfl_kvlist_remove(struct cfl_kvlist *kvlist, char *name); diff --git a/src/cfl_kvlist.c b/src/cfl_kvlist.c index 4ffc5ea..8692041 100644 --- a/src/cfl_kvlist.c +++ b/src/cfl_kvlist.c @@ -317,7 +317,7 @@ int cfl_kvlist_insert_s(struct cfl_kvlist *list, return 0; } -struct cfl_variant *cfl_kvlist_fetch_s(struct cfl_kvlist *list, char *key, size_t key_size) +struct cfl_variant *cfl_kvlist_fetch_internal_s(struct cfl_kvlist *list, char *key, size_t key_size, int case_sensitive) { struct cfl_list *head; struct cfl_kvpair *pair; @@ -329,14 +329,28 @@ struct cfl_variant *cfl_kvlist_fetch_s(struct cfl_kvlist *list, char *key, size_ continue; } - if (strncasecmp(pair->key, key, key_size) == 0) { - return pair->val; + if (case_sensitive == CFL_TRUE ) { + if (strncmp(pair->key, key, key_size) == 0) { + return pair->val; + } + } else { + if (strncasecmp(pair->key, key, key_size) == 0) { + return pair->val; + } } } return NULL; } +struct cfl_variant *cfl_kvlist_fetch_s(struct cfl_kvlist *list, char *key, size_t key_size) { + return cfl_kvlist_fetch_internal_s(list, key, key_size, CFL_FALSE); +} + +struct cfl_variant *cfl_kvlist_fetch_case_s(struct cfl_kvlist *list, char *key, size_t key_size) +{ + return cfl_kvlist_fetch_internal_s(list, key, key_size, CFL_TRUE); +} int cfl_kvlist_insert_string(struct cfl_kvlist *list, char *key, char *value)