Skip to content

Commit

Permalink
kvlist: provide options for case sensitivity fetch
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Stephens <[email protected]>
  • Loading branch information
patrick-stephens committed Dec 19, 2024
1 parent 592e7e7 commit c18720f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/cfl/cfl_kvlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
20 changes: 17 additions & 3 deletions src/cfl_kvlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down

0 comments on commit c18720f

Please sign in to comment.