summaryrefslogtreecommitdiff
path: root/src/pulsecore
diff options
context:
space:
mode:
authorUlrich Eckhardt <ulrich.eckhardt@base-42.de>2016-05-16 19:51:05 +0200
committerArun Raghavan <arun@arunraghavan.net>2016-06-22 12:55:55 +0530
commit111e332556ce98d52a73baad8f0b51e4885b8383 (patch)
treee222f0ab7c8f5a30d5a54f5f60cb14d03a93cf20 /src/pulsecore
parentc9c8f4285f31fda5d3051832969983dfe0df1cab (diff)
core-util: Improve pa_replace() behaviour
- Assert that the search string isn't empty. - Add test. - Improve documentation.
Diffstat (limited to 'src/pulsecore')
-rw-r--r--src/pulsecore/core-util.c1
-rw-r--r--src/pulsecore/core-util.h4
2 files changed, 5 insertions, 0 deletions
diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c
index b6eb85a30..f816da9f6 100644
--- a/src/pulsecore/core-util.c
+++ b/src/pulsecore/core-util.c
@@ -3194,6 +3194,7 @@ char *pa_replace(const char*s, const char*a, const char *b) {
pa_assert(s);
pa_assert(a);
+ pa_assert(*a);
pa_assert(b);
an = strlen(a);
diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h
index d5a2d3957..5725ca78d 100644
--- a/src/pulsecore/core-util.h
+++ b/src/pulsecore/core-util.h
@@ -249,6 +249,10 @@ void pa_reduce(unsigned *num, unsigned *den);
unsigned pa_ncpus(void);
+/* Replaces all occurrences of `a' in `s' with `b'. The caller has to free the
+ * returned string. All parameters must be non-NULL and additionally `a' must
+ * not be a zero-length string.
+ */
char *pa_replace(const char*s, const char*a, const char *b);
/* Escapes p by inserting backslashes in front of backslashes. chars is a