line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Encode::Multibyte::Detect; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
54116
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
181
|
|
4
|
1
|
|
|
1
|
|
8
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
68
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.01'; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use base 'Exporter'; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
776
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @EXPORT = (); |
11
|
|
|
|
|
|
|
our @EXPORT_OK = qw(detect is_7bit is_valid_utf8 is_strict_utf8 |
12
|
|
|
|
|
|
|
is_valid_euc_cn is_valid_euc_jp is_valid_euc_kr is_valid_euc_tw); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( all => [@EXPORT_OK] ); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
require XSLoader; |
17
|
|
|
|
|
|
|
XSLoader::load('Encode::Multibyte::Detect'); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub detect { |
20
|
17
|
|
|
17
|
0
|
2098
|
my ($str, %opts) = @_; |
21
|
|
|
|
|
|
|
|
22
|
17
|
50
|
|
|
|
21
|
my %avail = map {$_ => 1} @{$opts{avail} || []}; |
|
0
|
|
|
|
|
0
|
|
|
17
|
|
|
|
|
84
|
|
23
|
|
|
|
|
|
|
|
24
|
17
|
100
|
|
|
|
77
|
return '' if is_7bit($str); |
25
|
|
|
|
|
|
|
|
26
|
12
|
100
|
|
|
|
58
|
return 'utf-8' if is_strict_utf8($str); |
27
|
|
|
|
|
|
|
|
28
|
8
|
50
|
33
|
|
|
21
|
return 'euc-cn' if $avail{'euc-cn'} && is_valid_euc_cn($str); |
29
|
8
|
50
|
33
|
|
|
20
|
return 'euc-jp' if $avail{'euc-jp'} && is_valid_euc_jp($str); |
30
|
8
|
50
|
33
|
|
|
29
|
return 'euc-kr' if $avail{'euc-kr'} && is_valid_euc_kr($str); |
31
|
8
|
50
|
33
|
|
|
17
|
return 'euc-tw' if $avail{'euc-tw'} && is_valid_euc_tw($str); |
32
|
|
|
|
|
|
|
|
33
|
8
|
100
|
|
|
|
30
|
return '' if $opts{strict}; |
34
|
|
|
|
|
|
|
|
35
|
4
|
100
|
|
|
|
21
|
return 'utf-8' if is_valid_utf8($str); |
36
|
|
|
|
|
|
|
|
37
|
2
|
|
|
|
|
7
|
return ''; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 NAME |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Encode::Multibyte::Detect - detect multibyte encoding |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 SYNOPSIS |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
use Encode::Multibyte::Detect qw(:all); |
49
|
|
|
|
|
|
|
use Encode; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
$enc = detect($octets, strict => 1, avail => [qw(euc-cn)]); |
52
|
|
|
|
|
|
|
if ($enc) { |
53
|
|
|
|
|
|
|
$string = decode($enc, $octets); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
is_7bit($octets); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
is_valid_utf8($octets); |
59
|
|
|
|
|
|
|
is_strict_utf8($octets); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
is_valid_euc_cn($octets); |
62
|
|
|
|
|
|
|
is_valid_euc_jp($octets); |
63
|
|
|
|
|
|
|
is_valid_euc_kr($octets); |
64
|
|
|
|
|
|
|
is_valid_euc_tw($octets); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 REPOSITORY |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
The source code for the Encode::Multibyte::Detect is held in a public git repository |
69
|
|
|
|
|
|
|
on Github: L |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 AUTHOR |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Aleksandr Aleshin Fsilencer@cpan.orgE> |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 COPYRIGHT |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
This software is copyright (c) 2012 by Aleksandr Aleshin. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
80
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |