Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kvlist: provide options for case sensitivity fetch #58

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading