From 7f49249674a15e6ead215e93eb84d57ace7e882d Mon Sep 17 00:00:00 2001 From: antirez Date: Thu, 6 Feb 2014 14:21:44 +0100 Subject: Join functions improved. The original implementation of sdsjoin did not allowed a binary separator nor was able to handle sds strings contaning bianry data. sdsjoin() was modified to get a spearator length. sdsjoinsds() was added to join arrays of SDS strings. --- sds.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'sds.c') diff --git a/sds.c b/sds.c index 5cdb152..c0d4a3e 100644 --- a/sds.c +++ b/sds.c @@ -759,13 +759,25 @@ sds sdsmapchars(sds s, const char *from, const char *to, size_t setlen) { /* 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 sdsjoin(char **argv, int argc, char *sep, size_t seplen) { sds join = sdsempty(); int j; for (j = 0; j < argc; j++) { join = sdscat(join, argv[j]); - if (j != argc-1) join = sdscat(join,sep); + if (j != argc-1) join = sdscatlen(join,sep,seplen); + } + return join; +} + +/* Like sdsjoin, but joins an array of SDS strings. */ +sds sdsjoinsds(sds *argv, int argc, const char *sep, size_t seplen) { + sds join = sdsempty(); + int j; + + for (j = 0; j < argc; j++) { + join = sdscatsds(join, argv[j]); + if (j != argc-1) join = sdscatlen(join,sep,seplen); } return join; } -- cgit v1.2.3-70-g09d2