Details
Details
- Reviewers
lntue michaelrj mcgrathr - Commits
- rGb4ab398cb11b: [libc] Implement strsep
Diff Detail
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Comment Actions
This is missing the bsd_ext.td addition for the <string.h> decl.
libc/test/src/string/strsep_test.cpp | ||
---|---|---|
2 | Perhaps you can templatize the strtok test and then reuse that here. |
Comment Actions
I'm not finding good documentation online, but according to the man page for strsep, it should behave slightly differently from strtok. Instead of skipping past repeated delimeters, it should instead treat them the same and possibly return a pointer to '\0'. I've copied the example below:
EXAMPLES The program below is a port of the one found in strtok(3), which, however, doesn't discard multiple delimiters or empty tokens: $ ./a.out 'a/bbb///cc;xxx:yyy:' ':;' '/' 1: a/bbb///cc --> a --> bbb --> --> --> cc 2: xxx --> xxx 3: yyy --> yyy 4: --> Program source #include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char *argv[]) { char *token, *subtoken; if (argc != 4) { fprintf(stderr, "Usage: %s string delim subdelim\n", argv[0]); exit(EXIT_FAILURE); } for (unsigned int j = 1; (token = strsep(&argv[1], argv[2])); j++) { printf("%u: %s\n", j, token); while ((subtoken = strsep(&token, argv[3]))) printf("\t --> %s\n", subtoken); } exit(EXIT_SUCCESS); } SEE ALSO index(3), memchr(3), rindex(3), strchr(3), string(3), strpbrk(3), strspn(3), strstr(3), strtok(3) Linux man-pages 6.01 2022-10-09 STRSEP(3)
Comment Actions
LGTM with one nit.
libc/src/string/string_utils.h | ||
---|---|---|
197–199 | Nit: This should be if constexpr (SkipDelim) to make it clear this is a compile-time if statement. |
libc/src/string/string_utils.h | ||
---|---|---|
197–199 | Done in commit |
Nit: This should be if constexpr (SkipDelim) to make it clear this is a compile-time if statement.