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 * unsigned int count_long_lines(const char *text)
26 * unsigned int i, long_lines = 0;
28 * // Can only fail on out-of-memory.
29 * lines = strsplit(NULL, string, "\n", NULL);
30 * for (i = 0; lines[i] != NULL; i++)
31 * if (strlen(lines[i]) > 80)
37 char **strsplit(const void *ctx, const char *string, const char *delims,
41 * strjoin - Join an array of substrings into one long string
42 * @ctx: the context to tallocate from (often NULL)
43 * @strings: the NULL-terminated array of strings to join
44 * @delim: the delimiter to insert between the strings
46 * This function joins an array of strings into a single string. The
47 * return value is allocated using talloc. Each string in @strings is
48 * followed by a copy of @delim.
51 * // Append the string "--EOL" to each line.
52 * char *append_to_all_lines(const char *string)
55 * unsigned int i, num, newnum;
57 * lines = strsplit(NULL, string, "\n", NULL);
58 * ret = strjoin(NULL, lines, "-- EOL\n");
63 char *strjoin(const void *ctx, char *strings[], const char *delim);
64 #endif /* CCAN_STR_TALLOC_H */