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 */
71 return ( tmp = NULL );
77 #include <_PDCLIB_test.h>
81 char s[] = "_a_bc__d_";
82 TESTCASE( strtok( s, "_" ) == &s[1] );
83 TESTCASE( s[1] == 'a' );
84 TESTCASE( s[2] == '\0' );
85 TESTCASE( strtok( NULL, "_" ) == &s[3] );
86 TESTCASE( s[3] == 'b' );
87 TESTCASE( s[4] == 'c' );
88 TESTCASE( s[5] == '\0' );
89 TESTCASE( strtok( NULL, "_" ) == &s[7] );
90 TESTCASE( s[6] == '_' );
91 TESTCASE( s[7] == 'd' );
92 TESTCASE( s[8] == '\0' );
93 TESTCASE( strtok( NULL, "_" ) == NULL );