1 /* wcstok( wchar_t *, const wchar_t * )
\r
3 This file is part of the Public Domain C Library (PDCLib).
\r
4 Permission is granted to use, modify, and / or redistribute at will.
\r
11 wchar_t * wcstok( wchar_t * _PDCLIB_restrict s1,
\r
12 const wchar_t * _PDCLIB_restrict s2,
\r
13 wchar_t ** _PDCLIB_restrict ptr )
\r
15 const wchar_t * p = s2;
\r
24 /* old string continued */
\r
27 /* No old string, no new string, nothing to do */
\r
33 /* skipping leading s2 characters */
\r
38 /* found seperator; skip and start over */
\r
48 /* no more to parse */
\r
49 return ( *ptr = NULL );
\r
52 /* skipping non-s2 characters */
\r
59 if ( **ptr == *p++ )
\r
61 /* found seperator; overwrite with '\0', position *ptr, return */
\r
69 /* parsed to end of string */
\r
77 #include <_PDCLIB_test.h>
\r
81 // MinGW at least has a very nonconforming (different signature!) variety
\r
84 wchar_t s[] = L"_a_bc__d_";
\r
85 wchar_t* state = NULL;
\r
88 TESTCASE( ( tokres = wcstok( s, L"_", &state ) ) == &s[1] );
\r
89 TESTCASE( s[1] == L'a' );
\r
90 TESTCASE( s[2] == L'\0' );
\r
91 TESTCASE( ( tokres = wcstok( NULL, L"_", &state ) ) == &s[3] );
\r
92 TESTCASE( s[3] == L'b' );
\r
93 TESTCASE( s[4] == L'c' );
\r
94 TESTCASE( s[5] == L'\0' );
\r
95 TESTCASE( ( tokres = wcstok( NULL, L"_", &state ) ) == &s[7] );
\r
96 TESTCASE( s[6] == L'_' );
\r
97 TESTCASE( s[7] == L'd' );
\r
98 TESTCASE( s[8] == L'\0' );
\r
99 TESTCASE( ( tokres = wcstok( NULL, L"_", &state ) ) == NULL );
\r
100 wcscpy( s, L"ab_cd" );
\r
101 TESTCASE( ( tokres = wcstok( s, L"_", &state ) ) == &s[0] );
\r
102 TESTCASE( s[0] == L'a' );
\r
103 TESTCASE( s[1] == L'b' );
\r
104 TESTCASE( s[2] == L'\0' );
\r
105 TESTCASE( ( tokres = wcstok( NULL, L"_", &state ) ) == &s[3] );
\r
106 TESTCASE( s[3] == L'c' );
\r
107 TESTCASE( s[4] == L'd' );
\r
108 TESTCASE( s[5] == L'\0' );
\r
109 TESTCASE( ( tokres = wcstok( NULL, L"_", &state ) ) == NULL );
\r
111 return TEST_RESULTS;
\r