michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "plstr.h" michael@0: michael@0: PR_IMPLEMENT(char *) michael@0: PL_strtok_r(char *s1, const char *s2, char **lasts) michael@0: { michael@0: const char *sepp; michael@0: int c, sc; michael@0: char *tok; michael@0: michael@0: if( s1 == NULL ) michael@0: { michael@0: if( *lasts == NULL ) michael@0: return NULL; michael@0: michael@0: s1 = *lasts; michael@0: } michael@0: michael@0: for( ; (c = *s1) != 0; s1++ ) michael@0: { michael@0: for( sepp = s2 ; (sc = *sepp) != 0 ; sepp++ ) michael@0: { michael@0: if( c == sc ) michael@0: break; michael@0: } michael@0: if( sc == 0 ) michael@0: break; michael@0: } michael@0: michael@0: if( c == 0 ) michael@0: { michael@0: *lasts = NULL; michael@0: return NULL; michael@0: } michael@0: michael@0: tok = s1++; michael@0: michael@0: for( ; (c = *s1) != 0; s1++ ) michael@0: { michael@0: for( sepp = s2; (sc = *sepp) != 0; sepp++ ) michael@0: { michael@0: if( c == sc ) michael@0: { michael@0: *s1++ = '\0'; michael@0: *lasts = s1; michael@0: return tok; michael@0: } michael@0: } michael@0: } michael@0: *lasts = NULL; michael@0: return tok; michael@0: }