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