Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/string bring in EXAMPLES from openbsd.



details:   https://anonhg.NetBSD.org/src/rev/07b412fde6c4
branches:  trunk
changeset: 535149:07b412fde6c4
user:      yamt <yamt%NetBSD.org@localhost>
date:      Sun Aug 11 09:39:10 2002 +0000

description:
bring in EXAMPLES from openbsd.

diffstat:

 lib/libc/string/strspn.3 |  18 ++++++++++++++++--
 lib/libc/string/strtok.3 |  39 +++++++++++++++++++++++++++++++++++++--
 2 files changed, 53 insertions(+), 4 deletions(-)

diffs (93 lines):

diff -r f1760d3a9161 -r 07b412fde6c4 lib/libc/string/strspn.3
--- a/lib/libc/string/strspn.3  Sun Aug 11 09:36:15 2002 +0000
+++ b/lib/libc/string/strspn.3  Sun Aug 11 09:39:10 2002 +0000
@@ -34,9 +34,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     from: @(#)strspn.3     8.1 (Berkeley) 6/4/93
-.\"    $NetBSD: strspn.3,v 1.7 2002/02/07 07:00:33 ross Exp $
+.\"    $NetBSD: strspn.3,v 1.8 2002/08/11 09:39:10 yamt Exp $
 .\"
-.Dd June 4, 1993
+.Dd August 11, 2002
 .Dt STRSPN 3
 .Os
 .Sh NAME
@@ -63,6 +63,20 @@
 .Fn strspn
 function
 returns the number of characters spanned.
+.Sh EXAMPLES
+The following call to
+.Fn strspn
+will return 3, since the first three characters of string
+.Fa s
+are part of string
+.Fa charset :
+.Bd -literal -offset indent
+char *s = "foobar";
+char *charset = "of";
+size_t span;
+
+span = strspn(s, charset);
+.Ed
 .Sh SEE ALSO
 .Xr index 3 ,
 .Xr memchr 3 ,
diff -r f1760d3a9161 -r 07b412fde6c4 lib/libc/string/strtok.3
--- a/lib/libc/string/strtok.3  Sun Aug 11 09:36:15 2002 +0000
+++ b/lib/libc/string/strtok.3  Sun Aug 11 09:39:10 2002 +0000
@@ -34,9 +34,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     from: @(#)strtok.3     8.2 (Berkeley) 2/3/94
-.\"    $NetBSD: strtok.3,v 1.15 2002/02/07 07:00:33 ross Exp $
+.\"    $NetBSD: strtok.3,v 1.16 2002/08/11 09:48:26 yamt Exp $
 .\"
-.Dd February 3, 1994
+.Dd August 11, 2002
 .Dt STRTOK 3
 .Os
 .Sh NAME
@@ -95,6 +95,41 @@
 it is not necessary to delineate tokenizing to a single string at a time
 when using
 .Fn strtok_r .
+.Sh EXAMPLES
+The following will construct an array of pointers to each individual word in
+the string
+.Va s :
+.Bd -literal -offset indent
+#define MAXTOKENS      128
+
+char s[512], *p, *tokens[MAXTOKENS];
+char *last;
+int i = 0;
+
+snprintf(s, sizeof(s), "cat dog horse cow");
+
+for ((p = strtok_r(s, " ", &last)); p;
+    (p = strtok_r(NULL, " ", &last)), i++) {
+       if (i < MAXTOKENS - 1)
+               tokens[i] = p;
+}
+tokens[i] = NULL;
+.Ed
+.Pp
+That is,
+.Li tokens[0]
+will point to
+.Qq cat ,
+.Li tokens[1]
+will point to
+.Qq dog ,
+.Li tokens[2]
+will point to
+.Qq horse ,
+and
+.Li tokens[3]
+will point to
+.Qq cow .
 .Sh SEE ALSO
 .Xr index 3 ,
 .Xr memchr 3 ,



Home | Main Index | Thread Index | Old Index