forked from chakra-core/ChakraCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwchartls.cpp
More file actions
128 lines (96 loc) · 3.16 KB
/
wchartls.cpp
File metadata and controls
128 lines (96 loc) · 3.16 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
/*++
Module Name:
wchartls.c
Abstract:
Implementation of wide char string functions that depend on per-thread data
--*/
#include "pal/palinternal.h"
#include "pal/thread.hpp"
#include "pal/dbgmsg.h"
#include "pal/unicode_data.h"
using namespace CorUnix;
SET_DEFAULT_DEBUG_CHANNEL(CRT);
/*++
Function:
PAL_wcstok
Finds the next token in a wide character string.
Return value:
A pointer to the next token found in strToken. Returns NULL when no more
tokens are found. Each call modifies strToken by substituting a NULL
character for each delimiter that is encountered.
Parameters:
strToken String containing token(s)
strDelimit Set of delimiter characters
--*/
WCHAR *
__cdecl
PAL_wcstok(WCHAR *strToken, const WCHAR *strDelimit)
{
CPalThread *pThread = NULL;
WCHAR *retval = NULL;
WCHAR *delim_ptr;
WCHAR *next_context; /* string to save in TLS for future calls */
PERF_ENTRY(wcstok);
ENTRY("PAL_wcstok (strToken=%p (%S), strDelimit=%p (%S))\n",
strToken?strToken:W16_NULLSTRING,
strToken?strToken:W16_NULLSTRING,
strDelimit?strDelimit:W16_NULLSTRING,
strDelimit?strDelimit:W16_NULLSTRING);
/* Get the per-thread buffer from the thread structure. */
pThread = InternalGetCurrentThread();
if(NULL == strDelimit)
{
ERROR("delimiter string is NULL\n");
goto done;
}
/* get token string from TLS if none is provided */
if(NULL == strToken)
{
TRACE("wcstok() called with NULL string, using previous string\n");
strToken = pThread->crtInfo.wcstokContext;
if(NULL == strToken)
{
ERROR("wcstok called with NULL string without a previous call\n");
goto done;
}
}
/* first, skip all leading delimiters */
while ((*strToken != '\0') && (PAL_wcschr(strDelimit,*strToken)))
{
strToken++;
}
/* if there were only delimiters, there's no string */
if('\0' == strToken[0])
{
TRACE("end of string already reached, returning NULL\n");
goto done;
}
/* we're now at the beginning of the token; look for the first delimiter */
delim_ptr = PAL_wcspbrk(strToken,strDelimit);
if(NULL == delim_ptr)
{
TRACE("no delimiters found, this is the last token\n");
/* place the next context at the end of the string, so that subsequent
calls will return NULL */
next_context = strToken+PAL_wcslen(strToken);
retval = strToken;
}
else
{
/* null-terminate current token */
*delim_ptr=0;
/* place the next context right after the delimiter */
next_context = delim_ptr+1;
retval = strToken;
TRACE("found delimiter; next token will be %p\n",next_context);
}
pThread->crtInfo.wcstokContext = next_context;
done:
LOGEXIT("PAL_wcstok() returns %p (%S)\n", retval?retval:W16_NULLSTRING, retval?retval:W16_NULLSTRING);
PERF_EXIT(wcstok);
return(retval);
}