summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwtc%netscape.com <devnull@localhost>2001-11-01 00:03:48 +0000
committerwtc%netscape.com <devnull@localhost>2001-11-01 00:03:48 +0000
commit73837b3a39b8d0fda0f1d69911f549c4cdc7eb26 (patch)
treee8f3e470b236fc196f8f717c413c4b047ffb90b7
parentc97f2b8898ea39f2317394cb054ce5f460a407fc (diff)
downloadnspr-hg-73837b3a39b8d0fda0f1d69911f549c4cdc7eb26.tar.gz
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 Tag: NSPRPUB_PRE_4_2_CLIENT_BRANCH
-rwxr-xr-xconfigure1
-rw-r--r--configure.in1
-rw-r--r--lib/libc/include/plstr.h25
-rw-r--r--lib/libc/src/Makefile.in1
-rw-r--r--lib/tests/string.c54
5 files changed, 81 insertions, 1 deletions
diff --git a/configure b/configure
index 0b5cbbbe..53fe6545 100755
--- a/configure
+++ b/configure
@@ -5379,6 +5379,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
diff --git a/configure.in b/configure.in
index 48e28bc3..dd839c92 100644
--- a/configure.in
+++ b/configure.in
@@ -2257,6 +2257,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
diff --git a/lib/libc/include/plstr.h b/lib/libc/include/plstr.h
index b619a934..551567e4 100644
--- a/lib/libc/include/plstr.h
+++ b/lib/libc/include/plstr.h
@@ -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.
*/
diff --git a/lib/libc/src/Makefile.in b/lib/libc/src/Makefile.in
index d79b9c9a..2977399e 100644
--- a/lib/libc/src/Makefile.in
+++ b/lib/libc/src/Makefile.in
@@ -57,6 +57,7 @@ CSRCS =\
strpbrk.c \
strstr.c \
strcstr.c \
+ strtok.c \
base64.c \
plerror.c \
plgetopt.c \
diff --git a/lib/tests/string.c b/lib/tests/string.c
index 895189c3..ec839752 100644
--- a/lib/tests/string.c
+++ b/lib/tests/string.c
@@ -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( PL_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");