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
14

INTRODUCTION

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

DESCRIPTION

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 dirs ?directoryList?
41              Tcl can load encoding data  files  from  the  file  system  that │
42              describe  additional encodings for it to work with. This command │
43              sets the search path for *.enc encoding data files to  the  list │
44              of  directories  directoryList. If directoryList is omitted then │
45              the command returns the current list of directories that make up │
46              the  search  path.  It is an error for directoryList to not be a │
47              valid list. If, when a search for an encoding data file is  hap‐ │
48              pening,  an  element  in directoryList does not refer to a read‐ │
49              able, searchable directory, that element is ignored.
50
51       encoding names
52              Returns a list containing the names of all of the encodings that
53              are currently available.
54
55       encoding system ?encoding?
56              Set the system encoding to encoding. If encoding is omitted then
57              the command returns the current  system  encoding.   The  system
58              encoding is used whenever Tcl passes strings to system calls.
59

EXAMPLE

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

SEE ALSO

83       Tcl_GetEncoding(3)
84
85

KEYWORDS

87       encoding
88
89
90
91Tcl                                   8.1                          encoding(n)
Impressum