sexp_assoc
This commit is contained in:
parent
53609faa82
commit
ce5de71e11
15
sexp.c
15
sexp.c
|
@ -130,3 +130,18 @@ cmsg_bytes_t sexp_data(sexp_t *x) {
|
|||
die("Unknown sexp kind %d in data accessor\n", x->kind);
|
||||
}
|
||||
}
|
||||
|
||||
sexp_t *sexp_assoc(sexp_t *list, cmsg_bytes_t key) {
|
||||
while (list != NULL) {
|
||||
sexp_t *candidate = sexp_head(list);
|
||||
if (sexp_stringp(candidate)) {
|
||||
cmsg_bytes_t candidate_data = sexp_data(candidate);
|
||||
if ((candidate_data.len == key.len)
|
||||
&& (!memcmp(candidate_data.bytes, key.bytes, key.len))) {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
list = sexp_tail(list);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue