1encoding(n)                  Tcl Built-In Commands                 encoding(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       encoding - Manipulate encodings
9

SYNOPSIS

11       encoding option ?arg arg ...?
12______________________________________________________________________________
13

INTRODUCTION

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
20       binary (which uses a single byte  per  character  but  only  handles  a
21       restricted  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

DESCRIPTION

29       Performs one of  several  encoding  related  operations,  depending  on
30       option.  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
36              sequence 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
42              result  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
50              describe 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
67              encoding is used whenever Tcl passes strings to system calls.
68

EXAMPLE

70       It  is  common  practice to write script files using a text editor that
71       produces output in the euc-jp  encoding,  which  represents  the  ASCII
72       characters  as  singe bytes and Japanese characters as two bytes.  This
73       makes it easy to embed literal strings  that  correspond  to  non-ASCII
74       characters  by  simply typing the strings in place in the script.  How‐
75       ever, because the source command always reads files using  the  current
76       system  encoding,  Tcl  will  only source such files correctly when the
77       encoding used to write the file is the same.  This tends not to be true
78       in  an  internationalized  setting.   For  example,  if such a file was
79       sourced in North America (where the ISO8859-1 is normally  used),  each
80       byte  in the file would be treated as a separate character that maps to
81       the 00 page in Unicode.  The resulting Tcl strings will not contain the
82       expected Japanese characters.  Instead, they will contain a sequence of
83       Latin-1 characters that correspond to the bytes of the original string.
84       The encoding command can be used to convert this string to the expected
85       Japanese Unicode characters.  For example,
86
87              set s [encoding convertfrom euc-jp "\xA4\xCF"]
88
89       would return the Unicode string “\u306F”, which is the Hiragana  letter
90       HA.
91

SEE ALSO

93       Tcl_GetEncoding(3)
94

KEYWORDS

96       encoding, unicode
97
98
99
100Tcl                                   8.1                          encoding(n)
Impressum