diff options
author | Hajime Fujita <crisp.fujita@nifty.com> | 2016-11-06 12:53:56 -0600 |
---|---|---|
committer | Tanu Kaskinen <tanuk@iki.fi> | 2017-01-19 03:00:45 +0200 |
commit | 04b46803cd6c6919757e1a871d5b746a6b277b41 (patch) | |
tree | a607419e83939e57fb92478870b77602e060dcca | |
parent | e2be9fca9c7a018e1ec42b57ba806bf5df2110fb (diff) |
core-util: add pa_split_space_in_place function
Reviewed-by: Anton Lundin <glance@acc.umu.se>
-rw-r--r-- | src/pulsecore/core-util.c | 19 | ||||
-rw-r--r-- | src/pulsecore/core-util.h | 1 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index f2999b248..9d571b88d 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -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() */ diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h index be023a802..e28b6aa7c 100644 --- a/src/pulsecore/core-util.h +++ b/src/pulsecore/core-util.h @@ -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); |