blob: a240945769b43295327fd0c2c60b253b1b6df0c0 [file] [log] [blame]
rsc76193d72003-09-30 17:47:42 +00001.TH UTF 7
2.SH NAME
3UTF, Unicode, ASCII, rune \- character set and format
4.SH DESCRIPTION
5The Plan 9 character set and representation are
6based on the Unicode Standard and on the ISO multibyte
7.SM UTF-8
8encoding (Universal Character
9Set Transformation Format, 8 bits wide).
10The Unicode Standard represents its characters in 16
11bits;
12.SM UTF-8
13represents such
14values in an 8-bit byte stream.
15Throughout this manual,
16.SM UTF-8
17is shortened to
18.SM UTF.
19.PP
20In Plan 9, a
21.I rune
22is a 16-bit quantity representing a Unicode character.
23Internally, programs may store characters as runes.
24However, any external manifestation of textual information,
25in files or at the interface between programs, uses a
26machine-independent, byte-stream encoding called
27.SM UTF.
28.PP
29.SM UTF
30is designed so the 7-bit
31.SM ASCII
32set (values hexadecimal 00 to 7F),
33appear only as themselves
34in the encoding.
35Runes with values above 7F appear as sequences of two or more
36bytes with values only from 80 to FF.
37.PP
38The
39.SM UTF
40encoding of the Unicode Standard is backward compatible with
41.SM ASCII\c
42:
43programs presented only with
44.SM ASCII
45work on Plan 9
46even if not written to deal with
47.SM UTF,
48as do
49programs that deal with uninterpreted byte streams.
50However, programs that perform semantic processing on
51.SM ASCII
52graphic
53characters must convert from
54.SM UTF
55to runes
56in order to work properly with non-\c
57.SM ASCII
58input.
59See
rsc058b0112005-01-03 06:40:20 +000060.IR rune (3).
rsc76193d72003-09-30 17:47:42 +000061.PP
62Letting numbers be binary,
63a rune x is converted to a multibyte
64.SM UTF
65sequence
66as follows:
67.PP
6801. x in [00000000.0bbbbbbb] 0bbbbbbb
69.br
7010. x in [00000bbb.bbbbbbbb] 110bbbbb, 10bbbbbb
71.br
7211. x in [bbbbbbbb.bbbbbbbb] 1110bbbb, 10bbbbbb, 10bbbbbb
73.br
74.PP
75Conversion 01 provides a one-byte sequence that spans the
76.SM ASCII
77character set in a compatible way.
78Conversions 10 and 11 represent higher-valued characters
79as sequences of two or three bytes with the high bit set.
80Plan 9 does not support the 4, 5, and 6 byte sequences proposed by X-Open.
81When there are multiple ways to encode a value, for example rune 0,
82the shortest encoding is used.
83.PP
84In the inverse mapping,
85any sequence except those described above
86is incorrect and is converted to rune hexadecimal 0080.
87.SH "SEE ALSO"
88.IR ascii (1),
89.IR tcs (1),
90.IR rune (3),
91.IR "The Unicode Standard" .