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