5 /* strtok( char *, const char * )
7 This file is part of the Public Domain C Library (PDCLib).
8 Permission is granted to use, modify, and / or redistribute at will.
11 #include <_PDCLIB_aux.h>
16 char * strtok( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2 )
18 static char * tmp = NULL;
28 /* old string continued */
31 /* No old string, no new string, nothing to do */
37 /* skipping leading s2 characters */
42 /* found seperator; skip and start over */
52 /* no more to parse */
53 return ( tmp = NULL );
56 /* skipping non-s2 characters */
65 /* found seperator; overwrite with '\0', position tmp, return */
73 /* parsed to end of string */
74 return ( tmp = NULL );
80 #include <_PDCLIB_test.h>
84 char s[] = "_a_bc__d_";
86 TESTCASE( strtok( s, "_" ) == &s[1] );
87 TESTCASE( s[1] == 'a' );
88 TESTCASE( s[2] == '\0' );
89 TESTCASE( strtok( NULL, "_" ) == &s[3] );
90 TESTCASE( s[3] == 'b' );
91 TESTCASE( s[4] == 'c' );
92 TESTCASE( s[5] == '\0' );
93 TESTCASE( strtok( NULL, "_" ) == &s[7] );
94 TESTCASE( s[6] == '_' );
95 TESTCASE( s[7] == 'd' );
96 TESTCASE( s[8] == '\0' );
97 TESTCASE( strtok( NULL, "_" ) == NULL );