line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Encode::Detect::Detector; |
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
|
2
|
|
|
2
|
|
107984
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
60
|
|
40
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
187
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
our $VERSION = "1.01"; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
require DynaLoader; |
45
|
|
|
|
|
|
|
our @ISA=qw(DynaLoader Exporter); |
46
|
|
|
|
|
|
|
Encode::Detect::Detector->bootstrap($VERSION); |
47
|
|
|
|
|
|
|
our @EXPORT=qw(detect); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
1; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
__END__ |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 NAME |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Encode::Detect::Detector - Detects the encoding of data |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 SYNOPSIS |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
use Encode::Detect::Detector; |
61
|
|
|
|
|
|
|
my $charset = detect($octets); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my $d = new Encode::Detect::Detector; |
64
|
|
|
|
|
|
|
$d->handle($octets); |
65
|
|
|
|
|
|
|
$d->handle($more_octets); |
66
|
|
|
|
|
|
|
$d->end; |
67
|
|
|
|
|
|
|
my $charset = $d->getresult; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 DESCRIPTION |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
This module provides an interface to Mozilla's universal charset |
72
|
|
|
|
|
|
|
detector, which detects the charset used to encode data. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 METHODS |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 $charset = Encode::Detect::Detector->detect($octets) |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Detect the charset used to encode the data in $octets and return the |
79
|
|
|
|
|
|
|
charset's name. Returns undef if the charset cannot be determined |
80
|
|
|
|
|
|
|
with sufficient confidence. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 $d = Encode::Detect::Detector->new() |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Creates a new C<Encode::Detect::Detector> object and returns it. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head2 $d->handle($octets) |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Provides an additional chunk of data to be examined by the detector. |
89
|
|
|
|
|
|
|
May be called multiple times. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Returns zero on success, nonzero if a memory allocation failed. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head2 $d->eof |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Informs the detector that there is no more data to be examined. In |
96
|
|
|
|
|
|
|
many cases, this is necessary in order for the detector to make a |
97
|
|
|
|
|
|
|
decision on the charset. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 $d->reset |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Resets the detector to its initial state. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head2 $d->getresult |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Returns the name of the detected charset or C<undef> if no charset has |
106
|
|
|
|
|
|
|
(yet) been decided upon. May be called at any time. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 SEE ALSO |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
L<Encode::Detect> |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 AUTHOR |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
John Gardiner Myers <jgmyers@proofpoint.com> |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 SUPPORT |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
For help and thank you notes, e-mail the author directly. To report a |
119
|
|
|
|
|
|
|
bug, submit a patch, or add to the wishlist please visit the CPAN bug |
120
|
|
|
|
|
|
|
manager at: F<http://rt.cpan.org> |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|