core-util: add pa_split_space_in_place function

Reviewed-by: Anton Lundin <glance@acc.umu.se>
This commit is contained in:
Hajime Fujita 2016-11-06 12:53:56 -06:00 committed by Tanu Kaskinen
parent e2be9fca9c
commit 04b46803cd
2 changed files with 20 additions and 0 deletions

View file

@ -1121,6 +1121,25 @@ char *pa_split_spaces(const char *c, const char **state) {
return pa_xstrndup(current, l);
}
/* Similar to pa_split_spaces, except this returns a string in-place.
Returned string is generally not NULL-terminated.
See pa_split_in_place(). */
const char *pa_split_spaces_in_place(const char *c, int *n, const char **state) {
const char *current = *state ? *state : c;
size_t l;
if (!*current || *c == 0)
return NULL;
current += strspn(current, WHITESPACE);
l = strcspn(current, WHITESPACE);
*state = current+l;
*n = l;
return current;
}
PA_STATIC_TLS_DECLARE(signame, pa_xfree);
/* Return the name of an UNIX signal. Similar to Solaris sig2str() */

View file

@ -112,6 +112,7 @@ static inline const char *pa_strna(const char *x) {
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);
const char *pa_split_spaces_in_place(const char *c, int *n, const char **state);
char *pa_strip_nl(char *s);
char *pa_strip(char *s);