1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/nsprpub/lib/libc/src/strtok.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,56 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "plstr.h" 1.10 + 1.11 +PR_IMPLEMENT(char *) 1.12 +PL_strtok_r(char *s1, const char *s2, char **lasts) 1.13 +{ 1.14 + const char *sepp; 1.15 + int c, sc; 1.16 + char *tok; 1.17 + 1.18 + if( s1 == NULL ) 1.19 + { 1.20 + if( *lasts == NULL ) 1.21 + return NULL; 1.22 + 1.23 + s1 = *lasts; 1.24 + } 1.25 + 1.26 + for( ; (c = *s1) != 0; s1++ ) 1.27 + { 1.28 + for( sepp = s2 ; (sc = *sepp) != 0 ; sepp++ ) 1.29 + { 1.30 + if( c == sc ) 1.31 + break; 1.32 + } 1.33 + if( sc == 0 ) 1.34 + break; 1.35 + } 1.36 + 1.37 + if( c == 0 ) 1.38 + { 1.39 + *lasts = NULL; 1.40 + return NULL; 1.41 + } 1.42 + 1.43 + tok = s1++; 1.44 + 1.45 + for( ; (c = *s1) != 0; s1++ ) 1.46 + { 1.47 + for( sepp = s2; (sc = *sepp) != 0; sepp++ ) 1.48 + { 1.49 + if( c == sc ) 1.50 + { 1.51 + *s1++ = '\0'; 1.52 + *lasts = s1; 1.53 + return tok; 1.54 + } 1.55 + } 1.56 + } 1.57 + *lasts = NULL; 1.58 + return tok; 1.59 +}