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
15 Strings in Tcl are logically a sequence of 16-bit Unicode characters.
16 These strings are represented in memory as a sequence of bytes that may
17 be in one of several encodings: modified UTF-8 (which uses 1 to 3 bytes
18 per character), 16-bit “Unicode” (which uses 2 bytes per character,
19 with an endianness that is dependent on the host architecture), and bi‐
20 nary (which uses a single byte per character but only handles a re‐
21 stricted range of characters). Tcl does not guarantee to always use
22 the same encoding for the same string.
23
24 Different operating system interfaces or applications may generate
25 strings in other encodings such as Shift-JIS. The encoding command
26 helps to bridge the gap between Unicode and these other formats.
27
29 Performs one of several encoding related operations, depending on op‐
30 tion. The legal options are:
31
32 encoding convertfrom ?encoding? data
33 Convert data to Unicode from the specified encoding. The char‐
34 acters in data are treated as binary data where the lower 8-bits
35 of each character is taken as a single byte. The resulting se‐
36 quence of bytes is treated as a string in the specified encod‐
37 ing. If encoding is not specified, the current system encoding
38 is used.
39
40 encoding convertto ?encoding? string
41 Convert string from Unicode to the specified encoding. The re‐
42 sult is a sequence of bytes that represents the converted
43 string. Each byte is stored in the lower 8-bits of a Unicode
44 character (indeed, the resulting string is a binary string as
45 far as Tcl is concerned, at least initially). If encoding is
46 not specified, the current system encoding is used.
47
48 encoding dirs ?directoryList?
49 Tcl can load encoding data files from the file system that de‐
50 scribe additional encodings for it to work with. This command
51 sets the search path for *.enc encoding data files to the list
52 of directories directoryList. If directoryList is omitted then
53 the command returns the current list of directories that make up
54 the search path. It is an error for directoryList to not be a
55 valid list. If, when a search for an encoding data file is hap‐
56 pening, an element in directoryList does not refer to a read‐
57 able, searchable directory, that element is ignored.
58
59 encoding names
60 Returns a list containing the names of all of the encodings that
61 are currently available. The encodings “utf-8” and “iso8859-1”
62 are guaranteed to be present in the list.
63
64 encoding system ?encoding?
65 Set the system encoding to encoding. If encoding is omitted then
66 the command returns the current system encoding. The system en‐
67 coding is used whenever Tcl passes strings to system calls.
68
70 The following example converts a byte sequence in Japanese euc-jp en‐
71 coding to a TCL string:
72
73 set s [encoding convertfrom euc-jp "\xA4\xCF"]
74
75 The result is the unicode codepoint: “\u306F”, which is the Hiragana
76 letter HA.
77
79 Tcl_GetEncoding(3)
80
82 encoding, unicode
83
84
85
86Tcl 8.1 encoding(n)