1 |
############################################## |
## ------------------------------------------------------------------------- |
2 |
# |
## $Id$ |
3 |
# $Id$ |
## ------------------------------------------------------------------------- |
4 |
# |
## $Log$ |
5 |
# $Log$ |
## Revision 1.3 2003/02/20 20:48:36 joko |
6 |
# Revision 1.1 2002/11/29 04:49:20 joko |
## renamed methods |
7 |
# + initial check-in |
## |
8 |
# |
## Revision 1.2 2002/12/05 13:57:22 joko |
9 |
# Revision 1.1 2002/10/10 03:26:00 cvsjoko |
## + now able to export 'scalar2utf8' |
10 |
# + new |
## + comments |
11 |
# |
## |
12 |
############################################## |
## Revision 1.1 2002/11/29 04:49:20 joko |
13 |
|
## + initial check-in |
14 |
|
## |
15 |
|
## Revision 1.1 2002/10/10 03:26:00 cvsjoko |
16 |
|
## + new |
17 |
|
## ------------------------------------------------------------------------- |
18 |
|
|
19 |
|
|
20 |
package Data::Transform::Encode; |
package Data::Transform::Encode; |
24 |
|
|
25 |
require Exporter; |
require Exporter; |
26 |
our @ISA = qw( Exporter ); |
our @ISA = qw( Exporter ); |
27 |
our @EXPORT_OK = qw( &var2utf8 &var_utf2iso ); |
our @EXPORT_OK = qw( &latin_to_utf8 &latin_to_utf8_scalar &utf8_to_latin &utf8_to_latin_scalar ); |
28 |
|
|
29 |
|
|
30 |
use Unicode::String qw(utf8 latin1); |
use Unicode::String qw(utf8 latin1); |
31 |
|
|
32 |
sub var2utf8 { |
# TODO: refactor using Greg London's "Iterate" from CPAN |
33 |
|
sub latin_to_utf8 { |
34 |
my $vref = shift; |
my $vref = shift; |
35 |
if (ref $vref eq 'HASH') { |
if (ref $vref eq 'HASH') { |
36 |
foreach (keys %{$vref}) { |
foreach (keys %{$vref}) { |
37 |
if ((ref $vref->{$_}) =~ m/ARRAY|HASH/) { |
if ((ref $vref->{$_}) =~ m/ARRAY|HASH/) { |
38 |
var2utf8($vref->{$_}); |
latin_to_utf8($vref->{$_}); |
39 |
} else { |
} else { |
40 |
$vref->{$_} = scalar2utf8($vref->{$_}); |
$vref->{$_} = latin_to_utf8_scalar($vref->{$_}); |
41 |
} |
} |
42 |
} |
} |
43 |
} elsif (ref $vref eq 'ARRAY') { |
} elsif (ref $vref eq 'ARRAY') { |
44 |
foreach (@{$vref}) { |
foreach (@{$vref}) { |
45 |
if (ref $_ ne 'SCALAR') { |
if (ref $_ ne 'SCALAR') { |
46 |
var2utf8($_); |
latin_to_utf8($_); |
47 |
} else { |
} else { |
48 |
$_ = scalar2utf8($_); |
$_ = latin_to_utf8_scalar($_); |
49 |
} |
} |
50 |
} |
} |
51 |
} |
} |
52 |
|
|
53 |
} |
} |
54 |
|
|
55 |
sub scalar2utf8 { |
sub latin_to_utf8_scalar { |
56 |
my $scalar = shift; |
my $scalar = shift; |
57 |
if ($scalar) { |
if ($scalar) { |
58 |
my $u = latin1($scalar); |
my $u = latin1($scalar); |
60 |
} |
} |
61 |
} |
} |
62 |
|
|
63 |
sub var_utf2iso { |
# TODO: refactor using Greg London's "Iterate" from CPAN |
64 |
|
sub utf8_to_latin { |
65 |
my $vref = shift; |
my $vref = shift; |
66 |
if (ref $vref eq 'HASH') { |
if (ref $vref eq 'HASH') { |
67 |
foreach (keys %{$vref}) { |
foreach (keys %{$vref}) { |
68 |
if ((ref $vref->{$_}) =~ m/ARRAY|HASH/) { |
if ((ref $vref->{$_}) =~ m/ARRAY|HASH/) { |
69 |
var_utf2iso($vref->{$_}); |
utf8_to_latin($vref->{$_}); |
70 |
} else { |
} else { |
71 |
$vref->{$_} = scalar2iso($vref->{$_}); |
$vref->{$_} = utf8_to_latin_scalar($vref->{$_}); |
72 |
} |
} |
73 |
} |
} |
74 |
} elsif (ref $vref eq 'ARRAY') { |
} elsif (ref $vref eq 'ARRAY') { |
75 |
foreach (@{$vref}) { |
foreach (@{$vref}) { |
76 |
if (ref $_ ne 'SCALAR') { |
if (ref $_ ne 'SCALAR') { |
77 |
var_utf2iso($_); |
utf8_to_latin($_); |
78 |
} else { |
} else { |
79 |
$_ = scalar2iso($_); |
$_ = utf8_to_latin_scalar($_); |
80 |
} |
} |
81 |
} |
} |
82 |
} |
} |
83 |
|
|
84 |
} |
} |
85 |
|
|
86 |
sub scalar2iso { |
sub utf8_to_latin_scalar { |
87 |
my $scalar = shift; |
my $scalar = shift; |
88 |
if ($scalar) { |
if ($scalar) { |
89 |
my $u = utf8($scalar); |
my $u = utf8($scalar); |
92 |
} |
} |
93 |
|
|
94 |
1; |
1; |
95 |
|
__END__ |