Add new functions, rc_stringlist_find and rc_stringlist_split.
This commit is contained in:
parent
ccc24d1086
commit
e0dfa472d1
@ -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;
|
||||
|
@ -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)
|
||||
|
@ -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 **);
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user