strtok.c (985B)
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 const char* sepp; 11 int c, sc; 12 char* tok; 13 14 if (s1 == NULL) { 15 if (*lasts == NULL) { 16 return NULL; 17 } 18 19 s1 = *lasts; 20 } 21 22 for (; (c = *s1) != 0; s1++) { 23 for (sepp = s2; (sc = *sepp) != 0; sepp++) { 24 if (c == sc) { 25 break; 26 } 27 } 28 if (sc == 0) { 29 break; 30 } 31 } 32 33 if (c == 0) { 34 *lasts = NULL; 35 return NULL; 36 } 37 38 tok = s1++; 39 40 for (; (c = *s1) != 0; s1++) { 41 for (sepp = s2; (sc = *sepp) != 0; sepp++) { 42 if (c == sc) { 43 *s1++ = '\0'; 44 *lasts = s1; 45 return tok; 46 } 47 } 48 } 49 *lasts = NULL; 50 return tok; 51 }