line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::HTML5::Parser::Charset::UniversalCharDet; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
## skip Test::Tabs |
4
|
9
|
|
|
9
|
|
73
|
use strict; |
|
9
|
|
|
|
|
27
|
|
|
9
|
|
|
|
|
323
|
|
5
|
9
|
|
|
9
|
|
47
|
use warnings; |
|
9
|
|
|
|
|
21
|
|
|
9
|
|
|
|
|
292
|
|
6
|
9
|
|
|
9
|
|
3879
|
use IO::HTML (); |
|
9
|
|
|
|
|
15752
|
|
|
9
|
|
|
|
|
2313
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION='0.992'; |
9
|
|
|
|
|
|
|
our $DEBUG; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# this really shouldn't work, but for some reason it does... |
12
|
|
|
|
|
|
|
sub _detect { |
13
|
708
|
50
|
|
708
|
|
3393
|
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
|
1402
|
my $de; |
22
|
|
|
|
|
|
|
eval { |
23
|
708
|
|
|
|
|
1932
|
$de = _detect $_[1]; |
24
|
708
|
|
|
|
|
2087
|
1; |
25
|
708
|
50
|
|
|
|
1223
|
} or do { |
26
|
0
|
0
|
|
|
|
0
|
warn $@ unless $DEBUG; |
27
|
0
|
0
|
|
|
|
0
|
die $@ if $DEBUG; |
28
|
|
|
|
|
|
|
}; |
29
|
708
|
50
|
33
|
|
|
10463
|
if (defined $de and defined $de->{encoding}) { |
30
|
708
|
|
|
|
|
3034
|
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; |