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