strings: Add strings__find and strings__cmp
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
46a3bc4626
commit
4d615b9e01
21
strings.c
21
strings.c
|
@ -88,3 +88,24 @@ strings_t strings__add(struct strings *self, const char *str)
|
|||
|
||||
return index;
|
||||
}
|
||||
|
||||
strings_t strings__find(struct strings *self, const char *str)
|
||||
{
|
||||
strings_t *s;
|
||||
struct search_key key = {
|
||||
.self = self,
|
||||
.str = str,
|
||||
};
|
||||
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
|
||||
s = tfind(&key, &self->tree, strings__compare);
|
||||
return s ? *s : 0;
|
||||
}
|
||||
|
||||
int strings__cmp(const struct strings *self, strings_t a, strings_t b)
|
||||
{
|
||||
return a == b ? 0 : strcmp(strings__ptr(self, a),
|
||||
strings__ptr(self, b));
|
||||
}
|
||||
|
|
|
@ -22,6 +22,9 @@ struct strings *strings__new(void);
|
|||
void strings__delete(struct strings *self);
|
||||
|
||||
strings_t strings__add(struct strings *self, const char *str);
|
||||
strings_t strings__find(struct strings *self, const char *str);
|
||||
|
||||
int strings__cmp(const struct strings *self, strings_t a, strings_t b);
|
||||
|
||||
static inline const char *strings__ptr(const struct strings *self, strings_t s)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue