字符串分割函数strsep

来源:互联网 发布:网络本科入学考试难吗 编辑:程序博客网 时间:2024/05/16 18:25
#ifndef __HAVE_ARCH_STRPBRK/** * strpbrk - Find the first occurrence of a set of characters * @cs: The string to be searched * @ct: The characters to search for */char *strpbrk(const char *cs, const char *ct){const char *sc1, *sc2;for (sc1 = cs; *sc1 != '\0'; ++sc1) {for (sc2 = ct; *sc2 != '\0'; ++sc2) {if (*sc1 == *sc2)return (char *)sc1;}}return NULL;}EXPORT_SYMBOL(strpbrk);#endif#ifndef __HAVE_ARCH_STRSEP/** * strsep - Split a string into tokens * @s: The string to be searched * @ct: The characters to search for * * strsep() updates @s to point after the token, ready for the next call. * * It returns empty tokens, too, behaving exactly like the libc function * of that name. In fact, it was stolen from glibc2 and de-fancy-fied. * Same semantics, slimmer shape. ;) */char *strsep(char **s, const char *ct){char *sbegin = *s;char *end;if (sbegin == NULL)return NULL;end = strpbrk(sbegin, ct);if (end)*end++ = '\0';*s = end;return sbegin;}EXPORT_SYMBOL(strsep);#endif

 
原创粉丝点击