line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::HTML5::Parser::Charset::UniversalCharDet; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
## skip Test::Tabs |
4
|
9
|
|
|
9
|
|
72
|
use strict; |
|
9
|
|
|
|
|
33
|
|
|
9
|
|
|
|
|
336
|
|
5
|
9
|
|
|
9
|
|
60
|
use warnings; |
|
9
|
|
|
|
|
20
|
|
|
9
|
|
|
|
|
265
|
|
6
|
9
|
|
|
9
|
|
3890
|
use IO::HTML (); |
|
9
|
|
|
|
|
15379
|
|
|
9
|
|
|
|
|
2190
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION='0.991'; |
9
|
|
|
|
|
|
|
our $DEBUG; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# this really shouldn't work, but for some reason it does... |
12
|
|
|
|
|
|
|
sub _detect { |
13
|
708
|
50
|
|
708
|
|
3265
|
return +{ encoding => 'UTF-8' } if !utf8::is_utf8($_[0]); # huh? |
14
|
0
|
|
|
|
|
0
|
open my $fh, '<:raw', \$_[0]; |
15
|
0
|
|
|
|
|
0
|
my $e = IO::HTML::sniff_encoding($fh => 'string'); |
16
|
0
|
0
|
|
|
|
0
|
return +{ encoding => $e } if defined $e; |
17
|
0
|
|
|
|
|
0
|
return +{}; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub detect_byte_string ($$) { |
21
|
708
|
|
|
708
|
0
|
1406
|
my $de; |
22
|
|
|
|
|
|
|
eval { |
23
|
708
|
|
|
|
|
1744
|
$de = _detect $_[1]; |
24
|
708
|
|
|
|
|
1955
|
1; |
25
|
708
|
50
|
|
|
|
1348
|
} or do { |
26
|
0
|
0
|
|
|
|
0
|
warn $@ unless $DEBUG; |
27
|
0
|
0
|
|
|
|
0
|
die $@ if $DEBUG; |
28
|
|
|
|
|
|
|
}; |
29
|
708
|
50
|
33
|
|
|
10610
|
if (defined $de and defined $de->{encoding}) { |
30
|
708
|
|
|
|
|
2958
|
return lc $de->{encoding}; |
31
|
|
|
|
|
|
|
} else { |
32
|
0
|
|
|
|
|
|
return undef; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} # detect_byte_string |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
#Copyright 2007-2011 Wakaba |
37
|
|
|
|
|
|
|
#Copyright 2009-2012 Toby Inkster |
38
|
|
|
|
|
|
|
# |
39
|
|
|
|
|
|
|
#This library is free software; you can redistribute it |
40
|
|
|
|
|
|
|
#and/or modify it under the same terms as Perl itself. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
1; |