line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Encode::Detect; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# * ***** BEGIN LICENSE BLOCK ***** |
4
|
|
|
|
|
|
|
# Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# The contents of this file are subject to the Mozilla Public License Version |
7
|
|
|
|
|
|
|
# 1.1 (the "License"); you may not use this file except in compliance with |
8
|
|
|
|
|
|
|
# the License. You may obtain a copy of the License at |
9
|
|
|
|
|
|
|
# http://www.mozilla.org/MPL/ |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
# Software distributed under the License is distributed on an "AS IS" basis, |
12
|
|
|
|
|
|
|
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
13
|
|
|
|
|
|
|
# for the specific language governing rights and limitations under the |
14
|
|
|
|
|
|
|
# License. |
15
|
|
|
|
|
|
|
# |
16
|
|
|
|
|
|
|
# The Original Code is Encode::Detect wrapper |
17
|
|
|
|
|
|
|
# |
18
|
|
|
|
|
|
|
# The Initial Developer of the Original Code is |
19
|
|
|
|
|
|
|
# Proofpoint, Inc. |
20
|
|
|
|
|
|
|
# Portions created by the Initial Developer are Copyright (C) 2005 |
21
|
|
|
|
|
|
|
# the Initial Developer. All Rights Reserved. |
22
|
|
|
|
|
|
|
# |
23
|
|
|
|
|
|
|
# Contributor(s): |
24
|
|
|
|
|
|
|
# |
25
|
|
|
|
|
|
|
# Alternatively, the contents of this file may be used under the terms of |
26
|
|
|
|
|
|
|
# either the GNU General Public License Version 2 or later (the "GPL"), or |
27
|
|
|
|
|
|
|
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
28
|
|
|
|
|
|
|
# in which case the provisions of the GPL or the LGPL are applicable instead |
29
|
|
|
|
|
|
|
# of those above. If you wish to allow use of your version of this file only |
30
|
|
|
|
|
|
|
# under the terms of either the GPL or the LGPL, and not to allow others to |
31
|
|
|
|
|
|
|
# use your version of this file under the terms of the MPL, indicate your |
32
|
|
|
|
|
|
|
# decision by deleting the provisions above and replace them with the notice |
33
|
|
|
|
|
|
|
# and other provisions required by the GPL or the LGPL. If you do not delete |
34
|
|
|
|
|
|
|
# the provisions above, a recipient may use your version of this file under |
35
|
|
|
|
|
|
|
# the terms of any one of the MPL, the GPL or the LGPL. |
36
|
|
|
|
|
|
|
# |
37
|
|
|
|
|
|
|
# ***** END LICENSE BLOCK ***** |
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
1
|
|
515
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
40
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
16
|
|
|
1
|
|
|
|
|
30
|
|
41
|
1
|
|
|
1
|
|
5
|
use base qw(Encode::Encoding); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
94
|
|
42
|
1
|
|
|
1
|
|
7
|
use Encode qw(find_encoding); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
94
|
|
43
|
1
|
|
|
1
|
|
410
|
use Encode::Detect::Detector; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
220
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
__PACKAGE__->Define(qw(Detect)); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
our $VERSION = "1.01"; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
0
|
1
|
0
|
sub perlio_ok { 0 } |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub decode ($$;$) { |
52
|
2
|
|
|
2
|
1
|
715
|
my ($self, $octets, $check) = @_; |
53
|
2
|
|
50
|
|
|
86
|
my $charset = detect($octets) || 'Windows-1252'; |
54
|
2
|
50
|
|
|
|
8
|
my $e = find_encoding($charset) or die "Unknown encoding: $charset"; |
55
|
2
|
|
50
|
|
|
7673
|
my $decoded = $e->decode($octets, $check || 0); |
56
|
2
|
50
|
|
|
|
12
|
$_[1] = $octets if $check; |
57
|
2
|
|
|
|
|
10
|
return $decoded; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
__END__ |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 NAME |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Encode::Detect - An Encode::Encoding subclass that detects the encoding of data |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 SYNOPSIS |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
use Encode; |
71
|
|
|
|
|
|
|
require Encode::Detect; |
72
|
|
|
|
|
|
|
my $utf8 = decode("Detect", $data); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 DESCRIPTION |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
This Perl module is an Encode::Encoding subclass that uses |
77
|
|
|
|
|
|
|
Encode::Detect::Detector to determine the charset of the input data |
78
|
|
|
|
|
|
|
and then decodes it using the encoder of the detected charset. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
It is similar to Encode::Guess, but does not require the configuration |
81
|
|
|
|
|
|
|
of a set of expected encodings. Like Encode::Guess, it only supports |
82
|
|
|
|
|
|
|
decoding--it cannot encode. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 SEE ALSO |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
L<Encode>, L<Encode::Encoding>, L<Encode::Detect::Detector> |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 AUTHOR |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
John Gardiner Myers <jgmyers@proofpoint.com> |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 SUPPORT |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
For help and thank you notes, e-mail the author directly. To report a |
95
|
|
|
|
|
|
|
bug, submit a patch, or add to the wishlist please visit the CPAN bug |
96
|
|
|
|
|
|
|
manager at: F<http://rt.cpan.org> |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|