3 /* strtok( char *, const char * )
5 This file is part of the Public Domain C Library (PDCLib).
6 Permission is granted to use, modify, and / or redistribute at will.
13 char * strtok( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2 )
15 static char * tmp = NULL;
25 /* old string continued */
28 /* No old string, no new string, nothing to do */
34 /* skipping leading s2 characters */
39 /* found seperator; skip and start over */
49 /* no more to parse */
50 return ( tmp = NULL );
53 /* skipping non-s2 characters */
62 /* found seperator; overwrite with '\0', position tmp, return */
70 /* parsed to end of string */
78 #include <_PDCLIB_test.h>
82 char s[] = "_a_bc__d_";
83 TESTCASE( strtok( s, "_" ) == &s[1] );
84 TESTCASE( s[1] == 'a' );
85 TESTCASE( s[2] == '\0' );
86 TESTCASE( strtok( NULL, "_" ) == &s[3] );
87 TESTCASE( s[3] == 'b' );
88 TESTCASE( s[4] == 'c' );
89 TESTCASE( s[5] == '\0' );
90 TESTCASE( strtok( NULL, "_" ) == &s[7] );
91 TESTCASE( s[6] == '_' );
92 TESTCASE( s[7] == 'd' );
93 TESTCASE( s[8] == '\0' );
94 TESTCASE( strtok( NULL, "_" ) == NULL );
96 TESTCASE( strtok( s, "_" ) == &s[0] );
97 TESTCASE( s[0] == 'a' );
98 TESTCASE( s[1] == 'b' );
99 TESTCASE( s[2] == '\0' );
100 TESTCASE( strtok( NULL, "_" ) == &s[3] );
101 TESTCASE( s[3] == 'c' );
102 TESTCASE( s[4] == 'd' );
103 TESTCASE( s[5] == '\0' );
104 TESTCASE( strtok( NULL, "_" ) == NULL );