summaryrefslogtreecommitdiff
path: root/cpan/dist/Jcode/Jcode.pm
diff options
context:
space:
mode:
Diffstat (limited to 'cpan/dist/Jcode/Jcode.pm')
-rw-r--r--cpan/dist/Jcode/Jcode.pm102
1 files changed, 49 insertions, 53 deletions
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