1CHARSETS(7) Linux Programmer's Manual CHARSETS(7)
2
3
4
6 charsets - programmer's view of character sets and internationalization
7
9 Linux is an international operating system. Various of its utilities
10 and device drivers (including the console driver) support multilingual
11 character sets including Latin-alphabet letters with diacritical marks,
12 accents, ligatures, and entire non-Latin alphabets including Greek,
13 Cyrillic, Arabic, and Hebrew.
14
15 This manual page presents a programmer's-eye view of different charac‐
16 ter-set standards and how they fit together on Linux. Standards dis‐
17 cussed include ASCII, ISO 8859, KOI8-R, Unicode, ISO 2022 and ISO 4873.
18 The primary emphasis is on character sets actually used as locale char‐
19 acter sets, not the myriad others that can be found in data from other
20 systems.
21
22 A complete list of charsets used in a officially supported locale in
23 glibc 2.2.3 is: ISO-8859-{1,2,3,5,6,7,8,9,13,15}, CP1251, UTF-8,
24 EUC-{KR,JP,TW}, KOI8-{R,U}, GB2312, GB18030, GBK, BIG5, BIG5-HKSCS and
25 TIS-620 (in no particular order.) (Romanian may be switching to
26 ISO-8859-16.)
27
28
30 ASCII (American Standard Code For Information Interchange) is the orig‐
31 inal 7-bit character set, originally designed for American English. It
32 is currently described by the ECMA-6 standard.
33
34 Various ASCII variants replacing the dollar sign with other currency
35 symbols and replacing punctuation with non-English alphabetic charac‐
36 ters to cover German, French, Spanish and others in 7 bits exist. All
37 are deprecated; GNU libc doesn't support locales whose character sets
38 aren't true supersets of ASCII. (These sets are also known as ISO-646,
39 a close relative of ASCII that permitted replacing these characters.)
40
41 As Linux was written for hardware designed in the US, it natively sup‐
42 ports ASCII.
43
44
46 ISO 8859 is a series of 15 8-bit character sets all of which have US
47 ASCII in their low (7-bit) half, invisible control characters in posi‐
48 tions 128 to 159, and 96 fixed-width graphics in positions 160-255.
49
50 Of these, the most important is ISO 8859-1 (Latin-1). It is natively
51 supported in the Linux console driver, fairly well supported in X11R6,
52 and is the base character set of HTML.
53
54 Console support for the other 8859 character sets is available under
55 Linux through user-mode utilities (such as setfont(8)) that modify key‐
56 board bindings and the EGA graphics table and employ the "user mapping"
57 font table in the console driver.
58
59 Here are brief descriptions of each set:
60
61 8859-1 (Latin-1)
62 Latin-1 covers most Western European languages such as Albanian,
63 Catalan, Danish, Dutch, English, Faroese, Finnish, French, Ger‐
64 man, Galician, Irish, Icelandic, Italian, Norwegian, Portuguese,
65 Spanish, and Swedish. The lack of the ligatures Dutch ij, French
66 oe and old-style ,,German`` quotation marks is considered toler‐
67 able.
68
69 8859-2 (Latin-2)
70 Latin-2 supports most Latin-written Slavic and Central European
71 languages: Croatian, Czech, German, Hungarian, Polish, Rumanian,
72 Slovak, and Slovene.
73
74 8859-3 (Latin-3)
75 Latin-3 is popular with authors of Esperanto, Galician, and Mal‐
76 tese. (Turkish is now written with 8859-9 instead.)
77
78 8859-4 (Latin-4)
79 Latin-4 introduced letters for Estonian, Latvian, and Lithua‐
80 nian. It is essentially obsolete; see 8859-10 (Latin-6) and
81 8859-13 (Latin-7).
82
83 8859-5 Cyrillic letters supporting Bulgarian, Byelorussian, Macedonian,
84 Russian, Serbian and Ukrainian. Ukrainians read the letter
85 `ghe' with downstroke as `heh' and would need a ghe with
86 upstroke to write a correct ghe. See the discussion of KOI8-R
87 below.
88
89 8859-6 Supports Arabic. The 8859-6 glyph table is a fixed font of sep‐
90 arate letter forms, but a proper display engine should combine
91 these using the proper initial, medial, and final forms.
92
93 8859-7 Supports Modern Greek.
94
95 8859-8 Supports modern Hebrew without niqud (punctuation signs). Niqud
96 and full-fledged Biblical Hebrew are outside the scope of this
97 character set; under Linux, UTF-8 is the preferred encoding for
98 these.
99
100 8859-9 (Latin-5)
101 This is a variant of Latin-1 that replaces Icelandic letters
102 with Turkish ones.
103
104 8859-10 (Latin-6)
105 Latin 6 adds the last Inuit (Greenlandic) and Sami (Lappish)
106 letters that were missing in Latin 4 to cover the entire Nordic
107 area. RFC 1345 listed a preliminary and different `latin6'.
108 Skolt Sami still needs a few more accents than these.
109
110 8859-11
111 This only exists as a rejected draft standard. The draft stan‐
112 dard was identical to TIS-620, which is used under Linux for
113 Thai.
114
115 8859-12
116 This set does not exist. While Vietnamese has been suggested for
117 this space, it does not fit within the 96 (non-combining) char‐
118 acters ISO 8859 offers. UTF-8 is the preferred character set for
119 Vietnamese use under Linux.
120
121 8859-13 (Latin-7)
122 Supports the Baltic Rim languages; in particular, it includes
123 Latvian characters not found in Latin-4.
124
125 8859-14 (Latin-8)
126 This is the Celtic character set, covering Gaelic and Welsh.
127 This charset also contains the dotted characters needed for Old
128 Irish.
129
130 8859-15 (Latin-9)
131 This adds the Euro sign and French and Finnish letters that were
132 missing in Latin-1.
133
134 8859-16 (Latin-10)
135 This set covers many of the languages covered by 8859-2, and
136 supports Romanian more completely then that set does.
137
139 KOI8-R is a non-ISO character set popular in Russia. The lower half is
140 US ASCII; the upper is a Cyrillic character set somewhat better
141 designed than ISO 8859-5. KOI8-U is a common character set, based off
142 KOI8-R, that has better support for Ukrainian. Neither of these sets
143 are ISO-2022 compatible, unlike the ISO-8859 series.
144
145 Console support for KOI8-R is available under Linux through user-mode
146 utilities that modify keyboard bindings and the EGA graphics table, and
147 employ the "user mapping" font table in the console driver.
148
149
151 JIS X 0208 is a Japanese national standard character set. Though there
152 are some more Japanese national standard character sets (like JIS X
153 0201, JIS X 0212, and JIS X 0213), this is the most important one.
154 Characters are mapped into a 94x94 two-byte matrix, whose each byte is
155 in the range 0x21-0x7e. Note that JIS X 0208 is a character set, not an
156 encoding. This means that JIS X 0208 itself is not used for expressing
157 text data. JIS X 0208 is used as a component to construct encodings
158 such as EUC-JP, Shift_JIS, and ISO-2022-JP. EUC-JP is the most impor‐
159 tant encoding for Linux and includes US ASCII and JIS X 0208. In EUC-
160 JP, JIS X 0208 characters are expressed in two bytes, each of which is
161 the JIS X 0208 code plus 0x80.
162
163
165 KS X 1001 is a Korean national standard character set. Just as JIS X
166 0208, characters are mapped into a 94x94 two-byte matrix. KS X 1001 is
167 used like JIS X 0208, as a component to construct encodings such as
168 EUC-KR, Johab, and ISO-2022-KR. EUC-KR is the most important encoding
169 for Linux and includes US ASCII and KS X 1001. KS C 5601 is an older
170 name for KS X 1001.
171
172
174 GB 2312 is a mainland Chinese national standard character set used to
175 express simplified Chinese. Just like JIS X 0208, characters are mapped
176 into a 94x94 two-byte matrix used to construct EUC-CN. EUC-CN is the
177 most important encoding for Linux and includes US ASCII and GB 2312.
178 Note that EUC-CN is often called as GB, GB 2312, or CN-GB.
179
180
182 Big5 is a popular character set in Taiwan to express traditional Chi‐
183 nese. (Big5 is both a character set and an encoding.) It is a superset
184 of US ASCII. Non-ASCII characters are expressed in two bytes. Bytes
185 0xa1-0xfe are used as leading bytes for two-byte characters. Big5 and
186 its extension is widely used in Taiwan and Hong Kong. It is not ISO
187 2022-compliant.
188
189
191 TIS 620 is a Thai national standard character set and a superset of US
192 ASCII. Like ISO 8859 series, Thai characters are mapped into 0xa1-0xfe.
193 TIS 620 is the only commonly used character set under Linux besides
194 UTF-8 to have combining characters.
195
196
198 Unicode (ISO 10646) is a standard which aims to unambiguously represent
199 every character in every human language. Unicode's structure permits
200 20.1 bits to encode every character. Since most computers don't include
201 20.1-bit integers, Unicode is usually encoded as 32-bit integers inter‐
202 nally and either a series of 16-bit integers (UTF-16) (needing two
203 16-bit integers only when encoding certain rare characters) or a series
204 of 8-bit bytes (UTF-8). Information on Unicode is available at
205 <http://www.unicode.com>.
206
207 Linux represents Unicode using the 8-bit Unicode Transformation Format
208 (UTF-8). UTF-8 is a variable length encoding of Unicode. It uses 1
209 byte to code 7 bits, 2 bytes for 11 bits, 3 bytes for 16 bits, 4 bytes
210 for 21 bits, 5 bytes for 26 bits, 6 bytes for 31 bits.
211
212 Let 0,1,x stand for a zero, one, or arbitrary bit. A byte 0xxxxxxx
213 stands for the Unicode 00000000 0xxxxxxx which codes the same symbol as
214 the ASCII 0xxxxxxx. Thus, ASCII goes unchanged into UTF-8, and people
215 using only ASCII do not notice any change: not in code, and not in file
216 size.
217
218 A byte 110xxxxx is the start of a 2-byte code, and 110xxxxx 10yyyyyy is
219 assembled into 00000xxx xxyyyyyy. A byte 1110xxxx is the start of a
220 3-byte code, and 1110xxxx 10yyyyyy 10zzzzzz is assembled into xxxxyyyy
221 yyzzzzzz. (When UTF-8 is used to code the 31-bit ISO 10646 then this
222 progression continues up to 6-byte codes.)
223
224 For most people who use ISO-8859 character sets, this means that the
225 characters outside of ASCII are now coded with two bytes. This tends to
226 expand ordinary text files by only one or two percent. For Russian or
227 Greek users, this expands ordinary text files by 100%, since text in
228 those languages is mostly outside of ASCII. For Japanese users this
229 means that the 16-bit codes now in common use will take three bytes.
230 While there are algorithmic conversions from some character sets (esp.
231 ISO-8859-1) to Unicode, general conversion requires carrying around
232 conversion tables, which can be quite large for 16-bit codes.
233
234 Note that UTF-8 is self-synchronizing: 10xxxxxx is a tail, any other
235 byte is the head of a code. Note that the only way ASCII bytes occur
236 in a UTF-8 stream, is as themselves. In particular, there are no embed‐
237 ded NULs ('\0') or '/'s that form part of some larger code.
238
239 Since ASCII, and, in particular, NUL and '/', are unchanged, the kernel
240 does not notice that UTF-8 is being used. It does not care at all what
241 the bytes it is handling stand for.
242
243 Rendering of Unicode data streams is typically handled through `sub‐
244 font' tables which map a subset of Unicode to glyphs. Internally the
245 kernel uses Unicode to describe the subfont loaded in video RAM. This
246 means that in UTF-8 mode one can use a character set with 512 different
247 symbols. This is not enough for Japanese, Chinese and Korean, but it
248 is enough for most other purposes.
249
250 At the current time, the console driver does not handle combining char‐
251 acters. So Thai, Sioux and any other script needing combining charac‐
252 ters can't be handled on the console.
253
254
256 The ISO 2022 and 4873 standards describe a font-control model based on
257 VT100 practice. This model is (partially) supported by the Linux ker‐
258 nel and by xterm(1). It is popular in Japan and Korea.
259
260 There are 4 graphic character sets, called G0, G1, G2 and G3, and one
261 of them is the current character set for codes with high bit zero (ini‐
262 tially G0), and one of them is the current character set for codes with
263 high bit one (initially G1). Each graphic character set has 94 or 96
264 characters, and is essentially a 7-bit character set. It uses codes
265 either 040-0177 (041-0176) or 0240-0377 (0241-0376). G0 always has
266 size 94 and uses codes 041-0176.
267
268 Switching between character sets is done using the shift functions ^N
269 (SO or LS1), ^O (SI or LS0), ESC n (LS2), ESC o (LS3), ESC N (SS2), ESC
270 O (SS3), ESC ~ (LS1R), ESC } (LS2R), ESC | (LS3R). The function LSn
271 makes character set Gn the current one for codes with high bit zero.
272 The function LSnR makes character set Gn the current one for codes with
273 high bit one. The function SSn makes character set Gn (n=2 or 3) the
274 current one for the next character only (regardless of the value of its
275 high order bit).
276
277 A 94-character set is designated as Gn character set by an escape
278 sequence ESC ( xx (for G0), ESC ) xx (for G1), ESC * xx (for G2), ESC +
279 xx (for G3), where xx is a symbol or a pair of symbols found in the ISO
280 2375 International Register of Coded Character Sets. For example, ESC
281 ( @ selects the ISO 646 character set as G0, ESC ( A selects the UK
282 standard character set (with pound instead of number sign), ESC ( B
283 selects ASCII (with dollar instead of currency sign), ESC ( M selects a
284 character set for African languages, ESC ( ! A selects the Cuban char‐
285 acter set, etc. etc.
286
287 A 96-character set is designated as Gn character set by an escape
288 sequence ESC - xx (for G1), ESC . xx (for G2) or ESC / xx (for G3).
289 For example, ESC - G selects the Hebrew alphabet as G1.
290
291 A multibyte character set is designated as Gn character set by an
292 escape sequence ESC $ xx or ESC $ ( xx (for G0), ESC $ ) xx (for G1),
293 ESC $ * xx (for G2), ESC $ + xx (for G3). For example, ESC $ ( C
294 selects the Korean character set for G0. The Japanese character set
295 selected by ESC $ B has a more recent version selected by ESC & @ ESC $
296 B.
297
298 ISO 4873 stipulates a narrower use of character sets, where G0 is fixed
299 (always ASCII), so that G1, G2 and G3 can only be invoked for codes
300 with the high order bit set. In particular, ^N and ^O are not used
301 anymore, ESC ( xx can be used only with xx=B, and ESC ) xx, ESC * xx,
302 ESC + xx are equivalent to ESC - xx, ESC . xx, ESC / xx, respectively.
303
304
306 console(4), console_codes(4), console_ioctl(4), ascii(7),
307 iso_8859-1(7), unicode(7), utf-8(7)
308
309
310
311Linux 2001-05-07 CHARSETS(7)