From 83ddc0936e52120f2af86a552f3adb240a4f0ac4 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 4 Feb 2009 17:19:15 +0100 Subject: add new calls pa_replace() and pa_unescape() --- src/pulsecore/core-util.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'src/pulsecore/core-util.c') diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index e65b1796..b7ebdeb7 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -97,6 +97,7 @@ #include #include #include +#include #include "core-util.h" @@ -2553,3 +2554,49 @@ unsigned pa_ncpus(void) { return ncpus <= 0 ? 1 : (unsigned) ncpus; } + +char *pa_replace(const char*s, const char*a, const char *b) { + pa_strbuf *sb; + size_t an; + + pa_assert(s); + pa_assert(a); + pa_assert(b); + + an = strlen(a); + sb = pa_strbuf_new(); + + for (;;) { + const char *p; + + if (!(p = strstr(s, a))) + break; + + pa_strbuf_putsn(sb, s, p-s); + pa_strbuf_puts(sb, b); + s = p + an; + } + + pa_strbuf_puts(sb, s); + + return pa_strbuf_tostring_free(sb); +} + +char *pa_unescape(char *p) { + char *s, *d; + pa_bool_t escaped = FALSE; + + for (s = p, d = p; *s; s++) { + if (!escaped && *s == '\\') { + escaped = TRUE; + continue; + } + + *(d++) = *s; + escaped = FALSE; + } + + *d = 0; + + return p; +} -- cgit