Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #include "plstr.h"
7 :
8 : PR_IMPLEMENT(char *)
9 : PL_strtok_r(char *s1, const char *s2, char **lasts)
10 : {
11 : const char *sepp;
12 : int c, sc;
13 : char *tok;
14 :
15 0 : if( s1 == NULL )
16 : {
17 0 : if( *lasts == NULL )
18 0 : return NULL;
19 :
20 0 : s1 = *lasts;
21 : }
22 :
23 0 : for( ; (c = *s1) != 0; s1++ )
24 : {
25 0 : for( sepp = s2 ; (sc = *sepp) != 0 ; sepp++ )
26 : {
27 0 : if( c == sc )
28 0 : break;
29 : }
30 0 : if( sc == 0 )
31 0 : break;
32 : }
33 :
34 0 : if( c == 0 )
35 : {
36 0 : *lasts = NULL;
37 0 : return NULL;
38 : }
39 :
40 0 : tok = s1++;
41 :
42 0 : for( ; (c = *s1) != 0; s1++ )
43 : {
44 0 : for( sepp = s2; (sc = *sepp) != 0; sepp++ )
45 : {
46 0 : if( c == sc )
47 : {
48 0 : *s1++ = '\0';
49 0 : *lasts = s1;
50 0 : return tok;
51 : }
52 : }
53 : }
54 0 : *lasts = NULL;
55 0 : return tok;
56 : }
|