7 * streq - Are two strings equal?
11 * This macro is arguably more readable than "!strcmp(a, b)".
15 * printf("String is empty!\n");
17 #define streq(a,b) (strcmp((a),(b)) == 0)
20 * strstarts - Does this string start with this prefix?
21 * @str: string to test
22 * @prefix: prefix to look for at start of str
25 * if (strstarts(str, "foo"))
26 * printf("String %s begins with 'foo'!\n", str);
28 #define strstarts(str,prefix) (strncmp((str),(prefix),strlen(prefix)) == 0)
31 * strends - Does this string end with this postfix?
32 * @str: string to test
33 * @postfix: postfix to look for at end of str
36 * if (strends(str, "foo"))
37 * printf("String %s end with 'foo'!\n", str);
39 static inline bool strends(const char *str, const char *postfix)
41 if (strlen(str) < strlen(postfix))
44 return streq(str + strlen(str) - strlen(postfix), postfix);
48 * strsplit - Split string into an array of substrings
49 * @ctx: the context to tallocate from (often NULL)
50 * @string: the string to split
51 * @delims: delimiters where lines should be split.
52 * @nump: optional pointer to place resulting number of lines
54 * This function splits a single string into multiple strings. The
55 * original string is untouched: an array is allocated (using talloc)
56 * pointing to copies of each substring. Multiple delimiters result
57 * in empty substrings.
59 * The final char * in the array will be NULL, so you can use this or
60 * @nump to find the array length.
63 * unsigned int count_long_lines(const char *text)
66 * unsigned int i, long_lines = 0;
68 * // Can only fail on out-of-memory.
69 * lines = strsplit(NULL, string, "\n", NULL);
70 * for (i = 0; lines[i] != NULL; i++)
71 * if (strlen(lines[i]) > 80)
77 char **strsplit(const void *ctx, const char *string, const char *delims,
79 #endif /* CCAN_STRING_H */