1 #ifndef CCAN_STR_TALLOC_H
2 #define CCAN_STR_TALLOC_H
7 * strsplit - Split string into an array of substrings
8 * @ctx: the context to tallocate from (often NULL)
9 * @string: the string to split
10 * @delims: delimiters where lines should be split.
11 * @nump: optional pointer to place resulting number of lines
13 * This function splits a single string into multiple strings. The
14 * original string is untouched: an array is allocated (using talloc)
15 * pointing to copies of each substring. Multiple delimiters result
16 * in empty substrings. By definition, no delimiters will appear in
19 * The final char * in the array will be NULL, so you can use this or
20 * @nump to find the array length.
23 * #include <ccan/talloc/talloc.h>
24 * #include <ccan/str_talloc/str_talloc.h>
26 * static unsigned int count_long_lines(const char *string)
29 * unsigned int i, long_lines = 0;
31 * // Can only fail on out-of-memory.
32 * lines = strsplit(NULL, string, "\n", NULL);
33 * for (i = 0; lines[i] != NULL; i++)
34 * if (strlen(lines[i]) > 80)
40 char **strsplit(const void *ctx, const char *string, const char *delims,
44 * strjoin - Join an array of substrings into one long string
45 * @ctx: the context to tallocate from (often NULL)
46 * @strings: the NULL-terminated array of strings to join
47 * @delim: the delimiter to insert between the strings
49 * This function joins an array of strings into a single string. The
50 * return value is allocated using talloc. Each string in @strings is
51 * followed by a copy of @delim.
54 * // Append the string "--EOL" to each line.
55 * static char *append_to_all_lines(const char *string)
59 * lines = strsplit(NULL, string, "\n", NULL);
60 * ret = strjoin(NULL, lines, "-- EOL\n");
65 char *strjoin(const void *ctx, char *strings[], const char *delim);
66 #endif /* CCAN_STR_TALLOC_H */