Debian Codegraph @

doc/encoding.n

raw
1 '\"
2 '\" Copyright (c) 1998 Scriptics Corporation.
3 '\"
4 '\" See the file "license.terms" for information on usage and redistribution
5 '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
6 '\"
7 .TH encoding n "8.1" Tcl "Tcl Built-In Commands"
8 .so man.macros
9 .BS
10 .SH NAME
11 encoding \- Manipulate encodings
12 .SH SYNOPSIS
13 \fBencoding \fIoption\fR ?\fIarg arg ...\fR?
14 .BE
15 .SH INTRODUCTION
16 .PP
17 Strings in Tcl are logically a sequence of 16-bit Unicode characters.
18 These strings are represented in memory as a sequence of bytes that
19 may be in one of several encodings: modified UTF\-8 (which uses 1 to 3
20 bytes per character), 16-bit
21 .QW Unicode
22 (which uses 2 bytes per character, with an endianness that is
23 dependent on the host architecture), and binary (which uses a single
24 byte per character but only handles a restricted range of characters).
25 Tcl does not guarantee to always use the same encoding for the same
26 string.
27 .PP
28 Different operating system interfaces or applications may generate
29 strings in other encodings such as Shift\-JIS. The \fBencoding\fR
30 command helps to bridge the gap between Unicode and these other
31 formats.
32 .SH DESCRIPTION
33 .PP
34 Performs one of several encoding related operations, depending on
35 \fIoption\fR. The legal \fIoption\fRs are:
36 .\" METHOD: convertfrom
37 .TP
38 \fBencoding convertfrom\fR ?\fIencoding\fR? \fIdata\fR
39 .
40 Convert \fIdata\fR to Unicode from the specified \fIencoding\fR. The
41 characters in \fIdata\fR are treated as binary data where the lower
42 8-bits of each character is taken as a single byte. The resulting
43 sequence of bytes is treated as a string in the specified
44 \fIencoding\fR. If \fIencoding\fR is not specified, the current
45 system encoding is used.
46 .\" METHOD: convertto
47 .TP
48 \fBencoding convertto\fR ?\fIencoding\fR? \fIstring\fR
49 .
50 Convert \fIstring\fR from Unicode to the specified \fIencoding\fR.
51 The result is a sequence of bytes that represents the converted
52 string. Each byte is stored in the lower 8-bits of a Unicode
53 character (indeed, the resulting string is a binary string as far as
54 Tcl is concerned, at least initially). If \fIencoding\fR is not
55 specified, the current system encoding is used.
56 .\" METHOD: dirs
57 .TP
58 \fBencoding dirs\fR ?\fIdirectoryList\fR?
59 .
60 Tcl can load encoding data files from the file system that describe
61 additional encodings for it to work with. This command sets the search
62 path for \fB*.enc\fR encoding data files to the list of directories
63 \fIdirectoryList\fR. If \fIdirectoryList\fR is omitted then the
64 command returns the current list of directories that make up the
65 search path. It is an error for \fIdirectoryList\fR to not be a valid
66 list. If, when a search for an encoding data file is happening, an
67 element in \fIdirectoryList\fR does not refer to a readable,
68 searchable directory, that element is ignored.
69 .\" METHOD: names
70 .TP
71 \fBencoding names\fR
72 .
73 Returns a list containing the names of all of the encodings that are
74 currently available.
75 The encodings
76 .QW utf-8
77 and
78 .QW iso8859-1
79 are guaranteed to be present in the list.
80 .\" METHOD: system
81 .TP
82 \fBencoding system\fR ?\fIencoding\fR?
83 .
84 Set the system encoding to \fIencoding\fR. If \fIencoding\fR is
85 omitted then the command returns the current system encoding. The
86 system encoding is used whenever Tcl passes strings to system calls.
87 .SH EXAMPLE
88 .PP
89 The following example converts a byte sequence in Japanese euc-jp encoding to a TCL string:
90 .PP
91 .CS
92 set s [\fBencoding convertfrom\fR euc-jp "\exA4\exCF"]
93 .CE
94 .PP
95 The result is the unicode codepoint:
96 .QW "\eu306F" ,
97 which is the Hiragana letter HA.
98 .SH "SEE ALSO"
99 Tcl_GetEncoding(3), fconfigure(n)
100 .SH KEYWORDS
101 encoding, unicode
102 .\" Local Variables:
103 .\" mode: nroff
104 .\" End: