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