diff options
Diffstat (limited to 'src/librc')
-rw-r--r-- | src/librc/librc-stringlist.c | 25 | ||||
-rw-r--r-- | src/librc/librc.h | 2 | ||||
-rw-r--r-- | src/librc/rc.h.in | 13 | ||||
-rw-r--r-- | src/librc/rc.map | 2 |
4 files changed, 42 insertions, 0 deletions
diff --git a/src/librc/librc-stringlist.c b/src/librc/librc-stringlist.c index 4dc07030..35889fb7 100644 --- a/src/librc/librc-stringlist.c +++ b/src/librc/librc-stringlist.c @@ -80,6 +80,31 @@ bool rc_stringlist_delete(RC_STRINGLIST *list, const char *value) } librc_hidden_def(rc_stringlist_delete) +RC_STRING *rc_stringlist_find(RC_STRINGLIST *list, const char *value) +{ + RC_STRING *s; + + TAILQ_FOREACH(s, list, entries) + if (strcmp(s->value, value) == 0) + return s; + return NULL; +} +librc_hidden_def(rc_stringlist_find) + +RC_STRINGLIST *rc_stringlist_split(const char *value, const char *sep) +{ + RC_STRINGLIST *list = rc_stringlist_new(); + char *d = xstrdup(value); + char *p = d, *token; + + while ((token = strsep(&p, sep))) + rc_stringlist_add(list, token); + free(d); + + return list; +} +librc_hidden_def(rc_stringlist_split) + void rc_stringlist_sort(RC_STRINGLIST **list) { RC_STRINGLIST *l = *list; diff --git a/src/librc/librc.h b/src/librc/librc.h index e75ebec1..34fed0e5 100644 --- a/src/librc/librc.h +++ b/src/librc/librc.h @@ -116,8 +116,10 @@ librc_hidden_proto(rc_service_value_set) librc_hidden_proto(rc_stringlist_add) librc_hidden_proto(rc_stringlist_addu) librc_hidden_proto(rc_stringlist_delete) +librc_hidden_proto(rc_stringlist_find) librc_hidden_proto(rc_stringlist_free) librc_hidden_proto(rc_stringlist_new) +librc_hidden_proto(rc_stringlist_split) librc_hidden_proto(rc_stringlist_sort) librc_hidden_proto(rc_sys) librc_hidden_proto(rc_yesno) diff --git a/src/librc/rc.h.in b/src/librc/rc.h.in index 12cc42c3..96287144 100644 --- a/src/librc/rc.h.in +++ b/src/librc/rc.h.in @@ -445,6 +445,19 @@ RC_STRING *rc_stringlist_addu(RC_STRINGLIST *, const char *); * @return true on success, otherwise false */ bool rc_stringlist_delete(RC_STRINGLIST *, const char *); +/*! Find the item on the list. + * @param list to search + * @param item to find. + * @return pointer to item */ +RC_STRING *rc_stringlist_find(RC_STRINGLIST *, const char *); + +/*! Split a string into a stringlist based on seperator. + * @param string to split + * @param seperator + * @return new list */ +RC_STRINGLIST *rc_stringlist_split(const char *, const char *); + + /*! Sort the list according to C locale * @param list to sort */ void rc_stringlist_sort(RC_STRINGLIST **); diff --git a/src/librc/rc.map b/src/librc/rc.map index e1dd8437..e9fed69b 100644 --- a/src/librc/rc.map +++ b/src/librc/rc.map @@ -44,6 +44,8 @@ global: rc_stringlist_add; rc_stringlist_addu; rc_stringlist_delete; + rc_stringlist_find; + rc_stringlist_split; rc_stringlist_new; rc_stringlist_sort; rc_stringlist_free; |