line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id$ |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Copyright (c) 2007 Daisuke Maki daisuke@endeworks.jp> |
4
|
|
|
|
|
|
|
# All rights reserved. |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Data::Decode::Util; |
7
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
66
|
|
8
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
53
|
|
9
|
2
|
|
|
2
|
|
11
|
use Encode (); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
37
|
|
10
|
2
|
|
|
2
|
|
10
|
use Exporter 'import'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
370
|
|
11
|
|
|
|
|
|
|
our @EXPORT_OK = qw(try_decode pick_encoding); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub try_decode |
14
|
|
|
|
|
|
|
{ |
15
|
0
|
|
|
0
|
1
|
|
my ($encoding, $data) = @_; |
16
|
0
|
0
|
|
|
|
|
return () unless $encoding; |
17
|
0
|
|
|
|
|
|
my $decoded = eval { Encode::decode($encoding, $data, Encode::FB_CROAK()) }; |
|
0
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
return $decoded; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub pick_encoding |
22
|
|
|
|
|
|
|
{ |
23
|
0
|
|
|
0
|
1
|
|
for my $e (@_) { |
24
|
0
|
0
|
|
|
|
|
next unless defined $e; |
25
|
0
|
0
|
|
|
|
|
next unless Encode::find_encoding($e); |
26
|
0
|
|
|
|
|
|
return $e; |
27
|
|
|
|
|
|
|
} |
28
|
0
|
|
|
|
|
|
return (); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
1; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
__END__ |