forked from chakra-core/ChakraCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtcstok_s.inl
More file actions
72 lines (62 loc) · 1.68 KB
/
tcstok_s.inl
File metadata and controls
72 lines (62 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
/***
*tcstok_s.inl - general implementation of _tcstok_s
*
*
*Purpose:
* This file contains the general algorithm for strtok_s and its variants.
*
****/
_FUNC_PROLOGUE
_CHAR * __cdecl _FUNC_NAME(_CHAR *_String, const _CHAR *_Control, _CHAR **_Context)
{
_CHAR *token;
const _CHAR *ctl;
/* validation section */
_VALIDATE_POINTER_ERROR_RETURN(_Context, EINVAL, NULL);
_VALIDATE_POINTER_ERROR_RETURN(_Control, EINVAL, NULL);
_VALIDATE_CONDITION_ERROR_RETURN(_String != NULL || *_Context != NULL, EINVAL, NULL);
/* If string==NULL, continue with previous string */
if (!_String)
{
_String = *_Context;
}
/* Find beginning of token (skip over leading delimiters). Note that
* there is no token iff this loop sets string to point to the terminal null. */
for ( ; *_String != 0 ; _String++)
{
for (ctl = _Control; *ctl != 0 && *ctl != *_String; ctl++)
;
if (*ctl == 0)
{
break;
}
}
token = _String;
/* Find the end of the token. If it is not the end of the string,
* put a null there. */
for ( ; *_String != 0 ; _String++)
{
for (ctl = _Control; *ctl != 0 && *ctl != *_String; ctl++)
;
if (*ctl != 0)
{
*_String++ = 0;
break;
}
}
/* Update the context */
*_Context = _String;
/* Determine if a token has been found. */
if (token == _String)
{
return NULL;
}
else
{
return token;
}
}