/[cvs]/nfo/perl/scripts/outlook2ldap/libs/Data/Transform/Encode.pm
ViewVC logotype

Annotation of /nfo/perl/scripts/outlook2ldap/libs/Data/Transform/Encode.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Sat Jan 18 15:38:05 2003 UTC (21 years, 7 months ago) by joko
Branch: MAIN
CVS Tags: v008-2, v008-1
+ initial check-in

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

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed