OSDN Git Service

Updated to tcl 8.4.1
[pf3gnuchains/pf3gnuchains3x.git] / tcl / doc / encoding.n
1 '\"
2 '\" Copyright (c) 1998 by 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 '\" RCS: @(#) $Id$
8 '\" 
9 .so man.macros
10 .TH encoding n "8.1" Tcl "Tcl Built-In Commands"
11 .BS
12 .SH NAME
13 encoding \- Manipulate encodings
14 .SH SYNOPSIS
15 \fBencoding \fIoption\fR ?\fIarg arg ...\fR?
16 .BE
17
18 .SH INTRODUCTION
19 .PP
20 Strings in Tcl are encoded using 16-bit Unicode characters.  Different
21 operating system interfaces or applications may generate strings in
22 other encodings such as Shift-JIS.  The \fBencoding\fR command helps
23 to bridge the gap between Unicode and these other formats.
24
25 .SH DESCRIPTION
26 .PP
27 Performs one of several encoding related operations, depending on
28 \fIoption\fR.  The legal \fIoption\fRs are:
29 .TP
30 \fBencoding convertfrom ?\fIencoding\fR? \fIdata\fR
31 Convert \fIdata\fR to Unicode from the specified \fIencoding\fR.  The
32 characters in \fIdata\fR are treated as binary data where the lower
33 8-bits of each character is taken as a single byte.  The resulting
34 sequence of bytes is treated as a string in the specified
35 \fIencoding\fR.  If \fIencoding\fR is not specified, the current
36 system encoding is used.
37 .TP
38 \fBencoding convertto ?\fIencoding\fR? \fIstring\fR
39 Convert \fIstring\fR from Unicode to the specified \fIencoding\fR.
40 The result is a sequence of bytes that represents the converted
41 string.  Each byte is stored in the lower 8-bits of a Unicode
42 character.  If \fIencoding\fR is not specified, the current
43 system encoding is used.
44 .TP
45 \fBencoding names\fR
46 Returns a list containing the names of all of the encodings that are
47 currently available. 
48 .TP
49 \fBencoding system\fR ?\fIencoding\fR?
50 Set the system encoding to \fIencoding\fR. If \fIencoding\fR is
51 omitted then the command returns the current system encoding.  The
52 system encoding is used whenever Tcl passes strings to system calls.
53
54 .SH EXAMPLE
55 .PP
56 It is common practice to write script files using a text editor that
57 produces output in the euc-jp encoding, which represents the ASCII
58 characters as singe bytes and Japanese characters as two bytes.  This
59 makes it easy to embed literal strings that correspond to non-ASCII
60 characters by simply typing the strings in place in the script.
61 However, because the \fBsource\fR command always reads files using the
62 ISO8859-1 encoding, Tcl will treat each byte in the file as a separate
63 character that maps to the 00 page in Unicode.  The
64 resulting Tcl strings will not contain the expected Japanese
65 characters.  Instead, they will contain a sequence of Latin-1
66 characters that correspond to the bytes of the original string.  The
67 \fBencoding\fR command can be used to convert this string to the
68 expected Japanese Unicode characters.  For example,
69 .CS
70         set s [encoding convertfrom euc-jp "\\xA4\\xCF"]
71 .CE
72 would return the Unicode string "\\u306F", which is the Hiragana
73 letter HA.
74
75 .SH "SEE ALSO"
76 Tcl_GetEncoding(3)
77
78 .SH KEYWORDS
79 encoding