Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v8plus / man / man3 / Encode::Guess.3
CommitLineData
920dae64
AT
1.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32
2.\"
3.\" Standard preamble:
4.\" ========================================================================
5.de Sh \" Subsection heading
6.br
7.if t .Sp
8.ne 5
9.PP
10\fB\\$1\fR
11.PP
12..
13.de Sp \" Vertical space (when we can't use .PP)
14.if t .sp .5v
15.if n .sp
16..
17.de Vb \" Begin verbatim text
18.ft CW
19.nf
20.ne \\$1
21..
22.de Ve \" End verbatim text
23.ft R
24.fi
25..
26.\" Set up some character translations and predefined strings. \*(-- will
27.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
28.\" double quote, and \*(R" will give a right double quote. | will give a
29.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
30.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
31.\" expand to `' in nroff, nothing in troff, for use with C<>.
32.tr \(*W-|\(bv\*(Tr
33.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
34.ie n \{\
35. ds -- \(*W-
36. ds PI pi
37. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
39. ds L" ""
40. ds R" ""
41. ds C` ""
42. ds C' ""
43'br\}
44.el\{\
45. ds -- \|\(em\|
46. ds PI \(*p
47. ds L" ``
48. ds R" ''
49'br\}
50.\"
51.\" If the F register is turned on, we'll generate index entries on stderr for
52.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
53.\" entries marked with X<> in POD. Of course, you'll have to process the
54.\" output yourself in some meaningful fashion.
55.if \nF \{\
56. de IX
57. tm Index:\\$1\t\\n%\t"\\$2"
58..
59. nr % 0
60. rr F
61.\}
62.\"
63.\" For nroff, turn off justification. Always turn off hyphenation; it makes
64.\" way too many mistakes in technical documents.
65.hy 0
66.if n .na
67.\"
68.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69.\" Fear. Run. Save yourself. No user-serviceable parts.
70. \" fudge factors for nroff and troff
71.if n \{\
72. ds #H 0
73. ds #V .8m
74. ds #F .3m
75. ds #[ \f1
76. ds #] \fP
77.\}
78.if t \{\
79. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80. ds #V .6m
81. ds #F 0
82. ds #[ \&
83. ds #] \&
84.\}
85. \" simple accents for nroff and troff
86.if n \{\
87. ds ' \&
88. ds ` \&
89. ds ^ \&
90. ds , \&
91. ds ~ ~
92. ds /
93.\}
94.if t \{\
95. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
101.\}
102. \" troff and (daisy-wheel) nroff accents
103.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110.ds ae a\h'-(\w'a'u*4/10)'e
111.ds Ae A\h'-(\w'A'u*4/10)'E
112. \" corrections for vroff
113.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115. \" for low resolution devices (crt and lpr)
116.if \n(.H>23 .if \n(.V>19 \
117\{\
118. ds : e
119. ds 8 ss
120. ds o a
121. ds d- d\h'-1'\(ga
122. ds D- D\h'-1'\(hy
123. ds th \o'bp'
124. ds Th \o'LP'
125. ds ae ae
126. ds Ae AE
127.\}
128.rm #[ #] #H #V #F C
129.\" ========================================================================
130.\"
131.IX Title "Encode::Guess 3"
132.TH Encode::Guess 3 "2001-09-21" "perl v5.8.8" "Perl Programmers Reference Guide"
133.SH "NAME"
134Encode::Guess \-\- Guesses encoding from data
135.SH "SYNOPSIS"
136.IX Header "SYNOPSIS"
137.Vb 1
138\& # if you are sure $data won't contain anything bogus
139.Ve
140.PP
141.Vb 4
142\& use Encode;
143\& use Encode::Guess qw/euc-jp shiftjis 7bit-jis/;
144\& my $utf8 = decode("Guess", $data);
145\& my $data = encode("Guess", $utf8); # this doesn't work!
146.Ve
147.PP
148.Vb 7
149\& # more elaborate way
150\& use Encode::Guess;
151\& my $enc = guess_encoding($data, qw/euc-jp shiftjis 7bit-jis/);
152\& ref($enc) or die "Can't guess: $enc"; # trap error this way
153\& $utf8 = $enc->decode($data);
154\& # or
155\& $utf8 = decode($enc->name, $data)
156.Ve
157.SH "ABSTRACT"
158.IX Header "ABSTRACT"
159Encode::Guess enables you to guess in what encoding a given data is
160encoded, or at least tries to.
161.SH "DESCRIPTION"
162.IX Header "DESCRIPTION"
163By default, it checks only ascii, utf8 and \s-1UTF\-16/32\s0 with \s-1BOM\s0.
164.PP
165.Vb 1
166\& use Encode::Guess; # ascii/utf8/BOMed UTF
167.Ve
168.PP
169To use it more practically, you have to give the names of encodings to
170check (\fIsuspects\fR as follows). The name of suspects can either be
171canonical names or aliases.
172.PP
173\&\s-1CAVEAT:\s0 Unlike \s-1UTF\-\s0(16|32), \s-1BOM\s0 in utf8 is \s-1NOT\s0 \s-1AUTOMATICALLY\s0 \s-1STRIPPED\s0.
174.PP
175.Vb 2
176\& # tries all major Japanese Encodings as well
177\& use Encode::Guess qw/euc-jp shiftjis 7bit-jis/;
178.Ve
179.PP
180If the \f(CW$Encode::Guess::NoUTFAutoGuess\fR variable is set to a true
181value, no heuristics will be applied to \s-1UTF8/16/32\s0, and the result
182will be limited to the suspects and \f(CW\*(C`ascii\*(C'\fR.
183.IP "Encode::Guess\->set_suspects" 4
184.IX Item "Encode::Guess->set_suspects"
185You can also change the internal suspects list via \f(CW\*(C`set_suspects\*(C'\fR
186method.
187.Sp
188.Vb 2
189\& use Encode::Guess;
190\& Encode::Guess->set_suspects(qw/euc-jp shiftjis 7bit-jis/);
191.Ve
192.IP "Encode::Guess\->add_suspects" 4
193.IX Item "Encode::Guess->add_suspects"
194Or you can use \f(CW\*(C`add_suspects\*(C'\fR method. The difference is that
195\&\f(CW\*(C`set_suspects\*(C'\fR flushes the current suspects list while
196\&\f(CW\*(C`add_suspects\*(C'\fR adds.
197.Sp
198.Vb 5
199\& use Encode::Guess;
200\& Encode::Guess->add_suspects(qw/euc-jp shiftjis 7bit-jis/);
201\& # now the suspects are euc-jp,shiftjis,7bit-jis, AND
202\& # euc-kr,euc-cn, and big5-eten
203\& Encode::Guess->add_suspects(qw/euc-kr euc-cn big5-eten/);
204.Ve
205.ie n .IP "Encode::decode(""Guess"" ...)" 4
206.el .IP "Encode::decode(``Guess'' ...)" 4
207.IX Item "Encode::decode(Guess ...)"
208When you are content with suspects list, you can now
209.Sp
210.Vb 1
211\& my $utf8 = Encode::decode("Guess", $data);
212.Ve
213.IP "Encode::Guess\->guess($data)" 4
214.IX Item "Encode::Guess->guess($data)"
215But it will croak if:
216.RS 4
217.IP "*" 4
218Two or more suspects remain
219.IP "*" 4
220No suspects left
221.RE
222.RS 4
223.Sp
224So you should instead try this;
225.Sp
226.Vb 1
227\& my $decoder = Encode::Guess->guess($data);
228.Ve
229.Sp
230On success, \f(CW$decoder\fR is an object that is documented in
231Encode::Encoding. So you can now do this;
232.Sp
233.Vb 1
234\& my $utf8 = $decoder->decode($data);
235.Ve
236.Sp
237On failure, \f(CW$decoder\fR now contains an error message so the whole thing
238would be as follows;
239.Sp
240.Vb 3
241\& my $decoder = Encode::Guess->guess($data);
242\& die $decoder unless ref($decoder);
243\& my $utf8 = $decoder->decode($data);
244.Ve
245.RE
246.IP "guess_encoding($data, [, \fIlist of suspects\fR])" 4
247.IX Item "guess_encoding($data, [, list of suspects])"
248You can also try \f(CW\*(C`guess_encoding\*(C'\fR function which is exported by
249default. It takes \f(CW$data\fR to check and it also takes the list of
250suspects by option. The optional suspect list is \fInot reflected\fR to
251the internal suspects list.
252.Sp
253.Vb 5
254\& my $decoder = guess_encoding($data, qw/euc-jp euc-kr euc-cn/);
255\& die $decoder unless ref($decoder);
256\& my $utf8 = $decoder->decode($data);
257\& # check only ascii and utf8
258\& my $decoder = guess_encoding($data);
259.Ve
260.SH "CAVEATS"
261.IX Header "CAVEATS"
262.IP "\(bu" 4
263Because of the algorithm used, \s-1ISO\-8859\s0 series and other single-byte
264encodings do not work well unless either one of \s-1ISO\-8859\s0 is the only
265one suspect (besides ascii and utf8).
266.Sp
267.Vb 5
268\& use Encode::Guess;
269\& # perhaps ok
270\& my $decoder = guess_encoding($data, 'latin1');
271\& # definitely NOT ok
272\& my $decoder = guess_encoding($data, qw/latin1 greek/);
273.Ve
274.Sp
275The reason is that Encode::Guess guesses encoding by trial and error.
276It first splits \f(CW$data\fR into lines and tries to decode the line for each
277suspect. It keeps it going until all but one encoding is eliminated
278out of suspects list. \s-1ISO\-8859\s0 series is just too successful for most
279cases (because it fills almost all code points in \ex00\-\exff).
280.IP "\(bu" 4
281Do not mix national standard encodings and the corresponding vendor
282encodings.
283.Sp
284.Vb 3
285\& # a very bad idea
286\& my $decoder
287\& = guess_encoding($data, qw/shiftjis MacJapanese cp932/);
288.Ve
289.Sp
290The reason is that vendor encoding is usually a superset of national
291standard so it becomes too ambiguous for most cases.
292.IP "\(bu" 4
293On the other hand, mixing various national standard encodings
294automagically works unless \f(CW$data\fR is too short to allow for guessing.
295.Sp
296.Vb 6
297\& # This is ok if $data is long enough
298\& my $decoder =
299\& guess_encoding($data, qw/euc-cn
300\& euc-jp shiftjis 7bit-jis
301\& euc-kr
302\& big5-eten/);
303.Ve
304.IP "\(bu" 4
305\&\s-1DO\s0 \s-1NOT\s0 \s-1PUT\s0 \s-1TOO\s0 \s-1MANY\s0 \s-1SUSPECTS\s0! Don't you try something like this!
306.Sp
307.Vb 2
308\& my $decoder = guess_encoding($data,
309\& Encode->encodings(":all"));
310.Ve
311.PP
312It is, after all, just a guess. You should alway be explicit when it
313comes to encodings. But there are some, especially Japanese,
314environment that guess-coding is a must. Use this module with care.
315.SH "TO DO"
316.IX Header "TO DO"
317Encode::Guess does not work on \s-1EBCDIC\s0 platforms.
318.SH "SEE ALSO"
319.IX Header "SEE ALSO"
320Encode, Encode::Encoding