xref: /minix3/lib/libc/string/wcstok.3 (revision 2fe8fb192fe7e8720e3e7a77f928da545e872a6a)
1*2fe8fb19SBen Gras.\" $NetBSD: wcstok.3,v 1.6 2010/12/16 17:42:28 wiz Exp $
2*2fe8fb19SBen Gras.\"
3*2fe8fb19SBen Gras.\" Copyright (c) 1998 Softweyr LLC.  All rights reserved.
4*2fe8fb19SBen Gras.\"
5*2fe8fb19SBen Gras.\" strtok_r, from Berkeley strtok
6*2fe8fb19SBen Gras.\" Oct 13, 1998 by Wes Peters <wes@softweyr.com>
7*2fe8fb19SBen Gras.\"
8*2fe8fb19SBen Gras.\" Copyright (c) 1988, 1991, 1993
9*2fe8fb19SBen Gras.\"	The Regents of the University of California.  All rights reserved.
10*2fe8fb19SBen Gras.\"
11*2fe8fb19SBen Gras.\" This code is derived from software contributed to Berkeley by
12*2fe8fb19SBen Gras.\" the American National Standards Committee X3, on Information
13*2fe8fb19SBen Gras.\" Processing Systems.
14*2fe8fb19SBen Gras.\"
15*2fe8fb19SBen Gras.\" Redistribution and use in source and binary forms, with or without
16*2fe8fb19SBen Gras.\" modification, are permitted provided that the following conditions
17*2fe8fb19SBen Gras.\" are met:
18*2fe8fb19SBen Gras.\"
19*2fe8fb19SBen Gras.\" 1. Redistributions of source code must retain the above copyright
20*2fe8fb19SBen Gras.\"    notices, this list of conditions and the following disclaimer.
21*2fe8fb19SBen Gras.\"
22*2fe8fb19SBen Gras.\" 2. Redistributions in binary form must reproduce the above
23*2fe8fb19SBen Gras.\"    copyright notices, this list of conditions and the following
24*2fe8fb19SBen Gras.\"    disclaimer in the documentation and/or other materials provided
25*2fe8fb19SBen Gras.\"    with the distribution.
26*2fe8fb19SBen Gras.\"
27*2fe8fb19SBen Gras.\" 3. All advertising materials mentioning features or use of this
28*2fe8fb19SBen Gras.\"    software must display the following acknowledgement:
29*2fe8fb19SBen Gras.\"
30*2fe8fb19SBen Gras.\"	This product includes software developed by Softweyr LLC, the
31*2fe8fb19SBen Gras.\"      University of California, Berkeley, and its contributors.
32*2fe8fb19SBen Gras.\"
33*2fe8fb19SBen Gras.\" 4. Neither the name of Softweyr LLC, the University nor the names
34*2fe8fb19SBen Gras.\"    of its contributors may be used to endorse or promote products
35*2fe8fb19SBen Gras.\"    derived from this software without specific prior written
36*2fe8fb19SBen Gras.\"    permission.
37*2fe8fb19SBen Gras.\"
38*2fe8fb19SBen Gras.\" THIS SOFTWARE IS PROVIDED BY SOFTWEYR LLC, THE REGENTS AND
39*2fe8fb19SBen Gras.\" CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
40*2fe8fb19SBen Gras.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
41*2fe8fb19SBen Gras.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
42*2fe8fb19SBen Gras.\" DISCLAIMED.  IN NO EVENT SHALL SOFTWEYR LLC, THE REGENTS, OR
43*2fe8fb19SBen Gras.\" CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44*2fe8fb19SBen Gras.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
45*2fe8fb19SBen Gras.\" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
46*2fe8fb19SBen Gras.\" USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
47*2fe8fb19SBen Gras.\" ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
48*2fe8fb19SBen Gras.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
49*2fe8fb19SBen Gras.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50*2fe8fb19SBen Gras.\" SUCH DAMAGE.
51*2fe8fb19SBen Gras.\"
52*2fe8fb19SBen Gras.\" Original version ID:
53*2fe8fb19SBen Gras.\" FreeBSD: src/lib/libc/string/wcstok.3,v 1.4 2002/10/15 09:49:54 tjr Exp
54*2fe8fb19SBen Gras.\"
55*2fe8fb19SBen Gras.Dd October 3, 2002
56*2fe8fb19SBen Gras.Dt WCSTOK 3
57*2fe8fb19SBen Gras.Os
58*2fe8fb19SBen Gras.Sh NAME
59*2fe8fb19SBen Gras.Nm wcstok
60*2fe8fb19SBen Gras.Nd split wide-character string into tokens
61*2fe8fb19SBen Gras.Sh LIBRARY
62*2fe8fb19SBen Gras.Lb libc
63*2fe8fb19SBen Gras.Sh SYNOPSIS
64*2fe8fb19SBen Gras.In wchar.h
65*2fe8fb19SBen Gras.Ft wchar_t *
66*2fe8fb19SBen Gras.Fn wcstok "wchar_t * restrict str" "const wchar_t * restrict sep" "wchar_t ** restrict last"
67*2fe8fb19SBen Gras.Sh DESCRIPTION
68*2fe8fb19SBen GrasThe
69*2fe8fb19SBen Gras.Fn wcstok
70*2fe8fb19SBen Grasfunction
71*2fe8fb19SBen Grasis used to isolate sequential tokens in a nul-terminated wide-character
72*2fe8fb19SBen Grasstring,
73*2fe8fb19SBen Gras.Fa str .
74*2fe8fb19SBen GrasThese tokens are separated in the string by at least one of the
75*2fe8fb19SBen Grascharacters in
76*2fe8fb19SBen Gras.Fa sep .
77*2fe8fb19SBen GrasThe first time that
78*2fe8fb19SBen Gras.Fn wcstok
79*2fe8fb19SBen Grasis called,
80*2fe8fb19SBen Gras.Fa str
81*2fe8fb19SBen Grasshould be specified; subsequent calls, wishing to obtain further tokens
82*2fe8fb19SBen Grasfrom the same string, should pass a null pointer instead.
83*2fe8fb19SBen GrasThe separator string,
84*2fe8fb19SBen Gras.Fa sep ,
85*2fe8fb19SBen Grasmust be supplied each time, and may change between calls.
86*2fe8fb19SBen GrasThe context pointer
87*2fe8fb19SBen Gras.Fa last
88*2fe8fb19SBen Grasmust be provided on each call.
89*2fe8fb19SBen Gras.Pp
90*2fe8fb19SBen GrasThe
91*2fe8fb19SBen Gras.Fn wcstok
92*2fe8fb19SBen Grasfunction is the wide-character counterpart of the
93*2fe8fb19SBen Gras.Fn strtok_r
94*2fe8fb19SBen Grasfunction.
95*2fe8fb19SBen Gras.Sh RETURN VALUES
96*2fe8fb19SBen GrasThe
97*2fe8fb19SBen Gras.Fn wcstok
98*2fe8fb19SBen Grasfunction
99*2fe8fb19SBen Grasreturns a pointer to the beginning of each subsequent token in the string,
100*2fe8fb19SBen Grasafter replacing the token itself with a nul wide character (L'\e0').
101*2fe8fb19SBen GrasWhen no more tokens remain, a null pointer is returned.
102*2fe8fb19SBen Gras.Sh EXAMPLES
103*2fe8fb19SBen GrasThe following code fragment splits a wide-character string on
104*2fe8fb19SBen Gras.Tn ASCII
105*2fe8fb19SBen Grasspace, tab and newline characters and writes the tokens to
106*2fe8fb19SBen Grasstandard output:
107*2fe8fb19SBen Gras.Bd -literal -offset indent
108*2fe8fb19SBen Grasconst wchar_t *seps = L" \et\en";
109*2fe8fb19SBen Graswchar_t *last, *tok, text[] = L" \enone\ettwo\et\etthree  \en";
110*2fe8fb19SBen Gras
111*2fe8fb19SBen Grasfor (tok = wcstok(text, seps, &last); tok != NULL;
112*2fe8fb19SBen Gras    tok = wcstok(NULL, seps, &last))
113*2fe8fb19SBen Gras	wprintf(L"%ls\en", tok);
114*2fe8fb19SBen Gras.Ed
115*2fe8fb19SBen Gras.Sh SEE ALSO
116*2fe8fb19SBen Gras.Xr strtok 3 ,
117*2fe8fb19SBen Gras.Xr wcschr 3 ,
118*2fe8fb19SBen Gras.Xr wcscspn 3 ,
119*2fe8fb19SBen Gras.Xr wcspbrk 3 ,
120*2fe8fb19SBen Gras.Xr wcsrchr 3 ,
121*2fe8fb19SBen Gras.Xr wcsspn 3
122*2fe8fb19SBen Gras.Sh STANDARDS
123*2fe8fb19SBen GrasThe
124*2fe8fb19SBen Gras.Fn wcstok
125*2fe8fb19SBen Grasfunction
126*2fe8fb19SBen Grasconforms to
127*2fe8fb19SBen Gras.St -isoC-99 .
128*2fe8fb19SBen Gras.Pp
129*2fe8fb19SBen GrasSome early implementations of
130*2fe8fb19SBen Gras.Fn wcstok
131*2fe8fb19SBen Grasomit the context pointer argument,
132*2fe8fb19SBen Gras.Fa last ,
133*2fe8fb19SBen Grasand maintain state across calls in a static variable like
134*2fe8fb19SBen Gras.Xr strtok 3
135*2fe8fb19SBen Grasdoes.
136