sds.c: new function sdsjoin() to join strings.

This commit is contained in:
antirez
2013-07-04 18:30:59 +02:00
parent 3e3501262b
commit 2150cfebb7
2 changed files with 14 additions and 0 deletions

View File

@ -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"