]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/locale/multibyte.3
contrib/tzdata: import tzdata 2023d
[FreeBSD/FreeBSD.git] / lib / libc / locale / multibyte.3
1 .\" Copyright (c) 2002-2004 Tim J. Robbins. All rights reserved.
2 .\" Copyright (c) 1993
3 .\"     The Regents of the University of California.  All rights reserved.
4 .\"
5 .\" This code is derived from software contributed to Berkeley by
6 .\" Donn Seeley of BSDI.
7 .\"
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
10 .\" are met:
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\"    notice, this list of conditions and the following disclaimer.
13 .\" 2. Redistributions in binary form must reproduce the above copyright
14 .\"    notice, this list of conditions and the following disclaimer in the
15 .\"    documentation and/or other materials provided with the distribution.
16 .\" 3. Neither the name of the University nor the names of its contributors
17 .\"    may be used to endorse or promote products derived from this software
18 .\"    without specific prior written permission.
19 .\"
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" SUCH DAMAGE.
31 .\"
32 .Dd September 9, 2019
33 .Dt MULTIBYTE 3
34 .Os
35 .Sh NAME
36 .Nm multibyte
37 .Nd multibyte and wide character manipulation functions
38 .Sh LIBRARY
39 .Lb libc
40 .Sh SYNOPSIS
41 .In limits.h
42 .In stdlib.h
43 .In wchar.h
44 .Sh DESCRIPTION
45 The basic elements of some written natural languages, such as Chinese,
46 cannot be represented uniquely with single C
47 .Vt char Ns s .
48 The C standard supports two different ways of dealing with
49 extended natural language encodings:
50 wide characters and
51 multibyte characters.
52 Wide characters are an internal representation
53 which allows each basic element to map
54 to a single object of type
55 .Vt wchar_t .
56 Multibyte characters are used for input and output
57 and code each basic element as a sequence of C
58 .Vt char Ns s .
59 Individual basic elements may map into one or more
60 (up to
61 .Dv MB_LEN_MAX )
62 bytes in a multibyte character.
63 .Pp
64 The current locale
65 .Pq Xr setlocale 3
66 governs the interpretation of wide and multibyte characters.
67 The locale category
68 .Dv LC_CTYPE
69 specifically controls this interpretation.
70 The
71 .Vt wchar_t
72 type is wide enough to hold the largest value
73 in the wide character representations for all locales.
74 .Pp
75 Multibyte strings may contain
76 .Sq shift
77 indicators to switch to and from
78 particular modes within the given representation.
79 If explicit bytes are used to signal shifting,
80 these are not recognized as separate characters
81 but are lumped with a neighboring character.
82 There is always a distinguished
83 .Sq initial
84 shift state.
85 Some functions (e.g.,
86 .Xr mblen 3 ,
87 .Xr mbtowc 3
88 and
89 .Xr wctomb 3 )
90 maintain static shift state internally, whereas
91 others store it in an
92 .Vt mbstate_t
93 object passed by the caller.
94 Shift states are undefined after a call to
95 .Xr setlocale 3
96 with the
97 .Dv LC_CTYPE
98 or
99 .Dv LC_ALL
100 categories.
101 .Pp
102 For convenience in processing,
103 the wide character with value 0
104 (the null wide character)
105 is recognized as the wide character string terminator,
106 and the character with value 0
107 (the null byte)
108 is recognized as the multibyte character string terminator.
109 Null bytes are not permitted within multibyte characters.
110 .Pp
111 The C library provides the following functions for dealing with
112 multibyte characters:
113 .Bl -column "Description"
114 .It Sy "Function        Description"
115 .It Xr mblen 3 Ta "get number of bytes in a character"
116 .It Xr mbrlen 3 Ta "get number of bytes in a character (restartable)"
117 .It Xr mbrtowc 3 Ta "convert a character to a wide-character code (restartable)"
118 .It Xr mbsrtowcs 3 Ta "convert a character string to a wide-character string (restartable)"
119 .It Xr mbstowcs 3 Ta "convert a character string to a wide-character string"
120 .It Xr mbtowc 3 Ta "convert a character to a wide-character code"
121 .It Xr wcrtomb 3 Ta "convert a wide-character code to a character (restartable)"
122 .It Xr wcstombs 3 Ta "convert a wide-character string to a character string"
123 .It Xr wcsrtombs 3 Ta "convert a wide-character string to a character string (restartable)"
124 .It Xr wctomb 3 Ta "convert a wide-character code to a character"
125 .El
126 .Sh SEE ALSO
127 .Xr localedef 1 ,
128 .Xr setlocale 3 ,
129 .Xr stdio 3 ,
130 .Xr big5 5 ,
131 .Xr euc 5 ,
132 .Xr gb18030 5 ,
133 .Xr gb2312 5 ,
134 .Xr gbk 5 ,
135 .Xr mskanji 5 ,
136 .Xr utf8 5
137 .Sh STANDARDS
138 These functions conform to
139 .St -isoC-99 .