diff options
Diffstat (limited to 'cpan/lib/Jcode')
| -rw-r--r-- | cpan/lib/Jcode/Constants.pm | 33 | ||||
| -rw-r--r-- | cpan/lib/Jcode/H2Z.pm | 18 | ||||
| -rw-r--r-- | cpan/lib/Jcode/Tr.pm | 47 | ||||
| -rw-r--r-- | cpan/lib/Jcode/Unicode/Constants.pm | 69 | ||||
| -rw-r--r-- | cpan/lib/Jcode/Unicode/NoXS.pm | 34 |
5 files changed, 95 insertions, 106 deletions
diff --git a/cpan/lib/Jcode/Constants.pm b/cpan/lib/Jcode/Constants.pm index 7bce2ea0..57a4b88e 100644 --- a/cpan/lib/Jcode/Constants.pm +++ b/cpan/lib/Jcode/Constants.pm @@ -1,5 +1,5 @@ # -# $Id: Constants.pm,v 1.1 2000/11/15 05:44:53 dankogai Exp $ +# $Id: Constants.pm,v 1.2 2001/05/18 05:14:38 dankogai Exp dankogai $ # package Jcode::Constants; @@ -7,8 +7,8 @@ package Jcode::Constants; use strict; use vars qw($RCSID $VERSION); -$RCSID = q$Id: Constants.pm,v 1.1 2000/11/15 05:44:53 dankogai Exp $; -$VERSION = do { my @r = (q$Revision: 1.1 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; +$RCSID = q$Id: Constants.pm,v 1.2 2001/05/18 05:14:38 dankogai Exp dankogai $; +$VERSION = do { my @r = (q$Revision: 1.2 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; use Carp; @@ -17,7 +17,7 @@ BEGIN { use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); @ISA = qw(Exporter); @EXPORT = qw(); - @EXPORT_OK = qw(&_max &_mkbuf %CHARCODE %ESC %RE); + @EXPORT_OK = qw(%CHARCODE %ESC %RE); %EXPORT_TAGS = ( 'all' => [ @EXPORT_OK, @EXPORT ] ); } @@ -59,30 +59,5 @@ my %_0208 = ( UTF8 => '[\xc0-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf][\x80-\xbf]' ); -# -# Util. Functions -# - -# Make buffer when and only when necessary - -sub _mkbuf { - my $thingy = shift; - if (ref $thingy){ - return $thingy; - } - else{ - my $buf = $thingy; - return \$buf; - } -} - -sub _max { - my $result = shift; - for my $n (@_){ - $result = $n if $n > $result; - } - return $result; -} - 1; diff --git a/cpan/lib/Jcode/H2Z.pm b/cpan/lib/Jcode/H2Z.pm index 79aa3794..53c81201 100644 --- a/cpan/lib/Jcode/H2Z.pm +++ b/cpan/lib/Jcode/H2Z.pm @@ -1,5 +1,5 @@ # -# $Id: H2Z.pm,v 0.61 2000/11/15 05:45:25 dankogai Exp $ +# $Id: H2Z.pm,v 0.70 2001/05/15 19:35:59 dankogai Exp $ # package Jcode::H2Z; @@ -7,8 +7,8 @@ package Jcode::H2Z; use strict; use vars qw($RCSID $VERSION); -$RCSID = q$Id: H2Z.pm,v 0.61 2000/11/15 05:45:25 dankogai Exp $; -$VERSION = do { my @r = (q$Revision: 0.61 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; +$RCSID = q$Id: H2Z.pm,v 0.70 2001/05/15 19:35:59 dankogai Exp $; +$VERSION = do { my @r = (q$Revision: 0.70 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; use Carp; @@ -116,14 +116,14 @@ use vars qw(%_D2Z $_PAT_D2Z # init only once; -$_PAT_D2Z = join("|", keys %_D2Z); -$_PAT_H2Z = join("|", keys %_H2Z); +#$_PAT_D2Z = join("|", keys %_D2Z); +#$_PAT_H2Z = join("|", keys %_H2Z); %_Z2H = reverse %_H2Z; %_Z2D = reverse %_D2Z; -$_PAT_Z2H = join("|", keys %_Z2H); -$_PAT_Z2D = join("|", keys %_Z2D); +#$_PAT_Z2H = join("|", keys %_Z2H); +#$_PAT_Z2D = join("|", keys %_Z2D); sub h2z { my $r_str = shift; @@ -133,7 +133,7 @@ sub h2z { $n = ( $$r_str =~ s( ($RE{EUC_KANA} - (:?\x8e[\xde\xdf])?) + (?:\x8e[\xde\xdf])?) ){ my $str = $1; $_D2Z{$str} || $_H2Z{$str} || @@ -157,7 +157,7 @@ sub z2h { my $r_str = shift; my $n = ( $$r_str =~ s( - ($RE{EUC_C}|$RE{EUC_KANA}) + ($RE{EUC_C}) ){ $_Z2D{$1} || $_Z2H{$1} || $1; }eogx diff --git a/cpan/lib/Jcode/Tr.pm b/cpan/lib/Jcode/Tr.pm index 4d8ee1ff..e29e29bb 100644 --- a/cpan/lib/Jcode/Tr.pm +++ b/cpan/lib/Jcode/Tr.pm @@ -1,5 +1,5 @@ # -# $Id: Tr.pm,v 0.63 2000/11/22 09:05:01 dankogai Exp dankogai $ +# $Id: Tr.pm,v 0.70 2001/05/15 19:35:59 dankogai Exp $ # package Jcode::Tr; @@ -7,8 +7,8 @@ package Jcode::Tr; use strict; use vars qw($VERSION $RCSID); -$RCSID = q$Id: Tr.pm,v 0.63 2000/11/22 09:05:01 dankogai Exp dankogai $; -$VERSION = do { my @r = (q$Revision: 0.63 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; +$RCSID = q$Id: Tr.pm,v 0.70 2001/05/15 19:35:59 dankogai Exp $; +$VERSION = do { my @r = (q$Revision: 0.70 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; use Carp; @@ -33,26 +33,29 @@ sub tr { return $n; } -sub _maketable { - my ($from, $to, $opt) = @_; - - grep(s/([\x8e\x8f]$RE{EUC_C}-[\x8e\x8f]$RE{EUC_C})/&_expnd3($1)/geo, - $from,$to); - grep(s/($RE{EUC_C}-$RE{EUC_C})/&_expnd2($1)/geo, - $from,$to); - grep(s/($RE{ASCII}-$RE{ASCII})/&_expnd1($1)/geo, - $from,$to); - - my @to = $to =~ /[\x8e\x8f]$RE{EUC_C}|$RE{EUC_C}|[\x00-\xff]/go; - my @from = $from =~ /[\x8e\x8f]$RE{EUC_C}|$RE{EUC_C}|[\x00-\xff]/go; - - push(@to, ($opt =~ /d/ ? '' : $to[$#to]) x (@from - @to)) if @to < @from; +sub _maketable{ + my( $from, $to, $opt ) = @_; + + $from =~ s/($RE{EUC_0212}-$RE{EUC_0212})/&_expnd3($1)/geo; + $from =~ s/($RE{EUC_KANA}-$RE{EUC_KANA})/&_expnd2($1)/geo; + $from =~ s/($RE{EUC_C }-$RE{EUC_C })/&_expnd2($1)/geo; + $from =~ s/($RE{ASCII }-$RE{ASCII })/&_expnd1($1)/geo; + $to =~ s/($RE{EUC_0212}-$RE{EUC_0212})/&_expnd3($1)/geo; + $to =~ s/($RE{EUC_KANA}-$RE{EUC_KANA})/&_expnd2($1)/geo; + $to =~ s/($RE{EUC_C }-$RE{EUC_C })/&_expnd2($1)/geo; + $to =~ s/($RE{ASCII }-$RE{ASCII })/&_expnd1($1)/geo; + + my @from = $from =~ /$RE{EUC_0212}|$RE{EUC_KANA}|$RE{EUC_C}|[\x00-\xff]/go; + my @to = $to =~ /$RE{EUC_0212}|$RE{EUC_KANA}|$RE{EUC_C}|[\x00-\xff]/go; + + push @to, $to[-1] x $#from - $#to if $#to < $#from && $opt !~ /d/; @_TABLE{@from} = @to; + } sub _expnd1 { my ($str) = @_; - s/\\(.)/$1/og; + # s/\\(.)/$1/og; # I dunno what this was doing!? my($c1, $c2) = unpack('CxC', $str); if ($c1 <= $c2) { for ($str = ''; $c1 <= $c2; $c1++) { @@ -75,10 +78,10 @@ sub _expnd2 { sub _expnd3 { my ($str) = @_; - my ($c1, $c2, $c3, $c4) = unpack('CCCxCCC', $str); - if ($c1 == $c3 && $c2 <= $c4) { - for ($str = ''; $c2 <= $c4; $c2++) { - $str .= pack('CCC', $c1, $c2); + my ($c1, $c2, $c3, $c4, $c5, $c6) = unpack('CCCxCCC', $str); + if ($c1 == $c4 && $c2 == $c5 && $c3 <= $c6) { + for ($str = ''; $c3 <= $c6; $c3++) { + $str .= pack('CCC', $c1, $c2, $c3); } } return $str; diff --git a/cpan/lib/Jcode/Unicode/Constants.pm b/cpan/lib/Jcode/Unicode/Constants.pm index 4538da03..f3769683 100644 --- a/cpan/lib/Jcode/Unicode/Constants.pm +++ b/cpan/lib/Jcode/Unicode/Constants.pm @@ -1,14 +1,45 @@ # -# $Id: Constants.pm,v 1.1 2000/11/15 05:44:53 dankogai Exp $ +# $Id: Constants.pm,v 1.2 2001/05/18 05:14:38 dankogai Exp dankogai $ # package Jcode::Unicode::Constants; +=head1 NAME + +Jcode::Unicode::Constants -- UCS2-EUC conversion table + +=head1 SYNOPSIS + +NONE + +=head1 DESCRIPTION + +This module just contains a huge hash that converts UCS2 from/to EUC. + +=head1 SEE ALSO + +ftp://ftp.unicode.org/Public/MAPPINGS/EASTASIA/JIS/ + +Unicode mapping data + +=head1 COPYRIGHT + +Copyright 1999 Dan Kogai <dankogai@dan.co.jp> + +This library is free software; you can redistribute it +and/or modify it under the same terms as Perl itself. + +Unicode conversion table here is based on files at +ftp://ftp.unicode.org/Public/MAPPINGS/EASTASIA/JIS/, +Copyright (c) 1991-1994 Unicode, Inc. + +=cut + use strict; use vars qw($RCSID $VERSION); -$RCSID = q$Id: Constants.pm,v 1.1 2000/11/15 05:44:53 dankogai Exp $; -$VERSION = do { my @r = (q$Revision: 1.1 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; +$RCSID = q$Id: Constants.pm,v 1.2 2001/05/18 05:14:38 dankogai Exp dankogai $; +$VERSION = do { my @r = (q$Revision: 1.2 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; use Carp; @@ -13041,35 +13072,3 @@ for my $c (0x00..0x7f){ %_E2U = (); 1; - - -=head1 NAME - -Jcode::Unicode::Constants -- UCS2-EUC conversion table - -=head1 SYNOPSIS - -NONE - -=head1 DESCRIPTION - -This module just contains a huge hash that converts UCS2 from/to EUC. - -=head1 SEE ALSO - -=item ftp://ftp.unicode.org/Public/MAPPINGS/EASTASIA/JIS/ - -Unicode mapping data - -=head1 COPYRIGHT - -Copyright 1999 Dan Kogai <dankogai@dan.co.jp> - -This library is free software; you can redistribute it -and/or modify it under the same terms as Perl itself. - -Unicode conversion table here is based on files at -ftp://ftp.unicode.org/Public/MAPPINGS/EASTASIA/JIS/, -Copyright (c) 1991-1994 Unicode, Inc. - -=cut diff --git a/cpan/lib/Jcode/Unicode/NoXS.pm b/cpan/lib/Jcode/Unicode/NoXS.pm index f0f0b57e..44800ea3 100644 --- a/cpan/lib/Jcode/Unicode/NoXS.pm +++ b/cpan/lib/Jcode/Unicode/NoXS.pm @@ -1,5 +1,5 @@ # -# $Id: NoXS.pm,v 0.61 2000/11/15 05:45:25 dankogai Exp $ +# $Id: NoXS.pm,v 0.71 2001/05/18 05:14:38 dankogai Exp dankogai $ # package Jcode::Unicode::NoXS; @@ -7,8 +7,8 @@ package Jcode::Unicode::NoXS; use strict; use vars qw($RCSID $VERSION); -$RCSID = q$Id: NoXS.pm,v 0.61 2000/11/15 05:45:25 dankogai Exp $; -$VERSION = do { my @r = (q$Revision: 0.61 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; +$RCSID = q$Id: NoXS.pm,v 0.71 2001/05/18 05:14:38 dankogai Exp dankogai $; +$VERSION = do { my @r = (q$Revision: 0.71 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; use Carp; @@ -55,7 +55,7 @@ sub _init_e2u{ sub Jcode::ucs2_euc{ my $thingy = shift; - my $r_str = _mkbuf($thingy); + my $r_str = ref $thingy ? $thingy : \$thingy; _init_u2e(); $$r_str =~ s( @@ -70,13 +70,13 @@ sub Jcode::ucs2_euc{ sub Jcode::euc_ucs2{ my $thingy = shift; - my $r_str = _mkbuf($thingy); + my $r_str = ref $thingy ? $thingy : \$thingy; _init_e2u(); # 3 bytes $$r_str =~ s( ($RE{EUC_0212}|$RE{EUC_C}|$RE{EUC_KANA}|[\x00-\xff]) - ) + ) { exists $_E2U{$1} ? $_E2U{$1} : $CHARCODE{UNDEF_UNICODE}; }geox; @@ -86,21 +86,21 @@ sub Jcode::euc_ucs2{ sub Jcode::euc_utf8{ my $thingy = shift; - my $r_str = _mkbuf($thingy); + my $r_str = ref $thingy ? $thingy : \$thingy; &Jcode::euc_ucs2($r_str); &Jcode::ucs2_utf8($r_str); } sub Jcode::utf8_euc{ my $thingy = shift; - my $r_str = _mkbuf($thingy); + my $r_str = ref $thingy ? $thingy : \$thingy; &Jcode::utf8_ucs2($r_str); &Jcode::ucs2_euc($r_str); } sub Jcode::ucs2_utf8{ my $thingy = shift; - my $r_str = _mkbuf($thingy); + my $r_str = ref $thingy ? $thingy : \$thingy; my $result; for my $uc (unpack("n*", $$r_str)) { if ($uc < 0x80) { @@ -123,7 +123,7 @@ sub Jcode::ucs2_utf8{ sub Jcode::utf8_ucs2{ my $thingy = shift; - my $r_str = _mkbuf($thingy); + my $r_str = ref $thingy ? $thingy : \$thingy; my $result; $$r_str =~ s/^[\200-\277]+//o; # can't start with 10xxxxxx $$r_str =~ @@ -162,6 +162,8 @@ This module is called by Jcode.pm on demand. This module is not intended for direct use by users. This modules implements functions related to Unicode. Following functions are defined here; +=over 4 + =item Jcode::ucs2_euc(); =item Jcode::euc_ucs2(); @@ -174,10 +176,14 @@ Following functions are defined here; =item Jcode::utf8_euc(); +=back + =cut =head1 VARIABLES +=over 4 + =item B<$Jcode::Unicode::PEDANTIC> When set to non-zero, x-to-unicode conversion becomes pedantic. @@ -186,12 +192,18 @@ That is, '\' (chr(0x5c)) is converted to zenkaku backslash and By Default, Jcode::Unicode leaves ascii ([0x00-0x7f]) as it is. +=back + =head1 MODULES +=over 4 + =item Jcode::Unicode::Constants Jumbo hash that contains UCS2-EUC conversion table is there. +=back + =head1 BUGS * It's very slow to initialize, due to the size of the conversion @@ -201,7 +213,7 @@ Jumbo hash that contains UCS2-EUC conversion table is there. =head1 SEE ALSO -=item http://www.unicode.org/ +http://www.unicode.org/ =head1 COPYRIGHT |
