summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2013-07-04 18:30:59 +0200
committerantirez <antirez@gmail.com>2013-07-04 18:30:59 +0200
commit585b0a61ce0cc7ddf136c1c4e462a0d4ad2a8fc7 (patch)
treeee46fcb6ac0734cecee7fa083aa9c10f15915546
parent1135e9faa253789a6d6e67fd6a44d7395af8fb35 (diff)
downloadredis-585b0a61ce0cc7ddf136c1c4e462a0d4ad2a8fc7.tar.gz
sds.c: new function sdsjoin() to join strings.
-rw-r--r--src/sds.c13
-rw-r--r--src/sds.h1
2 files changed, 14 insertions, 0 deletions
diff --git a/src/sds.c b/src/sds.c
index 4cf700b9a..aa45fc4f5 100644
--- a/src/sds.c
+++ b/src/sds.c
@@ -621,6 +621,19 @@ sds sdsmapchars(sds s, const char *from, const char *to, size_t setlen) {
return s;
}
+/* Join an array of C strings using the specified separator (also a C string).
+ * Returns the result as an sds string. */
+sds sdsjoin(char **argv, int argc, char *sep) {
+ sds join = sdsempty();
+ int j;
+
+ for (j = 0; j < argc; j++) {
+ join = sdscat(join, argv[j]);
+ if (j != argc-1) join = sdscat(join,sep);
+ }
+ return join;
+}
+
#ifdef SDS_TEST_MAIN
#include <stdio.h>
#include "testhelp.h"
diff --git a/src/sds.h b/src/sds.h
index c5a4f30a9..46d914fd1 100644
--- a/src/sds.h
+++ b/src/sds.h
@@ -89,6 +89,7 @@ sds sdsfromlonglong(long long value);
sds sdscatrepr(sds s, const char *p, size_t len);
sds *sdssplitargs(const char *line, int *argc);
sds sdsmapchars(sds s, const char *from, const char *to, size_t setlen);
+sds sdsjoin(char **argv, int argc, char *sep);
/* Low level functions exposed to the user API */
sds sdsMakeRoomFor(sds s, size_t addlen);