Add new functions, rc_stringlist_find and rc_stringlist_split.

This commit is contained in:
Roy Marples 2008-09-18 15:12:43 +00:00
parent ccc24d1086
commit e0dfa472d1
4 changed files with 42 additions and 0 deletions

View File

@ -80,6 +80,31 @@ bool rc_stringlist_delete(RC_STRINGLIST *list, const char *value)
} }
librc_hidden_def(rc_stringlist_delete) 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) void rc_stringlist_sort(RC_STRINGLIST **list)
{ {
RC_STRINGLIST *l = *list; RC_STRINGLIST *l = *list;

View File

@ -116,8 +116,10 @@ librc_hidden_proto(rc_service_value_set)
librc_hidden_proto(rc_stringlist_add) librc_hidden_proto(rc_stringlist_add)
librc_hidden_proto(rc_stringlist_addu) librc_hidden_proto(rc_stringlist_addu)
librc_hidden_proto(rc_stringlist_delete) librc_hidden_proto(rc_stringlist_delete)
librc_hidden_proto(rc_stringlist_find)
librc_hidden_proto(rc_stringlist_free) librc_hidden_proto(rc_stringlist_free)
librc_hidden_proto(rc_stringlist_new) librc_hidden_proto(rc_stringlist_new)
librc_hidden_proto(rc_stringlist_split)
librc_hidden_proto(rc_stringlist_sort) librc_hidden_proto(rc_stringlist_sort)
librc_hidden_proto(rc_sys) librc_hidden_proto(rc_sys)
librc_hidden_proto(rc_yesno) librc_hidden_proto(rc_yesno)

View File

@ -445,6 +445,19 @@ RC_STRING *rc_stringlist_addu(RC_STRINGLIST *, const char *);
* @return true on success, otherwise false */ * @return true on success, otherwise false */
bool rc_stringlist_delete(RC_STRINGLIST *, const char *); 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 /*! Sort the list according to C locale
* @param list to sort */ * @param list to sort */
void rc_stringlist_sort(RC_STRINGLIST **); void rc_stringlist_sort(RC_STRINGLIST **);

View File

@ -44,6 +44,8 @@ global:
rc_stringlist_add; rc_stringlist_add;
rc_stringlist_addu; rc_stringlist_addu;
rc_stringlist_delete; rc_stringlist_delete;
rc_stringlist_find;
rc_stringlist_split;
rc_stringlist_new; rc_stringlist_new;
rc_stringlist_sort; rc_stringlist_sort;
rc_stringlist_free; rc_stringlist_free;