/[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.2 - (hide annotations)
Sat Jan 18 18:25:39 2003 UTC (21 years, 7 months ago) by joko
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +4 -1 lines
FILE REMOVED
- removed - now taken from nfo/perl/libs

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

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