Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | .\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13 |
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 "2002-06-01" "perl v5.8.0" "Perl Programmers Reference Guide" | |
133 | .SH "NAME" | |
134 | Encode::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" | |
159 | Encode::Guess enables you to guess in what encoding a given data is | |
160 | encoded, or at least tries to. | |
161 | .SH "DESCRIPTION" | |
162 | .IX Header "DESCRIPTION" | |
163 | By 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 | |
169 | To use it more practically, you have to give the names of encodings to | |
170 | check (\fIsuspects\fR as follows). The name of suspects can either be | |
171 | canonical names or aliases. | |
172 | .PP | |
173 | .Vb 2 | |
174 | \& # tries all major Japanese Encodings as well | |
175 | \& use Encode::Guess qw/euc-jp shiftjis 7bit-jis/; | |
176 | .Ve | |
177 | .IP "Encode::Guess\->set_suspects" 4 | |
178 | .IX Item "Encode::Guess->set_suspects" | |
179 | You can also change the internal suspects list via \f(CW\*(C`set_suspects\*(C'\fR | |
180 | method. | |
181 | .Sp | |
182 | .Vb 2 | |
183 | \& use Encode::Guess; | |
184 | \& Encode::Guess->set_suspects(qw/euc-jp shiftjis 7bit-jis/); | |
185 | .Ve | |
186 | .IP "Encode::Guess\->add_suspects" 4 | |
187 | .IX Item "Encode::Guess->add_suspects" | |
188 | Or you can use \f(CW\*(C`add_suspects\*(C'\fR method. The difference is that | |
189 | \&\f(CW\*(C`set_suspects\*(C'\fR flushes the current suspects list while | |
190 | \&\f(CW\*(C`add_suspects\*(C'\fR adds. | |
191 | .Sp | |
192 | .Vb 5 | |
193 | \& use Encode::Guess; | |
194 | \& Encode::Guess->add_suspects(qw/euc-jp shiftjis 7bit-jis/); | |
195 | \& # now the suspects are euc-jp,shiftjis,7bit-jis, AND | |
196 | \& # euc-kr,euc-cn, and big5-eten | |
197 | \& Encode::Guess->add_suspects(qw/euc-kr euc-cn big5-eten/); | |
198 | .Ve | |
199 | .ie n .IP "Encode::decode(""Guess"" ...)" 4 | |
200 | .el .IP "Encode::decode(``Guess'' ...)" 4 | |
201 | .IX Item "Encode::decode(Guess ...)" | |
202 | When you are content with suspects list, you can now | |
203 | .Sp | |
204 | .Vb 1 | |
205 | \& my $utf8 = Encode::decode("Guess", $data); | |
206 | .Ve | |
207 | .IP "Encode::Guess\->guess($data)" 4 | |
208 | .IX Item "Encode::Guess->guess($data)" | |
209 | But it will croak if Encode::Guess fails to eliminate all other | |
210 | suspects but the right one or no suspect was good. So you should | |
211 | instead try this; | |
212 | .Sp | |
213 | .Vb 1 | |
214 | \& my $decoder = Encode::Guess->guess($data); | |
215 | .Ve | |
216 | .Sp | |
217 | On success, \f(CW$decoder\fR is an object that is documented in | |
218 | Encode::Encoding. So you can now do this; | |
219 | .Sp | |
220 | .Vb 1 | |
221 | \& my $utf8 = $decoder->decode($data); | |
222 | .Ve | |
223 | .Sp | |
224 | On failure, \f(CW$decoder\fR now contains an error message so the whole thing | |
225 | would be as follows; | |
226 | .Sp | |
227 | .Vb 3 | |
228 | \& my $decoder = Encode::Guess->guess($data); | |
229 | \& die $decoder unless ref($decoder); | |
230 | \& my $utf8 = $decoder->decode($data); | |
231 | .Ve | |
232 | .IP "guess_encoding($data, [, \fIlist of suspects\fR])" 4 | |
233 | .IX Item "guess_encoding($data, [, list of suspects])" | |
234 | You can also try \f(CW\*(C`guess_encoding\*(C'\fR function which is exported by | |
235 | default. It takes \f(CW$data\fR to check and it also takes the list of | |
236 | suspects by option. The optional suspect list is \fInot reflected\fR to | |
237 | the internal suspects list. | |
238 | .Sp | |
239 | .Vb 5 | |
240 | \& my $decoder = guess_encoding($data, qw/euc-jp euc-kr euc-cn/); | |
241 | \& die $decoder unless ref($decoder); | |
242 | \& my $utf8 = $decoder->decode($data); | |
243 | \& # check only ascii and utf8 | |
244 | \& my $decoder = guess_encoding($data); | |
245 | .Ve | |
246 | .SH "CAVEATS" | |
247 | .IX Header "CAVEATS" | |
248 | .IP "\(bu" 4 | |
249 | Because of the algorithm used, \s-1ISO\-8859\s0 series and other single-byte | |
250 | encodings do not work well unless either one of \s-1ISO\-8859\s0 is the only | |
251 | one suspect (besides ascii and utf8). | |
252 | .Sp | |
253 | .Vb 5 | |
254 | \& use Encode::Guess; | |
255 | \& # perhaps ok | |
256 | \& my $decoder = guess_encoding($data, 'latin1'); | |
257 | \& # definitely NOT ok | |
258 | \& my $decoder = guess_encoding($data, qw/latin1 greek/); | |
259 | .Ve | |
260 | .Sp | |
261 | The reason is that Encode::Guess guesses encoding by trial and error. | |
262 | It first splits \f(CW$data\fR into lines and tries to decode the line for each | |
263 | suspect. It keeps it going until all but one encoding was eliminated | |
264 | out of suspects list. \s-1ISO\-8859\s0 series is just too successful for most | |
265 | cases (because it fills almost all code points in \ex00\-\exff). | |
266 | .IP "\(bu" 4 | |
267 | Do not mix national standard encodings and the corresponding vendor | |
268 | encodings. | |
269 | .Sp | |
270 | .Vb 3 | |
271 | \& # a very bad idea | |
272 | \& my $decoder | |
273 | \& = guess_encoding($data, qw/shiftjis MacJapanese cp932/); | |
274 | .Ve | |
275 | .Sp | |
276 | The reason is that vendor encoding is usually a superset of national | |
277 | standard so it becomes too ambiguous for most cases. | |
278 | .IP "\(bu" 4 | |
279 | On the other hand, mixing various national standard encodings | |
280 | automagically works unless \f(CW$data\fR is too short to allow for guessing. | |
281 | .Sp | |
282 | .Vb 6 | |
283 | \& # This is ok if $data is long enough | |
284 | \& my $decoder = | |
285 | \& guess_encoding($data, qw/euc-cn | |
286 | \& euc-jp shiftjis 7bit-jis | |
287 | \& euc-kr | |
288 | \& big5-eten/); | |
289 | .Ve | |
290 | .IP "\(bu" 4 | |
291 | \&\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! | |
292 | .Sp | |
293 | .Vb 2 | |
294 | \& my $decoder = guess_encoding($data, | |
295 | \& Encode->encodings(":all")); | |
296 | .Ve | |
297 | .PP | |
298 | It is, after all, just a guess. You should alway be explicit when it | |
299 | comes to encodings. But there are some, especially Japanese, | |
300 | environment that guess-coding is a must. Use this module with care. | |
301 | .SH "TO DO" | |
302 | .IX Header "TO DO" | |
303 | Encode::Guess does not work on \s-1EBCDIC\s0 platforms. | |
304 | .SH "SEE ALSO" | |
305 | .IX Header "SEE ALSO" | |
306 | Encode, Encode::Encoding |