diff options
| author | fukachan <fukachan> | 2002-04-14 08:20:37 +0000 |
|---|---|---|
| committer | fukachan <fukachan> | 2002-04-14 08:20:37 +0000 |
| commit | 3403ab4f986f211ac0342778080ef21bae409e43 (patch) | |
| tree | 0ad5dbc52c620c0453ff86ec168e8b9f64e5cb22 | |
| parent | b9cb387d093c2435a928bddb36d624ffb358cc69 (diff) | |
| download | fml8-3403ab4f986f211ac0342778080ef21bae409e43.tar.gz fml8-3403ab4f986f211ac0342778080ef21bae409e43.tar.bz2 fml8-3403ab4f986f211ac0342778080ef21bae409e43.zip | |
Jcode-0.79Jcode-0-79
| -rw-r--r-- | cpan/dist/Jcode/INSTALL | 2 | ||||
| -rw-r--r-- | cpan/dist/Jcode/Jcode.pm | 102 | ||||
| -rw-r--r-- | cpan/dist/Jcode/Jcode/H2Z.pm | 8 | ||||
| -rw-r--r-- | cpan/dist/Jcode/Jcode/Tr.pm | 8 | ||||
| -rw-r--r-- | cpan/dist/Jcode/Jcode/Unicode/NoXS.pm | 6 | ||||
| -rw-r--r-- | cpan/dist/Jcode/MANIFEST | 3 | ||||
| -rw-r--r-- | cpan/dist/Jcode/Makefile.PL | 8 | ||||
| -rw-r--r-- | cpan/dist/Jcode/README | 2 | ||||
| -rw-r--r-- | cpan/dist/Jcode/Unicode/Unicode.xs | 8 | ||||
| -rw-r--r-- | cpan/dist/Jcode/Unicode/table.h | 2 | ||||
| -rw-r--r-- | cpan/dist/Jcode/Unicode/uni.c | 30 | ||||
| -rw-r--r-- | cpan/dist/Jcode/t/tr.t | 12 | ||||
| -rw-r--r-- | cpan/lib/Jcode.pm | 102 | ||||
| -rw-r--r-- | cpan/lib/Jcode/H2Z.pm | 8 | ||||
| -rw-r--r-- | cpan/lib/Jcode/Tr.pm | 8 | ||||
| -rw-r--r-- | cpan/lib/Jcode/Unicode/NoXS.pm | 6 | ||||
| -rw-r--r-- | cpan/lib/Jcode/_test.pl | 16 |
17 files changed, 178 insertions, 153 deletions
diff --git a/cpan/dist/Jcode/INSTALL b/cpan/dist/Jcode/INSTALL index 0e30cf4d..dae0b7af 100644 --- a/cpan/dist/Jcode/INSTALL +++ b/cpan/dist/Jcode/INSTALL @@ -1,5 +1,5 @@ # -# $Id: INSTALL,v 0.70 2001/05/15 19:35:59 dankogai Exp $ +# $Id: INSTALL,v 0.77 2002/01/14 11:06:55 dankogai Exp $ # To install diff --git a/cpan/dist/Jcode/Jcode.pm b/cpan/dist/Jcode/Jcode.pm index b61ace7b..0b3683e2 100644 --- a/cpan/dist/Jcode/Jcode.pm +++ b/cpan/dist/Jcode/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/dist/Jcode/Jcode/H2Z.pm b/cpan/dist/Jcode/Jcode/H2Z.pm index 53c81201..c5706c76 100644 --- a/cpan/dist/Jcode/Jcode/H2Z.pm +++ b/cpan/dist/Jcode/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/dist/Jcode/Jcode/Tr.pm b/cpan/dist/Jcode/Jcode/Tr.pm index e29e29bb..28aac783 100644 --- a/cpan/dist/Jcode/Jcode/Tr.pm +++ b/cpan/dist/Jcode/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/dist/Jcode/Jcode/Unicode/NoXS.pm b/cpan/dist/Jcode/Jcode/Unicode/NoXS.pm index 44800ea3..ba738989 100644 --- a/cpan/dist/Jcode/Jcode/Unicode/NoXS.pm +++ b/cpan/dist/Jcode/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/dist/Jcode/MANIFEST b/cpan/dist/Jcode/MANIFEST index e4c19586..6bd1abcd 100644 --- a/cpan/dist/Jcode/MANIFEST +++ b/cpan/dist/Jcode/MANIFEST @@ -1,4 +1,4 @@ -HISTORY +Changes INSTALL Jcode.pm Jcode/Constants.pm @@ -29,5 +29,6 @@ t/table.euc t/tr.t t/unibench.pl t/x0212.euc +t/stripped.euc t/zenkaku.euc win_install.pl diff --git a/cpan/dist/Jcode/Makefile.PL b/cpan/dist/Jcode/Makefile.PL index edcb7b4f..ba41c42b 100644 --- a/cpan/dist/Jcode/Makefile.PL +++ b/cpan/dist/Jcode/Makefile.PL @@ -1,6 +1,6 @@ #!/usr/local/bin/perl # -# $Id: Makefile.PL,v 0.70 2001/05/15 19:35:59 dankogai Exp $ +# $Id: Makefile.PL,v 0.77 2002/01/14 11:06:55 dankogai Exp $ # use ExtUtils::MakeMaker; @@ -11,6 +11,10 @@ WriteMakefile VERSION_FROM => 'Jcode.pm', PREREQ_PM => { 'MIME::Base64' => "2.1", - } + }, + ($] >= 5.005 ? ## Add these new keywords supported since 5.005 + (ABSTRACT_FROM => 'Jcode.pm', # retrieve abstract from module + AUTHOR => 'Dan Kogai <dankogai@dan.co.jp>') : () + ), ); diff --git a/cpan/dist/Jcode/README b/cpan/dist/Jcode/README index 85723b3d..48b993f1 100644 --- a/cpan/dist/Jcode/README +++ b/cpan/dist/Jcode/README @@ -1,5 +1,5 @@ # -# $Id: README,v 0.70 2001/05/15 19:35:59 dankogai Exp $ +# $Id: README,v 0.77 2002/01/14 11:06:55 dankogai Exp $ # Jcode: diff --git a/cpan/dist/Jcode/Unicode/Unicode.xs b/cpan/dist/Jcode/Unicode/Unicode.xs index 97c49ae8..7ed3fda1 100644 --- a/cpan/dist/Jcode/Unicode/Unicode.xs +++ b/cpan/dist/Jcode/Unicode/Unicode.xs @@ -29,7 +29,7 @@ euc_ucs2(src, ...) if (items > 1) { pedantic = SvIV(ST(1)); }; dstlen = srclen * 3 + 10; /* large enough? */ ST(0) = sv_2mortal(newSV(dstlen)); - dstlen = _euc_ucs2(SvPVX(ST(0)), s, pedantic); + dstlen = _euc_ucs2((unsigned char *)SvPVX(ST(0)), (unsigned char *)s, pedantic); SvCUR_set(ST(0), dstlen); SvPOK_only(ST(0)); if (SvROK(src)) { sv_setsv(SvRV(src), ST(0)); } @@ -46,7 +46,7 @@ ucs2_euc(src, ...) if (items > 1) { pedantic = SvIV(ST(1)); }; dstlen = srclen * 3 + 10; /* large enough? */ ST(0) = sv_2mortal(newSV(dstlen)); - dstlen = _ucs2_euc(SvPVX(ST(0)), s, srclen, pedantic); + dstlen = _ucs2_euc((unsigned char *)SvPVX(ST(0)), (unsigned char *)s, srclen, pedantic); SvCUR_set(ST(0), dstlen); SvPOK_only(ST(0)); if (SvROK(src)) { sv_setsv(SvRV(src), ST(0)); } @@ -61,7 +61,7 @@ utf8_ucs2(src, ...) char *s = SvROK(src) ? SvPV(SvRV(src), srclen) :SvPV(src, srclen); dstlen = srclen * 3 + 10; /* large enough? */ ST(0) = sv_2mortal(newSV(dstlen)); - dstlen = _utf8_ucs2(SvPVX(ST(0)), s); + dstlen = _utf8_ucs2((unsigned char *)SvPVX(ST(0)), (unsigned char *)s); SvCUR_set(ST(0), dstlen); SvPOK_only(ST(0)); if (SvROK(src)) { sv_setsv(SvRV(src), ST(0)); } @@ -76,7 +76,7 @@ ucs2_utf8(src, ...) char *s = SvROK(src) ? SvPV(SvRV(src), srclen) :SvPV(src, srclen); dstlen = srclen * 3 + 10; /* large enough? */ ST(0) = sv_2mortal(newSV(dstlen)); - dstlen = _ucs2_utf8(SvPVX(ST(0)), s, srclen); + dstlen = _ucs2_utf8((unsigned char *)SvPVX(ST(0)), (unsigned char *)s, srclen); SvCUR_set(ST(0), dstlen); SvPOK_only(ST(0)); if (SvROK(src)) { sv_setsv(SvRV(src), ST(0)); } diff --git a/cpan/dist/Jcode/Unicode/table.h b/cpan/dist/Jcode/Unicode/table.h index d4c8be77..954b9c92 100644 --- a/cpan/dist/Jcode/Unicode/table.h +++ b/cpan/dist/Jcode/Unicode/table.h @@ -1,5 +1,5 @@ /* - * $Id: table.h,v 0.70 2001/05/15 19:35:59 dankogai Exp $ + * $Id: table.h,v 0.77 2002/01/14 11:06:55 dankogai Exp $ * (c) 1999 Dan Kogai <dankogai@dan.co.jp> */ diff --git a/cpan/dist/Jcode/Unicode/uni.c b/cpan/dist/Jcode/Unicode/uni.c index e2aeb48c..f045a708 100644 --- a/cpan/dist/Jcode/Unicode/uni.c +++ b/cpan/dist/Jcode/Unicode/uni.c @@ -1,5 +1,5 @@ /* - * $Id: uni.c,v 0.70 2001/05/15 19:35:59 dankogai Exp $ + * $Id: uni.c,v 0.79 2002/01/16 02:18:49 dankogai Exp dankogai $ * (c) 1999 Dan Kogai <dankogai@dan.co.jp> */ @@ -59,7 +59,7 @@ Octet *u2e(Quad *qp, int pedantic){ if (t != NULL){ return q2o(t->euc); }else{ - return "\xa2\xae"; /* ¢® */ + return (unsigned char *)"\xa2\xae"; /* ¢® */ } } @@ -72,10 +72,10 @@ size_t _ucs2_euc(Octet *dst, Octet *src, int nchar, int pedantic){ for (nchar /= 2; nchar > 0; nchar--, src += 2) { q = o2q(src, 2); - strcpy(ebuf, u2e(&q, pedantic)); - strcpy(dst, ebuf); - dst += strlen(ebuf); - result += strlen(ebuf); + strcpy((char *)ebuf, (char *)u2e(&q, pedantic)); + strcpy((char *)dst, (char *)ebuf); + dst += strlen((char *)ebuf); + result += strlen((char *)ebuf); } return result; } @@ -101,17 +101,17 @@ Octet *e2u(Quad *qp, int pedantic){ static Octet buf[4]; if (IS_ASCII(*qp)){ if (!pedantic || not_iso646_jp(*qp)){ - sprintf(buf, "%c%c", '\0', *qp); + sprintf((char *)buf, "%c%c", '\0', *qp); return buf; } } t = (Table_t *)bsearch(qp, E2U, TABLE_SIZE, sizeof(Table_t), e_match); if (t != NULL){ - sprintf(buf, "%c%c", + sprintf((char *)buf, "%c%c", ((t->ucs2 & 0xff00) >> 8), (t->ucs2 & 0xff)); return buf; }else{ - return "\x30\x13"; /* ¢® */ + return (unsigned char *)"\x30\x13"; /* ¢® */ } } @@ -161,23 +161,23 @@ size_t _ucs2_utf8(Octet *dst, Octet *src, int nchar){ { ucs2 = o2q(src, 2); if (ucs2 < 0x80){ /* 1 byte */ - sprintf(ebuf, "%c", ucs2); + sprintf((char *)ebuf, "%c", ucs2); } else if(ucs2 < 0x800){ /* 2 bytes */ - sprintf(ebuf, "%c%c", + sprintf((char *)ebuf, "%c%c", (0xC0 | (ucs2 >> 6)), (0x80 | (ucs2 & 0x3F)) ); }else{ /* 3 bytes */ - sprintf(ebuf, "%c%c%c", + sprintf((char *)ebuf, "%c%c%c", (0xE0 | (ucs2 >> 12)), (0x80 | ((ucs2 >> 6) & 0x3F)), (0x80 | (ucs2 & 0x3F)) ); } - strcpy(dst, ebuf); - dst += strlen(ebuf); - result += strlen(ebuf); + strcpy((char *)dst, (char *)ebuf); + dst += strlen((char *)ebuf); + result += strlen((char *)ebuf); } return result; } diff --git a/cpan/dist/Jcode/t/tr.t b/cpan/dist/Jcode/t/tr.t index 497cae92..1a420305 100644 --- a/cpan/dist/Jcode/t/tr.t +++ b/cpan/dist/Jcode/t/tr.t @@ -30,6 +30,10 @@ my $katakana; $file = "t/zenkaku.euc"; open F, $file or die "$file:$!"; read F, $katakana, -s $file; profile(sprintf("prep: katakana ok %d\n", ++$n)); +my $stripped; $file = "t/stripped.euc"; open F, $file or die "$file:$!"; +read F, $stripped, -s $file; +profile(sprintf("prep: stripped ok %d\n", ++$n)); + #print jcode($katakana)->tr('A-Za-z¥¡-¥óާ-ŽÝ','a-zA-Z¤¡-¤óާ-ŽÝ'); #__END__ @@ -57,6 +61,14 @@ for my $icode (keys %code2str){ } } +# test tr($s,'','d'); + +my $ok = (jcode($hiragana)->tr('¤¡-¤ó','','d')->euc eq $stripped) ? +"ok" : "not ok"; + +profile(sprintf("H2Z: %s -> %s %s %d\n", + '¤¡-¤ó', "\'\' \'d\'", $ok, ++$n )); + print 1, "..", $NTESTS, "\n"; for my $TEST (@TESTS){ print $TEST; 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); |
