1encoding(n) Tcl Built-In Commands encoding(n)
2
3
4
5______________________________________________________________________________
6
8 encoding - Manipulate encodings
9
11 encoding option ?arg arg ...?
12_________________________________________________________________
13
14
16 Strings in Tcl are encoded using 16-bit Unicode characters. Different
17 operating system interfaces or applications may generate strings in
18 other encodings such as Shift-JIS. The encoding command helps to
19 bridge the gap between Unicode and these other formats.
20
22 Performs one of several encoding related operations, depending on
23 option. The legal options are:
24
25 encoding convertfrom ?encoding? data
26 Convert data to Unicode from the specified encoding. The char‐
27 acters in data are treated as binary data where the lower 8-bits
28 of each character is taken as a single byte. The resulting
29 sequence of bytes is treated as a string in the specified encod‐
30 ing. If encoding is not specified, the current system encoding
31 is used.
32
33 encoding convertto ?encoding? string
34 Convert string from Unicode to the specified encoding. The
35 result is a sequence of bytes that represents the converted
36 string. Each byte is stored in the lower 8-bits of a Unicode
37 character. If encoding is not specified, the current system
38 encoding is used.
39
40 encoding names
41 Returns a list containing the names of all of the encodings that
42 are currently available.
43
44 encoding system ?encoding?
45 Set the system encoding to encoding. If encoding is omitted then
46 the command returns the current system encoding. The system
47 encoding is used whenever Tcl passes strings to system calls.
48
50 It is common practice to write script files using a text editor that
51 produces output in the euc-jp encoding, which represents the ASCII
52 characters as singe bytes and Japanese characters as two bytes. This
53 makes it easy to embed literal strings that correspond to non-ASCII
54 characters by simply typing the strings in place in the script. How‐
55 ever, because the source command always reads files using the current
56 system encoding, Tcl will only source such files correctly when the
57 encoding used to write the file is the same. This tends not to be true
58 in an internationalized setting. For example, if such a file was
59 sourced in North America (where the ISO8859-1 is normally used), each
60 byte in the file would be treated as a separate character that maps to
61 the 00 page in Unicode. The resulting Tcl strings will not contain the
62 expected Japanese characters. Instead, they will contain a sequence of
63 Latin-1 characters that correspond to the bytes of the original string.
64 The encoding command can be used to convert this string to the expected
65 Japanese Unicode characters. For example,
66 set s [encoding convertfrom euc-jp "\xA4\xCF"]
67 would return the Unicode string "\u306F", which is the Hiragana letter
68 HA.
69
70
72 Tcl_GetEncoding(3)
73
74
76 encoding
77
78
79
80Tcl 8.1 encoding(n)