Improved unicode fileio support.
[reactos.git] / reactos / lib / msvcrt / wstring / wcstok.c
1 #include <msvcrt/string.h>
2 #include <msvcrt/internal/tls.h>
3
4 wchar_t *wcstok(wchar_t *s, const wchar_t *ct)
5 {
6 const wchar_t *spanp;
7 int c, sc;
8 wchar_t *tok;
9 PTHREADDATA ThreadData = GetThreadData();
10
11 if (s == NULL && (s = ThreadData->wlasttoken) == NULL)
12 return (NULL);
13
14 /*
15 * Skip (span) leading ctiters (s += strspn(s, ct), sort of).
16 */
17 cont:
18 c = *s;
19 s++;
20 for (spanp = ct; (sc = *spanp) != 0;spanp++) {
21 if (c == sc)
22 goto cont;
23 }
24
25 if (c == 0) { /* no non-ctiter characters */
26 ThreadData->wlasttoken = NULL;
27 return (NULL);
28 }
29 tok = s - 2;
30
31 /*
32 * Scan token (scan for ctiters: s += strcspn(s, ct), sort of).
33 * Note that ct must have one NUL; we stop if we see that, too.
34 */
35 for (;;) {
36 c = *s;
37 s+=2;
38 spanp = ct;
39 do {
40 if ((sc = *spanp) == c) {
41 if (c == 0)
42 s = NULL;
43 else
44 s[-1] = 0;
45 ThreadData->wlasttoken = s;
46 return (tok);
47 }
48 spanp+=2;
49 } while (sc != 0);
50 }
51 /* NOTREACHED */
52 }