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