/[suikacvs]/perl/lib/Encode/Table.pm
Suika

Contents of /perl/lib/Encode/Table.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations) (download)
Sat Oct 5 05:01:24 2002 UTC (22 years, 1 month ago) by wakaba
Branch: MAIN
Changes since 1.2: +10 -3 lines
2002-10-05  Nanashi-san

	* Table.pm: New module.
	(Commited by Wakaba <w@suika.fam.cx>.)

1 wakaba 1.1
2     =head1 NAME
3    
4     Encode::Table --- Inter-coding-space table convertion
5    
6     =cut
7    
8     package Encode::Table;
9     use strict;
10     use vars qw(%TABLE $VERSION);
11 wakaba 1.3 $VERSION = do {my @r =(q$Revision: 1.2 $ =~ /\d+/g);sprintf "%d."."%02d" x $#r, @r};
12 wakaba 1.1
13     ## Builtin tables
14     for (0x00..0x7F) {
15     my $c = chr $_;
16     $TABLE{ascii_to_ucs}->{$c} = $c;
17     $TABLE{ucs_to_ascii}->{$c} = $c;
18     }
19 wakaba 1.2 $Encode::Table::ascii::VERSION = $VERSION;
20 wakaba 1.3 for (0xA0..0xFF) {
21     my $c = chr $_;
22     $TABLE{isoiec8859_1_to_ucs}->{$c} = $c;
23     $TABLE{ucs_to_isoiec8859_1}->{$c} = $c;
24     }
25     $Encode::Table::isoiec8859_1::VERSION = $VERSION;
26 wakaba 1.1
27     my %_Cache;
28 wakaba 1.2 sub convert ($@%) {
29 wakaba 1.3 return $_[0] unless @{$_[1]} > 0;
30 wakaba 1.1 my @s = split //, shift;
31     my $tbl = shift;
32     my $tbls = join ' ', @$tbl;
33 wakaba 1.2 my %option = @_;
34     load_table (@$tbl) if $option{-autoload};
35 wakaba 1.1 for my $c (@s) {
36     unless (defined $_Cache{$tbls}->{$c}) {
37     for (@$tbl) {
38     if (defined $TABLE{$_}->{$c}) {
39     $_Cache{$tbls}->{$c} = $TABLE{$_}->{$c}; last;
40     }
41     }
42     $_Cache{$tbls}->{$c} = $c unless defined $_Cache{$tbls}->{$c}; ## Not found
43     }
44     $c = $_Cache{$tbls}->{$c};
45     }
46     join '', @s;
47     }
48    
49 wakaba 1.2 sub load_table (@) {
50     no strict 'refs';
51     for (@_) {
52     my $name = $_;
53     if ($name =~ /^ucs_to_(.+)$/) { $name = $1 }
54     elsif ($name =~ /^(.+)_to_ucs$/) { $name = $1 }
55     unless (${ 'Encode::Table::' . $name . '::VERSION' }) {
56     eval qq{require Encode::Table::$name; Encode::Table::$name->import} or warn $@;
57     }
58     }
59     }
60    
61 wakaba 1.1 1;
62     __END__
63    
64     =head1 AUTHORS
65    
66     Nanashi-san
67    
68     =head1 LICENSE
69    
70     Copyright 2002 AUTHORS
71    
72     This library is free software; you can redistribute it
73     and/or modify it under the same terms as Perl itself.
74    
75     =cut
76    
77 wakaba 1.3 # $Date: 2002/10/05 01:34:55 $
78     ### $RCSfile: Table.pm,v $ ends here

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24