Added lib/tests/Makefile to the list of makefiles to be generated by

configure.
Modified files: configure configure.in
Bugzilla bug 106372: added new function PL_strtok_r.  The function was
implemented by Roland Mainz <Roland.Mainz@informatik.med.uni-giessen.de>.
Modified files: lib/libc/include/plstr.h lib/libc/src/Makefile.in
    lib/tests/string.c
Added file: lib/libc/src/strtok.c
This commit is contained in:
wtc%netscape.com 2001-10-31 23:49:52 +00:00
Родитель e7e8955c4c
Коммит cdc92528f7
6 изменённых файлов: 167 добавлений и 1 удалений

1
nsprpub/configure поставляемый
Просмотреть файл

@ -5378,6 +5378,7 @@ lib/ds/Makefile
lib/libc/Makefile
lib/libc/include/Makefile
lib/libc/src/Makefile
lib/tests/Makefile
pr/Makefile
pr/include/Makefile
pr/include/md/Makefile

Просмотреть файл

@ -2256,6 +2256,7 @@ lib/ds/Makefile
lib/libc/Makefile
lib/libc/include/Makefile
lib/libc/src/Makefile
lib/tests/Makefile
pr/Makefile
pr/include/Makefile
pr/include/md/Makefile

Просмотреть файл

@ -18,6 +18,7 @@
* Rights Reserved.
*
* Contributor(s):
* Roland Mainz <roland mainz@informatik.med.uni-giessen.de>
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU General Public License Version 2 or later (the
@ -434,7 +435,29 @@ PR_EXTERN(char *)
PL_strncaserstr(const char *big, const char *little, PRUint32 max);
/*
* Things not (yet?) included: strspn/strcspn, strtok/strtok_r, strsep.
* PL_strtok_r
*
* Splits the string s1 into tokens, separated by one or more characters
* from the separator string s2. The argument lasts points to a
* user-supplied char * pointer in which PL_strtok_r stores information
* for it to continue scanning the same string.
*
* In the first call to PL_strtok_r, s1 points to a string and the value
* of *lasts is ignored. PL_strtok_r returns a pointer to the first
* token, writes '\0' into the character following the first token, and
* updates *lasts.
*
* In subsequent calls, s1 is null and lasts must stay unchanged from the
* previous call. The separator string s2 may be different from call to
* call. PL_strtok_r returns a pointer to the next token in s1. When no
* token remains in s1, PL_strtok_r returns null.
*/
PR_EXTERN(char *)
PL_strtok_r(char *s1, const char *s2, char **lasts);
/*
* Things not (yet?) included: strspn/strcspn, strsep.
* memchr, memcmp, memcpy, memccpy, index, rindex, bcmp, bcopy, bzero.
* Any and all i18n/l10n stuff.
*/

Просмотреть файл

@ -57,6 +57,7 @@ CSRCS =\
strpbrk.c \
strstr.c \
strcstr.c \
strtok.c \
base64.c \
plerror.c \
plgetopt.c \

Просмотреть файл

@ -0,0 +1,86 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Netscape Portable Runtime (NSPR).
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2001 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Roland Mainz <roland mainz@informatik.med.uni-giessen.de>
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU General Public License Version 2 or later (the
* "GPL"), in which case the provisions of the GPL are applicable
* instead of those above. If you wish to allow use of your
* version of this file only under the terms of the GPL and not to
* allow others to use your version of this file under the MPL,
* indicate your decision by deleting the provisions above and
* replace them with the notice and other provisions required by
* the GPL. If you do not delete the provisions above, a recipient
* may use your version of this file under either the MPL or the
* GPL.
*/
#include "plstr.h"
PR_IMPLEMENT(char *)
PL_strtok_r(char *s1, const char *s2, char **lasts)
{
const char *sepp;
int c, sc;
char *tok;
if( s1 == NULL )
{
if( *lasts == NULL )
return NULL;
s1 = *lasts;
}
for( ; (c = *s1) != 0; s1++ )
{
for( sepp = s2 ; (sc = *sepp) != 0 ; sepp++ )
{
if( c == sc )
break;
}
if( sc == 0 )
break;
}
if( c == 0 )
{
*lasts = NULL;
return NULL;
}
tok = s1++;
for( ; (c = *s1) != 0; s1++ )
{
for( sepp = s2; (sc = *sepp) != 0; sepp++ )
{
if( c == sc )
{
*s1++ = '\0';
*lasts = s1;
return tok;
}
}
}
*lasts = NULL;
return tok;
}

Просмотреть файл

@ -3003,6 +3003,59 @@ PRBool test_030(void)
return PR_TRUE;
}
/* PL_strtok_r */
PRBool test_031(void)
{
static const char *tokens[] = {
"wtc", "relyea", "nelsonb", "jpierre", "nicolson",
"ian.mcgreer", "kirk.erickson", "sonja.mirtitsch", "mhein"
};
static const char *seps[] = {
", ", ",", " ", "\t", ",,,", " ,", " ", " \t\t", ","
};
static const char s2[] = ", \t";
char string[ 1024 ];
char *s1;
char *token;
char *lasts;
unsigned int i;
printf("Test 031 (PL_strtok_r) ..."); fflush(stdout);
/* Build the string. */
string[0] = '\0';
for( i = 0; i < sizeof(tokens)/sizeof(tokens[0]); i++ )
{
PL_strcat(string, tokens[i]);
PL_strcat(string, seps[i]);
}
/* Scan the string for tokens. */
i = 0;
s1 = string;
while( (token = PL_strtok_r(s1, s2, &lasts)) != NULL)
{
if( strcmp(token, tokens[i]) != 0 )
{
printf("FAIL wrong token scanned\n");
return PR_FALSE;
}
i++;
s1 = NULL;
}
if( i != sizeof(tokens)/sizeof(tokens[0]) )
{
printf("FAIL wrong number of tokens scanned\n");
return PR_FALSE;
}
printf("PASS\n");
return PR_TRUE;
}
int
main
(
@ -3044,6 +3097,7 @@ main
&& test_028()
&& test_029()
&& test_030()
&& test_031()
)
{
printf("Suite passed.\n");