mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-23 00:28:26 -05:00
sds.c: new function sdsjoin() to join strings.
This commit is contained in:
parent
1135e9faa2
commit
585b0a61ce
13
src/sds.c
13
src/sds.c
@ -621,6 +621,19 @@ sds sdsmapchars(sds s, const char *from, const char *to, size_t setlen) {
|
|||||||
return s;
|
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
|
#ifdef SDS_TEST_MAIN
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "testhelp.h"
|
#include "testhelp.h"
|
||||||
|
@ -89,6 +89,7 @@ sds sdsfromlonglong(long long value);
|
|||||||
sds sdscatrepr(sds s, const char *p, size_t len);
|
sds sdscatrepr(sds s, const char *p, size_t len);
|
||||||
sds *sdssplitargs(const char *line, int *argc);
|
sds *sdssplitargs(const char *line, int *argc);
|
||||||
sds sdsmapchars(sds s, const char *from, const char *to, size_t setlen);
|
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 */
|
/* Low level functions exposed to the user API */
|
||||||
sds sdsMakeRoomFor(sds s, size_t addlen);
|
sds sdsMakeRoomFor(sds s, size_t addlen);
|
||||||
|
Loading…
Reference in New Issue
Block a user