NAME
Jcode - Japanese Charset Handler
SYNOPSIS
use Jcode;
# traditional
Jcode::convert(\$str, $ocode, $icode, "z");
# or OOP!
print Jcode->new($str)->h2z->tr($from, $to)->utf8;
DESCRIPTION
Jcode.pm supports both object and traditional approach. With object approach, you can go like;
$iso_2022_jp = Jcode::new($str)->h2z->jis;
Which is more elegant than;
$iso_2022_jp = &jcode::convert(\$str,'jis',jcode::getcode(\str), "z");
For those unfamiliar with objects, Jcode.pm still supports getcode() and convert().
Methods
Methods mentioned here all return Jcode object unless otherwise mentioned.
- $j = Jcode->new($str [, $icode]);
-
Creates Jcode object $j from $str. Input code is automatically checked unless you explicitly set $icode (This is necessary if you want to convert from UTF8).
The object keeps the string in EUC format enternaly. When the object itself is evaluated, it returns the EUC-converted string so you can "print $j;" without calling access method if you are using EUC (thanks to function overload).
If you don't have to preseve the value of $str, you can use reference as
Jcode->new(\$str);
That saves time and memory in exchange of the loss of original value of $str. Any functions below where $str is used, you can give \$str instead.
- $j->set($str [, $icode]);
-
Sets $j's string to $str. Handy when you use Jcode object repeatedly (saves time and memory to create object).
# converts mailbox to SJIS format
my $jconv = new Jcode; while(<>){print $jconv->set(\$_)->mime_decode->sjis;}
- $j->append($str [, $icode]);
-
Appends $str to $jstr's string.
- $j = jcode($str [, $icode]);
-
shortcut for Jcode->new() so you can go like;
$sjis = jcode($str)->sjis;
- $euc = $j->euc;
- $jis = $j->jis;
- $sjis = $j->sjis;
-
What you code is what you get :)
- $iso_2022_jp = j$str->iso_2022_jp
-
Same as $j->z2h->jis. Hankaku Kanas are forcibly converted to Zenkaku.
Methods that use MIME::Base64
To use methods below, you need MIME::Base64. To install, simply
perl -MCPAN -e
'CPAN::Shell->install("MIME::Base64")'
- $mime_header = $j->mime_encode;
-
Converts $str to MIME-Header documented in RFC1522.
- $j->mime_decode;
-
Decodes MIME-Header in Jcode object.
You can retrieve the number of matches via $j->{nmatch};
Methods implemented by Jcode::H2Z
Methods here are actually implemented in Jcode::H2Z.
- $j->h2z([$keep_dakuten]);
-
Converts X201 kana (Hankaku) to X208 kana (Zenkaku). When $keep_dakuten is set, it leaves dakuten as is (That is, "ka + dakuten" is left as is instead of being converted to "ga")
You can retrieve the number of matches via $j->{nmatch};
- $j->z2h;
-
Converts X208 kana (Zenkaku) to X201 kana (Hankazu).
You can retrieve the number of matches via $j->{nmatch};
Methods implemented in Jcode::Tr
Methods here are actually implemented in Jcode::Tr.
- $j->tr($from, $to);
-
Applies tr on Jcode object. $from and $to can contain EUC Japanese.
You can retrieve the number of matches via $j->{nmatch};
Methods implemented in Jcode::Unicode
Warning: Unicode support by Jcode is far from efficient!
Traditional Way
- ($code, [$nmatch]) = getcode($str);
-
Returns char code of $str. When array context is used instead of scaler, it also returns how many character codes are found. As mentioned above, $str can be \$str instead.
Warning: UTF8 is not automatically detected!
jcode.pl Users: This function is 100% upper-conpatible with jcode::getcode() !
- Jcode::convert($str, [$ocode, $icode, $opt]);
-
Converts $str to char code specified by $ocode. When $icode is specified also, it assumes $icode for input string instead of the one checked by getcode(). As mentioned above, $str can be \$str instead.
jcode.pl Users: This function is 100% upper-conpatible with jcode::convert() !
COPYRIGHT
Copyright 1999 Dan Kogai <dankogai@dan.co.jp>
Based upon jcode.pl, Copyright 1995-1999 Kazumasa Utashiro <utashiro@iij.ad.jp>
Use and redistribution for ANY PURPOSE, without significant modification, is granted as long as all copyright notices are retained. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES ARE DISCLAIMED.
11 POD Errors
The following errors were encountered while parsing the POD:
- Around line 184:
You forgot a '=back' before '=head2'
- Around line 190:
'=item' outside of any '=over'
- Around line 229:
You forgot a '=back' before '=head2'
- Around line 233:
'=item' outside of any '=over'
- Around line 266:
You forgot a '=back' before '=head2'
- Around line 270:
'=item' outside of any '=over'
- Around line 285:
You forgot a '=back' before '=head2'
- Around line 289:
'=item' outside of any '=over'
- Around line 311:
You forgot a '=back' before '=head1'
- Around line 313:
'=item' outside of any '=over'
- Around line 536:
You forgot a '=back' before '=head1'