Jcode::Nihongo(3pm)
โจ Jcode::Nihongo(3pm) โจ
User Contributed Perl Documentation ๐ okay bestie, this is the manpage for the Jcode Japanese charset handler ๐
โจ ๅๅ โจ
Jcode - ๆฅๆฌ่ชๆๅญ้ๅใใณใใฉ ๐ the Japanese text-handling queen ๐
โจ ๆฆ่ฆ โจ
use Jcode;
#
# ๅคๅผใใใใ
Jcode::convert($str, $ocode, $icode, "z");
# ใใใใฏใชใใธใงใฏใๆๅใง๏ผ
print Jcode->new($str)->h2z->tr($from, $to)->utf8;
โจ ่ชฌๆ โจ
ngl this module is so cute ๐ฅน Jcode.pm supports BOTH the object-y way and the old-school way, so you can pick whatever matches your vibe ๐ฆ With the object approach it looks like this, literally so clean:
$iso_2022_jp = Jcode->new($str)->h2z->jis;
The old way is also giving, but honestly the one above is more elegant ๐ :
$iso_2022_jp = $str;
&jcode::convert(\$iso_2022_jp, 'jis', &jcode::getcode(\$str), "z");
If objects are new to you, no stress ๐ซถ Jcode.pm still supports getcode() and convert(), so you're totally covered.
If your Perl is 5.8.1 or newer, Jcode acts as a wrapper around Encode, which is the standard charset handler module since Perl 5.8 โจ iykyk.
โจ ใกใฝใใ โจ
Unless I say otherwise, every method here returns a Jcode object ๐ธ
โจ ใณใณในใใฉใฏใฟ โจ
$j = Jcode->new($str [, $icode])โ makes aJcodeobject$jout of$str๐ง If you don't explicitly set$icode, the input code gets auto-detected, so lowkey magic. For the available charsets, check outgetcodefurther down.
On Perl 5.8.1 and up, $icode can be ANY encoding name that Encode understands ๐
$j = Jcode->new($european, 'iso-latin1');
When you stringify the object, you get back the EUC-converted string. So instead of "print $j->euc", you can just write "print $j" ๐
- ใชใใกใฌใณในๆธกใ โ you can pass a reference instead of a scalar value, like this:
Jcode->new(\$str);
This saves a tiny bit of time ๐
The catch is that the value of $str itself gets converted (kinda like $str is "tied" to the jcode object, no cap ๐).
$j->set($str [, $icode])โ sets$stras the internal string of$j๐ This is clutch when you're reusing the same Jcode object over and over, because you save both object-creation time and memory โจ
# mailboxใSJISๅฝขๅผใซๅคๆ
my $jconv = new Jcode;
$/ = 00;
while(<>){
print $jconv->set(\$_)->mime_decode->sjis;
}
$j->append($str [, $icode]);โ tacks$stronto the end of$j's internal string ๐ฆ$j = jcode($str [, $icode]);โ the short-and-sweet version ofJcode->new()๐ You can do stuff like:
$sjis = jcode($str)->sjis;
โจ ๆๅญๅใฎใจใณใณใผใ โจ
Generally, you get the string converted into the encoding you want with $j->encoded (fill in whatever encoding you're after) ๐
$sjis = $j->sjis$euc = $j->euc$jis = $j->jis$sjis = $j->sjis$ucs2 = $j->ucs2$utf8 = $j->utf8โ honestly self-explanatory ๐ WYCIWYG = What you code is what you get :)$iso_2022_jp = $j->iso_2022_jpโ this is the same as"$j->h2z->jis"๐ง Half-width kana are forcibly converted to full-width, no exceptions bestie.
On Perl 5.8.1 and up, you can use any encoding name and alias that Encode supports. For example:
$european = $j->iso_latin1; # ใกใฝใใๅ็จใซ'-'ใฏ'_'ใซ็ฝฎใๆใใพใ
Fun fact: Encode::Encoder uses this same little trick ๐ค
$j->fallback($fallback)โ On Perl 5.8.1 and up,Jcodeholds its internal string as UTF-8 ๐ญ Any character that can't be mapped to the->encodinggets swapped out for'?'. That's the standardEncodebehaviour, so don't panic.
my $unistr = "\x{262f}"; # ้ฐ้ฝใใผใฏ
my $j = jcode($unistr); # $j->euc ใฎ็ตๆใฏ '?' ใซ
You can change this by specifying a fallback, just like in Encode ๐
The values are the same as the ones in Encode. For convenience, "Jcode::FB_PERLQQ", "Jcode::FB_XMLCREF" and "Jcode::FB_HTMLCREF" are aliases for their Encode counterparts โจ
print $j->fallback(Jcode::FB_PERLQQ)->euc; # '\x{262f}'
print $j->fallback(Jcode::FB_XMLCREF)->euc; # '☯'
print $j->fallback(Jcode::FB_HTMLCREF)->euc; # '☯'
The default fallback is stored in the global variable $Jcode::FALLBACK, so you can override it by assigning to it:
$Jcode::FALLBACK = Jcode::FB_PERLQQ; # ใใใฉใซใใฎใใฉใผใซใใใฏในใญใผใใ่จญๅฎ
[@lines =] $jcode->jfold([$width, $newline_str, $kref])โ folds the lines inside the jcode string every$widthcharacters (default: 72) ๐ท$widthcounts "half-width" characters, so a full-width character counts as 2 โจ
The newline given by $newline_str (default is "\n") gets added in. It returns all the folded lines as a list ๐
On Perl 5.8.1 and up, passing an array reference of EUC strings as the third argument $kref gives you a simple line-head kinsoku shori (the hanging-punctuation thing called ใถใไธใใ) ๐ซง
$length = $jcode->jlength();โ returns the character count, not the byte length, counting each full-width character as one character ๐
๐ Heads up: this is the first half of the page, so there's more juicy stuff coming next. Stay tuned, bestie ๐ง
โจ ใตใใซใผใใณ โจ
($code, [$nmatch]) = getcode($str)
okay so this one is a subroutine ๐
It hands you back the character encoding of $str. The possible codes are:
asciiโ Ascii, with no Japanese codes in it ๐ธbinaryโ Binary, so it's not a text file ๐งฑeucโ EUC-JP ๐ฏ๐ตsjisโ SHIFT_JIS ๐jisโ JIS (ISO-2022-JP) ๐ucs2โ UCS2 (Raw Unicode) ๐ฆutf8โ UTF8 ๐
If you call it in list context instead of scalar context, you also get back how many characters' worth of codes it found. Same deal as before: $str can be \$str too, bestie โจ
jcode.pl people, listen up ๐ This function is 100% backwards compatible with jcode::getcode(). Well, almost 100% ๐
- when the return value is a list, the order is reversed ๐.
jcode::getcode()gives you$nmatchfirst. jcode::getcode()returns'undef'when the number of EUC characters and SJIS characters is equal ๐.Jcode::getcode()returns EUC in that case instead, becauseJcode.pmhas no middle ground ๐ซ
Jcode::convert($str, [$ocode, $icode, $opt])
This one converts $str into the character code you name with $ocode ๐. If you also pass $icode, it just assumes your input is that code and skips the getcode() check entirely โจ Again, $str can be \$str ๐
jcode.pl people ๐ This function is 100% backwards compatible with jcode::convert()! No "almost" this time ๐
๐ฅ
โจ ใใฐ โจ
Heads up ๐จ When you're on Perl 5.8.1 or newer, Jcode acts as a wrapper around Encode. That means any bugs in Encode can hit Jcode too. Not a Jcode problem, a whole-chain problem ๐ญ
โจ ่ฌ่พ โจ
This package owes a lot to ๆญไปฃ ๅๆญฃ <utashiro@iij.ad.jp> ๐ซถ and their Perl4 library jcode.pl, for the motivation, the design, and a big chunk of the code. Literally the foundation of everything ๐๏ธ
ๅคงๅด ๅๅบ <ohzaki@iod.ricoh.co.jp> was a huge help with polishing the regular expressions, right from the super early days ๐
makamaka@donzoko.net and their JEncode gave me a major lightbulb moment about how to merge Jcode and Encode ๐ก They also donated the Japanese manual, which is so sweet ๐ฅน
And the whole Jcode ML <jcode5@ring.gr.jp> crew ๐ Honestly this thing would not be finished without you all ๐
โจ ๅ่ โจ
- Encode ๐ง
<http://www.iana.org/assignments/character-sets>๐
โจ ่ไฝๆจฉ โจ
Copyright 1999-2005 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. Main character energy, legally speaking ๐
That's the whole page, bestie ๐ Pulled from Perl v5.40.1, dated 2025-06-11, for Jcode::Nihongo(3pm). Go forth and convert those encodings, you absolute legend ๐ฆโจ
๐ฆ where this page comes from
- ubuntu questing: libjcode-pm-perl 2.07-1 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libjcode-pm-perl 2.07-1 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libjcode-pm-perl 2.07-1 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ๐ girlified by anthropic/claude-haiku-5.5 on : a language model's rewrite of the original, under its terms