[pulseaudio-discuss] [PATCH v6 04/37] raop: Add pulsecore/core-utils a pa_str_in_list function

Arun Raghavan arun at accosted.net
Tue Feb 9 11:13:23 UTC 2016


On Sun, 2016-01-31 at 22:16 -0600, Hajime Fujita wrote:
> From: Martin Blanchard <tinram at gmx.fr>
> 
> ---
>  src/pulsecore/core-util.c | 20 ++++++++++++++++++++
>  src/pulsecore/core-util.h |  5 +++--
>  2 files changed, 23 insertions(+), 2 deletions(-)
> 
> diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c
> index 19c89a9..9fd4301 100644
> --- a/src/pulsecore/core-util.c
> +++ b/src/pulsecore/core-util.c
> @@ -2977,6 +2977,26 @@ bool pa_in_system_mode(void) {
>      return !!atoi(e);
>  }
>  
> +/* Checks a delimiters-separated list of words in haystack for needle */
> +bool pa_str_in_list(const char *haystack, const char *delimiters, const char *needle) {
> +    char *s;
> +    const char *state = NULL;
> +
> +    if (!haystack || !needle)
> +        return false;
> +
> +    while ((s = pa_split(haystack, delimiters, &state))) {

Would be nicer to use pa_split_in_place() here.

-- Arun

> +        if (pa_streq(needle, s)) {
> +            pa_xfree(s);
> +            return true;
> +        }
> +
> +        pa_xfree(s);
> +    }
> +
> +    return false;
> +}
> +
>  /* Checks a whitespace-separated list of words in haystack for needle */
>  bool pa_str_in_list_spaces(const char *haystack, const char *needle) {
>      char *s;
> diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h
> index d5a2d39..56b527f 100644
> --- a/src/pulsecore/core-util.h
> +++ b/src/pulsecore/core-util.h
> @@ -109,8 +109,8 @@ static inline const char *pa_strna(const char *x) {
>      return x ? x : "n/a";
>  }
>  
> -char *pa_split(const char *c, const char*delimiters, const char **state);
> -const char *pa_split_in_place(const char *c, const char*delimiters, int *n, const char **state);
> +char *pa_split(const char *c, const char *delimiters, const char **state);
> +const char *pa_split_in_place(const char *c, const char *delimiters, int *n, const char **state);
>  char *pa_split_spaces(const char *c, const char **state);
>  
>  char *pa_strip_nl(char *s);
> @@ -228,6 +228,7 @@ static inline bool pa_safe_streq(const char *a, const char *b) {
>  }
>  
>  bool pa_str_in_list_spaces(const char *needle, const char *haystack);
> +bool pa_str_in_list(const char *haystack, const char *delimiters, const char *needle);
>  
>  char *pa_get_host_name_malloc(void);
>  char *pa_get_user_name_malloc(void);


More information about the pulseaudio-discuss mailing list