Initial revision
[reactos.git] / reactos / ntoskrnl / rtl / strtok.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/rtl/strtok.c
5 * PURPOSE: Unicode and thread safe implementation of strtok
6 * PROGRAMMER: David Welch (welch@mcmail.com)
7 * UPDATE HISTORY:
8 * Created 22/05/98
9 */
10
11 /* INCLUDES *****************************************************************/
12
13 #include <internal/kernel.h>
14 #include <internal/linkage.h>
15 #include <ddk/ntddk.h>
16
17 #include <internal/debug.h>
18
19
20 /* FUNCTIONS *****************************************************************/
21
22 PWSTR RtlStrtok(PUNICODE_STRING _string, PWSTR _sep,
23 PWSTR* temp)
24 /*
25 * FUNCTION: Splits a string into tokens
26 * ARGUMENTS:
27 * string = string to operate on
28 * if NULL then continue with previous string
29 * sep = Token deliminators
30 * temp = Tempory storage provided by the caller
31 * ARGUMENTS: Returns the beginning of the next token
32 */
33 {
34 PWSTR string;
35 PWSTR sep;
36 PWSTR start;
37
38 if (_string!=NULL)
39 {
40 string = _string->Buffer;
41 }
42 else
43 {
44 string = *temp;
45 }
46
47 start = string;
48
49 while ((*string)!=0)
50 {
51 sep = _sep;
52 while ((*sep)!=0)
53 {
54 if ((*string)==(*sep))
55 {
56 *string=0;
57 *temp=string+1;
58 return(start);
59 }
60 sep++;
61 }
62 string++;
63 }
64 *temp=NULL;
65 return(start);
66 }