xref: /reactos/sdk/lib/ucrt/mbstring/mbstok.cpp (revision a6a07059)
1 /***
2 *mbstok.c - Break string into tokens (MBCS)
3 *
4 *       Copyright (c) Microsoft Corporation.  All rights reserved.
5 *
6 *Purpose:
7 *       Break string into tokens (MBCS)
8 *
9 *******************************************************************************/
10 #ifndef _MBCS
11     #error This file should only be compiled with _MBCS defined
12 #endif
13 
14 #include <corecrt_internal.h>
15 #include <corecrt_internal_mbstring.h>
16 #include <locale.h>
17 #include <stddef.h>
18 #include <string.h>
19 
20 /***
21 * _mbstok - Break string into tokens (MBCS)
22 *
23 *Purpose:
24 *       strtok considers the string to consist of a sequence of zero or more
25 *       text tokens separated by spans of one or more control chars. the first
26 *       call, with string specified, returns a pointer to the first char of the
27 *       first token, and will write a null char into string immediately
28 *       following the returned token. subsequent calls with zero for the first
29 *       argument (string) will work thru the string until no tokens remain. the
30 *       control string may be different from call to call. when no tokens remain
31 *       in string a nullptr pointer is returned. remember the control chars with a
32 *       bit map, one bit per ascii char. the null char is always a control char.
33 *
34 *       MBCS chars supported correctly.
35 *
36 *Entry:
37 *       char *string = string to break into tokens.
38 *       char *sepset = set of characters to use as seperators
39 *
40 *Exit:
41 *       returns pointer to token, or nullptr if no more tokens
42 *
43 *Exceptions:
44 *       Input parameters are validated. Refer to the validation section of the function.
45 *
46 *******************************************************************************/
47 
48 extern "C" unsigned char * __cdecl _mbstok_l(
49     unsigned char*       const string,
50     unsigned char const* const sepset,
51     _locale_t            const locale
52     )
53 {
54     return _mbstok_s_l(string, sepset, &__acrt_getptd()->_mbstok_token, locale);
55 }
56 
57 extern "C" unsigned char * __cdecl _mbstok(
58         unsigned char * string,
59         const unsigned char * sepset
60         )
61 {
62     /* We call the deprecated _mbstok_l (and not _mbstok_s_l) so that we keep one
63      * single nextoken in the single thread case, i.e. the nextoken declared as static
64      * inside _mbstok_l
65      */
66     _BEGIN_SECURE_CRT_DEPRECATION_DISABLE
67     return _mbstok_l(string, sepset, nullptr);
68     _END_SECURE_CRT_DEPRECATION_DISABLE
69 }
70