summaryrefslogtreecommitdiff
path: root/cpan/lib
diff options
context:
space:
mode:
Diffstat (limited to 'cpan/lib')
-rw-r--r--cpan/lib/Jcode.pm102
-rw-r--r--cpan/lib/Jcode/H2Z.pm8
-rw-r--r--cpan/lib/Jcode/Tr.pm8
-rw-r--r--cpan/lib/Jcode/Unicode/NoXS.pm6
-rw-r--r--cpan/lib/Jcode/_test.pl16
5 files changed, 76 insertions, 64 deletions
diff --git a/cpan/lib/Jcode.pm b/cpan/lib/Jcode.pm
index b61ace7b..0b3683e2 100644
--- a/cpan/lib/Jcode.pm
+++ b/cpan/lib/Jcode.pm
@@ -1,5 +1,5 @@
#
-# $Id: Jcode.pm,v 0.71 2001/05/18 05:14:38 dankogai Exp dankogai $
+# $Id: Jcode.pm,v 0.79 2002/01/16 02:16:39 dankogai Exp dankogai $
#
=head1 NAME
@@ -34,28 +34,25 @@ and convert().
=cut
package Jcode;
-require 5.004;
-
+use 5.004;
+use Carp;
use strict;
-use vars qw($RCSID $VERSION);
+use vars qw($RCSID $VERSION $DEBUG);
-$RCSID = q$Id: Jcode.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 };
+$RCSID = q$Id: Jcode.pm,v 0.79 2002/01/16 02:16:39 dankogai Exp dankogai $;
+$VERSION = do { my @r = (q$Revision: 0.79 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
+$DEBUG = 0;
-use Carp;
+use Exporter;
+use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
+@ISA = qw(Exporter);
+@EXPORT = qw(jcode getcode);
+@EXPORT_OK = qw($RCSID $VERSION $DEBUG);
+%EXPORT_TAGS = ( all => [ @EXPORT_OK, @EXPORT ] );
-BEGIN {
- use Exporter;
- use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
- @ISA = qw(Exporter);
- @EXPORT = qw(jcode getcode);
- @EXPORT_OK = qw($RCSID $VERSION $DEBUG $USE_CACHE $NOXS);
- %EXPORT_TAGS = ( all => [ @EXPORT_OK, @EXPORT ] );
-}
-use vars @EXPORT_OK;
+use vars qw($USE_CACHE $NOXS);
-$DEBUG = 0;
$USE_CACHE = 1;
$NOXS = 0;
@@ -64,21 +61,20 @@ print $RCSID, "\n" if $DEBUG;
use Jcode::Constants qw(:all);
use overload
- '""' => sub { ${$_[0]->[0]} },
- '==' => sub {overload::StrVal($_[0]) eq overload::StrVal($_[1])},
- '=' => sub{ $_[0]->set( $_[1] ) },
- '.=' => sub{ $_[0]->append( $_[1] ) },
+ q("") => sub { ${$_[0]->[0]} },
+ q(==) => sub {overload::StrVal($_[0]) eq overload::StrVal($_[1])},
+ q(=) => sub { $_[0]->set( $_[1] ) },
+ q(.=) => sub { $_[0]->append( $_[1] ) },
fallback => 1,
;
-
=head1 Methods
Methods mentioned here all return Jcode object unless otherwise mentioned.
=over 4
-=item $j = Jcode->new($str [, $icode]);
+=item $j = Jcode-E<gt>new($str [, $icode]);
Creates Jcode object $j from $str. Input code is automatically checked
unless you explicitly set $icode. For available charset, see L<getcode>
@@ -98,7 +94,7 @@ Jcode->new(\$str);
This saves time a little bit. In exchange of the value of $str being
converted. (In a way, $str is now "tied" to jcode object).
-=item $j->set($str [, $icode]);
+=item $j-E<gt>set($str [, $icode]);
Sets $j's internal string to $str. Handy when you use Jcode object repeatedly
(saves time and memory to create object).
@@ -110,7 +106,7 @@ Sets $j's internal string to $str. Handy when you use Jcode object repeatedly
print $jconv->set(\$_)->mime_decode->sjis;
}
-=item $j->append($str [, $icode]);
+=item $j-E<gt>append($str [, $icode]);
Appends $str to $j's internal string.
@@ -172,15 +168,15 @@ shortcut for Jcode->new() so you can go like;
$sjis = jcode($str)->sjis;
-=item $euc = $j->euc;
+=item $euc = $j-E<gt>euc;
-=item $jis = $j->jis;
+=item $jis = $j-E<gt>jis;
-=item $sjis = $j->sjis;
+=item $sjis = $j-E<gt>sjis;
What you code is what you get :)
-=item $iso_2022_jp = $j->iso_2022_jp
+=item $iso_2022_jp = $j-E<gt>iso_2022_jp
Same as $j->z2h->jis.
Hankaku Kanas are forcibly converted to Zenkaku.
@@ -197,7 +193,7 @@ sub iso_2022_jp{return $_[0]->h2z->jis}
=over 4
-=item [@lines =] $jcode->jfold([$bytes_per_line, $newline_str]);
+=item [@lines =] $jcode-E<gt>jfold([$bytes_per_line, $newline_str]);
folds lines in jcode string every $bytes_per_line (default: 72)
in a way that does not clobber the multibyte string.
@@ -238,14 +234,14 @@ To use methods below, you need MIME::Base64. To install, simply
=over 4
-=item $mime_header = $j->mime_encode([$lf, $bpl]);
+=item $mime_header = $j-E<gt>mime_encode([$lf, $bpl]);
Converts $str to MIME-Header documented in RFC1522.
When $lf is specified, it uses $lf to fold line (default: \n).
When $bpl is specified, it uses $bpl for the number of bytes (default: 76;
this number must be smaller than 76).
-=item $j->mime_decode;
+=item $j-E<gt>mime_decode;
Decodes MIME-Header in Jcode object.
@@ -303,7 +299,6 @@ sub _add_encoded_word {
return $result . $line;
}
-
sub _mime_unstructured_header {
my ($oldheader, $lf, $bpl) = @_;
my(@words, @wordstmp, $i);
@@ -321,7 +316,7 @@ sub _mime_unstructured_header {
push(@words, $wordstmp[-1]);
for my $word (@words) {
if ($word =~ /^[\x21-\x7E]+$/) {
- $header =~ /(?:.*\n)?(.*)/;
+ $header =~ /(?:.*\n)*(.*)/;
if (length($1) + length($word) > $bpl) {
$header .= "$lf $word";
} else {
@@ -330,7 +325,7 @@ sub _mime_unstructured_header {
} else {
$header = _add_encoded_word($word, $header, $bpl);
}
- $header =~ /(?:.*\n)?(.*)/;
+ $header =~ /(?:.*\n)*(.*)/;
if (length($1) == $bpl) {
$header .= "$lf ";
} else {
@@ -369,7 +364,7 @@ Methods below are actually implemented in Jcode::H2Z.
=over 4
-=item $j->h2z([$keep_dakuten]);
+=item $j-E<gt>h2z([$keep_dakuten]);
Converts X201 kana (Hankaku) to X208 kana (Zenkaku).
When $keep_dakuten is set, it leaves dakuten as is
@@ -378,7 +373,7 @@ being converted to "ga")
You can retrieve the number of matches via $j->nmatch;
-=item $j->z2h;
+=item $j-E<gt>z2h;
Converts X208 kana (Zenkaku) to X201 kana (Hankazu).
@@ -410,7 +405,7 @@ Methods here are actually implemented in Jcode::Tr.
=over 4
-=item $j->tr($from, $to);
+=item $j-E<gt>tr($from, $to);
Applies tr on Jcode object. $from and $to can contain EUC Japanese.
@@ -461,11 +456,11 @@ See L<Jcode::Unicode> and L<Jcode::Unicode::NoXS> for details
=over 4
-=item $ucs2 = $j->ucs2;
+=item $ucs2 = $j-E<gt>ucs2;
Returns UCS2 (Raw Unicode) string.
-=item $ucs2 = $j->utf8;
+=item $ucs2 = $j-E<gt>utf8;
Returns utf8 String.
@@ -483,7 +478,6 @@ sub utf8{
euc_utf8(${$_[0]->[0]});
}
-
=head2 Instance Variables
If you need to access instance variables of Jcode object, use access
@@ -496,15 +490,15 @@ access methods instead; Once again, that's OOP)
=over 4
-=item $j->r_str
+=item $j-E<gt>r_str
Reference to the EUC-coded String.
-=item $j->icode
+=item $j-E<gt>icode
Input charcode in recent operation.
-=item $j->nmatch
+=item $j-E<gt>nmatch
Number of matches (Used in $j->tr, etc.)
@@ -669,13 +663,13 @@ sub jis_euc {
#
# Based upon the contribution of
# Kazuto Ichimura <ichimura@shimada.nuee.nagoya-u.ac.jp>
-#
+# optimized by <ohzaki@iod.ricoh.co.jp>
sub euc_jis{
my $thingy = shift;
my $r_str = ref $thingy ? $thingy : \$thingy;
$$r_str =~ s{
- ($RE{EUC_C}+|$RE{EUC_KANA}+|$RE{EUC_0212}+)
+ ((?:$RE{EUC_C})+|(?:$RE{EUC_KANA})+|(?:$RE{EUC_0212})+)
}{
my $str = $1;
my $esc =
@@ -775,6 +769,11 @@ __END__
Unicode support by Jcode is far from efficient!
+=head1 IN FUTURE
+
+Hopefully Jcode will be superceded by Encode module that is part of
+the standard module on Perl 5.7 and up
+
=head1 ACKNOWLEDGEMENTS
This package owes a lot in motivation, design, and code, to the jcode.pl
@@ -786,18 +785,15 @@ very first stage of development.
And folks at Jcode Mailing list <jcode5@ring.gr.jp>. Without them, I
couldn't have coded this far.
-
=head1 SEE ALSO
-=over 4
-
-=item L<Jcode::Unicode>
+L<Jcode::Unicode>
-=item L<Jcode::Unicode::NoXS>
+L<Jcode::Unicode::NoXS>
-=back
+http://www.iana.org/assignments/character-sets
-=cut
+L<Encode>
=head1 COPYRIGHT
diff --git a/cpan/lib/Jcode/H2Z.pm b/cpan/lib/Jcode/H2Z.pm
index 53c81201..c5706c76 100644
--- a/cpan/lib/Jcode/H2Z.pm
+++ b/cpan/lib/Jcode/H2Z.pm
@@ -1,5 +1,5 @@
#
-# $Id: H2Z.pm,v 0.70 2001/05/15 19:35:59 dankogai Exp $
+# $Id: H2Z.pm,v 0.77 2002/01/14 11:06:55 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.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 };
+$RCSID = q$Id: H2Z.pm,v 0.77 2002/01/14 11:06:55 dankogai Exp $;
+$VERSION = do { my @r = (q$Revision: 0.77 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
use Carp;
@@ -157,7 +157,7 @@ sub z2h {
my $r_str = shift;
my $n = (
$$r_str =~ s(
- ($RE{EUC_C})
+ ($RE{EUC_C}|$RE{EUC_0212}|$RE{EUC_KANA})
){
$_Z2D{$1} || $_Z2H{$1} || $1;
}eogx
diff --git a/cpan/lib/Jcode/Tr.pm b/cpan/lib/Jcode/Tr.pm
index e29e29bb..28aac783 100644
--- a/cpan/lib/Jcode/Tr.pm
+++ b/cpan/lib/Jcode/Tr.pm
@@ -1,5 +1,5 @@
#
-# $Id: Tr.pm,v 0.70 2001/05/15 19:35:59 dankogai Exp $
+# $Id: Tr.pm,v 0.77 2002/01/14 11:06:55 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.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 };
+$RCSID = q$Id: Tr.pm,v 0.77 2002/01/14 11:06:55 dankogai Exp $;
+$VERSION = do { my @r = (q$Revision: 0.77 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
use Carp;
@@ -48,7 +48,7 @@ sub _maketable{
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/;
+ push @to, ($opt =~ /d/ ? '' : $to[-1]) x ($#from - $#to) if $#to < $#from;
@_TABLE{@from} = @to;
}
diff --git a/cpan/lib/Jcode/Unicode/NoXS.pm b/cpan/lib/Jcode/Unicode/NoXS.pm
index 44800ea3..ba738989 100644
--- a/cpan/lib/Jcode/Unicode/NoXS.pm
+++ b/cpan/lib/Jcode/Unicode/NoXS.pm
@@ -1,5 +1,5 @@
#
-# $Id: NoXS.pm,v 0.71 2001/05/18 05:14:38 dankogai Exp dankogai $
+# $Id: NoXS.pm,v 0.77 2002/01/14 11:06:55 dankogai Exp $
#
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.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 };
+$RCSID = q$Id: NoXS.pm,v 0.77 2002/01/14 11:06:55 dankogai Exp $;
+$VERSION = do { my @r = (q$Revision: 0.77 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
use Carp;
diff --git a/cpan/lib/Jcode/_test.pl b/cpan/lib/Jcode/_test.pl
new file mode 100644
index 00000000..7b8bb80d
--- /dev/null
+++ b/cpan/lib/Jcode/_test.pl
@@ -0,0 +1,16 @@
+
+use ExtUtils::testlib;
+use Jcode::Unicode;
+use Getopt::Std;
+getopts("p");
+
+my $file = "../t/table.euc";
+my $euc, $ucs2, $utf8;
+open F, $file or die $!;
+read F, $euc, -s $file;
+
+print "1..2\n";
+print "Ok 1\n" if $ucs2 = Jcode::Unicode::euc_ucs2($euc, $opt_p);
+print "Ok 2\n" if $euc eq Jcode::Unicode::ucs2_euc($ucs2, $opt_p);
+print "Ok 3\n" if $utf8 = Jcode::Unicode::ucs2_utf8($ucs2);
+print "Ok 4\n" if $ucs2 eq Jcode::Unicode::utf8_ucs2($utf8);