encoding(3,n)(n) Tcl Built-In Commands encoding(3,n)(n) NAME encoding(3,n) - Manipulate encodings SYNOPSIS encoding(3,n) option ?arg arg ...? INTRODUCTION Strings in(1,8) Tcl are encoded using 16-bit Unicode characters. Different operating system interfaces or applications may generate strings in(1,8) other encodings such as Shift-JIS. The encoding(3,n) command helps to bridge the gap between Unicode and these other formats. DESCRIPTION Performs one of several encoding(3,n) related operations, depending on option. The legal options are: encoding(3,n) convertfrom ?encoding(3,n)? data Convert data to Unicode from the specified encoding(3,n). The char- acters in(1,8) data are treated as binary data where the lower 8-bits of each character is taken as a single byte. The resulting sequence of bytes is treated as a string(3,n) in(1,8) the specified encod- ing. If encoding(3,n) is not specified, the current system encoding(3,n) is used. encoding(3,n) convertto ?encoding(3,n)? string(3,n) Convert string(3,n) from Unicode to the specified encoding(3,n). The result is a sequence of bytes that represents the converted string. Each byte is stored in(1,8) the lower 8-bits of a Unicode character. If encoding(3,n) is not specified, the current system encoding(3,n) is used. encoding(3,n) names Returns a list containing the names of all of the encodings that are currently available. encoding(3,n) system ?encoding(3,n)? Set the system encoding(3,n) to encoding(3,n). If encoding(3,n) is omitted then the command returns the current system encoding. The system encoding(3,n) is used whenever Tcl passes strings to system calls. EXAMPLE It is common practice to write(1,2) script files using a text editor that produces output in(1,8) the euc-jp encoding(3,n), which represents the ASCII characters as singe bytes and Japanese characters as two bytes. This makes it easy to embed literal strings that correspond to non-ASCII characters by simply typing the strings in(1,8) place in(1,8) the script. How- ever, because the source command always reads files using the current system encoding(3,n), Tcl will only source such files correctly when the encoding(3,n) used to write(1,2) the file(1,n) is the same. This tends not to be true in(1,8) an internationalized setting. For example, if(3,n) such a file(1,n) was sourced in(1,8) North America (where the ISO8859-1 is normally used), each byte in(1,8) the file(1,n) would be treated as a separate character that maps to the 00 page in(1,8) Unicode. The resulting Tcl strings will not contain the expected Japanese characters. Instead, they will contain a sequence of Latin-1 characters that correspond to the bytes of the original string. The encoding(3,n) command can be used to convert this string(3,n) to the expected Japanese Unicode characters. For example, set(7,n,1 builtins) s [encoding(3,n) con- vertfrom euc-jp "\xA4\xCF"] would return the Unicode string(3,n) "\u306F", which is the Hiragana letter HA. SEE ALSO Tcl_GetEncoding(3) KEYWORDS encoding(3,n) Tcl 8.1 encoding(3,n)(n)